feat: add embedding cache to skip re-embedding unchanged code chunks#41
Closed
rajkumarsakthivel wants to merge 2 commits into
Closed
feat: add embedding cache to skip re-embedding unchanged code chunks#41rajkumarsakthivel wants to merge 2 commits into
rajkumarsakthivel wants to merge 2 commits into
Conversation
Content-hash-keyed SQLite cache so identical code is never re-embedded across index runs. On re-index, only cache misses go through the model. Shows cache hit rate in `cce index` output and cache stats in `cce status`. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
fazleelahhee
added a commit
that referenced
this pull request
Apr 27, 2026
Skip re-embedding chunks whose content is unchanged across index runs. SQLite store keyed by SHA-256 of chunk content; on re-index, only cache misses go through the embedding model. On a typical re-index after editing a few files, 95%+ of embeddings come from cache. Ported from #41 (rajkumarsakthivel) with the following improvements: 1. **Binary float32 storage instead of JSON.** Vectors go through struct.pack/unpack — same encoding the sqlite-vec store uses elsewhere. ~4× smaller on disk: a 384-dim cache for a 10k-chunk project drops from ~60MB to ~15MB. 2. **Thread-safe SQLite connection.** `check_same_thread=False` matches the rest of the storage layer. The cache is now called from asyncio.to_thread workers (post-parallelism rewrite) — the original would have raised in that path. 3. **try/finally for cache.close().** Pipeline now closes the cache even if recording cache_hits/cache_misses raises after embed(). Guarantees no leaked SQLite handle. 4. **prune_orphans(known_hashes).** New method drops cached entries whose content hash is no longer present in the live index. Pipeline calls it automatically on `cce index --full` so the cache doesn't grow monotonically forever (concrete on a high-churn project: prior to this, every chunk content variant ever seen accumulated). Refuses to operate on an empty known-set as a safety guard. 5. **Tests use pytest.approx for float comparison.** Round-tripping through float32 loses sub-bit precision; exact equality would fail for non-trivial vectors. Added tests for prune_orphans (with the empty-set safety check) — the upstream PR didn't cover pruning. Other surfaces: - `cce status` shows cache size and disk footprint when the cache exists for the current project - `cce index` summary line includes "X% cache hit" when at least one hit was served, so users see the speedup directly - README adds section 7 ("Content-Hash Embedding Cache") and the roadmap entry; section numbers shifted (Cross-Session Memory is now section 8) Tests: 279 passed (267 prior + 12 new), 4:21s. Co-Authored-By: Raj <rajkumar.sakti@gmail.com> Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Owner
|
Thanks Raj — this is a great feature and the design is sound. We've ported it onto PR #42 in commit Four quality improvements on the way over:
Tests pass (279 total, 12 new), and the README section + roadmap entry from your PR are preserved verbatim. Closing in favor of #42. Sorry for the late merge — really nice work. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Content-hash-keyed SQLite cache so identical code is never re-embedded across index runs. On re-index, only cache misses go through the model. Shows cache hit rate in
cce indexoutput and cache stats incce status.