# liliang-cn/cortexdb architecture

> Architecture diagram of the GitHub repository liliang-cn/cortexdb, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/liliang-cn/cortexdb
- Repository: https://github.com/liliang-cn/cortexdb

## Overview

CortexDB is an embedded AI-memory and knowledge-graph product, usable locally or through shared gRPC. A typical workflow captures or imports material, stores searchable memories and graph knowledge, then retrieves context for an agent. The graph also preserves major documented capabilities: graph/RAG, ontology governance, connectors, live exploration, and multiple access surfaces. Relationships are limited to explicit README statements and shown call sites; several subsystems are represented by their exact directory because their implementation was not sampled.

Main entry points: [`pkg/cortexdb/cortexdb.go`](https://github.com/liliang-cn/cortexdb/blob/main/pkg/cortexdb/cortexdb.go) (CortexDB facade), [`pkg/core/store_query.go`](https://github.com/liliang-cn/cortexdb/blob/main/pkg/core/store_query.go) (Embedding store), [`pkg/cortexdb/graphrag_tool_ingest.go`](https://github.com/liliang-cn/cortexdb/blob/main/pkg/cortexdb/graphrag_tool_ingest.go) (Graph RAG ingest), [`pkg/connector`](https://github.com/liliang-cn/cortexdb/tree/main/pkg/connector) (Source connectors)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_capture["Capture and ingest"]
  node_memoryflow["Memory workflows<br/>[service.go]"]
  node_importflow["Data import"]
  node_connector["Source connectors"]
  node_graphrag_ingest["Graph RAG ingest"]
end

subgraph group_knowledge["Memory and knowledge"]
  node_agentmem["Agent memory search<br/>[search.go]"]
  node_knowledge_api["Knowledge and memory API<br/>[knowledge_api.go]"]
  node_ontology["Ontology governance"]
  node_graphflow["Graph extraction flow<br/>[pipeline.go]"]
  node_graph_engine["Graph and RDF engine"]
end

subgraph group_retrieval["Search and reasoning"]
  node_graphrag_search["Graph RAG search"]
  node_semantic_router["Semantic routing<br/>[router.go]"]
  node_vector_index["Vector indexes"]
end

subgraph group_storage["Persistence"]
  node_core_store[("Embedding store<br/>[store_query.go]")]
  node_cortexdb["CortexDB facade<br/>[cortexdb.go]"]
end

subgraph group_access["Product interfaces"]
  node_mcp["MCP tools<br/>[main.go]"]
  node_grpc["Shared gRPC API<br/>[server.go]"]
  node_liveview["Live graph view<br/>[server.go]"]
  node_http_api["HTTP API<br/>[server.go]"]
  node_obsidian["Obsidian plugin<br/>[main.js]"]
end

node_agent(("AI agent"))
node_source(("External data sources"))

node_source -->|"supplies data"| node_connector
node_connector -->|"imports knowledge"| node_cortexdb
node_importflow -.->|"imports material"| node_cortexdb
node_memoryflow -->|"saves memories"| node_cortexdb
node_agent -->|"uses tools"| node_mcp
node_mcp -->|"serves tools"| node_cortexdb
node_agent -->|"calls services"| node_grpc
node_grpc -->|"delegates calls"| node_cortexdb
node_agent -->|"requests memory"| node_knowledge_api
node_knowledge_api -.->|"stores embeddings"| node_core_store
node_cortexdb -.->|"persists data"| node_core_store
node_graphrag_ingest -->|"writes graph"| node_graph_engine
node_graphrag_ingest -->|"stores chunks"| node_core_store
node_graphflow -->|"builds graph"| node_cortexdb
node_graphrag_search -->|"retrieves graph"| node_graph_engine
node_agentmem -->|"searches vectors"| node_core_store
node_semantic_router -.->|"routes search"| node_core_store
node_vector_index -.->|"accelerates retrieval"| node_core_store
node_ontology -->|"stores schemas"| node_core_store
node_liveview -->|"reads graph data"| node_cortexdb
node_http_api -->|"delegates requests"| node_cortexdb
node_obsidian -->|"offers brain tools"| node_agent

click node_memoryflow "https://github.com/liliang-cn/cortexdb/blob/main/pkg/memoryflow/service.go"
click node_importflow "https://github.com/liliang-cn/cortexdb/tree/main/pkg/importflow"
click node_connector "https://github.com/liliang-cn/cortexdb/tree/main/pkg/connector"
click node_graphrag_ingest "https://github.com/liliang-cn/cortexdb/blob/main/pkg/cortexdb/graphrag_tool_ingest.go"
click node_agentmem "https://github.com/liliang-cn/cortexdb/blob/main/pkg/agentmem/search.go"
click node_knowledge_api "https://github.com/liliang-cn/cortexdb/blob/main/pkg/cortexdb/knowledge_api.go"
click node_ontology "https://github.com/liliang-cn/cortexdb/blob/main/pkg/cortexdb/ontology_storage.go"
click node_graphflow "https://github.com/liliang-cn/cortexdb/blob/main/pkg/graphflow/pipeline.go"
click node_graph_engine "https://github.com/liliang-cn/cortexdb/tree/main/pkg/graph"
click node_graphrag_search "https://github.com/liliang-cn/cortexdb/blob/main/pkg/cortexdb/graphrag_tool_search.go"
click node_semantic_router "https://github.com/liliang-cn/cortexdb/blob/main/pkg/semantic-router/router.go"
click node_vector_index "https://github.com/liliang-cn/cortexdb/tree/main/pkg/index"
click node_core_store "https://github.com/liliang-cn/cortexdb/blob/main/pkg/core/store_query.go"
click node_cortexdb "https://github.com/liliang-cn/cortexdb/blob/main/pkg/cortexdb/cortexdb.go"
click node_mcp "https://github.com/liliang-cn/cortexdb/blob/main/cmd/cortexdb-mcp-stdio/main.go"
click node_grpc "https://github.com/liliang-cn/cortexdb/blob/main/pkg/rpcserver/server.go"
click node_liveview "https://github.com/liliang-cn/cortexdb/blob/main/pkg/liveview/server.go"
click node_http_api "https://github.com/liliang-cn/cortexdb/blob/main/pkg/httpapi/server.go"
click node_obsidian "https://github.com/liliang-cn/cortexdb/blob/main/plugins/obsidian-cortexdb/src/main.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_memoryflow,node_importflow,node_connector,node_graphrag_ingest toneBlue
class node_agentmem,node_knowledge_api,node_ontology,node_graphflow,node_graph_engine toneAmber
class node_graphrag_search,node_semantic_router,node_vector_index toneMint
class node_core_store,node_cortexdb toneRose
class node_mcp,node_grpc,node_liveview,node_http_api,node_obsidian,node_agent,node_source toneIndigo
```

## Components

### Capture and ingest

- [Memory workflows](https://github.com/liliang-cn/cortexdb/blob/main/pkg/memoryflow/service.go): `pkg/memoryflow/service.go`
- [Data import](https://github.com/liliang-cn/cortexdb/tree/main/pkg/importflow): `pkg/importflow`
- [Source connectors](https://github.com/liliang-cn/cortexdb/tree/main/pkg/connector): `pkg/connector`
- [Graph RAG ingest](https://github.com/liliang-cn/cortexdb/blob/main/pkg/cortexdb/graphrag_tool_ingest.go): `pkg/cortexdb/graphrag_tool_ingest.go`

### Memory and knowledge

- [Agent memory search](https://github.com/liliang-cn/cortexdb/blob/main/pkg/agentmem/search.go): `pkg/agentmem/search.go`
- [Knowledge and memory API](https://github.com/liliang-cn/cortexdb/blob/main/pkg/cortexdb/knowledge_api.go): `pkg/cortexdb/knowledge_api.go`
- [Ontology governance](https://github.com/liliang-cn/cortexdb/blob/main/pkg/cortexdb/ontology_storage.go): `pkg/cortexdb/ontology_storage.go`
- [Graph extraction flow](https://github.com/liliang-cn/cortexdb/blob/main/pkg/graphflow/pipeline.go): `pkg/graphflow/pipeline.go`
- [Graph and RDF engine](https://github.com/liliang-cn/cortexdb/tree/main/pkg/graph): `pkg/graph`

### Search and reasoning

- [Graph RAG search](https://github.com/liliang-cn/cortexdb/blob/main/pkg/cortexdb/graphrag_tool_search.go): `pkg/cortexdb/graphrag_tool_search.go`
- [Semantic routing](https://github.com/liliang-cn/cortexdb/blob/main/pkg/semantic-router/router.go): `pkg/semantic-router/router.go`
- [Vector indexes](https://github.com/liliang-cn/cortexdb/tree/main/pkg/index): `pkg/index`

### Persistence

- [Embedding store](https://github.com/liliang-cn/cortexdb/blob/main/pkg/core/store_query.go): `pkg/core/store_query.go`
- [CortexDB facade](https://github.com/liliang-cn/cortexdb/blob/main/pkg/cortexdb/cortexdb.go): `pkg/cortexdb/cortexdb.go`

### Product interfaces

- [MCP tools](https://github.com/liliang-cn/cortexdb/blob/main/cmd/cortexdb-mcp-stdio/main.go): `cmd/cortexdb-mcp-stdio/main.go`
- [Shared gRPC API](https://github.com/liliang-cn/cortexdb/blob/main/pkg/rpcserver/server.go): `pkg/rpcserver/server.go`
- [Live graph view](https://github.com/liliang-cn/cortexdb/blob/main/pkg/liveview/server.go): `pkg/liveview/server.go`
- [HTTP API](https://github.com/liliang-cn/cortexdb/blob/main/pkg/httpapi/server.go): `pkg/httpapi/server.go`
- [Obsidian plugin](https://github.com/liliang-cn/cortexdb/blob/main/plugins/obsidian-cortexdb/src/main.js): `plugins/obsidian-cortexdb/src/main.js`

### Other components

- **AI agent**
- **External data sources**

## Connections

- External data sources → Source connectors: supplies data
- Source connectors → CortexDB facade: imports knowledge
- Data import → CortexDB facade: imports material
- Memory workflows → CortexDB facade: saves memories (evidence: `pkg/memoryflow/service.go`)
- AI agent → MCP tools: uses tools (evidence: `README.md`)
- MCP tools → CortexDB facade: serves tools (evidence: `cmd/cortexdb-mcp-stdio/main.go`)
- AI agent → Shared gRPC API: calls services (evidence: `README.md`)
- Shared gRPC API → CortexDB facade: delegates calls (evidence: `pkg/rpcserver/server.go`)
- AI agent → Knowledge and memory API: requests memory (evidence: `README.md`)
- Knowledge and memory API → Embedding store: stores embeddings
- CortexDB facade → Embedding store: persists data
- Graph RAG ingest → Graph and RDF engine: writes graph (evidence: `pkg/cortexdb/graphrag_tool_ingest.go`)
- Graph RAG ingest → Embedding store: stores chunks (evidence: `pkg/cortexdb/graphrag_tool_ingest.go`)
- Graph extraction flow → CortexDB facade: builds graph (evidence: `pkg/graphflow/pipeline.go`)
- Graph RAG search → Graph and RDF engine: retrieves graph (evidence: `pkg/cortexdb/graphrag_tool_search.go`)
- Agent memory search → Embedding store: searches vectors (evidence: `pkg/agentmem/search.go`)
- Semantic routing → Embedding store: routes search
- Vector indexes → Embedding store: accelerates retrieval
- Ontology governance → Embedding store: stores schemas (evidence: `pkg/cortexdb/ontology_storage.go`)
- Live graph view → CortexDB facade: reads graph data (evidence: `pkg/liveview/server.go`)
- HTTP API → CortexDB facade: delegates requests (evidence: `pkg/httpapi/server.go`)
- Obsidian plugin → AI agent: offers brain tools (evidence: `README.md`)
