fix(evict): keep search index in sync on eviction#958
Conversation
mem::evict now removes evicted observations and memories from the BM25/vector index in addition to deleting them from KV, mirroring the remember / auto-forget / retention delete paths. Pre-fix: evicted entries lingered in search results until a full rebuild, because the index removal hook was wired into every other delete path except eviction. Tests: test/evict-index-sync.test.ts (new file, 8 cases). Signed-off-by: Hleb Shauchenka <me@marleb.org>
|
@shgew is attempting to deploy a commit to the rohitg00's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe eviction function now removes evicted observations and memories from both the search index ( ChangesEviction Search/Vector Index Synchronization
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
test/evict-index-sync.test.ts (1)
74-74: ⚡ Quick winAdd
beforeEachto clear mocks between tests.The mocked functions (
vectorIndexRemove,flushIndexSave, and theremovefunction fromgetSearchIndex) persist across test cases. Without clearing, assertions liketoHaveBeenCalled()in the second test may pass due to calls from the first test, potentially masking failures.🧹 Proposed fix
+import { beforeEach, describe, expect, it, vi } from "vitest"; -import { describe, expect, it, vi } from "vitest";Then add the hook inside the describe block:
describe("mem::evict keeps the search index in sync", () => { + beforeEach(() => { + vi.clearAllMocks(); + }); + it("removes evicted low-importance observations from the index and flushes", async () => {🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@test/evict-index-sync.test.ts` at line 74, Inside the "mem::evict keeps the search index in sync" describe block, add a beforeEach hook that clears all mocks between test cases. This hook should call the appropriate mock clearing functions (such as jest.clearAllMocks() or by resetting individual mocks like vectorIndexRemove, flushIndexSave, and the remove function from getSearchIndex) to ensure that mock call counts and assertions in each test are not affected by calls from previous tests.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@test/evict-index-sync.test.ts`:
- Line 74: Inside the "mem::evict keeps the search index in sync" describe
block, add a beforeEach hook that clears all mocks between test cases. This hook
should call the appropriate mock clearing functions (such as
jest.clearAllMocks() or by resetting individual mocks like vectorIndexRemove,
flushIndexSave, and the remove function from getSearchIndex) to ensure that mock
call counts and assertions in each test are not affected by calls from previous
tests.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 30c9573c-2f6e-483d-b7cf-0e203e17a76d
📒 Files selected for processing (2)
src/functions/evict.tstest/evict-index-sync.test.ts
vi mocks persisted across the two cases in this suite, so toHaveBeenCalled assertions in the second test could pass on calls from the first. Add a beforeEach(vi.clearAllMocks) to isolate them.
What
mem::evictnow removes evicted observations and memories from the BM25/vector index in addition to deleting them from KV, mirroring theremember/auto-forget/retentiondelete paths.Why
Pre-fix: evicted entries lingered in search results until a full rebuild, because the index removal hook was wired into every other delete path except eviction.
Tests
test/evict-index-sync.test.ts(new file, 2 cases that exercise the post-evict search consistency invariant). Targeted suite: 2/2 pass.Compatibility
Bug fix. No env changes. Callers that already expected post-evict search consistency observe correct behavior; callers that relied on the stale index will see fresher results.
Summary by CodeRabbit