cozo-memory 1.1.5 โ†’ 1.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -11,26 +11,10 @@
11
11
  - [Quick Start](#quick-start)
12
12
  - [Key Features](#key-features)
13
13
  - [Positioning & Comparison](#positioning--comparison)
14
- - [Performance & Benchmarks](#performance--benchmarks)
15
- - [Architecture](#architecture)
16
14
  - [Installation](#installation)
17
- - [Start / Integration](#start--integration)
18
- - [Configuration & Backends](#configuration--backends)
19
- - [Data Model](#data-model)
20
- - [MCP Tools](#mcp-tools)
21
- - [mutate_memory (Write)](#mutate_memory-write)
22
- - [query_memory (Read)](#query_memory-read)
23
- - [analyze_graph (Analysis)](#analyze_graph-analysis)
24
- - [manage_system (Maintenance)](#manage_system-maintenance)
25
- - [Production Monitoring](#production-monitoring)
26
- - [Technical Highlights](#technical-highlights)
27
- - [Optional: HTTP API Bridge](#optional-http-api-bridge)
28
- - [Development](#development)
29
- - [User Preference Profiling](#user-preference-profiling-mem0-style)
15
+ - [Integration](#integration)
16
+ - [Documentation](#documentation)
30
17
  - [Troubleshooting](#troubleshooting)
31
- - [Roadmap](#roadmap)
32
- - [Contributing](#contributing)
33
- - [License](#license)
34
18
 
35
19
  ## Quick Start
36
20
 
@@ -53,105 +37,33 @@ npm install && npm run build
53
37
  npm run start
54
38
  ```
55
39
 
56
- Now you can add the server to your MCP client (e.g. Claude Desktop).
40
+ Now add the server to your MCP client (e.g. Claude Desktop) โ€“ see [Integration](#integration) below.
57
41
 
58
42
  ## Key Features
59
43
 
60
- ๐Ÿ” **Hybrid Search (since v0.7)** - Combines semantic search (HNSW), full-text search (FTS), and graph signals via Reciprocal Rank Fusion (RRF)
44
+ ๐Ÿ” **Hybrid Search** - Combines semantic (HNSW), full-text (FTS), and graph signals via Reciprocal Rank Fusion for intelligent retrieval
61
45
 
62
- ๐Ÿ”€ **Dynamic Fusion Framework (v2.3)** - Advanced 4-path retrieval system combining Dense Vector, Sparse Vector, FTS, and Graph traversal with configurable weights and fusion strategies (RRF, Weighted Sum, Max, Adaptive)
46
+ ๐Ÿง  **Agentic Retrieval** - Auto-routing engine analyzes query intent via local LLM to select optimal search strategy (Vector, Graph, or Community)
63
47
 
64
- ๐Ÿง  **Logical Edges from Knowledge Graph (v1.0)** - Metadata-driven implicit relationship discovery with 5 patterns: same category, same type, hierarchical, contextual, and transitive logical edges
48
+ โฑ๏ธ **Time-Travel Queries** - Version all changes via CozoDB Validity; query any point in history with full audit trails
65
49
 
66
- ๐Ÿ”€ **Multi-Hop Reasoning with Vector Pivots (v2.5)** - Logic-aware Retrieve-Reason-Prune pipeline using vector search as springboard for graph traversal with helpfulness scoring and pivot depth security
50
+ ๐ŸŽฏ **GraphRAG-R1 Adaptive Retrieval** - Intelligent system with Progressive Retrieval Attenuation (PRA) and Cost-Aware F1 (CAF) scoring that learns from usage
67
51
 
68
- โณ **Temporal Graph Neural Networks (v2.4)** - Time-aware node embeddings capturing historical context, temporal smoothness, and recency-weighted aggregation using Time2Vec encoding and multi-signal fusion
52
+ โณ **Temporal Conflict Resolution** - Automatic detection and resolution of contradictory observations with semantic analysis and audit preservation
69
53
 
70
- ๐Ÿง  **Agentic Retrieval Layer (v2.0)** - Auto-routing engine that analyzes query intent via local LLM to select the optimal search strategy (Vector, Graph, or Community)
54
+ ๐Ÿ  **100% Local** - Embeddings via ONNX/Transformers; no external services, no cloud, complete data ownership
71
55
 
72
- ๏ฟฝ **GraphRAG-R1 Adaptive Retrieval (v2.6)** - Intelligent retrieval system with Progressive Retrieval Attenuation (PRA) and Cost-Aware F1 (CAF) scoring that automatically selects optimal strategies based on query complexity and learns from historical performance
56
+ ๐Ÿง  **Multi-Hop Reasoning** - Logic-aware graph traversal with vector pivots for deep relational reasoning
73
57
 
74
- ๏ฟฝ๐Ÿง  **Multi-Level Memory (v2.0)** - Context-aware memory system with built-insession and task management
58
+ ๐Ÿ—‚๏ธ **Hierarchical Memory** - Multi-level architecture (L0-L3) with intelligent compression and LLM-backed summarization
75
59
 
76
- ๐ŸŽฏ **Tiny Learned Reranker (v2.0)** - Integrated Cross-Encoder model (`ms-marco-MiniLM-L-6-v2`) for ultra-precise re-ranking of top search results
77
-
78
- ๐ŸŽฏ **Multi-Vector Support (since v1.7)** - Dual embeddings per entity: content-embedding for context, name-embedding for identification
79
-
80
- โšก **Semantic Caching (since v0.8.5)** - Two-level cache (L1 memory + L2 persistent) with semantic query matching
81
-
82
- โฑ๏ธ **Time-Travel Queries** - Version all changes via CozoDB Validity; query any point in history
83
-
84
- ๐Ÿ”— **Atomic Transactions (since v1.2)** - Multi-statement transactions ensuring data consistency
85
-
86
- ๐Ÿ“Š **Graph Algorithms (since v1.3/v1.6)** - PageRank, Betweenness Centrality, HITS, Community Detection, Shortest Path
87
-
88
- ๐Ÿ—๏ธ **Hierarchical GraphRAG (v2.0)** - Automatic generation of thematic "Community Summaries" using local LLMs to enable global "Big Picture" reasoning
89
-
90
- ๐Ÿงน **Janitor Service** - LLM-backed automatic cleanup with hierarchical summarization, observation pruning, and **automated session compression**
91
-
92
- ๐Ÿ—œ๏ธ **Context Compaction & Auto-Summarization (v2.2)** - Automatic and manual memory consolidation with progressive summarization and LLM-backed Executive Summaries
93
-
94
- ๐Ÿง  **Fact Lifecycle Management (v2.1)** - Native "soft-deletion" via CozoDB Validity retraction; invalidated facts are hidden from current views but preserved in history for audit trails
95
-
96
- ๐Ÿ‘ค **User Preference Profiling** - Persistent user preferences with automatic 50% search boost
97
-
98
- ๐Ÿ” **Near-Duplicate Detection** - Automatic LSH-based deduplication to avoid redundancy
99
-
100
- ๐Ÿง  **Inference Engine** - Implicit knowledge discovery with multiple strategies
101
-
102
- ๐Ÿ  **100% Local** - Embeddings via ONNX/Transformers; no external services required
103
-
104
- ๐Ÿ“ฆ **Export/Import (since v1.8)** - Export to JSON, Markdown, or Obsidian-ready ZIP; import from Mem0, MemGPT, Markdown, or native format
105
-
106
- ๐Ÿ“„ **PDF Support (since v1.9)** - Direct PDF ingestion with text extraction via pdfjs-dist; supports file path and content parameters
107
-
108
- ๐Ÿ• **Dual Timestamp Format (since v1.9)** - All timestamps returned in both Unix microseconds and ISO 8601 format for maximum flexibility
109
-
110
- ### Detailed Features
111
- - **Hybrid Search (v0.7 Optimized)**: Combination of semantic search (HNSW), **Full-Text Search (FTS)**, and graph signals, merged via Reciprocal Rank Fusion (RRF).
112
- - **Full-Text Search (FTS)**: Native CozoDB v0.7 FTS indices with stemming, stopword filtering, and robust query sanitizing (cleaning of `+ - * / \ ( ) ? .`) for maximum stability.
113
- - **Near-Duplicate Detection (LSH)**: Automatically detects very similar observations via MinHash-LSH (CozoDB v0.7) to avoid redundancy.
114
- - **Recency Bias**: Older content is dampened in fusion (except for explicit keyword searches), so "currently relevant" appears higher more often.
115
- - **Graph-RAG & Graph-Walking (v1.7 Optimized)**: Advanced retrieval method combining semantic vector seeds with recursive graph traversals. Now uses an optimized **Graph-Walking** algorithm via Datalog, using HNSW index lookups for precise distance calculations during traversal.
116
- - **Multi-Vector Support (v1.7)**: Each entity now has two specialized vectors:
117
- 1. **Content-Embedding**: Represents the content context (observations).
118
- 2. **Name-Embedding**: Optimized for identification via name/label.
119
- This significantly improves accuracy when entering graph walks.
120
- - **Semantic & Persistent Caching (v0.8.5)**: Two-level caching system:
121
- 1. **L1 Memory Cache**: Ultra-fast in-memory LRU cache (< 0.1ms).
122
- 2. **L2 Persistent Cache**: Storage in CozoDB for restart resistance.
123
- 3. **Semantic Matching**: Detects semantically similar queries via vector distance.
124
- 4. **Janitor TTL**: Automatic cleanup of outdated cache entries by the Janitor service.
125
- - **Time-Travel**: Changes are versioned via CozoDB `Validity`; historical queries are possible.
126
- - **JSON Merge Operator (++)**: Uses the v0.7 merge operator for efficient, atomic metadata updates.
127
- - **Multi-Statement Transactions (v1.2)**: Supports atomic transactions across multiple operations using CozoDB block syntax `{ ... }`. Guarantees that related changes (e.g., create entity + add observation + link relationship) are executed fully or not at all.
128
- - **Graph Metrics & Ranking Boost (v1.3 / v1.6)**: Integrates advanced graph algorithms:
129
- - **PageRank**: Calculates the "importance" of knowledge nodes for ranking.
130
- - **Betweenness Centrality**: Identifies central bridge elements in the knowledge network.
131
- - **HITS (Hubs & Authorities)**: Distinguishes between information sources (Authorities) and pointers (Hubs).
132
- - **Connected Components**: Detects isolated knowledge islands and subgraphs.
133
- - These metrics are automatically used in hybrid search (`advancedSearch`) and `graphRag`.
134
- - **Native CozoDB Operators (v1.5)**: Now uses explicit `:insert`, `:update`, and `:delete` operators instead of generic `:put` (upsert) calls. Increases data safety through strict validation of database states (e.g., error when trying to "insert" an existing entity).
135
- - **Advanced Time-Travel Analysis (v1.5)**: Extension of relationship history with time range filters (`since`/`until`) and automatic diff summaries to analyze changes (additions/removals) over specific periods.
136
- - **Graph Features (v1.6)**: Native integration of Shortest Path (Dijkstra) with path reconstruction, Community Detection (LabelPropagation), and advanced centrality measures.
137
- - **Graph Evolution**: Tracks the temporal development of relationships (e.g., role change from "Manager" to "Consultant") via CozoDB `Validity` queries.
138
- - **Bridge Discovery**: Identifies "bridge entities" connecting different communities โ€“ ideal for creative brainstorming.
139
- - **Inference**: Implicit suggestions and context extension (e.g., transitive expertise rule).
140
- - **Conflict Detection (Application-Level & Triggers)**: Automatically detects contradictions in metadata (e.g., "active" vs. "discontinued" / `archived: true`). Uses robust logic in the app layer to ensure data integrity before writing.
141
- - **Data Integrity (Trigger Concept)**: Prevents invalid states like self-references in relationships (Self-Loops) directly at creation.
142
- - **Hierarchical Summarization**: The Janitor condenses old fragments into "Executive Summary" nodes to preserve the "Big Picture" long-term.
143
- - **User Preference Profiling**: A specialized `global_user_profile` entity stores persistent preferences (likes, work style), which receive a **50% score boost** in every search.
144
- - **Fact Lifecycle Management (v2.1)**: Uses CozoDB's native **Validity** retraction mechanism to manage the lifecycle of information. Instead of destructive deletions, facts are invalidated by asserting a `[timestamp, false]` record. This ensures:
145
- 1. **Auditability**: You can always "time-travel" back to see what the system knew at any given point.
146
- 2. **Consistency**: All standard retrieval (Search, Graph-RAG, Inference) uses the `@ "NOW"` filter to automatically exclude retracted facts.
147
- 3. **Atomic Retraction**: Invalidation can be part of a multi-statement transaction, allowing for clean "update" patterns (invalidate old + insert new).
148
- - **All Local**: Embeddings via Transformers/ONNX; no external embedding service required.
60
+ > **[โ†’ See all features](docs/FEATURES.md)** | **[Version History](CHANGELOG.md)**
149
61
 
150
62
  ## Positioning & Comparison
151
63
 
152
64
  Most "Memory" MCP servers fall into two categories:
153
- 1. **Simple Knowledge Graphs**: CRUD operations on triples, often only text search.
154
- 2. **Pure Vector Stores**: Semantic search (RAG), but little understanding of complex relationships.
65
+ 1. **Simple Knowledge Graphs**: CRUD operations on triples, often only text search
66
+ 2. **Pure Vector Stores**: Semantic search (RAG), but little understanding of complex relationships
155
67
 
156
68
  This server fills the gap in between ("Sweet Spot"): A **local, database-backed memory engine** combining vector, graph, and keyword signals.
157
69
 
@@ -169,109 +81,10 @@ This server fills the gap in between ("Sweet Spot"): A **local, database-backed
169
81
 
170
82
  The core advantage is **Intelligence and Traceability**: By combining an **Agentic Retrieval Layer** with **Hierarchical GraphRAG**, the system can answer both specific factual questions and broad thematic queries with much higher accuracy than pure vector stores.
171
83
 
172
- ## Performance & Benchmarks
173
-
174
- Benchmarks on a standard developer laptop (Windows, Node.js 20+, CPU-only):
175
-
176
- | Metric | Value | Note |
177
- | :--- | :--- | :--- |
178
- | **Graph-Walking (Recursive)** | **~130 ms** | Vector Seed + Recursive Datalog Traversal |
179
- | **Graph-RAG (Breadth-First)** | **~335 ms** | Vector Seeds + 2-Hop Expansion |
180
- | **Hybrid Search (Cache Hit)** | **< 0.1 ms** | **v0.8+ Semantic Cache** |
181
- | **Hybrid Search (Cold)** | **~35 ms** | FTS + HNSW + RRF Fusion |
182
- | **Vector Search (Raw)** | **~51 ms** | Pure semantic search as reference |
183
- | **FTS Search (Raw)** | **~12 ms** | Native Full-Text Search Performance |
184
- | **Ingestion** | **~102 ms** | Per Op (Write + Embedding + FTS/LSH Indexing) |
185
- | **RAM Usage** | **~1.7 GB** | Primarily due to local `Xenova/bge-m3` model |
186
-
187
- ### Running Benchmarks
188
-
189
- You can test performance on your system with the integrated benchmark tool:
190
-
191
- ```bash
192
- npm run benchmark
193
- ```
194
-
195
- This tool (`src/benchmark.ts`) performs the following tests:
196
- 1. **Initialization**: Cold start duration of the server incl. model loading.
197
- 2. **Ingestion**: Mass import of test entities and observations (throughput).
198
- 3. **Search Performance**: Latency measurement for Hybrid Search vs. Raw Vector Search.
199
- 4. **RRF Overhead**: Determination of additional computation time for fusion logic.
200
-
201
- ### Running Evaluation Suite (RAG Quality)
202
-
203
- To evaluate the quality and recall of different retrieval strategies (Search vs. Graph-RAG vs. Graph-Walking), use the evaluation suite:
204
-
205
- ```bash
206
- npm run eval
207
- ```
208
-
209
- This tool compares strategies using a synthetic dataset and measures **Recall@K**, **MRR**, and **Latency**.
210
-
211
- | Method | Recall@10 | Avg Latency | Best For |
212
- | :--- | :--- | :--- | :--- |
213
- | **Graph-RAG** | **1.00** | **~32 ms** | Deep relational reasoning |
214
- | **Graph-RAG (Reranked)** | **1.00** | **~36 ms** | Maximum precision for relational data |
215
- | **Graph-Walking** | 1.00 | ~50 ms | Associative path exploration |
216
- | **Hybrid Search** | 1.00 | ~89 ms | Broad factual retrieval |
217
- | **Reranked Search** | 1.00 | ~20 ms* | Ultra-precise factual search (Warm cache) |
218
-
219
- ## Architecture
220
-
221
- ```mermaid
222
- graph TB
223
- Client[MCP Client<br/>Claude Desktop, etc.]
224
- Server[MCP Server<br/>FastMCP + Zod Schemas]
225
- Services[Memory Services]
226
- Embeddings[Embeddings<br/>ONNX Runtime]
227
- Search[Hybrid Search<br/>RRF Fusion]
228
- Cache[Semantic Cache<br/>L1 + L2]
229
- Inference[Inference Engine<br/>Multi-Strategy]
230
- DB[(CozoDB SQLite<br/>Relations + Validity<br/>HNSW Indices<br/>Datalog/Graph)]
231
-
232
- Client -->|stdio| Server
233
- Server --> Services
234
- Services --> Embeddings
235
- Services --> Search
236
- Services --> Cache
237
- Services --> Inference
238
- Services --> DB
239
-
240
- style Client fill:#e1f5ff,color:#000
241
- style Server fill:#fff4e1,color:#000
242
- style Services fill:#f0e1ff,color:#000
243
- style DB fill:#e1ffe1,color:#000
244
- ```
245
-
246
- ### Graph-Walking Visualization
247
-
248
- ```mermaid
249
- graph LR
250
- Start([Query: What is Alice working on?])
251
- V1[Vector Search<br/>Find: Alice]
252
- E1[Alice<br/>Person]
253
- E2[Project X<br/>Project]
254
- E3[Feature Flags<br/>Technology]
255
- E4[Bob<br/>Person]
256
-
257
- Start --> V1
258
- V1 -.semantic similarity.-> E1
259
- E1 -->|works_on| E2
260
- E2 -->|uses_tech| E3
261
- E1 -->|colleague_of| E4
262
- E4 -.semantic: also relevant.-> E2
263
-
264
- style Start fill:#e1f5ff,color:#000
265
- style V1 fill:#fff4e1,color:#000
266
- style E1 fill:#ffe1e1,color:#000
267
- style E2 fill:#e1ffe1,color:#000
268
- style E3 fill:#f0e1ff,color:#000
269
- style E4 fill:#ffe1e1,color:#000
270
- ```
271
-
272
84
  ## Installation
273
85
 
274
86
  ### Prerequisites
87
+
275
88
  - Node.js 20+ (recommended)
276
89
  - **RAM: 1.7 GB minimum** (for default bge-m3 model)
277
90
  - Model download: ~600 MB
@@ -306,9 +119,9 @@ npm run build
306
119
  npm run start
307
120
  ```
308
121
 
309
- Notes:
310
- - On first start, `@xenova/transformers` downloads the embedding model (may take time).
311
- - Embeddings are processed on the CPU.
122
+ **Notes:**
123
+ - On first start, `@xenova/transformers` downloads the embedding model (may take time)
124
+ - Embeddings are processed on the CPU
312
125
 
313
126
  ### Embedding Model Options
314
127
 
@@ -361,217 +174,114 @@ EMBEDDING_MODEL=Xenova/all-MiniLM-L6-v2 npm run start
361
174
  # Set model in .env or via command line, then:
362
175
  EMBEDDING_MODEL=Xenova/all-MiniLM-L6-v2 npm run download-model
363
176
  ```
364
- }
365
- ```
366
177
 
367
178
  **Note:** Changing models requires re-embedding existing data. The model is downloaded once on first use.
368
179
 
369
- ## Framework Adapters
370
-
371
- Official adapters for seamless integration with popular AI frameworks:
372
-
373
- ### ๐Ÿฆœ LangChain Adapter
374
-
375
- ```bash
376
- npm install @cozo-memory/langchain @cozo-memory/adapters-core
377
- ```
180
+ ## Integration
378
181
 
379
- ```typescript
380
- import { CozoMemoryChatHistory, CozoMemoryRetriever } from '@cozo-memory/langchain';
381
- import { BufferMemory } from 'langchain/memory';
382
-
383
- // Chat history with session management
384
- const chatHistory = new CozoMemoryChatHistory({
385
- sessionName: 'user-123'
386
- });
182
+ ### Claude Desktop
387
183
 
388
- const memory = new BufferMemory({ chatHistory });
184
+ #### Using npx (Recommended)
389
185
 
390
- // Retriever with hybrid search or Graph-RAG
391
- const retriever = new CozoMemoryRetriever({
392
- useGraphRAG: true,
393
- graphRAGDepth: 2
394
- });
186
+ ```json
187
+ {
188
+ "mcpServers": {
189
+ "cozo-memory": {
190
+ "command": "npx",
191
+ "args": ["cozo-memory"]
192
+ }
193
+ }
194
+ }
395
195
  ```
396
196
 
397
- ### ๐Ÿฆ™ LlamaIndex Adapter
197
+ #### Using global installation
398
198
 
399
- ```bash
400
- npm install @cozo-memory/llamaindex @cozo-memory/adapters-core
199
+ ```json
200
+ {
201
+ "mcpServers": {
202
+ "cozo-memory": {
203
+ "command": "cozo-memory"
204
+ }
205
+ }
206
+ }
401
207
  ```
402
208
 
403
- ```typescript
404
- import { CozoVectorStore } from '@cozo-memory/llamaindex';
405
- import { VectorStoreIndex } from 'llamaindex';
406
-
407
- // Vector store with Graph-RAG support
408
- const vectorStore = new CozoVectorStore({
409
- useGraphRAG: true
410
- });
209
+ #### Using local build
411
210
 
412
- const index = await VectorStoreIndex.fromDocuments(
413
- documents,
414
- { vectorStore }
415
- );
211
+ ```json
212
+ {
213
+ "mcpServers": {
214
+ "cozo-memory": {
215
+ "command": "node",
216
+ "args": ["C:/Path/to/cozo-memory/dist/index.js"]
217
+ }
218
+ }
219
+ }
416
220
  ```
417
221
 
418
- **Features:**
419
- - โœ… Persistent chat history (LangChain)
420
- - โœ… Hybrid search retrieval (both)
421
- - โœ… Graph-RAG mode (both)
422
- - โœ… Session management (LangChain)
423
- - โœ… Vector store operations (LlamaIndex)
222
+ ### Framework Adapters
424
223
 
425
- **Documentation:** See [adapters/README.md](./adapters/README.md) for complete examples and API reference.
426
-
427
- ## Temporal Graph Neural Networks (v2.4)
428
-
429
- CozoDB Memory now includes **Temporal Graph Neural Network (TGNN) embeddings** that capture time-aware node representations combining historical context, temporal smoothness, and graph structure.
430
-
431
- ### What are Temporal Embeddings?
432
-
433
- Traditional embeddings are static snapshots. Temporal embeddings evolve over time, capturing:
434
-
435
- 1. **Historical Context** - Weighted aggregation of past observations with exponential decay
436
- 2. **Temporal Smoothness** - Recency-weighted signals ensure gradual changes, not sudden jumps
437
- 3. **Time Encoding** - Time2Vec-inspired sinusoidal encoding captures periodicity and time differences
438
- 4. **Neighborhood Aggregation** - Related entities influence the embedding through weighted graph signals
224
+ Official adapters for seamless integration with popular AI frameworks:
439
225
 
440
- ### Architecture
226
+ **๐Ÿฆœ LangChain Adapter**
441
227
 
228
+ ```bash
229
+ npm install @cozo-memory/langchain @cozo-memory/adapters-core
442
230
  ```
443
- Entity Embedding = Fuse(
444
- content_embedding (0.4), # Semantic meaning
445
- temporal_encoding (0.2), # Time information (Time2Vec)
446
- historical_context (0.2), # Past observations (exponential decay)
447
- neighborhood_agg (0.2) # Related entities (graph signals)
448
- )
449
- ```
450
-
451
- ### Key Features
452
-
453
- - **Time2Vec Encoding** - Sinusoidal functions capture temporal patterns without discretization
454
- - **Exponential Decay Weighting** - Recent observations matter more (30-day half-life)
455
- - **Multi-Signal Fusion** - Combines content, temporal, historical, and graph signals
456
- - **Confidence Scoring** - Reflects data freshness and completeness (0-1 scale)
457
- - **Memory Caching** - Efficient temporal state for multi-hop traversals
458
- - **Time-Travel Support** - Generate embeddings at any historical timepoint via CozoDB Validity
459
-
460
- ### Usage Example
461
231
 
462
232
  ```typescript
463
- import { TemporalEmbeddingService } from 'cozo-memory';
464
-
465
- const temporalService = new TemporalEmbeddingService(
466
- embeddingService,
467
- dbQuery
468
- );
469
-
470
- // Generate embedding at current time
471
- const embedding = await temporalService.generateTemporalEmbedding(
472
- entityId,
473
- new Date()
474
- );
475
-
476
- // Or at a historical timepoint
477
- const pastEmbedding = await temporalService.generateTemporalEmbedding(
478
- entityId,
479
- new Date('2026-02-01')
480
- );
481
-
482
- // Compare temporal trajectories
483
- const similarity = cosineSimilarity(
484
- embedding.embedding,
485
- pastEmbedding.embedding
486
- );
487
- ```
488
-
489
- ### Confidence Scoring
490
-
491
- Confidence reflects data quality and freshness:
233
+ import { CozoMemoryChatHistory, CozoMemoryRetriever } from '@cozo-memory/langchain';
492
234
 
235
+ const chatHistory = new CozoMemoryChatHistory({ sessionName: 'user-123' });
236
+ const retriever = new CozoMemoryRetriever({ useGraphRAG: true, graphRAGDepth: 2 });
493
237
  ```
494
- Base: 0.5
495
- + Recent entity (< 7 days): +0.3
496
- + Many observations (> 5): +0.15
497
- + Well-connected (> 10 relations): +0.15
498
- = Max: 1.0
499
- ```
500
-
501
- ### Research Foundation
502
238
 
503
- Based on cutting-edge research (2023-2026):
504
-
505
- - **ACM Temporal Graph Learning Primer** (2025) - Comprehensive TGNN taxonomy
506
- - **TempGNN** (2023) - Temporal embeddings for dynamic session-based recommendations
507
- - **Time-Aware Graph Embedding** (2021) - Temporal smoothness and task-oriented approaches
508
- - **Allan-Poe** (2025) - All-in-One Graph-Based Hybrid Search with dynamic fusion
509
-
510
- ### Testing
239
+ **๐Ÿฆ™ LlamaIndex Adapter**
511
240
 
512
241
  ```bash
513
- npx ts-node src/test-temporal-embeddings.ts
242
+ npm install @cozo-memory/llamaindex @cozo-memory/adapters-core
514
243
  ```
515
244
 
516
- ## Start / Integration
517
-
518
- ### MCP Server (stdio)
519
-
520
- The MCP server runs over stdio (for Claude Desktop etc.). Start:
245
+ ```typescript
246
+ import { CozoVectorStore } from '@cozo-memory/llamaindex';
521
247
 
522
- ```bash
523
- npm run start
248
+ const vectorStore = new CozoVectorStore({ useGraphRAG: true });
524
249
  ```
525
250
 
526
- Default database path: `memory_db.cozo.db` in project root (created automatically).
251
+ **Documentation:** See [adapters/README.md](./adapters/README.md) for complete examples and API reference.
252
+
253
+ ## CLI & TUI
527
254
 
528
255
  ### CLI Tool
529
256
 
530
- CozoDB Memory includes a full-featured CLI for all operations:
257
+ Full-featured CLI for all operations:
531
258
 
532
259
  ```bash
533
260
  # System operations
534
261
  cozo-memory system health
535
262
  cozo-memory system metrics
536
- cozo-memory system reflect
537
263
 
538
264
  # Entity operations
539
- cozo-memory entity create -n "MyEntity" -t "person" -m '{"age": 30}'
265
+ cozo-memory entity create -n "MyEntity" -t "person"
540
266
  cozo-memory entity get -i <entity-id>
541
- cozo-memory entity delete -i <entity-id>
542
-
543
- # Observations
544
- cozo-memory observation add -i <entity-id> -t "Some note"
545
-
546
- # Relations
547
- cozo-memory relation create --from <id1> --to <id2> --type "knows" -s 0.8
548
267
 
549
268
  # Search
550
269
  cozo-memory search query -q "search term" -l 10
551
- cozo-memory search context -q "context query"
552
270
  cozo-memory search agentic -q "agentic query"
553
271
 
554
272
  # Graph operations
555
- cozo-memory graph explore -s <entity-id> -h 3
556
273
  cozo-memory graph pagerank
557
274
  cozo-memory graph communities
558
- cozo-memory graph summarize
559
-
560
- # Session & Task management
561
- cozo-memory session start -n "My Session"
562
- cozo-memory session stop -i <session-id>
563
- cozo-memory task start -n "My Task" -s <session-id>
564
- cozo-memory task stop -i <task-id>
565
275
 
566
276
  # Export/Import
567
- cozo-memory export json -o backup.json --include-metadata --include-relationships --include-observations
568
- cozo-memory export markdown -o notes.md
569
- cozo-memory export obsidian -o vault.zip
277
+ cozo-memory export json -o backup.json
570
278
  cozo-memory import file -i data.json -f cozo
571
279
 
572
280
  # All commands support -f json or -f pretty for output formatting
573
281
  ```
574
282
 
283
+ > **See CLI help for complete command reference: `cozo-memory --help`**
284
+
575
285
  ### TUI (Terminal User Interface)
576
286
 
577
287
  Interactive TUI with mouse support powered by Python Textual:
@@ -591,791 +301,48 @@ cozo-memory-tui
591
301
  - โŒจ๏ธ Keyboard shortcuts (q=quit, h=help, r=refresh)
592
302
  - ๐Ÿ“Š Interactive menus for all operations
593
303
  - ๐ŸŽจ Rich terminal UI with colors and animations
594
- - ๐Ÿ“‹ Real-time results display
595
- - ๐Ÿ” Forms for entity creation, search, graph operations
596
- - ๐Ÿ“ค Export/Import wizards
597
-
598
- ### Claude Desktop Integration
599
-
600
- #### Using npx (Recommended)
601
-
602
- ```json
603
- {
604
- "mcpServers": {
605
- "cozo-memory": {
606
- "command": "npx",
607
- "args": ["cozo-memory"]
608
- }
609
- }
610
- }
611
- ```
612
-
613
- #### Using global installation
614
-
615
- ```json
616
- {
617
- "mcpServers": {
618
- "cozo-memory": {
619
- "command": "cozo-memory"
620
- }
621
- }
622
- }
623
- ```
624
-
625
- #### Using local build
626
-
627
- ```json
628
- {
629
- "mcpServers": {
630
- "cozo-memory": {
631
- "command": "node",
632
- "args": ["C:/Path/to/cozo-memory/dist/index.js"]
633
- }
634
- }
635
- }
636
- ```
637
-
638
- ## Configuration & Backends
639
-
640
- The system supports various storage backends. **SQLite** is used by default as it requires no extra installation and offers the best balance of performance and simplicity for most use cases.
641
-
642
- ### Changing Backend (e.g., to RocksDB)
643
-
644
- RocksDB offers advantages for very large datasets (millions of entries) and write-intensive workloads due to better parallelism and data compression.
645
304
 
646
- To change the backend, set the `DB_ENGINE` environment variable before starting:
305
+ ## Architecture Overview
647
306
 
648
- **PowerShell:**
649
- ```powershell
650
- $env:DB_ENGINE="rocksdb"; npm run dev
651
- ```
652
-
653
- **Bash:**
654
- ```bash
655
- DB_ENGINE=rocksdb npm run dev
307
+ ```mermaid
308
+ graph TB
309
+ Client[MCP Client<br/>Claude Desktop, etc.]
310
+ Server[MCP Server<br/>FastMCP + Zod Schemas]
311
+ Services[Memory Services]
312
+ Embeddings[Embeddings<br/>ONNX Runtime]
313
+ Search[Hybrid Search<br/>RRF Fusion]
314
+ Cache[Semantic Cache<br/>L1 + L2]
315
+ Inference[Inference Engine<br/>Multi-Strategy]
316
+ DB[(CozoDB SQLite<br/>Relations + Validity<br/>HNSW Indices<br/>Datalog/Graph)]
317
+
318
+ Client -->|stdio| Server
319
+ Server --> Services
320
+ Services --> Embeddings
321
+ Services --> Search
322
+ Services --> Cache
323
+ Services --> Inference
324
+ Services --> DB
325
+
326
+ style Client fill:#e1f5ff,color:#000
327
+ style Server fill:#fff4e1,color:#000
328
+ style Services fill:#f0e1ff,color:#000
329
+ style DB fill:#e1ffe1,color:#000
656
330
  ```
657
331
 
658
- | Backend | Status | Recommendation |
659
- | :--- | :--- | :--- |
660
- | **SQLite** | Active (Default) | Standard for desktop/local usage. |
661
- | **RocksDB** | Prepared & Tested | For high-performance or very large datasets. |
662
- | **MDBX** | Not supported | Requires manual build of `cozo-node` from source. |
663
-
664
- ### Environment Variables
665
-
666
- | Variable | Default | Description |
667
- |----------|---------|-------------|
668
- | `DB_ENGINE` | `sqlite` | Database backend: `sqlite` or `rocksdb` |
669
- | `EMBEDDING_MODEL` | `Xenova/bge-m3` | Embedding model (see [Embedding Model Options](#embedding-model-options)) |
670
- | `PORT` | `3001` | HTTP API bridge port (if using `npm run bridge`) |
332
+ > **See [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md) for detailed architecture documentation**
671
333
 
672
- ---
334
+ ## MCP Tools Overview
673
335
 
674
- ## Data Model
675
-
676
- CozoDB Relations (simplified) โ€“ all write operations create new `Validity` entries (Time-Travel):
677
- - `entity`: `id`, `created_at: Validity` โ‡’ `name`, `type`, `embedding(1024)`, `name_embedding(1024)`, `metadata(Json)`
678
- - `observation`: `id`, `created_at: Validity` โ‡’ `entity_id`, `text`, `embedding(1024)`, `metadata(Json)`
679
- - `relationship`: `from_id`, `to_id`, `relation_type`, `created_at: Validity` โ‡’ `strength(0..1)`, `metadata(Json)`
680
- - `entity_community`: `entity_id` โ‡’ `community_id` (Key-Value Mapping from LabelPropagation)
681
- - `memory_snapshot`: `snapshot_id` โ‡’ Counts + `metadata` + `created_at(Int)`
682
-
683
- ## MCP Tools
684
-
685
- The interface is reduced to **4 consolidated tools**. The concrete operation is always chosen via `action`.
336
+ The interface is reduced to **4 consolidated tools**:
686
337
 
687
338
  | Tool | Purpose | Key Actions |
688
339
  |------|---------|-------------|
689
- | `mutate_memory` | Write operations | create_entity, update_entity, delete_entity, add_observation, create_relation, start_session, stop_session, start_task, stop_task, run_transaction, add_inference_rule, ingest_file, invalidate_observation, invalidate_relation |
690
- | `query_memory` | Read operations | search, advancedSearch, context, entity_details, history, graph_rag, graph_walking, agentic_search, dynamic_fusion, adaptive_retrieval (Multi-Level Context support) |
691
- | `analyze_graph` | Graph analysis | explore, communities, pagerank, betweenness, hits, shortest_path, bridge_discovery, semantic_walk, infer_relations |
692
- | `manage_system` | Maintenance | health, metrics, export_memory, import_memory, snapshot_create, snapshot_list, snapshot_diff, cleanup, defrag, reflect, summarize_communities, clear_memory, compact |
693
-
694
- ### mutate_memory (Write)
695
-
696
- Actions:
697
- - `create_entity`: `{ name, type, metadata? }`
698
- - `update_entity`: `{ id, name?, type?, metadata? }`
699
- - `delete_entity`: `{ entity_id }`
700
- - `add_observation`: `{ entity_id?, entity_name?, entity_type?, text, metadata? }`
701
- - `create_relation`: `{ from_id, to_id, relation_type, strength?, metadata? }`
702
- - `start_session`: `{ name?, metadata? }` **(New v2.0)**: Starts a new session context (metadata can include `user_id`, `project`, etc.)
703
- - `stop_session`: `{ session_id }` **(New v2.0)**: Closes/archives an active session.
704
- - `start_task`: `{ name, session_id?, metadata? }` **(New v2.0)**: Starts a specific task within a session.
705
- - `stop_task`: `{ task_id }` **(New v2.0)**: Marks a task as completed.
706
- - `run_transaction`: `{ operations: Array<{ action, params }> }` **(New v1.2)**: Executes multiple operations atomically.
707
- - `add_inference_rule`: `{ name, datalog }`
708
- - `ingest_file`: `{ format, file_path?, content?, entity_id?, entity_name?, entity_type?, chunking?, metadata?, observation_metadata?, deduplicate?, max_observations? }`
709
- - `invalidate_observation`: `{ observation_id }` **(New v2.1)**: Retracts an observation using Validity `[now, false]`.
710
- - `invalidate_relation`: `{ from_id, to_id, relation_type }` **(New v2.1)**: Retracts a relationship using Validity `[now, false]`.
711
- - `format` options: `"markdown"`, `"json"`, `"pdf"` **(New v1.9)**
712
- - `file_path`: Optional path to file on disk (alternative to `content` parameter)
713
- - `content`: File content as string (required if `file_path` not provided)
714
- - `chunking` options: `"none"`, `"paragraphs"` (future: `"semantic"`)
715
-
716
- Important Details:
717
- - `run_transaction` supports `create_entity`, `add_observation`, and `create_relation`. Parameters are automatically suffixed to avoid collisions.
718
- - `create_relation` rejects self-references (`from_id === to_id`).
719
- - `strength` is optional and defaults to `1.0`.
720
- - `add_observation` additionally provides `inferred_suggestions` (suggestions from the Inference Engine).
721
- - `add_observation` performs deduplication (exact + semantic via LSH). If duplicates are found, returns `status: "duplicate_detected"` with `existing_observation_id` and an estimated `similarity`.
722
- - `update_entity` uses the JSON Merge Operator `++` (v0.7) to merge existing metadata with new values instead of overwriting them.
723
- - `add_inference_rule` validates Datalog code upon saving. Invalid syntax or missing required columns result in an error.
724
-
725
- Examples:
726
-
727
- ```json
728
- { "action": "create_entity", "name": "Alice", "type": "Person", "metadata": { "role": "Dev" } }
729
- ```
340
+ | `mutate_memory` | Write operations | create_entity, update_entity, delete_entity, add_observation, create_relation, transactions, sessions, tasks |
341
+ | `query_memory` | Read operations | search, advancedSearch, context, graph_rag, graph_walking, agentic_search, adaptive_retrieval |
342
+ | `analyze_graph` | Graph analysis | explore, communities, pagerank, betweenness, hits, shortest_path, semantic_walk |
343
+ | `manage_system` | Maintenance | health, metrics, export, import, cleanup, defrag, reflect, snapshots |
730
344
 
731
- ```json
732
- { "action": "add_observation", "entity_id": "ENTITY_ID", "text": "Alice is working on the feature flag system." }
733
- ```
734
-
735
- Example (Duplicate):
736
-
737
- ```json
738
- { "action": "add_observation", "entity_id": "ENTITY_ID", "text": "Alice is working on the feature flag system." }
739
- ```
740
-
741
- ```json
742
- { "status": "duplicate_detected", "existing_observation_id": "OBS_ID", "similarity": 1 }
743
- ```
744
-
745
- ```json
746
- { "action": "create_relation", "from_id": "ALICE_ID", "to_id": "PROJ_ID", "relation_type": "works_on", "strength": 1.0 }
747
- ```
748
-
749
- Custom Datalog Rules (Inference):
750
-
751
- - Inference rules are stored as `action: "add_inference_rule"`.
752
- - The Datalog query must return a result set with **exactly these 5 columns**: `from_id, to_id, relation_type, confidence, reason`.
753
- - `$id` is the placeholder for the entity ID for which inference is started.
754
-
755
- Example (Transitive Manager โ‡’ Upper Manager):
756
-
757
- ```json
758
- {
759
- "action": "add_inference_rule",
760
- "name": "upper_manager",
761
- "datalog": "?[from_id, to_id, relation_type, confidence, reason] :=\n *relationship{from_id: $id, to_id: mid, relation_type: \"manager_of\", @ \"NOW\"},\n *relationship{from_id: mid, to_id: target, relation_type: \"manager_of\", @ \"NOW\"},\n from_id = $id,\n to_id = target,\n relation_type = \"upper_manager_of\",\n confidence = 0.6,\n reason = \"Transitive manager path found\""
762
- }
763
- ```
764
-
765
- Bulk Ingestion (Markdown/JSON/PDF):
766
-
767
- ```json
768
- {
769
- "action": "ingest_file",
770
- "entity_name": "Project Documentation",
771
- "format": "markdown",
772
- "chunking": "paragraphs",
773
- "content": "# Title\n\nSection 1...\n\nSection 2...",
774
- "deduplicate": true,
775
- "max_observations": 50
776
- }
777
- ```
778
-
779
- PDF Ingestion via File Path:
780
-
781
- ```json
782
- {
783
- "action": "ingest_file",
784
- "entity_name": "Research Paper",
785
- "format": "pdf",
786
- "file_path": "/path/to/document.pdf",
787
- "chunking": "paragraphs",
788
- "deduplicate": true
789
- }
790
- ```
791
-
792
- ### query_memory (Read)
793
-
794
- Actions:
795
- - `search`: `{ query, limit?, entity_types?, include_entities?, include_observations?, rerank? }`
796
- - `advancedSearch`: `{ query, limit?, filters?, graphConstraints?, vectorOptions?, rerank? }`
797
- - `context`: `{ query, context_window?, time_range_hours? }`
798
- - `entity_details`: `{ entity_id, as_of? }`
799
- - `history`: `{ entity_id }`
800
- - `graph_rag`: `{ query, max_depth?, limit?, filters?, rerank? }` Graph-based reasoning. Finds vector seeds (with inline filtering) first and then expands transitive relationships. Uses recursive Datalog for efficient BFS expansion.
801
- - `graph_walking`: `{ query, start_entity_id?, max_depth?, limit? }` (v1.7) Recursive semantic graph search. Starts at vector seeds or a specific entity and follows relationships to other semantically relevant entities. Ideal for deeper path exploration.
802
- - `agentic_search`: `{ query, limit?, rerank? }` **(New v2.0)**: **Auto-Routing Search**. Uses a local LLM (Ollama) to analyze query intent and automatically routes it to the most appropriate strategy (`vector_search`, `graph_walk`, or `community_summary`).
803
- - `adaptive_retrieval`: `{ query, limit? }` **(New v2.6)**: **GraphRAG-R1 Adaptive Retrieval**. Intelligent system inspired by GraphRAG-R1 (Yu et al., WWW 2026) that automatically classifies query complexity (Simple/Moderate/Complex/Exploratory) and selects the optimal retrieval strategy from 5 options (Vector-Only, Graph-Walk, Hybrid-Fusion, Community-Expansion, Semantic-Walk). Features Progressive Retrieval Attenuation (PRA) to prevent over-retrieval and Cost-Aware F1 (CAF) scoring to balance answer quality with computational cost. Learns from usage and adapts strategy selection based on historical performance stored in CozoDB.
804
- - `dynamic_fusion`: `{ query, config?, limit? }` **(New v2.3)**: **Dynamic Fusion Framework**. Combines 4 retrieval paths (Dense Vector, Sparse Vector, FTS, Graph) with configurable weights and fusion strategies. Inspired by Allan-Poe (arXiv:2511.00855).
805
- - `get_relation_evolution`: `{ from_id, to_id?, since?, until? }` (in `analyze_graph`) Shows temporal development of relationships including time range filter and diff summary.
806
-
807
- Important Details:
808
- - `advancedSearch` allows precise filtering:
809
- - `filters.entityTypes`: List of entity types.
810
- - `filters.metadata`: Key-Value Map for exact metadata matches.
811
- - `graphConstraints.requiredRelations`: Only entities having certain relationships.
812
- - `graphConstraints.targetEntityIds`: Only entities connected to these target IDs.
813
- - `context` returns a JSON object with entities, observations, graph connections, and inference suggestions.
814
- - `search` uses RRF (Reciprocal Rank Fusion) to mix vector and keyword signals.
815
- - `graph_rag` combines vector search with graph-based traversals (default depth 2) for "structured reasoning". Expansion is bidirectional across all relationship types.
816
- - **User Profiling**: Results linked to the `global_user_profile` entity are automatically preferred (boosted).
817
- - `time_range_hours` filters candidate results in the time window (in hours, can be float).
818
- - `as_of` accepts ISO strings or `"NOW"`; invalid format results in an error.
819
- - If status contradictions are detected, optional `conflict_flag` is attached to entities/observations; `context` additionally provides `conflict_flags` as a summary.
820
-
821
- Examples:
822
-
823
- ```json
824
- { "action": "search", "query": "Feature Flag", "limit": 10 }
825
- ```
826
-
827
- ```json
828
- {
829
- "action": "advancedSearch",
830
- "query": "Manager",
831
- "filters": { "metadata": { "role": "Lead" } },
832
- "graphConstraints": { "requiredRelations": ["works_with"] }
833
- }
834
- ```
835
-
836
- ```json
837
- { "action": "graph_rag", "query": "What is Alice working on?", "max_depth": 2 }
838
- ```
839
-
840
- ```json
841
- { "action": "context", "query": "What is Alice working on right now?", "context_window": 20 }
842
- ```
843
-
844
- #### Dynamic Fusion Framework (v2.3)
845
-
846
- The Dynamic Fusion Framework combines 4 retrieval paths with configurable weights and fusion strategies:
847
-
848
- **Retrieval Paths:**
849
- 1. **Dense Vector Search (HNSW)**: Semantic similarity via embeddings
850
- 2. **Sparse Vector Search**: Keyword-based matching with TF-IDF scoring
851
- 3. **Full-Text Search (FTS)**: BM25 scoring on entity names
852
- 4. **Graph Traversal**: Multi-hop relationship expansion from vector seeds
853
-
854
- **Fusion Strategies:**
855
- - `rrf` (Reciprocal Rank Fusion): Combines rankings with position-based scoring
856
- - `weighted_sum`: Direct weighted combination of scores
857
- - `max`: Takes maximum score across all paths
858
- - `adaptive`: Query-dependent weighting (future enhancement)
859
-
860
- **Configuration Example:**
861
-
862
- ```json
863
- {
864
- "action": "dynamic_fusion",
865
- "query": "database with graph capabilities",
866
- "limit": 10,
867
- "config": {
868
- "vector": {
869
- "enabled": true,
870
- "weight": 0.4,
871
- "topK": 20,
872
- "efSearch": 100
873
- },
874
- "sparse": {
875
- "enabled": true,
876
- "weight": 0.3,
877
- "topK": 20,
878
- "minScore": 0.1
879
- },
880
- "fts": {
881
- "enabled": true,
882
- "weight": 0.2,
883
- "topK": 20,
884
- "fuzzy": true
885
- },
886
- "graph": {
887
- "enabled": true,
888
- "weight": 0.1,
889
- "maxDepth": 2,
890
- "maxResults": 20,
891
- "relationTypes": ["related_to", "uses"]
892
- },
893
- "fusion": {
894
- "strategy": "rrf",
895
- "rrfK": 60,
896
- "minScore": 0.0,
897
- "deduplication": true
898
- }
899
- }
900
- }
901
- ```
902
-
903
- **Response includes:**
904
- - `results`: Fused and ranked results with path contribution details
905
- - `stats`: Performance metrics including:
906
- - `totalResults`: Number of results after fusion
907
- - `pathContributions`: Count of results from each path
908
- - `fusionTime`: Total execution time
909
- - `pathTimes`: Individual execution times per path
910
-
911
- **Use Cases:**
912
- - **Broad Exploration**: Enable all paths with balanced weights
913
- - **Precision Search**: High vector weight, low graph weight
914
- - **Relationship Discovery**: High graph weight with specific relation types
915
- - **Keyword Matching**: High sparse/FTS weights for exact term matching
916
-
917
- ```json
918
-
919
- #### Conflict Detection (Status)
920
-
921
- If there are contradictory statements about the status of an entity, a conflict is marked. The system considers **temporal consistency**:
922
-
923
- - **Status Contradiction**: An entity has both "active" and "inactive" status in the **same calendar year**.
924
- - **Status Change (No Conflict)**: If statements are from different years (e.g., 2024 "discontinued", 2025 "active"), this is interpreted as a legitimate change and **not** marked as a conflict.
925
-
926
- The detection uses regex matching on keywords like:
927
- - **Active**: active, running, ongoing, in operation, continued, not discontinued.
928
- - **Inactive**: discontinued, cancelled, stopped, shut down, closed, deprecated, archived, ended, abandoned.
929
-
930
- **Integration in API Responses:**
931
- - `entities[i].conflict_flag` or `observations[i].conflict_flag`: Flag directly on the match.
932
- - `conflict_flags`: List of all detected conflicts in `context` or `search` result.
933
-
934
- ### analyze_graph (Analysis)
935
-
936
- Actions:
937
- - `explore`: `{ start_entity, end_entity?, max_hops?, relation_types? }`
938
- - with `end_entity`: shortest path (BFS)
939
- - without `end_entity`: Neighborhood up to max. 5 hops (aggregated by minimal hop count)
940
- - `communities`: `{}` recalculates communities and writes `entity_community`
941
- - `pagerank`: `{}` Calculates PageRank scores for all entities.
942
- - `betweenness`: `{}` Calculates Betweenness Centrality (centrality measure for bridge elements).
943
- - `hits`: `{}` Calculates HITS scores (Hubs & Authorities).
944
- - `connected_components`: `{}` Identifies isolated subgraphs.
945
- - `shortest_path`: `{ start_entity, end_entity }` Calculates shortest path via Dijkstra (incl. distance and path reconstruction).
946
- - `bridge_discovery`: `{}` Searches for entities acting as bridges between isolated communities (high Betweenness relevance).
947
- - `semantic_walk`: `{ start_entity, max_depth?, min_similarity? }` (v1.7) Recursive semantic graph search. Starts at an entity and recursively follows paths consisting of explicit relationships AND semantic similarity (vector distance). Finds "associative paths" in the knowledge graph.
948
- - `hnsw_clusters`: `{}` Analyzes clusters directly on the HNSW graph (Layer 0). Extremely fast as no vector calculations are needed.
949
- - `infer_relations`: `{ entity_id }` provides suggestions from multiple strategies.
950
- - `get_relation_evolution`: `{ from_id, to_id?, since?, until? }` shows temporal development of relationships including time range filter and diff summary.
951
-
952
- Examples:
953
-
954
- ```json
955
- { "action": "shortest_path", "start_entity": "ID_A", "end_entity": "ID_B" }
956
- ```
957
-
958
- ```json
959
- { "action": "explore", "start_entity": "ENTITY_ID", "max_hops": 3 }
960
- ```
961
-
962
- ### manage_system (Maintenance)
963
-
964
- Actions:
965
- - `health`: `{}` returns DB counts + embedding cache stats + performance metrics.
966
- - `metrics`: `{}` returns detailed operation counts, error statistics, and performance data.
967
- - `export_memory`: `{ format, includeMetadata?, includeRelationships?, includeObservations?, entityTypes?, since? }` exports memory to various formats.
968
- - `import_memory`: `{ data, sourceFormat, mergeStrategy?, defaultEntityType? }` imports memory from external sources.
969
- - `snapshot_create`: `{ metadata? }`
970
- - `snapshot_list`: `{}`
971
- - `snapshot_diff`: `{ snapshot_id_a, snapshot_id_b }`
972
- - `cleanup`: `{ confirm, older_than_days?, max_observations?, min_entity_degree?, model? }`
973
- - `defrag`: `{ confirm, similarity_threshold?, min_island_size? }` **(New v2.3)**: Memory defragmentation. Reorganizes memory structure by:
974
- - **Duplicate Detection**: Finds and merges near-duplicate observations using cosine similarity (threshold 0.8-1.0, default 0.95)
975
- - **Island Connection**: Connects small knowledge islands (โ‰ค3 nodes) to main graph via semantic bridges
976
- - **Orphan Removal**: Deletes orphaned entities without observations or relations
977
- - With `confirm: false`: Dry-run mode showing candidates without making changes
978
- - With `confirm: true`: Executes defragmentation and returns statistics
979
- - `compact`: `{ session_id?, entity_id?, model? }` **(New v2.2)**: Manual context compaction. Supports three modes:
980
- - **Session Compaction**: `{ session_id, model? }` - Summarizes session observations into 2-3 bullet points and stores in user profile
981
- - **Entity Compaction**: `{ entity_id, model? }` - Compacts entity observations when threshold exceeded, creates Executive Summary
982
- - **Global Compaction**: `{}` (no parameters) - Compacts all entities exceeding threshold (default: 20 observations)
983
- - `summarize_communities`: `{ model?, min_community_size? }` **(New v2.0)**: Triggers the **Hierarchical GraphRAG** pipeline. Recomputes communities, generates thematic summaries via LLM, and stores them as `CommunitySummary` entities.
984
- - `reflect`: `{ entity_id?, mode?, model? }` Analyzes memory for contradictions and new insights. Supports `summary` (default) and `discovery` (autonomous link refinement) modes.
985
- - `clear_memory`: `{ confirm }`
986
-
987
- Janitor Cleanup Details:
988
- - `cleanup` supports `dry_run`: with `confirm: false` only candidates are listed.
989
- - With `confirm: true`, the Janitor becomes active:
990
- - **Hierarchical Summarization**: Detects isolated or old observations, has them summarized by a local LLM (Ollama), and creates a new `ExecutiveSummary` node. Old fragments are deleted to reduce noise while preserving knowledge.
991
- - **Automated Session Compression**: Automatically identifies inactive sessions, summarizes their activity into a few bullet points, and stores the summary in the User Profile while marking the session as archived.
992
-
993
- Context Compaction Details **(New v2.2)**:
994
- - **Automatic Compaction**: Triggered automatically when observations exceed threshold (default: 20)
995
- - Runs in background during `addObservation`
996
- - Uses lock mechanism to prevent concurrent compaction
997
- - **Manual Compaction**: Available via `compact` action in `manage_system`
998
- - **Session Mode**: Summarizes session observations and stores in `global_user_profile`
999
- - **Entity Mode**: Compacts specific entity with custom threshold
1000
- - **Global Mode**: Compacts all entities exceeding threshold
1001
- - **Progressive Summarization**: New observations are merged with existing Executive Summaries instead of simple append
1002
- - **LLM Integration**: Uses Ollama (default model: `demyagent-4b-i1:Q6_K`) for intelligent summarization
1003
-
1004
- **Before Janitor:**
1005
- ```
1006
- Entity: Project X
1007
- โ”œโ”€ Observation 1: "Started in Q1" (90 days old, isolated)
1008
- โ”œโ”€ Observation 2: "Uses React" (85 days old, isolated)
1009
- โ”œโ”€ Observation 3: "Team of 5" (80 days old, isolated)
1010
- โ””โ”€ Observation 4: "Deployed to staging" (75 days old, isolated)
1011
- ```
1012
-
1013
- **After Janitor:**
1014
- ```
1015
- Entity: Project X
1016
- โ””โ”€ ExecutiveSummary: "Project X is a React-based application started in Q1
1017
- with a team of 5 developers, currently deployed to staging environment."
1018
- ```
1019
-
1020
- ### Self-Improving Memory Loop (`reflect`)
1021
- The `reflect` service analyzes observations of an entity (or top 5 active entities) to find contradictions, patterns, or temporal developments.
1022
- - **Modes**:
1023
- - `summary` (default): Generates a textual "Reflective Insight" observation.
1024
- - `discovery`: Autonomously finds potential relationships using the Inference Engine and validates them via LLM.
1025
- - High-confidence links (>0.8) are created automatically.
1026
- - Medium-confidence links (>0.5) are returned as suggestions.
1027
- - Results are persisted as new observations (for `summary`) or relationships (for `discovery`) with metadata field `{ "kind": "reflection" }` or `{ "source": "reflection" }`.
1028
- - Text is stored with prefix `Reflective Insight: `.
1029
-
1030
- Defaults: `older_than_days=30`, `max_observations=20`, `min_entity_degree=2`, `model="demyagent-4b-i1:Q6_K"`.
1031
-
1032
- Export/Import Details:
1033
- - `export_memory` supports three formats:
1034
- - **JSON** (`format: "json"`): Native Cozo format, fully re-importable with all metadata and timestamps.
1035
- - **Markdown** (`format: "markdown"`): Human-readable document with entities, observations, and relationships.
1036
- - **Obsidian** (`format: "obsidian"`): ZIP archive with Wiki-Links `[[Entity]]`, YAML frontmatter, ready for Obsidian vault.
1037
- - `import_memory` supports four source formats:
1038
- - **Cozo** (`sourceFormat: "cozo"`): Import from native JSON export.
1039
- - **Mem0** (`sourceFormat: "mem0"`): Import from Mem0 format (user_id becomes entity).
1040
- - **MemGPT** (`sourceFormat: "memgpt"`): Import from MemGPT archival/recall memory.
1041
- - **Markdown** (`sourceFormat: "markdown"`): Parse markdown sections as entities with observations.
1042
- - Merge strategies: `skip` (default, skip duplicates), `overwrite` (replace existing), `merge` (combine metadata).
1043
- - Optional filters: `entityTypes` (array), `since` (Unix timestamp in ms), `includeMetadata`, `includeRelationships`, `includeObservations`.
1044
-
1045
- Example Export:
1046
- ```json
1047
- {
1048
- "action": "export_memory",
1049
- "format": "obsidian",
1050
- "includeMetadata": true,
1051
- "entityTypes": ["Person", "Project"]
1052
- }
1053
- ```
1054
-
1055
- Example Import:
1056
- ```json
1057
- {
1058
- "action": "import_memory",
1059
- "sourceFormat": "mem0",
1060
- "data": "{\"user_id\": \"alice\", \"memories\": [...]}",
1061
- "mergeStrategy": "skip"
1062
- }
1063
- ```
1064
-
1065
- Production Monitoring Details:
1066
- - `health` provides comprehensive system status including entity/observation/relationship counts, embedding cache statistics, and performance metrics (last operation time, average operation time, total operations).
1067
- - `metrics` returns detailed operational metrics:
1068
- - **Operation Counts**: Tracks create_entity, update_entity, delete_entity, add_observation, create_relation, search, and graph_operations.
1069
- - **Error Statistics**: Total errors and breakdown by operation type.
1070
- - **Performance Metrics**: Last operation duration, average operation duration, and total operations executed.
1071
- - Delete operations now include detailed logging with verification steps and return statistics about deleted data (observations, outgoing/incoming relations).
1072
-
1073
- ## Production Monitoring
1074
-
1075
- The system includes comprehensive monitoring capabilities for production deployments:
1076
-
1077
- ### Metrics Tracking
1078
-
1079
- All operations are automatically tracked with detailed metrics:
1080
- - Operation counts by type (create, update, delete, search, etc.)
1081
- - Error tracking with breakdown by operation
1082
- - Performance metrics (latency, throughput)
1083
-
1084
- ### Health Endpoint
1085
-
1086
- The `health` action provides real-time system status:
1087
- ```json
1088
- { "action": "health" }
1089
- ```
1090
-
1091
- Returns:
1092
- - Database counts (entities, observations, relationships)
1093
- - Embedding cache statistics (hit rate, size)
1094
- - Performance metrics (last operation time, average time, total operations)
1095
-
1096
- ### Metrics Endpoint
1097
-
1098
- The `metrics` action provides detailed operational metrics:
1099
- ```json
1100
- { "action": "metrics" }
1101
- ```
1102
-
1103
- Returns:
1104
- - **operations**: Count of each operation type
1105
- - **errors**: Total errors and breakdown by operation
1106
- - **performance**: Last operation duration, average duration, total operations
1107
-
1108
- ### Enhanced Delete Operations
1109
-
1110
- Delete operations include comprehensive logging and verification:
1111
- - Detailed step-by-step logging with `[Delete]` prefix
1112
- - Counts related data before deletion
1113
- - Verification after deletion
1114
- - Returns statistics: `{ deleted: { observations: N, outgoing_relations: N, incoming_relations: N } }`
1115
-
1116
- Example:
1117
- ```json
1118
- { "action": "delete_entity", "entity_id": "ENTITY_ID" }
1119
- ```
1120
-
1121
- Returns deletion statistics showing exactly what was removed.
1122
-
1123
- ## Multi-Hop Reasoning with Vector Pivots (v2.5)
1124
-
1125
- **Research-backed implementation** based on HopRAG (ACL 2025), Retrieval Pivot Attacks (arXiv:2602.08668), and Neo4j GraphRAG patterns.
1126
-
1127
- ### Retrieve-Reason-Prune Pipeline
1128
-
1129
- 1. **RETRIEVE**: Find semantic pivot points via HNSW vector search
1130
- 2. **REASON**: Logic-aware graph traversal with relationship context
1131
- 3. **PRUNE**: Helpfulness scoring combining textual similarity + logical importance
1132
- 4. **AGGREGATE**: Deduplicate and rank entities by occurrence and confidence
1133
-
1134
- ### Key Features
1135
-
1136
- - **Logic-Aware Traversal**: Considers relationship types, strengths, and PageRank scores
1137
- - **Helpfulness Scoring**: Combines semantic similarity (60%) + logical importance (40%)
1138
- - **Pivot Depth Security**: Enforces max depth limit to prevent uncontrolled graph expansion
1139
- - **Confidence Decay**: Exponential decay (0.9^depth) for recency weighting
1140
- - **Adaptive Pruning**: Filters paths below confidence threshold
1141
-
1142
- ### Usage Example
1143
-
1144
- ```typescript
1145
- const multiHop = new MultiHopVectorPivot(db, embeddingService);
1146
- const result = await multiHop.multiHopVectorPivot(
1147
- "how does deep learning relate to NLP",
1148
- maxHops: 3,
1149
- limit: 10
1150
- );
1151
-
1152
- // Returns:
1153
- // - pivots: Initial vector search results
1154
- // - paths: High-quality reasoning paths
1155
- // - aggregated_results: Ranked entities with scores
1156
- // - total_hops: Maximum traversal depth
1157
- // - execution_time_ms: Performance metrics
1158
- ```
1159
-
1160
- ### Research Foundation
1161
-
1162
- - **HopRAG (ACL 2025)**: Logic-aware RAG with pseudo-queries as edges, achieving 76.78% higher answer accuracy
1163
- - **Retrieval Pivot Attacks**: Security patterns for hybrid RAG systems with boundary enforcement
1164
- - **Neo4j GraphRAG**: Multi-hop reasoning patterns for knowledge graphs
1165
-
1166
- ## Logical Edges from Knowledge Graph (v1.0)
1167
-
1168
- **Research-backed implementation** based on SAGE (ICLR 2026), Metadata Knowledge Graphs (Atlan 2026), and Knowledge Graph Completion research.
1169
-
1170
- ### Five Logical Edge Patterns
1171
-
1172
- 1. **Same Category Edges** - Entities with identical category metadata (confidence: 0.8)
1173
- 2. **Same Type Edges** - Entities of the same type (confidence: 0.7)
1174
- 3. **Hierarchical Edges** - Parent-child relationships from metadata (confidence: 0.9)
1175
- 4. **Contextual Edges** - Entities sharing domain, time period, location, or organization (confidence: 0.7-0.75)
1176
- 5. **Transitive Logical Edges** - Derived from explicit relationships + metadata patterns (confidence: 0.55-0.6)
1177
-
1178
- ### Usage Example
1179
-
1180
- ```typescript
1181
- const logicalEdges = new LogicalEdgesService(db);
1182
-
1183
- // Discover all logical edges for an entity
1184
- const edges = await logicalEdges.discoverLogicalEdges(entityId);
1185
-
1186
- // Optionally materialize as explicit relationships
1187
- const created = await logicalEdges.materializeLogicalEdges(entityId);
1188
-
1189
- // Returns:
1190
- // - from_id, to_id: Entity IDs
1191
- // - relation_type: "same_category", "same_type", "hierarchical", "contextual", "transitive_logical"
1192
- // - confidence: 0.55-0.9 based on pattern
1193
- // - reason: Human-readable explanation
1194
- // - pattern: Pattern type for analysis
1195
- ```
1196
-
1197
- ### Key Features
1198
-
1199
- - **Metadata-Driven**: Discovers relationships from entity metadata without explicit encoding
1200
- - **Multi-Pattern**: Combines 5 different logical inference patterns
1201
- - **Deduplication**: Automatically removes duplicate edges, keeping highest confidence
1202
- - **Materialization**: Optional: create explicit relationships for performance optimization
1203
- - **Explainability**: Each edge includes reason and pattern for interpretability
1204
-
1205
- ### Research Foundation
1206
-
1207
- - **SAGE (ICLR 2026)**: Implicit graph exploration with on-demand edge discovery
1208
- - **Metadata Knowledge Graphs (Atlan 2026)**: Metadata-driven relationship inference
1209
- - **Knowledge Graph Completion (Frontiers 2025)**: Predicting implicit relationships using embeddings
1210
-
1211
- ## Technical Highlights
1212
-
1213
- ### Dual Timestamp Format (v1.9)
1214
-
1215
- All write operations (`create_entity`, `add_observation`, `create_relation`) return timestamps in both formats:
1216
- - `created_at`: Unix microseconds (CozoDB native format, precise for calculations)
1217
- - `created_at_iso`: ISO 8601 string (human-readable, e.g., `"2026-02-28T17:21:19.343Z"`)
1218
-
1219
- This dual format provides maximum flexibility - use Unix timestamps for time calculations and comparisons, or ISO strings for display and logging.
1220
-
1221
- Example response:
1222
- ```json
1223
- {
1224
- "id": "...",
1225
- "created_at": 1772299279343000,
1226
- "created_at_iso": "2026-02-28T17:21:19.343Z",
1227
- "status": "Entity created"
1228
- }
1229
- ```
1230
-
1231
- ### Local ONNX Embeddings (Transformers)
1232
-
1233
- Default Model: `Xenova/bge-m3` (1024 dimensions).
1234
-
1235
- Embeddings are processed on the CPU to ensure maximum compatibility. They are kept in an LRU cache (1000 entries, 1h TTL). On embedding errors, a zero vector is returned to keep tool calls stable.
1236
-
1237
- ### Hybrid Search (Vector + Keyword + Graph + Inference) + RRF
1238
-
1239
- The search combines:
1240
- - Vector similarity via HNSW indices (`~entity:semantic`, `~observation:semantic`)
1241
- - Keyword matching via Regex (`regex_matches(...)`)
1242
- - Graph signal via PageRank (for central entities)
1243
- - Community Expansion: Entities from the community of top seeds are introduced with a boost
1244
- - Inference signal: probabilistic candidates (e.g., `expert_in`) with `confidence` as score
1245
-
1246
- Fusion: Reciprocal Rank Fusion (RRF) across sources `vector`, `keyword`, `graph`, `community`, `inference`.
1247
-
1248
- Temporal Decay (active by default):
1249
- - Before RRF fusion, scores are dampened based on time (`created_at`).
1250
- - Half-life: 90 days (exponential decay), with source-specific floors:
1251
- - `keyword`: no decay (corresponds to "explicitly searched")
1252
- - `graph`/`community`: at least 0.6
1253
- - `vector`: at least 0.2
1254
-
1255
- Uncertainty/Transparency:
1256
- - Inference candidates are marked as `source: "inference"` and provide a short reason (uncertainty hint) in the result.
1257
- - In `context` output, inferred entities additionally carry an `uncertainty_hint` so an LLM can distinguish "hard fact" vs. "conjecture".
1258
-
1259
- ### Tiny Learned Reranker (Cross-Encoder)
1260
-
1261
- For maximum precision, CozoDB Memory integrates a specialized **Cross-Encoder Reranker** (Phase 2 RAG).
1262
-
1263
- - **Model**: `Xenova/ms-marco-MiniLM-L-6-v2` (Local ONNX)
1264
- - **Mechanism**: After initial hybrid retrieval, the top candidates (up to 30) are re-evaluated by the cross-encoder. Unlike bi-encoders (vectors), cross-encoders process query and document simultaneously, capturing deep semantic nuances.
1265
- - **Latency**: Minimal overhead (~4-6ms for top 10 candidates).
1266
- - **Supported Tools**: Available as a `rerank: true` parameter in `search`, `advancedSearch`, `graph_rag`, and `agentic_search`.
1267
-
1268
- ### Inference Engine
1269
-
1270
- Inference uses multiple strategies (non-persisting):
1271
- - **Co-occurrence**: Entity names in observation texts (`related_to`, confidence 0.7)
1272
- - **Semantic Proximity**: Similar entities via HNSW (`similar_to`, up to max. 0.9)
1273
- - **Transitivity**: Aโ†’B and Bโ†’C (`potentially_related`, confidence 0.5)
1274
- - **Expertise Rule**: `Person` + `works_on` + `uses_tech` โ‡’ `expert_in` (confidence 0.7)
1275
- - **Query-Triggered Expertise**: Search queries with keywords like `expert`, `skill`, `knowledge`, `competence` automatically trigger a dedicated expert search over the graph network.
1276
-
1277
- ## Optional: HTTP API Bridge
1278
-
1279
- ### API Bridge
1280
-
1281
- For Tools, there is an Express server embedding the `MemoryServer` directly.
1282
-
1283
- Start:
1284
-
1285
- ```bash
1286
- npm run bridge
1287
- ```
1288
-
1289
- Configuration:
1290
- - Port via `PORT` (Default: `3001`)
1291
-
1292
- Selected Endpoints (Prefix `/api`):
1293
- - `GET /entities`, `POST /entities`, `GET /entities/:id`, `DELETE /entities/:id`
1294
- - `POST /observations`
1295
- - `GET /search`, `GET /context`
1296
- - `GET /health`
1297
- - `GET /snapshots`, `POST /snapshots`
1298
-
1299
- ## Development
1300
-
1301
- ### Structure
1302
- - `src/index.ts`: MCP Server + Tool Registration + Schema Setup
1303
- - `src/embedding-service.ts`: Embedding Pipeline + LRU Cache
1304
- - `src/hybrid-search.ts`: Search Strategies + RRF + Community Expansion
1305
- - `src/inference-engine.ts`: Inference Strategies
1306
- - `src/api_bridge.ts`: Express API Bridge (for UI)
1307
-
1308
- ### Scripts (Root)
1309
- - `npm run build`: TypeScript Build
1310
- - `npm run dev`: ts-node Start of MCP Server
1311
- - `npm run start`: Starts `dist/index.js` (stdio)
1312
- - `npm run bridge`: Build + Start of API Bridge (`dist/api_bridge.js`)
1313
- - `npm run benchmark`: Runs performance tests
1314
-
1315
- ## User Preference Profiling (Mem0-Style)
1316
-
1317
- The system maintains a persistent profile of the user (preferences, dislikes, work style) via the specialized entity `global_user_profile`.
1318
-
1319
- - **Benefit**: Personalization without manual search ("I know you prefer TypeScript").
1320
- - **Mechanism**: All observations assigned to this entity receive a significant boost in search and context queries.
1321
- - **Initialization**: The profile is automatically created on first start.
1322
-
1323
- ### Manual Profile Editing
1324
-
1325
- You can now directly edit the user profile using the `edit_user_profile` MCP tool:
1326
-
1327
- ```typescript
1328
- // View current profile
1329
- { }
1330
-
1331
- // Update metadata
1332
- {
1333
- metadata: { timezone: "Europe/Berlin", language: "de" }
1334
- }
1335
-
1336
- // Add preferences
1337
- {
1338
- observations: [
1339
- { text: "Prefers TypeScript over JavaScript" },
1340
- { text: "Likes concise documentation" }
1341
- ]
1342
- }
1343
-
1344
- // Clear and reset preferences
1345
- {
1346
- clear_observations: true,
1347
- observations: [{ text: "New preference" }]
1348
- }
1349
-
1350
- // Update name and type
1351
- {
1352
- name: "Developer Profile",
1353
- type: "UserProfile"
1354
- }
1355
- ```
1356
-
1357
- **Note**: You can still use the implicit method via `mutate_memory` with `action='add_observation'` and `entity_id='global_user_profile'`.
1358
-
1359
- ### Manual Tests
1360
-
1361
- There are various test scripts for different features:
1362
-
1363
- ```bash
1364
- # Tests edge cases and basic operations
1365
- npx ts-node src/test-edge-cases.ts
1366
-
1367
- # Tests hybrid search and context retrieval
1368
- npx ts-node src/test-context.ts
1369
-
1370
- # Tests memory reflection (requires Ollama)
1371
- npx ts-node test-reflection.ts
1372
-
1373
- # Tests user preference profiling and search boost
1374
- npx ts-node test-user-pref.ts
1375
-
1376
- # Tests manual user profile editing
1377
- npx ts-node src/test-user-profile.ts
1378
- ```
345
+ > **See [docs/API.md](docs/API.md) for complete API reference with all parameters and examples**
1379
346
 
1380
347
  ## Troubleshooting
1381
348
 
@@ -1400,9 +367,42 @@ npx ts-node src/test-user-profile.ts
1400
367
  - Use `health` action to check cache hit rates
1401
368
  - Consider RocksDB backend for datasets > 100k entities
1402
369
 
1403
- ## Roadmap
370
+ > **See [docs/BENCHMARKS.md](docs/BENCHMARKS.md) for performance optimization tips**
371
+
372
+ ## Documentation
1404
373
 
1405
- CozoDB Memory is actively developed. Here's what's planned:
374
+ - **[docs/API.md](docs/API.md)** - Complete MCP tools reference with all parameters and examples
375
+ - **[docs/ARCHITECTURE.md](docs/ARCHITECTURE.md)** - System architecture, data model, and technical details
376
+ - **[docs/BENCHMARKS.md](docs/BENCHMARKS.md)** - Performance metrics, evaluation results, and optimization tips
377
+ - **[docs/FEATURES.md](docs/FEATURES.md)** - Detailed feature documentation with usage examples
378
+ - **[docs/USER-PROFILING.md](docs/USER-PROFILING.md)** - User preference profiling and personalization
379
+ - **[CHANGELOG.md](CHANGELOG.md)** - Version history and release notes
380
+ - **[CONTRIBUTING.md](CONTRIBUTING.md)** - Development guidelines
381
+
382
+ ## Development
383
+
384
+ ### Structure
385
+
386
+ - `src/index.ts`: MCP Server + Tool Registration
387
+ - `src/memory-service.ts`: Core business logic
388
+ - `src/db-service.ts`: Database operations
389
+ - `src/embedding-service.ts`: Embedding Pipeline + Cache
390
+ - `src/hybrid-search.ts`: Search Strategies + RRF
391
+ - `src/inference-engine.ts`: Inference Strategies
392
+ - `src/api_bridge.ts`: Express API Bridge (optional)
393
+
394
+ ### Scripts
395
+
396
+ ```bash
397
+ npm run build # TypeScript Build
398
+ npm run dev # ts-node Start of MCP Server
399
+ npm run start # Starts dist/index.js (stdio)
400
+ npm run bridge # Build + Start of API Bridge
401
+ npm run benchmark # Runs performance tests
402
+ npm run eval # Runs evaluation suite
403
+ ```
404
+
405
+ ## Roadmap
1406
406
 
1407
407
  ### Near-Term (v1.x)
1408
408
 
@@ -1414,35 +414,37 @@ CozoDB Memory is actively developed. Here's what's planned:
1414
414
 
1415
415
  ### Mid-Term (v2.x)
1416
416
 
1417
- - **Multi-Modal Embeddings** - Image and audio embedding support via CLIP/Whisper
1418
- - **Distributed Mode** - Multi-node deployment with CozoDB clustering
1419
- - **Real-Time Sync** - WebSocket-based live updates for collaborative use cases
1420
- - **Advanced Inference** - Causal reasoning, temporal pattern detection
1421
- - **Web UI** - Optional web interface for memory exploration and visualization
1422
-
1423
- ### Long-Term
417
+ - **Multi-Modal Embeddings** - Support for images, audio, code
418
+ - **Distributed Memory** - Sharding and replication for large-scale deployments
419
+ - **Advanced Inference** - Neural-symbolic reasoning, causal inference
420
+ - **Real-Time Sync** - WebSocket-based real-time updates
421
+ - **Web UI** - Browser-based management interface
1424
422
 
1425
- - **Federated Learning** - Privacy-preserving model updates across instances
1426
- - **Custom Embedding Models** - Fine-tune embeddings on domain-specific data
1427
- - **Plugin System** - Extensible architecture for custom tools and integrations
423
+ ### Long-Term (v3.x)
1428
424
 
1429
- ### Community Requests
1430
-
1431
- Have a feature idea? Open an issue with the `enhancement` label or check [Low-Hanging-Fruit.md](Low-Hanging-Fruit.md) for quick wins you can contribute.
425
+ - **Federated Learning** - Privacy-preserving collaborative learning
426
+ - **Quantum-Inspired Algorithms** - Advanced graph algorithms
427
+ - **Multi-Agent Coordination** - Shared memory across multiple agents
1432
428
 
1433
429
  ## Contributing
1434
430
 
1435
- Contributions are welcome! Please read [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines on:
1436
-
1437
- - Setting up the development environment
1438
- - Coding standards and best practices
1439
- - Testing and documentation requirements
1440
- - Pull request process
431
+ Contributions are welcome! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
1441
432
 
1442
433
  ## License
1443
434
 
1444
- This project is licensed under the Apache-2.0 License. See the [LICENSE](LICENSE) file for details.
435
+ Apache 2.0 - See [LICENSE](LICENSE) for details.
436
+
437
+ ## Acknowledgments
1445
438
 
1446
- ## Disclaimer
439
+ Built with:
440
+ - [CozoDB](https://github.com/cozodb/cozo) - Embedded graph database
441
+ - [ONNX Runtime](https://onnxruntime.ai/) - Local embedding generation
442
+ - [Transformers.js](https://huggingface.co/docs/transformers.js) - Xenova/bge-m3 model
443
+ - [FastMCP](https://github.com/jlowin/fastmcp) - MCP server framework
1447
444
 
1448
- Single-User, Local-First: This project was developed to work for a single user and a local installation.
445
+ Research foundations:
446
+ - GraphRAG-R1 (Yu et al., WWW 2026)
447
+ - HopRAG (ACL 2025)
448
+ - T-GRAG (Li et al., 2025)
449
+ - FEEG Framework (Samuel et al., 2026)
450
+ - Allan-Poe (arXiv:2511.00855)