MATIH Platform is in active MVP development. Documentation reflects current implementation status.
14. Context Graph & Ontology
Storage Backends
Storage Backends Overview

Storage Backends Overview

The Context Graph uses a polyglot persistence strategy with three complementary storage backends: Dgraph for graph relationships and thinking traces, Pinecone/Qdrant for vector similarity search, and PostgreSQL with TimescaleDB for bi-temporal versioning. Each backend is optimized for specific query patterns while maintaining tenant isolation across all layers.


Storage Architecture

+------------------+    +------------------+    +-------------------+
|     Dgraph       |    |    Pinecone      |    |   PostgreSQL      |
|  (Graph Store)   |    |  (Vector Store)  |    | (Bi-Temporal)     |
|                  |    |                  |    |                   |
| - Entities       |    | - Entity embeds  |    | - Events          |
| - Relationships  |    | - Decision vecs  |    | - Decisions       |
| - Thinking traces|    | - Trajectory vecs|    | - Entity versions |
| - API call logs  |    | - Query patterns |    | - Version history |
+------------------+    +------------------+    +-------------------+
        |                       |                        |
        +----------+------------+------------------------+
                   |
           +-------v--------+
           |  Hybrid Store  |
           |   (GraphRAG)   |
           +----------------+

Backend Selection Guide

Query TypeRecommended BackendReason
Entity relationships and lineageDgraphNative graph traversal
Semantic similarity searchPineconeANN vector search
Point-in-time entity statePostgreSQLBi-temporal queries
Combined semantic + structuralHybrid StoreMerges both backends
Decision precedent searchPinecone + PostgreSQLEmbedding match + metadata filter
Version history and auditPostgreSQLFull version chain

Subsections

PageDescription
Dgraph Context StoreGraphQL-based CRUD for thinking traces and entity relationships
Hybrid Store (GraphRAG)Combined graph + vector retrieval with configurable strategies
Vector StoresPinecone and Qdrant implementations for embedding storage
Bitemporal VersioningPostgreSQL + TimescaleDB bi-temporal data management

Singleton Pattern

All storage backends follow the singleton factory pattern for lifecycle management:

from context_graph.storage.dgraph_context_store import (
    create_dgraph_context_store,
    get_dgraph_context_store,
)
from context_graph.storage.hybrid_store import (
    create_hybrid_store,
    get_hybrid_store,
)
from context_graph.storage.bitemporal_store import (
    create_bitemporal_store,
    get_bitemporal_store,
)

Each store exposes initialize(), close(), and health_check() methods for lifecycle management within the application startup and shutdown hooks.