Repository navigation
Retrieve follow-up questions with the conversation, not the bare question - #9
Merged
Merged
Conversation
…tion stream_answer retrieved on the raw question only, so a follow-up like "what does it cost?" was embedded with no idea what "it" was and pulled back the wrong chunks; the history reached the LLM but never the retriever. Build the retrieval query from the recent user turns plus the current question and retrieve on that, while still passing the original question to the prompt and using it for the citation highlight. search() takes an optional retrieval_query so the plain /v1/search endpoint is unchanged. Fixes #8
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 was wrong.
RAGService.stream_answerretrieved on the rawquestiononly (backend/src/docmind/rag/service.py:110). The conversation history reached the LLM but never the retriever, so a follow-up like "what does it cost?" was embedded on its own, with no idea what "it" referred to, and pulled back the wrong chunks — the model then answered from poor sources or said it could not find anything.The fix. Build the retrieval query from the recent user turns (the same window the prompt already uses) plus the current question, and retrieve on that. The original question is still what we pass to the prompt and what the citation highlight is keyed on.
search()gained an optionalretrieval_query, so the plainPOST /v1/searchendpoint is unchanged.How it was tested. New
backend/tests/test_rag_service.py: one test gives a prior "Tell me about the Nimbus plan" turn and then asks "what does it cost?" and asserts the retriever sees a query containing both the question and "Nimbus" (it fails on main); a second test asserts that without history the retrieval query is still the bare question. Full backend suite, ruff, ruff format --check and mypy all pass.Fixes #8