feat: include all query-hit snippets for page chunks in retrieval responses - #245
Open
gdccyuen wants to merge 1 commit into
Open
feat: include all query-hit snippets for page chunks in retrieval responses#245gdccyuen wants to merge 1 commit into
gdccyuen wants to merge 1 commit into
Conversation
…ponses Page chunks can be very large (whole scanned directory pages) and their LLM summary rarely contains the exact queried term, so retrieval results were unhelpful for name lookups. Extract every occurrence of the query terms from the full page content as bounded snippets (±100 chars, capped at 20, deduplicated) and append them after the summary. - New shared/services/retrieval/hydration/page_snippets.py - assemble_retrieval_results gains a query param; page chunks set content_source='content_snippets' when hits exist, else 'summary' - Thread query=context.query through all assembly call sites in routes.py - Unit tests (6) + worker contract tests (2) + API contract test (1)
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.
What
Fixes retrieval for page chunks (e.g. a scanned telephone-directory page): the API was returning only the chunk's LLM
summary— which rarely contains the queried name — making name lookups return "null"/useless results. Now the response includes every occurrence of the query terms from the full page content as bounded snippets.Problem
pagechunk (183K chars) + image chunksassemble_retrieval_resultsreplaced page-chunk content withmetadata.summary(content_source: 'summary') — a 2-line generic summary naming no oneChanges
packages/shared-python/shared/services/retrieval/hydration/page_snippets.py(new)extract_page_snippets(content, query_tokens, *, context_chars=100, max_snippets=20):…markersresult_assembly.pyassemble_retrieval_resultsgainsquery: str | None = Nonesummary + "\n\n" + snippetswithcontent_source='content_snippets'when hits exist; falls back to'summary'unchanged when there are no hitsexecution/routes.pyassemble_retrieval_resultscall sites passquery=context.queryTests
packages/shared-python/shared/tests/test_page_snippets.py(6 unit tests: all-occurrences, cap, case/boundary, no-hits, dedupe, bounded)apps/worker/tests/contract/test_page_memory_retrieval_contract.py(2 new: snippets appended when query matches; summary fallback without hits)apps/api/tests/contract/test_retrieval_contract.py(1 new: query "Gordon" → bothCHEUNG Hon-lam GordonandYUEN Chun-cheung Gordonin the page result,content_source='content_snippets', evidence includes document)Verified:
pnpm-style lint (ruff) + pyright clean; 36 affected tests pass.