Skip to content

fix(platform): stop a search returning one passage twice - #3176

Merged
Israeltheminer merged 2 commits into
mainfrom
fix/3061-dedupe-passages
Sep 3, 2026
Merged

fix(platform): stop a search returning one passage twice#3176
Israeltheminer merged 2 commits into
mainfrom
fix/3061-dedupe-passages

Conversation

@Israeltheminer

Copy link
Copy Markdown
Collaborator

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

dropRepeatedPassages in backend/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.

Mutation Went red
dedupe not called 2 cases
whitespace normalization dropped the wrapping case
corpus dropped from the key the cross-corpus case
dedupe moved before the retrievability gate the readable-copy case

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:sast green; branched from origin/main at e616480a8.

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
Israeltheminer force-pushed the fix/3061-dedupe-passages branch from db1c1fd to 815021e Compare September 3, 2026 15:20
@Israeltheminer
Israeltheminer merged commit 2261e4f into main Sep 3, 2026
48 checks passed
@Israeltheminer
Israeltheminer deleted the fix/3061-dedupe-passages branch September 3, 2026 18:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: a search can return the same passage twice

1 participant