cozo-memory 1.1.2 β 1.1.4
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 +356 -5
- package/dist/adaptive-retrieval.js +520 -0
- package/dist/db-inspect.js +25 -0
- package/dist/dynamic-fusion.js +602 -0
- package/dist/hybrid-search.js +4 -4
- package/dist/index.js +699 -23
- package/dist/inference-engine.js +104 -76
- package/dist/logical-edges-service.js +316 -0
- package/dist/multi-hop-vector-pivot.js +390 -0
- package/dist/temporal-embedding-service.js +313 -0
- package/dist/test-adaptive-integration.js +84 -0
- package/dist/test-adaptive-retrieval.js +135 -0
- package/dist/test-compaction.js +91 -0
- package/dist/test-dynamic-fusion.js +231 -0
- package/dist/test-fact-lifecycle.js +82 -0
- package/dist/test-logical-edges.js +282 -0
- package/dist/test-manual-compact.js +95 -0
- package/dist/test-multi-hop-vector-pivot-v2.js +239 -0
- package/dist/test-multi-hop-vector-pivot.js +240 -0
- package/dist/test-temporal-embeddings.js +123 -0
- package/dist/test-validity-retract.js +45 -0
- package/dist/test-validity-rm.js +49 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -59,11 +59,19 @@ Now you can add the server to your MCP client (e.g. Claude Desktop).
|
|
|
59
59
|
|
|
60
60
|
π **Hybrid Search (since v0.7)** - Combines semantic search (HNSW), full-text search (FTS), and graph signals via Reciprocal Rank Fusion (RRF)
|
|
61
61
|
|
|
62
|
-
|
|
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)
|
|
63
|
+
|
|
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
|
|
65
|
+
|
|
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
|
|
67
|
+
|
|
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
|
|
63
69
|
|
|
64
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)
|
|
65
71
|
|
|
66
|
-
|
|
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
|
|
73
|
+
|
|
74
|
+
οΏ½π§ **Multi-Level Memory (v2.0)** - Context-aware memory system with built-insession and task management
|
|
67
75
|
|
|
68
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
|
|
69
77
|
|
|
@@ -81,6 +89,10 @@ Now you can add the server to your MCP client (e.g. Claude Desktop).
|
|
|
81
89
|
|
|
82
90
|
π§Ή **Janitor Service** - LLM-backed automatic cleanup with hierarchical summarization, observation pruning, and **automated session compression**
|
|
83
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
|
+
|
|
84
96
|
π€ **User Preference Profiling** - Persistent user preferences with automatic 50% search boost
|
|
85
97
|
|
|
86
98
|
π **Near-Duplicate Detection** - Automatic LSH-based deduplication to avoid redundancy
|
|
@@ -129,6 +141,10 @@ Now you can add the server to your MCP client (e.g. Claude Desktop).
|
|
|
129
141
|
- **Data Integrity (Trigger Concept)**: Prevents invalid states like self-references in relationships (Self-Loops) directly at creation.
|
|
130
142
|
- **Hierarchical Summarization**: The Janitor condenses old fragments into "Executive Summary" nodes to preserve the "Big Picture" long-term.
|
|
131
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).
|
|
132
148
|
- **All Local**: Embeddings via Transformers/ONNX; no external embedding service required.
|
|
133
149
|
|
|
134
150
|
## Positioning & Comparison
|
|
@@ -350,6 +366,153 @@ EMBEDDING_MODEL=Xenova/all-MiniLM-L6-v2 npm run download-model
|
|
|
350
366
|
|
|
351
367
|
**Note:** Changing models requires re-embedding existing data. The model is downloaded once on first use.
|
|
352
368
|
|
|
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
|
+
```
|
|
378
|
+
|
|
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
|
+
});
|
|
387
|
+
|
|
388
|
+
const memory = new BufferMemory({ chatHistory });
|
|
389
|
+
|
|
390
|
+
// Retriever with hybrid search or Graph-RAG
|
|
391
|
+
const retriever = new CozoMemoryRetriever({
|
|
392
|
+
useGraphRAG: true,
|
|
393
|
+
graphRAGDepth: 2
|
|
394
|
+
});
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
### π¦ LlamaIndex Adapter
|
|
398
|
+
|
|
399
|
+
```bash
|
|
400
|
+
npm install @cozo-memory/llamaindex @cozo-memory/adapters-core
|
|
401
|
+
```
|
|
402
|
+
|
|
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
|
+
});
|
|
411
|
+
|
|
412
|
+
const index = await VectorStoreIndex.fromDocuments(
|
|
413
|
+
documents,
|
|
414
|
+
{ vectorStore }
|
|
415
|
+
);
|
|
416
|
+
```
|
|
417
|
+
|
|
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)
|
|
424
|
+
|
|
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
|
|
439
|
+
|
|
440
|
+
### Architecture
|
|
441
|
+
|
|
442
|
+
```
|
|
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
|
+
|
|
462
|
+
```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:
|
|
492
|
+
|
|
493
|
+
```
|
|
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
|
+
|
|
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
|
|
511
|
+
|
|
512
|
+
```bash
|
|
513
|
+
npx ts-node src/test-temporal-embeddings.ts
|
|
514
|
+
```
|
|
515
|
+
|
|
353
516
|
## Start / Integration
|
|
354
517
|
|
|
355
518
|
### MCP Server (stdio)
|
|
@@ -523,10 +686,10 @@ The interface is reduced to **4 consolidated tools**. The concrete operation is
|
|
|
523
686
|
|
|
524
687
|
| Tool | Purpose | Key Actions |
|
|
525
688
|
|------|---------|-------------|
|
|
526
|
-
| `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 |
|
|
527
|
-
| `query_memory` | Read operations | search, advancedSearch, context, entity_details, history, graph_rag, graph_walking, agentic_search (Multi-Level Context support) |
|
|
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) |
|
|
528
691
|
| `analyze_graph` | Graph analysis | explore, communities, pagerank, betweenness, hits, shortest_path, bridge_discovery, semantic_walk, infer_relations |
|
|
529
|
-
| `manage_system` | Maintenance | health, metrics, export_memory, import_memory, snapshot_create, snapshot_list, snapshot_diff, cleanup, reflect, summarize_communities, clear_memory |
|
|
692
|
+
| `manage_system` | Maintenance | health, metrics, export_memory, import_memory, snapshot_create, snapshot_list, snapshot_diff, cleanup, defrag, reflect, summarize_communities, clear_memory, compact |
|
|
530
693
|
|
|
531
694
|
### mutate_memory (Write)
|
|
532
695
|
|
|
@@ -543,6 +706,8 @@ Actions:
|
|
|
543
706
|
- `run_transaction`: `{ operations: Array<{ action, params }> }` **(New v1.2)**: Executes multiple operations atomically.
|
|
544
707
|
- `add_inference_rule`: `{ name, datalog }`
|
|
545
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]`.
|
|
546
711
|
- `format` options: `"markdown"`, `"json"`, `"pdf"` **(New v1.9)**
|
|
547
712
|
- `file_path`: Optional path to file on disk (alternative to `content` parameter)
|
|
548
713
|
- `content`: File content as string (required if `file_path` not provided)
|
|
@@ -635,6 +800,8 @@ Actions:
|
|
|
635
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.
|
|
636
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.
|
|
637
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).
|
|
638
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.
|
|
639
806
|
|
|
640
807
|
Important Details:
|
|
@@ -674,6 +841,81 @@ Examples:
|
|
|
674
841
|
{ "action": "context", "query": "What is Alice working on right now?", "context_window": 20 }
|
|
675
842
|
```
|
|
676
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
|
+
|
|
677
919
|
#### Conflict Detection (Status)
|
|
678
920
|
|
|
679
921
|
If there are contradictory statements about the status of an entity, a conflict is marked. The system considers **temporal consistency**:
|
|
@@ -728,6 +970,16 @@ Actions:
|
|
|
728
970
|
- `snapshot_list`: `{}`
|
|
729
971
|
- `snapshot_diff`: `{ snapshot_id_a, snapshot_id_b }`
|
|
730
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)
|
|
731
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.
|
|
732
984
|
- `reflect`: `{ entity_id?, mode?, model? }` Analyzes memory for contradictions and new insights. Supports `summary` (default) and `discovery` (autonomous link refinement) modes.
|
|
733
985
|
- `clear_memory`: `{ confirm }`
|
|
@@ -738,6 +990,17 @@ Janitor Cleanup Details:
|
|
|
738
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.
|
|
739
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.
|
|
740
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
|
+
|
|
741
1004
|
**Before Janitor:**
|
|
742
1005
|
```
|
|
743
1006
|
Entity: Project X
|
|
@@ -857,6 +1120,94 @@ Example:
|
|
|
857
1120
|
|
|
858
1121
|
Returns deletion statistics showing exactly what was removed.
|
|
859
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
|
+
|
|
860
1211
|
## Technical Highlights
|
|
861
1212
|
|
|
862
1213
|
### Dual Timestamp Format (v1.9)
|