The agentmemory project currently relies on 3 powerful search mechanisms to build its Hybrid Search and contextual reasoning engine:
1.Vector Search
2.BM25 Search
3.Graph Search
but the problem is that the system performs search indexing and traversal completely in-memory. This creates many critical bottlenecks like
cpu bound operations ,RAM exhaustion ,etc.
i saw this exact same bottleneck in Vector Search, and for that, I created the recent pull request to use sqlite-vec.
The Proposed Solution:
So, for the remaining BM25 Search and Graph Search, we should use SQLite storage instead of in-memory storage.
- BM25
Current: Builds a massive Inverted Index Map in Node.js RAM.
Proposed: Enable SQLite's native FTS5 extension. When memory text is saved, we insert it into an FTS5 virtual table. We simply query: SELECT obs_id FROM bm25_index WHERE text MATCH 'query' ORDER BY bm25(bm25_index) LIMIT 20.
- Graph Search via SQLite CTEs
current: this.kv.list() loads all nodes and edges into RAM to run BFS loops in JavaScript.
Proposed: Mirror nodes and edges into dedicated graph_nodes and graph_edges SQLite tables. Instead of JS loops, we send a WITH RECURSIVE (CTE) query directly to SQLite.
this will dramatically improve performance and solve the current bottlenecks. The main data remains safely in the KV store, but offloading the search logic to SQLite
The agentmemory project currently relies on 3 powerful search mechanisms to build its Hybrid Search and contextual reasoning engine:
1.Vector Search
2.BM25 Search
3.Graph Search
but the problem is that the system performs search indexing and traversal completely in-memory. This creates many critical bottlenecks like
cpu bound operations ,RAM exhaustion ,etc.
i saw this exact same bottleneck in Vector Search, and for that, I created the recent pull request to use sqlite-vec.
The Proposed Solution:
So, for the remaining BM25 Search and Graph Search, we should use SQLite storage instead of in-memory storage.
Current: Builds a massive Inverted Index Map in Node.js RAM.
Proposed: Enable SQLite's native FTS5 extension. When memory text is saved, we insert it into an FTS5 virtual table. We simply query: SELECT obs_id FROM bm25_index WHERE text MATCH 'query' ORDER BY bm25(bm25_index) LIMIT 20.
current: this.kv.list() loads all nodes and edges into RAM to run BFS loops in JavaScript.
Proposed: Mirror nodes and edges into dedicated graph_nodes and graph_edges SQLite tables. Instead of JS loops, we send a WITH RECURSIVE (CTE) query directly to SQLite.
this will dramatically improve performance and solve the current bottlenecks. The main data remains safely in the KV store, but offloading the search logic to SQLite