Local-First AI Memory
in Pure Go

One SQLite file holds vectors, search, RAG, agent memory, and a SPARQL knowledge graph — with MCP tools and a Rust-ready gRPC sidecar.

0
Single SQLite File
0
Index Types
0
Quantization Methods
0
Pure Go

Architecture-Level Features

Built around CortexDB, MemoryFlow, GraphFlow, embedded KG, and MCP tools

CortexDB Facade

Primary DB facade for vectors, FTS5, knowledge, memory, KnowledgeMemory recall, knowledge graph APIs, toolbox, and MCP.

MemoryFlow

Agent memory workflow for transcript ingest, recall, wake-up layers, diary, transcript reconstruction, and promotion.

GraphFlow

Corpus-to-graph workflow with extraction schema, build, analysis, report, JSON export, and HTML visualization.

ImportFlow

Import external structured data (CSV, MySQL/PostgreSQL dumps) into RAG and knowledge-graph foundations in one pass, with optional AI-assisted mapping, triple extraction, and text refinement.

Embedded RDF/KG

RDF triples/quads, namespaces, import/export, SPARQL practical subset, RDFS-lite, and SHACL-lite.

Toolbox and MCP

In-process tool calls through db.GraphRAGTools(), plus MCP server exposure for external agents.

gRPC Sidecar + Rust Client

cortexdb-grpc serves the full facade over gRPC with bearer-token auth; the cortexdb-client crate on crates.io gives Rust typed access and can auto-spawn the sidecar.

KnowledgeMemory and Memory APIs

High-level SaveMemory, SearchMemory, KnowledgeMemory.Recall, reflection, and context pack APIs for agent workflows.

No-Embedder Mode

Use lexical retrieval plus LLM-planned keywords, alternate queries, entity names, retrieval mode, or optional lexical semantic-router tool selection.

Architecture Overview

Modular Go packages for cortexdb, memoryflow, graphflow, importflow, embedded KG, storage, and tools

CortexDB Facade

Primary DB API for vectors, lexical search, knowledge, memory, KnowledgeMemory, KG, tools, and MCP.

MemoryFlow Package

Transcript ingest, recall, wake-up layers, diary, optional Hindsight strategy, and promotion.

GraphFlow Package

Corpus-to-graph extraction schema, build, analysis, report, JSON export, and HTML visualization.

ImportFlow Package

Source adapters (CSV, MySQL/PG dump) → MappingPlan → dual RAG + KG sinks, with pluggable AI MappingInferer, TextRefiner, and graphflow triple extraction.

Graph Package

Low-level property graph, RDF triples/quads, SPARQL, RDFS-lite inference, and SHACL-lite validation.

Core Package

SQLite storage, embeddings, collections, FTS5, vector indexes, chat, and session primitives.

Tools and MCP

GraphRAG toolbox, knowledge graph tools, KnowledgeMemory tools, memory tools, and MCP server integration.

gRPC Sidecar (rpcserver)

cortexdb.v1 proto contract, pkg/rpcserver conversion layer, cmd/cortexdb-grpc binary with token auth and OpenAI-compatible embedder config.

AgentMem Package

SQL-backed agent memory with zero embedder requirement: typed memories, banks, mental models, FTS5 trigram ranking with importance and time decay.

cortexdb/example.go
package main

import (
    "context"
    "github.com/liliang-cn/cortexdb/v2/pkg/cortexdb"
    "github.com/liliang-cn/cortexdb/v2/pkg/graph"
)

func main() {
    db, err := cortexdb.Open(cortexdb.DefaultConfig("KnowledgeMemory.db"))
    if err != nil {
        panic(err)
    }
    defer db.Close()

    ctx := context.Background()

    _, _ = db.UpsertKnowledgeGraph(ctx, cortexdb.KnowledgeGraphUpsertRequest{
        Triples: []cortexdb.KnowledgeGraphTriple{
            {Subject: graph.NewIRI("https://example.com/alice"), Predicate: graph.NewIRI(graph.RDFType), Object: graph.NewIRI("https://example.com/Person")},
        },
    })

    _, _ = db.QueryKnowledgeGraph(ctx, cortexdb.KnowledgeGraphQueryRequest{
        Query: `SELECT ?o WHERE { <https://example.com/alice> ?p ?o . }`,
    })
}

Live Demo: CortexDB Mapping Itself

One markdown overview of this project, fed through graphflow with an LLM extractor — out comes a queryable knowledge graph: 69 nodes, 74 edges, answers included.

Knowledge graph overview — 69 nodes extracted from the project docs
The full graph: layers, APIs, tools, binaries and the relations between them — extracted automatically from docs/PROJECT_OVERVIEW.md.
Zoom on the CortexDB hub node: created_by Liang Li, uses SQLite, implemented in Go
Zooming on the hub: CortexDB —created_by→ Liang Li, —uses→ SQLite storage kernel, —implemented_in→ Go, —adopts→ LLM interface injection.

Ask the graph — answers come from edges, not from an LLM

Who created CortexDB?
Liang Li CortexDB —created_by→ Liang Li
What is the storage kernel?
SQLite storage kernel CortexDB —uses→ SQLite
Which language is it implemented in?
Go CortexDB —implemented_in→ Go
What does the public facade depend on?
Engine layers: core storage & vector index, graph & semantics 2 edges traversed
Which node is the biggest hub?
GraphRAGTools 12 relations
# build the graph of this very project (any OpenAI-compatible LLM works)
go run ./examples/08_self_knowledge_graph

# then ask it questions — answers are graph traversals, fully deterministic
go test ./examples/08_self_knowledge_graph -v
View the demo source

Ready-to-Use Examples

Get started quickly with our comprehensive example applications

Core

Raw vectors, collections, and the Quick API for smallest-surface integration.

View Example

RAG Knowledge

Durable knowledge storage and lexical GraphRAG retrieval without requiring an embedder.

View Example

MemoryFlow

Transcript ingest, wake-up layers, diary entries, recall, and transcript reconstruction.

View Example

Knowledge Graph

RDF triples, SPARQL property paths and subqueries, incremental RDFS, and SHACL-lite.

View Example

GraphFlow

Corpus-to-graph extraction, build, analysis, report, JSON export, and HTML visualization.

View Example

ImportFlow

Import a CSV or SQL dump into RAG + knowledge graph: Source parsing, MappingPlan routing, and Plan/Run/AutoImport with optional AI inference.

View Example

Tools and MCP

In-process toolbox calls and MCP-aligned payloads for external agents.

View Example

Self Knowledge Graph

The demo above: turn this project's docs into a queryable knowledge graph via graphflow + any LLM, then answer questions from graph edges.

View Example

Rust Client (gRPC)

Typed cortexdb-client crate: save/search knowledge, memory, SPARQL, and tools from Rust; managed-server feature auto-spawns the sidecar.

View Example

Current Stack

Single-file storage, practical reasoning, and workflow APIs

1
SQLite File
Vectors, FTS5, RAG, memory, RDF — all in one file
3
Workflow Layers
MemoryFlow, GraphFlow, ImportFlow
0
CGO Dependencies
Pure Go via modernc.org/sqlite — no LLM SDK required either
2
Languages
Go native + Rust via the gRPC sidecar (cortexdb-client on crates.io)

Frequently Asked Questions

What is CortexDB? +

CortexDB is a pure-Go, single-file AI memory and knowledge graph library. One SQLite file (via modernc.org/sqlite, no CGO) holds vectors, FTS5 full-text search, RAG knowledge, scoped agent memory, and an RDF knowledge graph with SPARQL, RDFS-lite inference, and SHACL-lite validation.

Does CortexDB require an embedding model or LLM? +

No. CortexDB never imports an LLM SDK. Without an embedder it falls back to first-class lexical retrieval; plugging any embedding endpoint (OpenAI-compatible, e.g. Ollama) enables vector and hybrid search. All LLM-dependent features are optional interfaces.

Can I use CortexDB from Rust or other languages? +

Yes. The cortexdb-grpc sidecar serves the full API over gRPC with bearer-token auth, and the cortexdb-client crate on crates.io provides typed Rust access. Its managed-server feature can download and spawn the sidecar automatically. Any language with gRPC support can use the same cortexdb.v1 protocol.

What knowledge graph standards does CortexDB support? +

RDF triples and quads with namespaces, a practical SPARQL subset (SELECT, ASK, property paths, subqueries, updates), RDFS-lite incremental inference with explanations, SHACL-lite shape validation, and Turtle/N-Triples/N-Quads/TriG import and export.

Is CortexDB free and open source? +

Yes. CortexDB is open source under the MIT license. The Go library, the gRPC sidecar, the Rust client crate, and all examples are free to use, including commercially.

Ready to Build Something Amazing?

Join the developers building the next generation of AI applications with CortexDB