Repository navigation
Architecture v2
Eduards Čemis edited this page Nov 25, 2026
·
1 revision
Status: Active implementation target (post-v1.6.0)
Design Goals: Cross-tool portability · Zero mandatory Ollama · Markdown-first truth · Measurable retrieval viaevals/
flowchart TB
subgraph Clients["AI Coding Tools (Vendor-Neutral MCP)"]
CC["Claude Code"]
CU["Cursor"]
AG["Antigravity"]
WS["Windsurf / Codex / Cline"]
end
subgraph Server["Cognitive Memory MCP Server (stdio or Hardened Local HTTP)"]
API["MCP Tools: search · store · relate · sync · reindex · consolidate · delete"]
RRF["Hybrid Retrieval Engine (Reciprocal Rank Fusion)"]
DREAM["Zero-LLM / Optional-LLM Consolidation (Auto Dream)"]
end
subgraph Truth["Canonical Source of Truth (Zero Memory Tax)"]
MD["Markdown Vault / Git Repo (YAML frontmatter + valid_from/valid_until + wikilinks)"]
end
subgraph Index["Disposable Derived Index (SQLite)"]
META["memory + edges (is_external, valid_from, valid_until, superseded_by)"]
FTS["SQLite FTS5 (BM25) — Always On, Zero Dependencies"]
VEC["sqlite-vec (Cosine) — Optional Dense Layer (Ollama / Compatible)"]
end
Clients <--> API
API <--> RRF
API <--> MD
MD <-->|"reindex / sync"| Index
RRF --> FTS
RRF -.->|"when embedder online"| VEC
RRF -->|"1-2 hop CTE subgraph"| META
DREAM --> META
DREAM --> MD
-
Canonical Storage: Plain Markdown notes with structured YAML frontmatter (
id,profile,scope,importance,valid_from,valid_until,superseded_by,ref). Directly readable by humans, diffable in Git, searchable withgrep, and editable in Obsidian. -
Zero-Copy Grounding: Memories may attach a validated
refpointer (vault_path,wikilink,source_hash,section) and externalgrounded_in/referencesedges (obsidian://,vault://) so agents can jump straight back to raw source files instead of relying solely on lossy summaries. -
Disposable Index:
cognitive-memory reindexreconstructsmemory,fts_memory,edges, and (if an embedder is enabled)vec_memorycleanly from Markdown files without data loss.
-
Always-On Lexical Engine: Every active memory (
is_active = 1and not temporally superseded) is indexed in SQLiteFTS5across bothmain(project-local) andglobal(~/.cognitive-memory) schemas. -
Graceful Degradation: If Ollama is stopped, unreachable, or disabled (
EMBEDDING_PROVIDER=none),memory_storeandmemory_searchnever fail — they operate instantaneously in pure BM25/FTS5 mode. -
Hybrid RRF Fusion: When embeddings are available (Ollama or pluggable provider),
memory_searchruns bothFTS5BM25 and single-pass CTEsqlite-veccosine search and merges candidates via Reciprocal Rank Fusion:$$\text{RRF}(d) = \sum_{r \in {\text{bm25}, \text{vec}}} \frac{w_r}{k + \text{rank}_r(d)}$$ capturing exact identifiers/error codes (BM25) and conceptual paraphrases / cross-lingual queries (dense vectors).
-
Solving Contradictions: Updating or superseding a fact sets
valid_until = CURRENT_TIMESTAMPandsuperseded_by = <new_id>on the old record (creating asupersedesedge) instead of leaving conflicting active facts or permanently destroying history. -
Bounded Subgraph Expansion: Optional
includeGraph: true(depth capped at1or2via SQLite recursive CTE) returns directly connected memories andgrounded_inexternal pointers in a single tool call, avoiding both multi-turn round-trips and 3-hop hairball noise.
-
Scopes (
local|global|all): Project-specific knowledge stays in the local DB/vault; cross-project user preferences and tool conventions live in~/.cognitive-memory/. -
Profiles (
user|working|agent_core): Separates stable user preferences, ephemeral working investigations, and invariant architectural rules.
-
Default (
stdio): Pure JSON-RPC on stdout (all logs strictly routed to stderr). -
HTTP/SSE Local Daemon: Binds to
127.0.0.1by default, enforces localhost-only CORS, uses relative message endpoints, and refuses non-loopback binding unlessMCP_AUTH_TOKENis configured (verified with timing-safe comparison).
-
Single local/CI verification command:
pnpm verify(Biome + roottsc+ build + unit/integration tests + offline eval gate + UI build/tests). -
Eval Tracks (
evals/): Benchmarksbm25vs.densevs.hybrid-rrf, temporal contradiction resolution, distractor noise stress tests, and Markdown round-trip invariants. -
3D Web UI (
ui/): Frozen as an optional read-only visualization companion; core engineering investment stays on retrieval quality, storage integrity, and cross-tool ergonomics.