rag-memory-epf-mcp 3.6.0 → 4.0.0

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
@@ -13,7 +13,8 @@ A **project-local RAG memory** MCP server — knowledge graph + multilingual vec
13
13
  - **3-signal hybrid search** — vector similarity (bge-m3, 1024-dim) + FTS5 BM25 keyword matching + knowledge graph re-ranking, combined via Reciprocal Rank Fusion
14
14
  - **100+ languages** — Korean, Chinese, Japanese, Arabic, and more. Cross-lingual search works out of the box.
15
15
  - **Graph-aware scoring** — per-entity geometric decay (0.5^i) with hard cap prevents any single document from dominating results
16
- - **31 MCP tools** — knowledge graph CRUD, document pipeline, hybrid search, multi-hop traversal, graph analytics (centrality / community detection / structure), export/import, temporal queries
16
+ - **38 MCP tools** — knowledge graph CRUD, observation lifecycle (correct / retract / history), document pipeline, hybrid search, multi-hop traversal, graph analytics (centrality / community detection / structure), export/import, temporal queries
17
+ - **Observations that hold their history** — corrections supersede instead of overwrite, search returns only current facts, and every revision keeps its provenance
17
18
  - **Codepoint-safe chunking** — chunk offsets are Unicode codepoints, language-neutral across SQL `substr`, Python slicing, and JS `[...str]` iteration. Korean/CJK/emoji documents stay aligned. Verified by a publish-time invariant test.
18
19
  - **SQLite optimized** — WAL mode, 32MB cache, 256MB mmap, FTS5 triggers, 7 indexes
19
20
  - **MCP SDK 1.27.1** — Tool Annotations (readOnly/destructive/idempotent), latest protocol 2025-11-25
@@ -36,7 +37,7 @@ A **project-local RAG memory** MCP server — knowledge graph + multilingual vec
36
37
 
37
38
  Place this `.mcp.json` in each project folder with its own `DB_FILE_PATH`. Each project maintains completely isolated memory.
38
39
 
39
- ## Tools (31)
40
+ ## Tools (38)
40
41
 
41
42
  ### Knowledge Graph (7)
42
43
  | Tool | Description | Annotation |
@@ -47,7 +48,18 @@ Place this `.mcp.json` in each project folder with its own `DB_FILE_PATH`. Each
47
48
  | `updateRelations` | Update relationship confidence and metadata | idempotent |
48
49
  | `deleteEntities` | Remove entities and relationships | destructive |
49
50
  | `deleteRelations` | Remove specific relationships | destructive |
50
- | `deleteObservations` | Remove specific observations | destructive |
51
+ | `deleteObservations` | **Deprecated** soft-retract shim — see Observation Lifecycle | destructive |
52
+
53
+ ### Observation Lifecycle (7)
54
+ | Tool | Description | Annotation |
55
+ |------|------------|------------|
56
+ | `correctObservation` | Supersede a revision with corrected text, keeping the old one | |
57
+ | `retractObservation` | `active` → `retracted` (hidden from search, kept in history) | |
58
+ | `restoreObservation` | `retracted` → `active` | |
59
+ | `approveObservation` | `provisional` → `active` | |
60
+ | `declineObservation` | `provisional` → `retracted` (reason required) | |
61
+ | `purgeObservation` | Physically delete a revision and its successors (`confirm='PURGE'`) | destructive |
62
+ | `getObservationHistory` | Every revision, status, provenance and event | read-only |
51
63
 
52
64
  ### Document Pipeline (9)
53
65
  | Tool | Description | Annotation |
@@ -121,7 +133,8 @@ storeDocument(id, content, metadata)
121
133
  │ │ ├── chunks (sqlite-vec, 1024-dim) │ │
122
134
  │ │ ├── entity_embeddings (sqlite-vec) │ │
123
135
  │ │ ├── entities_fts + chunks_fts (FTS5) │ │
124
- │ │ └── 11 migrations (auto-applied) │ │
136
+ │ │ ├── observation lifecycle (4 tables) │ │
137
+ │ │ └── 13 migrations (auto-applied) │ │
125
138
  │ └────────────────────────────────────────┘ │
126
139
  │ │
127
140
  │ bge-m3 (ONNX, 100+ langs) │
@@ -140,6 +153,45 @@ storeDocument(id, content, metadata)
140
153
 
141
154
  ## Changelog
142
155
 
156
+ ### v4.0.0
157
+
158
+ **Observation lifecycle (schema v13).** Observations used to be a JSON array of strings on the
159
+ entity row. A correction overwrote a string, so the fact that it *was* a correction disappeared —
160
+ and if you deleted the wrong duplicate, nothing recorded that either. Observations now have stable
161
+ ids, provenance, and a status, and `entities.observations` becomes a projection synthesised from
162
+ the `active` revisions.
163
+
164
+ - **Corrections keep the previous revision.** `correctObservation(observation_id, content, change_kind, reason)`
165
+ marks the old revision `superseded` and inserts a new one that inherits its position in the array,
166
+ so a correction does not reorder anything.
167
+ - **Search returns `active` revisions only.** A retracted or superseded fact stops coming back from
168
+ `openNodes` / `searchNodes` / `readGraph` / `getNeighbors` without being destroyed.
169
+ - **`getObservationHistory({entity_name | observation_id | root_id})` is the only history surface.**
170
+ It always returns `{ roots: [...] }`, one root per logical observation, revisions oldest-first.
171
+ - **State transitions are a table, not a guess**: `retract` / `restore` / `approve` / `decline`.
172
+ `superseded` is terminal. Anything outside the table is rejected.
173
+ - **Provenance**: `addObservations` and `createEntities` accept `sources: [{source_kind, source_ref, source_hash?}]`.
174
+ Repeated content from a *new* source adds evidence to the existing revision instead of a duplicate.
175
+ Unknown provenance is zero source rows — the engine does not invent one.
176
+ - **`observation_ids`**: `addObservations` and `createEntities` return ids aligned 1:1 with the input,
177
+ `null` where no revision was created (dedup or source-only).
178
+ - **`purgeObservation(observation_id, 'PURGE')`** physically deletes, as a suffix purge from the
179
+ target to the newest revision of that root. It is separate, explicit, and almost never what you want.
180
+ - **⚠️ BREAKING**: `deleteObservations` is deprecated. It now performs a soft **retract** instead of
181
+ a delete, and a batch where any item matches two or more active revisions **aborts with zero
182
+ mutations** — v3.6 deleted every duplicate and carried on, but a machine cannot tell which
183
+ revision was meant. Use `retractObservation(observation_id)` to say which one.
184
+ - Migration to v13 writes a recovery point first (`<db>.v12.bak`) using the SQLite Online Backup API,
185
+ and verifies it — `quick_check` plus FTS5's own `integrity-check`, because a snapshot can be
186
+ structurally valid and still have a broken full-text index. **An existing one is never
187
+ overwritten**: the next attempt writes `.bak.1`, then `.bak.2`. Every file in that rotation was
188
+ taken before any schema change, so each is a valid pre-migration snapshot on its own and nothing
189
+ has to prove which matches the live database. Slots are bounded and a full set refuses to migrate.
190
+ Conversion runs in one transaction with two gates: `PRAGMA foreign_key_check`, then a byte-exact
191
+ comparison of the rebuilt projection against the original array. `foreign_keys` is checked at boot
192
+ and the server refuses to migrate without it. Restore and slot-exhaustion runbook:
193
+ `docs/UPDATING.md`.
194
+
143
195
  ### v3.6.0
144
196
  - **Lite install / lazy boot**: the MCP server connects immediately — FTS5 search, knowledge graph and CRUD work from the first second, while the bge-m3 model (~1.2GB) loads or downloads in the background. Hybrid search switches on automatically. Requires Node **>= 24**.
145
197
  - **Version-independent model cache** with a cross-process download lock: engine version bumps no longer re-download the model, and concurrent servers on one machine never corrupt a download. Cleaning the npx cache no longer deletes the model.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env node
2
+ import { type SourceInput } from './src/observations/lifecycle.js';
2
3
  import { EmbeddingGate } from './src/embeddingGate.js';
3
4
  import type { EmbedPriority } from './src/embeddingGate.js';
4
5
  import { BackfillCoordinator } from './src/backfillCoordinator.js';
@@ -59,6 +60,7 @@ export declare class RAGKnowledgeGraphManager {
59
60
  initialize(opts?: {
60
61
  skipModel?: boolean;
61
62
  gate?: EmbeddingGate;
63
+ __testForceFkOff?: boolean;
62
64
  }): Promise<void>;
63
65
  private ensureCurrentProfile;
64
66
  private buildRealLoader;
@@ -67,6 +69,7 @@ export declare class RAGKnowledgeGraphManager {
67
69
  entityInputHash(entityId: string): string | null;
68
70
  tryEmbedEntity(entityId: string, priority?: EmbedPriority): Promise<'embedded' | 'queued' | 'disabled'>;
69
71
  private mutateEntityAndInvalidate;
72
+ private invalidateDerivedForEntity;
70
73
  invalidateEntityVector(entityId: string): void;
71
74
  reembedChunkByRowid(rowid: number): Promise<boolean>;
72
75
  shutdownAll(): Promise<void>;
@@ -80,15 +83,41 @@ export declare class RAGKnowledgeGraphManager {
80
83
  }>;
81
84
  cleanup(): void;
82
85
  private _timestampObservation;
83
- createEntities(entities: Entity[]): Promise<Entity[]>;
86
+ createEntities(entities: Array<Entity & {
87
+ status?: 'active' | 'provisional';
88
+ sources?: SourceInput[];
89
+ }>): Promise<Array<Entity & {
90
+ created?: boolean;
91
+ observation_ids?: (string | null)[];
92
+ }>>;
84
93
  createRelations(relations: Relation[]): Promise<Relation[]>;
85
94
  addObservations(observations: {
86
95
  entityName: string;
87
96
  contents: string[];
88
- }[]): Promise<{
97
+ status?: 'active' | 'provisional';
98
+ sources?: SourceInput[];
99
+ }[]): Promise<Array<{
89
100
  entityName: string;
101
+ observation_ids: (string | null)[];
90
102
  addedObservations: string[];
91
- }[]>;
103
+ embedding_status?: string;
104
+ }>>;
105
+ correctObservation(observationId: string, content: string, changeKind?: 'correction' | 'world_change', reason?: string): Promise<string>;
106
+ private _transition;
107
+ retractObservation(observationId: string, reason?: string): Promise<void>;
108
+ restoreObservation(observationId: string, reason?: string): Promise<void>;
109
+ approveObservation(observationId: string, reason?: string): Promise<void>;
110
+ declineObservation(observationId: string, reason: string): Promise<void>;
111
+ purgeObservation(observationId: string, confirm: string): Promise<{
112
+ purged: number;
113
+ }>;
114
+ getObservationHistory(sel: {
115
+ entity_name?: string;
116
+ observation_id?: string;
117
+ root_id?: string;
118
+ }): Promise<{
119
+ roots: any[];
120
+ }>;
92
121
  deleteEntities(entityNames: string[]): Promise<void>;
93
122
  deleteObservations(deletions: {
94
123
  entityName: string;
@@ -97,7 +126,7 @@ export declare class RAGKnowledgeGraphManager {
97
126
  results: Array<{
98
127
  entityName: string;
99
128
  deleted: number;
100
- embedding_status: 'embedded' | 'queued' | 'disabled' | 'n/a';
129
+ embedding_status: string;
101
130
  }>;
102
131
  total_deleted: number;
103
132
  }>;
@@ -275,6 +304,10 @@ export declare class RAGKnowledgeGraphManager {
275
304
  entities: any[];
276
305
  relations: any[];
277
306
  documents: any[];
307
+ observation_roots: any[];
308
+ entity_observations: any[];
309
+ observation_sources: any[];
310
+ observation_events: any[];
278
311
  metadata: {
279
312
  exportedAt: string;
280
313
  version: string;
@@ -287,6 +320,10 @@ export declare class RAGKnowledgeGraphManager {
287
320
  entities?: any[];
288
321
  relations?: any[];
289
322
  documents?: any[];
323
+ observation_roots?: any[];
324
+ entity_observations?: any[];
325
+ observation_sources?: any[];
326
+ observation_events?: any[];
290
327
  }, options?: {
291
328
  merge?: boolean;
292
329
  }): Promise<{
@@ -300,6 +337,12 @@ export declare class RAGKnowledgeGraphManager {
300
337
  relations: number;
301
338
  documents: number;
302
339
  };
340
+ observation_order_remap: Array<{
341
+ root_id: string;
342
+ entity_id: string;
343
+ from: number;
344
+ to: number;
345
+ }>;
303
346
  }>;
304
347
  hybridSearch(query: string, limit?: number, useGraph?: boolean): Promise<{
305
348
  results: EnhancedSearchResult[];