fix(platform): stop a search returning one passage twice - #3176
Merged
Conversation
The same text can sit in the corpus twice — one file uploaded as two documents, or a paragraph two documents share. Both copies match, and a bounded result set then spends two of its slots saying one thing while a different answer falls off the end. A caller asking for eight passages can receive seven distinct ones. Deduped on the text a caller actually reads, keyed with the corpus so the same wording found in a document and on a crawled page stays two answers. Whitespace is normalized, so two copies differing only in how their source wrapped lines count as one. Fusion has already sorted by score, so the first occurrence is the best one. The order is load-bearing: this runs AFTER the retrievability filter. Deduping first could keep a copy the caller cannot read and drop the readable one, and the gate would then remove what was kept — losing the passage entirely rather than showing it once. Closes #3061. Supersedes #3105, whose two files #3125 deleted.
Israeltheminer
force-pushed
the
fix/3061-dedupe-passages
branch
from
September 3, 2026 15:20
db1c1fd to
815021e
Compare
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.
A search no longer spends two of its result slots on the same passage.
Closes #3061. Supersedes #3105, whose two files #3125 deleted.
Why
The same text can sit in the corpus twice — one file uploaded as two documents, or a paragraph two documents share. Both copies match, and a bounded result set then says one thing twice while a different answer falls off the end. A caller asking for eight passages can receive seven distinct ones.
Observed as duplication on a deployment: two pairs of corpus rows with matching content hashes, chunk counts and character counts under different refs.
What changed
dropRepeatedPassagesinbackend/core/knowledge/search.ts, keyed on the text a caller actually reads.The corpus is part of the key, so the same wording found in a document and on a crawled page stays two answers — they are different claims about where it came from. Whitespace is normalized, so two copies differing only in how their source wrapped lines count as one. Fusion has already sorted by score, so the first occurrence is the best one and no comparison is needed.
The order is load-bearing. It runs after the retrievability filter. Deduping first could keep a copy the caller cannot read and drop the readable one; the gate would then remove what was kept, losing the passage entirely rather than showing it once.
Tests
Five cases: two identical copies collapse to the higher-scoring ref, two distinct chunks of one document both survive, two copies differing only in line wrapping collapse, the readable copy is kept when the other is filtered out, and the same wording in two corpora stays two hits.
The last one is the reason that case exists — the ordering bug is invisible until a copy is unreadable.
Scope
Nothing purges the duplicate corpus rows themselves. This stops them being served twice; the rows remain, and a replacement upload still leaves an orphaned row behind. That is tracked separately in #3142.
Gate:
typecheck,oxlint --type-aware,oxfmt --check,lint:sastgreen; branched fromorigin/mainate616480a8.