perf: hoist uniqueQueryTokens out of per-result loop in rankAnswerEvidence#77
Merged
BigSimmo merged 1 commit intoJun 27, 2026
Conversation
Copilot created this pull request from a session on behalf of
BigSimmo
June 27, 2026 06:42
View session
BigSimmo
marked this pull request as ready for review
June 27, 2026 07:15
BigSimmo
deleted the
copilot/task-87357024-1243497866-251362f0-d540-4973-9b2d-4ef07954a0d6
branch
June 27, 2026 07:15
Contributor
There was a problem hiding this comment.
Pull request overview
This PR optimizes answer-evidence ranking by avoiding repeated tokenization of a constant query during scoring, reducing redundant work per result while preserving scoring behavior.
Changes:
- Hoists
uniqueQueryTokens(query)torankAnswerEvidenceand reuses the computed tokens for all results. - Refactors
answerEvidenceScoreandphraseScoreto accept precomputed tokens instead of the raw query string.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| results: SearchResult[], | ||
| queryClass: RagQueryClass = classifyRagQuery(query).queryClass, | ||
| ) { | ||
| const tokens = uniqueQueryTokens(query); |
9 tasks
BigSimmo
added a commit
that referenced
this pull request
Jul 25, 2026
) * fix: make reconciliation tooling deterministic and multi-task safe Inject a fixture repositoryRoot into preflight collection so the contract no longer scales with the live worktree farm (#67). Add a cooperative primary checkout write lease (#77) and a secret-safe atomic reconciliation evidence pack (#78), wired into lifecycle planning and the outstanding-issues ledger. Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com> * fix: remove accidental conflict markers from package.json The merge commit retained both script sets but left Git conflict markers in the published package.json; strip them so the manifest parses again. Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com> --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.
Summary
uniqueQueryTokens(query)was called 2× per result inrankAnswerEvidence— once inanswerEvidenceScoreand again insidephraseScore— producing N×2 identical tokenizations for a constant query. For a typical 15-result ranking pass this meant ~30 redundant calls (each involvingnormalizedClinicalSearchTokens+ regex +Setdedup).Tokens are now computed once in
rankAnswerEvidenceand threaded intoanswerEvidenceScoreandphraseScoreas a parameter:Verification
npm run verify:cheapnpm run verify:uiwhen UI, routing, styling, browser behavior, reduced-motion, or forced-colors behavior changednpm run verify:releasebefore release or handoff confidence claimsnpm run format:checknpm run check:production-readinesswhen clinical workflow, privacy, environment, Supabase, source governance, or deployment behavior changedClinical Governance Preflight
Complete this section when the change touches ingestion, answer generation, search/ranking, source rendering, document access, privacy, production env, or clinical output.
Clinical KB Database(sjrfecxgysukkwxsowpy)Notes
answer-rankingtests and 14 related tests pass unchanged.phraseScoresignature changed from(query: string, haystack: string)to(tokens: string[], haystack: string)— private function, no external callers.