Skip to content

Architecture: Migrate BM25 & Graph Search from In-Memory to SQLite #309

Description

@Tanmay-008

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.

  1. 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.

  1. 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

No activity

Activity on this issue will appear here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions