- Notifications
You must be signed in to change notification settings - Fork 0
fix(rag): restore live-validated retrieval order#915
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8dedbfa
fix(rag): restore live-validated retrieval order
BigSimmo 2f8e641
Merge remote-tracking branch 'origin/main' into codex/restore-live-re…
BigSimmo a18b08e
fix(rag): preserve answer ranking tie-breaks
BigSimmo 721c1be
fix(rag): preserve ranked fallback order while deduping duplicates
Copilot c4eb3ef
fix(rag): preserve ranked fallback order while deduping duplicates
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -549,6 +549,42 @@ function recordRetrievalLayer( | ||
| } | ||
| } | ||
| /** | ||
| * Keep distinct results in the current ranked order while upgrading duplicate chunks to the | ||
| * strongest released-hybrid copy. | ||
| * | ||
| * App-layer rank scores remain available to answer evidence ranking and telemetry, but the | ||
| * live corpus gate has not validated replacing the final distinct-result order with them. | ||
| */ | ||
| export function stabilizeReleasedSearchOrder(results: SearchResult[]) { | ||
| const compareReleasedSearchStrength = (left: SearchResult, right: SearchResult) => { | ||
| const leftHybrid = left.hybrid_score ?? left.similarity ?? 0; | ||
| const rightHybrid = right.hybrid_score ?? right.similarity ?? 0; | ||
| if (rightHybrid !== leftHybrid) return rightHybrid - leftHybrid; | ||
| const leftSimilarity = left.similarity ?? 0; | ||
| const rightSimilarity = right.similarity ?? 0; | ||
| if (rightSimilarity !== leftSimilarity) return rightSimilarity - leftSimilarity; | ||
| if (right.relevance?.score !== left.relevance?.score) | ||
| return (right.relevance?.score ?? 0) - (left.relevance?.score ?? 0); | ||
| return left.id.localeCompare(right.id); | ||
BigSimmo marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| }; | ||
| const strongestById = new Map<string, SearchResult>(); | ||
| for (const result of results) { | ||
| const current = strongestById.get(result.id); | ||
| if (!current || compareReleasedSearchStrength(result, current) < 0) strongestById.set(result.id, result); | ||
| } | ||
| const deduped: SearchResult[] = []; | ||
| const seen = new Set<string>(); | ||
| for (const result of results) { | ||
| if (seen.has(result.id)) continue; | ||
| seen.add(result.id); | ||
| deduped.push(strongestById.get(result.id) ?? result); | ||
| } | ||
| results.length = 0; | ||
| results.push(...deduped); | ||
| return results; | ||
| } | ||
| /** Record search score telemetry. */ | ||
| function recordSearchScoreTelemetry(telemetry: SearchTelemetry, results: SearchResult[]) { | ||
| if (!results.length) { | ||
| @@ -565,17 +601,7 @@ function recordSearchScoreTelemetry(telemetry: SearchTelemetry, results: SearchR | ||
| return; | ||
| } | ||
| // Preserve the rankScore ordering established by clinical/second-stage ranking. Coverage | ||
| // telemetry still uses the raw hybrid signal, but must never mutate the returned result order. | ||
| const deduped: SearchResult[] = []; | ||
| const seen = new Set<string>(); | ||
| for (const result of results) { | ||
| if (seen.has(result.id)) continue; | ||
| seen.add(result.id); | ||
| deduped.push(result); | ||
| } | ||
| results.length = 0; | ||
| results.push(...deduped); | ||
| stabilizeReleasedSearchOrder(results); | ||
BigSimmo marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| const coverageScores = results | ||
| .map((result) => Math.max(0, result.hybrid_score ?? result.similarity ?? 0)) | ||
| .sort((left, right) => right - left); | ||
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
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
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
Uh oh!
There was an error while loading. Please reload this page.