Skip to content

perf(docs): persist the doc-search BM25 index across sessions - #55

Open
pradeepmouli wants to merge 4 commits into
intuit:mainfrom
pradeepmouli:perf/doc-bm25-cache
Open

perf(docs): persist the doc-search BM25 index across sessions#55
pradeepmouli wants to merge 4 commits into
intuit:mainfrom
pradeepmouli:perf/doc-bm25-cache

Conversation

@pradeepmouli

Copy link
Copy Markdown
Contributor

Summary

Doc search (hybrid_doc_search_in_dir) currently rebuilds its entire DocBM25Index in memory on every query — loading all chunks from the store and re-tokenizing the whole corpus — while code search already persists its BM25 index to .infigraph/bm25_cache.bin. This PR gives doc search the same treatment:

  • DocBM25Index gains save/load/docs(). The on-disk format mirrors code search's BM25Index::save idiom (leading version byte + length-prefixed LE binary).
  • hybrid_doc_search_in_dir loads docs_bm25_cache.bin when it is at least as new as docs_embeddings.bin — the same mtime freshness anchor code search uses, so a doc reindex invalidates the cache automatically. On a cache hit the store.get_all_chunks() DB read is skipped too (the cache carries the chunk texts).
  • Miss/stale/corrupt cache → rebuild in memory exactly as before, then a best-effort atomic save (pid-unique temp file + rename). A cache failure can never fail or change a search — results are identical with and without the cache.

Two deliberate hardenings over the idiom being mirrored:

  • load is fully bounds-checked and returns Err (never panics) on truncated/corrupt input, since a bad cache must degrade to a rebuild.
  • The temp-file name is per-process unique, so concurrent searches can't race on the same temp path.

Group/combined doc stores get their own cache automatically (keyed off the store's artifact dir; combined stores publish per-generation directories, so no cross-generation staleness is possible).

Testing

  • 3 new unit tests: save/load round-trip preserves scores; empty/wrong-version/truncated inputs rejected without panic; atomic save leaves no temp file.
  • 3 new integration tests against a real DocStore: first search writes the cache and repeat results are identical; corrupt cache falls back silently and is rewritten; stale cache (newer embeddings) is rebuilt.
  • Full infigraph-docs suite: 93/93 passing on this branch (rebased on current main); cargo fmt/clippy -D warnings/cargo check --workspace clean.

🤖 Generated with Claude Code

https://claude.ai/code/session_01SjmvwHuwV5r7ZeZpJLp5oR

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant