Skip to content

Retrieve follow-up questions with the conversation, not the bare question - #9

Merged
sinnercode228 merged 1 commit into
mainfrom
fix/followup-retrieval-query
Oct 30, 2026
Merged

sinnercode228 merged 1 commit into
mainfrom
fix/followup-retrieval-query

Conversation

@sinnercode228

Copy link
Copy Markdown
Owner

What was wrong. RAGService.stream_answer retrieved on the raw question only (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 optional retrieval_query, so the plain POST /v1/search endpoint 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

…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
@sinnercode228
sinnercode228 merged commit ddbfb5c into main Oct 30, 2026
3 checks passed
@sinnercode228
sinnercode228 deleted the fix/followup-retrieval-query branch October 30, 2026 13:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Follow-up questions retrieve on the bare question, ignoring the conversation

1 participant