Architecture
System Overview
┌─────────────────────────────────────────────────────┐
│ CLI (clap) │
│ uteke-cli crate — auto-routes to server if running │
├─────────────────────────────────────────────────────┤
│ HTTP API (uteke-serve) │
│ /health /remember /recall /search /list /forget │
│ /stats /namespaces /room/* /mcp — CORS, ~42ms │
├─────────────────────────────────────────────────────┤
│ Uteke API │
│ uteke-core crate (lib) │
├──────────┬──────────┬───────────┬────────────────────┤
│ ONNX │ usearch │ FTS5 │ SQLite │
│ Embedding│ Vector │ Full-Text │ Metadata Store │
│ (768d) │ Index │ Search │ (rusqlite) │
│ │ (HNSW) │ (virtual │ │
│ │ RwLock │ table) │ │
├──────────┴──────────┴───────────┴────────────────────┤
│ ~/.codecora/uteke/ (local storage) │
│ uteke.db │ uteke_index.usearch │ embeddinggemma-q4/ │
└─────────────────────────────────────────────────────┘Workspace Crates
| Crate | Purpose |
|---|---|
uteke-privacy | Library — secret detector and redactor (regex only, no IO); published separately so tole shares the ruleset, re-exported as uteke_core::privacy |
uteke-core | Library — storage, embedding, vector search, FTS5, operations |
uteke-cli | CLI binary — clap commands, JSON output, server proxy |
uteke-server | HTTP server — persistent daemon for fast agent access |
uteke-mcp | MCP JSON-RPC server — stdio + Streamable HTTP transport (#381) |
docgen | Build tooling — auto-generates api-reference.md from route registry (publish = false) |
Components
| Component | Technology | Detail |
|---|---|---|
| Language | Rust (no unsafe) | Memory-safe, fast, single binary |
| Vector Index | usearch or vecq + RwLock | usearch (default): persistent HNSW. vecq: 4-bit quantized, pure Rust. Picked at runtime via UTEKE_VECTOR_BACKEND or [vector] backend (#1168) |
| Full-Text Search | SQLite FTS5 | Built-in, auto-created, phrase + token-OR fallback |
| Hybrid Search | RRF (k=60) | Merges vector + FTS5 via Reciprocal Rank Fusion |
| Fusion (default) | weighted RRF | Since 0.16.0: fuses the vector and hybrid rankings (#1123) |
| Storage | SQLite (rusqlite) | Embedded, zero-config, battle-tested |
| Embedding | EmbeddingGemma Q4 ONNX | 768d vectors, multilingual, downloaded on first run |
| Namespaces | SQLite column | Deprecated; use rooms, tags and author instead |
| Tiered Memory | Access tracking | Hot/Warm/Cold scoring boost |
| CLI | clap | Standard Rust CLI |
How It Works
remember— Text is embedded into a 768d vector via ONNX → stored in SQLite + indexed in usearchrecall— Query is embedded → usearch finds nearest neighbors + FTS5 finds keyword matches → RRF merges both result sets → hot memories get +0.1 score boost → returns ranked resultssearch— SQLite FTS5 keyword search (phrase match + token-OR fallback, scoped to namespace)forget— Incremental delete from usearch + SQLite (no rebuild)- Everything lives in
~/.codecora/uteke/— fully local, fully yours
Data Flow
Write Path (remember)
Content → ONNX embed (Mutex) → 768d vector
↓
SQLite INSERT (metadata + vector)
↓
usearch INSERT (RwLock write)
↓
usearch SAVE (atomic: .tmp + rename)SQLite-first dual-write: metadata persisted before index. If index write fails, data is still in SQLite and can be recovered via uteke repair.
Read Path (recall)
Query → Recall Cache check (TTL 5min, LRU 256)
↓ miss
ONNX embed (Mutex) → 768d vector
↓
┌─────────────────┴──────────────────┐
↓ ↓
usearch SEARCH (RwLock read) FTS5 SEARCH (SQLite)
→ top-k vectors + scores → top-k rows + BM25
↓ ↓
└───────────── RRF Merge ─────────────┘
↓
Tier boost (+0.1 hot)
↓
Entity/category filter (#667)
(pushed into core recall loop)
↓
Ranked resultsDelete Path (forget)
ID → usearch REMOVE (RwLock write, acquired first)
↓
SQLite DELETE (by specific ID)
↓
usearch SAVE (atomic)Index lock acquired before SQLite delete — narrows the inconsistency window.
Extract / Import / Export (v0.7.0)
| Endpoint | Method | Auth | Description |
|---|---|---|---|
/extract | POST | Write | LLM fact extraction + auto-store (1MB body limit) |
/import | POST | Write | JSONL import with re-embedding (5MB body limit) |
/export | GET | Read | JSONL export (optional ?namespace= filter) |
Maintenance & Monitoring (v0.7.0)
| Endpoint | Method | Auth | Description |
|---|---|---|---|
/prune | POST | Write | TTL-based deprecated memory cleanup |
/consolidate | POST | Write | Near-duplicate merging |
/aging | POST | Write | Memory lifecycle: status, preview, cleanup |
/importance | POST | Write | Recalculate importance scores |
/orphans | POST | Read | Find disconnected, low-importance memories |
/rebuild-backlinks | POST | Write | Rebuild referenced_by from forward edges |
Document Update (v0.7.0)
| Endpoint | Method | Auth | Description |
|---|---|---|---|
/doc/update | POST | Write | Partial document update with chunk rebuild |
Memory Mutation (v0.8.0)
| Endpoint | Method | Auth | Description |
|---|---|---|---|
/memory | PUT | Write | Partial memory update (content, tags, metadata, importance, pinned, memory_type) |
/memory/pin | POST | Write | Pin or unpin a memory by ID |
/memory/importance | POST | Write | Set importance score (0.0–1.0) for a memory |
Room ↔ Document Junction (v0.8.0)
| Endpoint | Method | Auth | Description |
|---|---|---|---|
/room/document/list | POST | Read | List document slugs linked to a room |
/room/document/add | PUT | Write | Link a document to a room |
/room/document/remove | DELETE | Write | Unlink a document from a room |
/doc/room/list | POST | Read | List rooms linked to a document |
Cross-Entity References (v0.8.0)
| Endpoint | Method | Auth | Description |
|---|---|---|---|
/memory/doc-refs | POST | Read | Get document slugs referenced by a memory |
/doc/mem-refs | POST | Read | Get memory IDs that reference a document |
Key Design Decisions
RwLock for Vector Index (not Mutex)
Read-heavy workload: recall/search operations far outnumber remember/forget. Multiple concurrent recalls share a read lock. Embedder remains Mutex because ONNX tokenizer requires &mut self internally.
Cross-Process File Lock (#543)
The RwLock provides intra-process concurrency only (multiple threads within a single uteke-serve process). For cross-process safety (multiple uteke-serve instances or CLI + server sharing the same store), a file-based lock (fs2 crate) guards the SQLite database and usearch index files. The lock is acquired on store open and held until the process exits or the store is dropped. This prevents concurrent writes from corrupting the index or database when multiple processes access the same ~/.codecora/uteke/ directory.
FTS5 + Vector Hybrid via RRF
Two systems with incompatible score scales (cosine 0..1 vs BM25 unbounded). Reciprocal Rank Fusion solves this by ranking based on position, not score magnitude. k=60 is the standard literature value.
Graph-Augmented Reranking (#378)
The graph recall strategy layers graph signals on top of the RRF result. compute_graph_signals() issues a single batched query over memory_edges (derived from [[slug]] / @tag / ^id auto-wiring, #346) and computes per-memory density/authority counts. rerank_with_graph() then applies an additive, log-scaled boost (ln(1+x) * weight) so well-connected memories drift upward while isolated ones are untouched. The boost saturates quickly (going 1→10 edges ≈ 100→1000 in lift), preventing hub dominance. The recall cache is strategy-keyed, so graph entries never collide with hybrid/ vector/fts5.
Atomic File Writes
All critical file I/O uses the .tmp + rename pattern. On POSIX filesystems, rename is atomic — a crash mid-write never leaves a corrupt file, only the old version.
Schema Versioning
Integer counter in schema_version table. Migrations run automatically on upgrade. Currently at v25. Schema history: v4 rooms, v5 memory_tags junction, v6 content_type column, v7 knowledge graph, v8 memory_edges + slug (#346), v9 timeline_events table (#347), v10 source + source_type (#348), v11 documents + document_chunks (#406), v12 hierarchy (parent_id on documents, room tables added to SCHEMA constant), v13 global documents (namespace deprecated, author column, slug uniqueness), v14 memory_type added to FTS5 index (#662), v15 room_documents junction table for room↔document linking (#689), v16 author_type column (human|agent) (#1083), v17 deprecated_at column — time-travel deprecation predicate (#1086), v18 provenance chain — source_hash, actor, evidence_json (#1172), v19 rooms.description for room rename/update (#1202), v20 audit-grade timeline — FK CASCADE dropped from timeline_events so history survives forget/deprecation, plus created-event backfill (#1280), v21 recall_count — recall/search hits counted apart from access_count (#1337), v22 author on memories, backfilled from the room link when a memory is in exactly one room (#1427), v23 rejected_values — tombstones of values forgotten as wrong, which every write refuses (#1597), v24 observations — the raw capture queue: conversation turns waiting for deferred, budgeted fact extraction (#1466), v25 idx_memories_source — an index so the session view finds a session's memories without scanning the table (#1670). Zero data loss guaranteed.
Rooms
Rooms group related memories with author attribution. Stored in rooms and room_memories tables (schema v4). Semantic room recall over-fetches via recall_hybrid(), then post-filters to room memory IDs. Room summaries use tag co-occurrence clustering — no LLM call required. Room documents group memories by memory_type into sections (Decisions, Facts, Procedures, etc).
Rooms can also be linked to documents via the room_documents junction table (schema v15, #689), enabling bidirectional room↔document associations. Documents reference memories via [[doc-slug]] wikilinks, which are auto-resolved to cross-entity edges (#691).
Memory Types (#349)
Every memory has a memory_type: fact, procedure, preference, decision, context, note, insight, reference, event. Type is set explicitly via --type or auto-inferred from content patterns (questions → context, URLs → reference, dates → event, etc.).
Timeline Events (#347)
The timeline_events table (schema v9) records an append-only audit log per memory: creation, updates, type changes, supersession, edge additions, pin/unpin. Events store metadata as JSON. Consolidation events attach to the OLD memory with replaced_by metadata.
Salience + Recency (#352)
Dual-axis recall boost applied after the RRF merge:
- Salience: higher-scored by type weight (decision > insight > fact > note)
- Recency: exponential decay
exp(-age/τ)where τ is a per-type time constant
Both are enabled by default (weight 0.1). Use --salience false / --recency false to disable. Previously opt-in (v0.7.3), now opt-out (#721). A per-request --salience / --recency is part of the recall request and is scoped to that one recall (Uteke::run_recall), so it cannot leak into a later query and nothing has to reset the engine afterwards.
Dream Cycle (#353)
The dream command runs a coordinated maintenance pipeline: lint → backlinks → dedup → contradict → orphans → compact → verify. Phase 4 (Contradict) scans for contradictory memories via tag overlap + embedding divergence (#720). Phases run in canonical dependency order regardless of user-supplied order. Individual phase errors are recorded but don't abort the pipeline. Namespace-scoped phases (lint, dedup, contradict, orphans, compact) only affect the target namespace; global phases (backlinks, verify) run across all namespaces.
Citation & Source Attribution (#348)
The source and source_type columns (schema v10) track where a memory came from. Source types: user, url, file, import, derived, system, unknown. Set via --source / --source-type on remember or set_source() post-insert.
MCP Transport (#381)
The uteke-mcp crate provides a shared JSON-RPC handler used by both:
- stdio binary (
uteke-mcp) — for local agents (Claude Desktop, Cursor) - HTTP endpoint (
POST /mcponuteke-serve) — for remote MCP clients
Protocol version: 2025-06-18 (Streamable HTTP spec). 1 MiB body limit enforced on HTTP endpoint. JSON-RPC 2.0 strict compliance (v0.6.7, #573/#576): tagged union responses, no notification response, Claude Code compatible.
Error mapping (#1752)
uteke_core::Error::class() classifies every core error once, into an ErrorClass. Each transport has ONE function that turns a class into its wire shape, and every handler or tool uses it:
- HTTP:
uteke_server::context::http_wire(throughReqCtx::core_error). - MCP:
core_failureandtool_errorinuteke-mcp. - CLI:
cli_failureinuteke-cli/src/exit.rs.
| Class (variants) | HTTP | MCP tool error text (isError: true) | CLI |
|---|---|---|---|
BadRequest (Validation) | 400 {"error": "Validation error: ..."} | Validation error: ... | exit 1, Error: ... |
NotFound (NotFound) | 404 {"error": "<message>"} | <message> | exit 1, Error: ... |
Busy (Busy) | 429 {"error": "<message>"} | <message> | exit 1, Error: ... |
SecretDetected | 400 {"error": "secret_detected", "message", "kinds"} | secret_detected: <message> | exit 1, Error: ... |
RejectedValue | 409 {"error": "rejected_value", "message", "reason"} | rejected_value: <message> | exit 1, Error: ... |
InvalidRoomId | 400 {"error": "invalid_room_id", "message", "room_id"} | invalid_room_id: <message> | exit 1, Error: ... |
Embedding (Embedding) | 500 {"error": "<sanitized message>"}; 503 on /doc/search, /doc/similar and /skill/* | Failed: <message> | exit 1, Error: ... |
Internal (Io, Database, Lock, Generic) | 500 {"error": "Internal server error"} (the detail goes to the log) | Failed: <message> | exit 1, Error: ... |
Notes:
POST /recall,POST /room/searchandPOST /namespaces/renameanswer aValidationerror with its bare message (noValidation error:prefix), throughReqCtx::core_error_bare.- MCP reserves JSON-RPC errors (
-32700parse error,-32603for an unknown method or tool, missingparamsor tool name) for protocol problems. A failure of a tool call that was understood, bad arguments, a missing target, a busy server or an internal failure, is a tool result withisError: true, as the MCP specification says, so the model can read it and retry. The read-only refusal already worked that way. - The CLI keeps exit status 1 for every class (0 success, 130 interrupted):
docs/cli-reference.mdand the tests define no other code, and scripts rely on 1.cli_failureis the place to add per-class codes. - A new
Errorvariant fails the table tests (Error::samples()and the exhaustive matches) until it is classified.
Performance
| Mode | Recall | Setup |
|---|---|---|
| Library (Rust) | ~45ms | In-process, no startup |
| Server (HTTP) | ~42ms | One-time ~2s init |
| CLI (binary) | ~3s | Per-invocation (model load) |
CLI vs Server
| Metric | CLI (cold) | Server (warm) | Speedup |
|---|---|---|---|
| Insert 100 | ~316s (0.3/s) | 7.7s (13/s) | 41x |
| Recall (avg) | 3,158ms | 42ms | 75x |
| Search (avg) | 3,158ms | 9ms | 367x |
Scaling (warm server)
| Data Size | Recall (avg) | Search (avg) |
|---|---|---|
| 100 memories | 42ms | 9ms |
| 1,000 memories | 49ms | 13ms |
| 10,000 memories* | ~55ms (est.) | ~20ms (est.) |
*10K estimated — HNSW vector search is O(log n)
Benchmarked on Oracle Cloud ARM (Ampere Altra), CPU-only, no GPU.
File Structure
~/.codecora/uteke/
├── uteke.db # SQLite (memories + metadata + FTS5)
├── uteke_index.usearch # Persistent HNSW vector index (default engine)
├── uteke_index.vecq # Quantized index (only with the vecq engine)
├── uteke_index.keys # Index key mapping (atomic save)
├── embeddinggemma-q4/ # Local ONNX embedding model (~200MB)
│ └── onnx/ # model_q4.onnx + model_q4.onnx_data
└── logs/
├── uteke.log # Current log
└── uteke.log.YYYY-MM-DD # Rotated logsIn Docker, the data directory defaults to /data (set via UTEKE_HOME). The image does not bundle the embedding model: the entrypoint downloads it into /data/models/ on the first start, or skips it when an external embedder is configured (see Docker).
Known Limitations
| Limitation | Status | Detail |
|---|---|---|
usearch ef not configurable | External | usearch v2.25.3 Rust bindings don't expose ef in search() |
| Embedder requires Mutex | Architectural | ONNX tokenizer internally uses &mut self |
| Consolidate is O(n²) | Algorithm | Pairwise cosine — slow above 1K memories |
| FTS5-only score is placeholder | Design | BM25 can't normalize to 0..1; actual ranking via RRF |
Document Engine (#406)
Full markdown content → SQLite (documents table), chunked summaries → embeddings (document_chunks).
Schema (added in v11)
-- Full documents with unlimited content
documents: id, slug, title, content, namespace, tags, metadata,
version, content_type, created_at, updated_at
-- Chunked sections with per-chunk embeddings
document_chunks: id, document_id, chunk_index, heading, content,
embedding BLOB, char_start, char_end, tagsChunking Pipeline
- Document content →
chunk_markdown()(#405) splits by headings - Each chunk →
embedder.embed()creates section-level embedding - Chunks stored with heading, content, char offsets, embedding BLOB
Chunk size derived from embedder.max_seq_len() (#407): ~4 chars per token.
- ONNX (256 tokens): 1,024 chars/chunk
- OpenAI (8191 tokens): 32,764 chars/chunk
Search Paths
- Direct ID/slug → SQLite PK → full content
- Semantic → embed query → ANN chunk search → resolve to document
- FTS5 → full text across all document content
- Graph → BFS from entity → connected documents
Cosine Auto-Linking (#401)
After every remember(), the vector index is searched for the top-20 most similar memories:
- Cosine ≥ 0.80 →
similar_toedge - Cosine ≥ 0.92 →
possible_duplicateedge
Edges are namespace-scoped (no cross-namespace links). Best-effort: errors logged, never fail remember().
Document chunks are not link targets here. Documents have their own similarity (#1730): the document vector is the mean of a document's chunk vectors, L2-normalised, read from SQLite. uteke doc similar, uteke doc duplicates, POST /doc/similar and uteke_doc_similar compare those vectors with the same default thresholds (0.80 similar_to, 0.92 possible_duplicate, configurable in [doc_similarity]) and can also score a draft text that is not stored. The relation is derived on every call; no document edge is stored (memory_edges points at memories, and a stored copy would go stale on every update, move, delete, re-embed and threshold change).
Personal skill library (#1731)
A skill (a directory with a SKILL.md) is indexed into four tables, skills, skill_versions, skill_usage and an append-only skill_ledger, and its current version's text files are stored as documents with content_type = 'skill' (slug skill/<slug>/<path>). Search, similarity and embedding are the document engine's; the kind is a filter at the lowest level (SQL for lists and keyword search, the window of the vector search), so skill files never reach doc list, doc search, recall or the doc similar / doc duplicates answers, and ordinary documents never reach skill search. skill similar is doc similar over the SKILL.md roots. The package hash (SHA-256 over every file's path length, path, content length and content, written sha256:<hex> and identical to tole's) is the version identity and what skill approve records. The remote surface is read-only and has one entry point, Uteke::skill_remote, shared by POST /skill/search|list|show|similar and the uteke_skill_* MCP tools, so both validate and bound a request identically; doc get and doc update treat a skill file as not found. See the skill commands.
Graph API (#408)
GET /graph returns all graph nodes, edges, and stats as JSON for visualization clients:
{
"nodes": [{ "id": "...", "label": "...", "entity_type": "..." }],
"edges": [{ "source_id": "...", "target_id": "...", "relation": "..." }],
"stats": { "node_count": N, "edge_count": N }
}