Repository navigation
feat: allow setting query transformers in BaseRAGQuestionAnswerer - #274
krisnaparahita wants to merge 2 commits into
Conversation
Adds a query_transformer_prompt param that rewrites the query via the LLM (e.g. prompts.prompt_query_rewrite / prompt_query_rewrite_hyde) before retrieval. The rewritten query is used only for document retrieval; the final answer is still generated from the original user prompt, per maintainer feedback on a prior attempt (pathwaycom#209). Fixes pathwaycom#67
zxqfd555
left a comment
There was a problem hiding this comment.
Thanks for the PR! The design looks good: the prompt goes through the LLM, the rewritten query is used only for retrieval, and the answer is built from the original question. One blocker, though.
It fails with the real chat wrappers. OpenAIChat, LiteLLMChat and CohereChat are annotated as -> str | None, so search_query becomes Optional(STR) while RetrieveQuerySchema.query requires STR. answer_query then fails while building the graph:
AssertionError: type of column query does not match - its type is Optional(STR) ... and STR in RetrieveQuerySchema
AssertionError: argument retrieval_queries has incorrect schema
Line: pw_ai_results = pw_ai_queries + self.indexer.retrieve_query(
The tests don't catch it because _QueryRewriteMockChat.__wrapped__ is annotated as -> str. Changing it to -> str | None reproduces the failure.
Wrapping the LLM result in pw.coalesce(..., pw.this.prompt) after await_futures() fixes the type and also falls back to the original query when the LLM returns None.
|
|
Hi @zxqfd555 Thanks for the detailed feedback, that pinpointed it exactly. Fixed by wrapping the rewrite result in Also fixed the test gap: changed Pushed to the branch. Let me know if you'd like anything else adjusted. |
Fixes #67
Summary
Validation