
Package Structure
Cohaku is a TypeScript ESM monorepo (Turborepo + pnpm) with multiple packages:cli package uses tsup (esbuild) to bundle all workspace dependencies into a single distributable binary (@cohaku/cli on npm). The mcp-server package is private and not published separately — it is bundled into the CLI.
Components
Storage Layer
TheSqliteDriver manages all persistence using better-sqlite3 with two extensions:
- sqlite-vec — Virtual tables for vector similarity search (cosine distance)
- FTS5 — Built-in full-text search with BM25 ranking and Porter stemming
~/.config/cohaku/memory.db).
Embedding
Uses@xenova/transformers to run all-MiniLM-L6-v2 locally. Produces 384-dimensional embeddings for:
- Memory content →
vec_memories - Entity names →
vec_nodes - Edge facts →
vec_edges
Memory Engine
TheMemoryEngine class orchestrates all operations:
- Generates embeddings on write
- Runs hybrid search (semantic + BM25) on query
- Computes 4-component scoring (semantic, BM25, recency, salience)
- Manages sessions, episodes, and the knowledge graph
MCP Server
Exposes 24 tools via the Model Context Protocol over stdio transport. Each tool maps to aMemoryEngine method with Zod validation on parameters.
Tools are organized into 6 categories:
| Category | Count | Description |
|---|---|---|
| Context | 1 | get_context — prioritized memory loading |
| Memory | 6 | CRUD, search, deduplication, consolidation |
| Knowledge Graph | 5 | Entities, edges, graph traversal search |
| Episodes | 3 | Chronological event logging |
| Sessions | 4 | Work session lifecycle with checkpoints |
| Config Generation | 9 | Export to Claude Code, Cursor, Copilot, Windsurf, etc. |