feat(search): passage-select + snippet-first for the answer path#327
Merged
Conversation
Add two gated levers to the /v1/search LLM answer synthesis, both default off so prod behavior is unchanged until flipped (A/B keep/revert; off = byte-identical to the prior path). - answer_bm25_select: when a scraped source exceeds the per-source byte budget, keep its query-relevant passages (sentence-chunked, BM25-ranked, reusing the existing chunker/ranker) instead of a blind head-truncation that drops answers sitting deep in the page. Two-pass with a partial-fill tail so it never feeds the model less than a head-truncation would (monotone on recall); non-adjacent passages are joined with a gap marker. - snippet_fallback is now snippet-first: prepend the SERP snippet to every answer source and block-guard the scraped body, so a fetched-but-blocked page (a "Wikimedia Error"/bot-wall shell) falls back to the clean snippet instead of grounding the answer on error text. The legacy path (flag off) is byte-identical, so the multi-round scout still fires on such sources. Also parse citations from the LAST ===CITATIONS=== marker (rsplit) so a source that quotes the marker cannot truncate the answer or divert parsing.
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Two gated levers for
/v1/searchLLM answer synthesis. Both default off, somerging changes nothing in prod until the flags are flipped; off = byte-identical
to the prior answer path (A/B keep/revert).
Changes
answer_bm25_select(new flag, default off): when a scraped source exceedsthe per-source byte budget, keep its query-relevant passages (sentence-chunked +
BM25-ranked, reusing the existing chunker/ranker) instead of a blind
head-truncation that drops answers buried deep in a page. Two-pass with a
partial-fill tail so it never feeds the model less than a head-truncation would
(monotone on recall); non-adjacent passages are joined with a
[...]gap marker.snippet_fallback(repurposed → snippet-first): prepend the SERP snippet toevery answer source and block-guard the scraped body, so a fetched-but-blocked
page (a "Wikimedia Error" / bot-wall shell) falls back to the clean snippet
instead of grounding on error text. The legacy path (flag off) is byte-identical,
so the multi-round scout still fires on such sources.
===CITATIONS===marker (rsplit) so asource that quotes the marker cannot truncate the answer or divert the parse.
Safety / rollout
cargo fmt+cargo clippy --workspace -D warnings+cargo test --workspaceall green; new unit tests cover passage-selection (deep-answer, budget-fill,
oversized-blob, passthrough) and the block-shell detector.
next release-please release; activating the levers is a separate config flip.