Skip to content

fix: prune deleted BM25 vocabulary entries#11997

Merged
anakin87 merged 1 commit into
deepset-ai:mainfrom
hxaxd:codex/issue-11993-bm25-vocab
Jul 14, 2026
Merged

fix: prune deleted BM25 vocabulary entries#11997
anakin87 merged 1 commit into
deepset-ai:mainfrom
hxaxd:codex/issue-11993-bm25-vocab

Conversation

@hxaxd

@hxaxd hxaxd commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Related Issues

Proposed Changes:

InMemoryDocumentStore.delete_documents() now removes vocabulary entries whose document frequency reaches zero after subtraction. This prevents terms that exist only in deleted documents from changing the epsilon-adjusted average IDF used by BM25Okapi.

PR #7549 introduced incremental BM25 indexing to avoid rebuilding the corpus for each query. Its deletion path used Counter.subtract(), which retains zero-count keys, while the scoring path treated every Counter key as part of the active vocabulary. The change repairs that state invariant at deletion time without giving up incremental indexing.

The PR also adds a regression test comparing a fresh store with a store that previously contained a deleted document, plus a release note.

How did you test it?

  • Added TestMemoryDocumentStore::test_bm25_okapi_scores_do_not_depend_on_deleted_documents.

Notes for the reviewer

The cleanup is limited to the distinct terms in each deleted document.

Checklist

  • I have read the contributors guidelines.
  • I have updated the related issue with new insights and changes.
  • I added unit tests; no public docstring change is needed.
  • The planned title follows the conventional-commit format: fix: prune deleted BM25 vocabulary entries.
  • The user-visible behavior is documented in a release note.
  • I have added the required release note.
  • I have run the full pre-commit checks.

Copilot AI review requested due to automatic review settings July 13, 2026 16:56
@hxaxd
hxaxd requested a review from a team as a code owner July 13, 2026 16:56
@hxaxd
hxaxd requested review from anakin87 and removed request for a team July 13, 2026 16:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@vercel

vercel Bot commented Jul 13, 2026

Copy link
Copy Markdown

@hxaxd is attempting to deploy a commit to the deepset Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  haystack/document_stores/in_memory
  document_store.py
Project Total  

This report was generated by python-coverage-comment-action

@anakin87 anakin87 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. Looks good!

@anakin87
anakin87 merged commit bcb2867 into deepset-ai:main Jul 14, 2026
22 of 23 checks passed
@hxaxd
hxaxd deleted the codex/issue-11993-bm25-vocab branch July 14, 2026 10:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: InMemoryDocumentStore retains zero-frequency vocabulary entries after document deletion, affecting BM25 scoring

3 participants