fix: search index corruption on incremental updates and compile indexing#57
Merged
keeganthomp merged 1 commit intomainfrom Apr 10, 2026
Merged
Conversation
The incremental search index (used by ingest → addDocument → save) had two compounding bugs that caused search to silently degrade after multiple ingests: 1. serialize() used d.tokens.length instead of d.tokenCount — loaded docs have tokens: [] (by design), so every save overwrote real token counts with 0. 2. recomputeIdf() iterated doc.tokens (empty for loaded docs) instead of doc.termFreqs.keys(), so IDF was only computed from the most recently added document, making all prior terms unsearchable. Additionally: - Compile now updates the search index with wiki articles (previously only ingest updated it, so --wiki searches returned nothing after compile). - --wiki/--raw scope flags now filter results from cached indexes (previously scope was only applied during build, not when loading from cache). - Fix all strict TypeScript errors across core and CLI packages. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
Summary
serialize()andrecomputeIdf()both silently broke after 2+ sequential ingests, making most terms unsearchable. The root cause was that loaded documents havetokens: [](an intentional optimization), but two code paths incorrectly usedtokensinstead oftokenCount/termFreqs.kib search --wikireturns results immediately after compile without needing a manual cache clear.--wiki/--rawscope flags now work on cached indexes — previously they were only applied during fresh builds, not when loading from cache.Test plan
bun run check(biome lint) cleantsc --noEmitzero errors for both core and CLI🤖 Generated with Claude Code