Skip to content

Conversation

@Ch-Abhinav-Chowdary
Copy link

Summary
Added a new optional parameter query_transformer_prompt: pw.UDF | None to BaseRAGQuestionAnswerer (and AdaptiveRAGQuestionAnswerer) to enable query rewriting/normalization before retrieval and prompt construction.
What changed
BaseRAGQuestionAnswerer.init: accepts and stores query_transformer_prompt.
BaseRAGQuestionAnswerer.answer_query: if provided, applies query_transformer_prompt to prompt before calling retriever and before generating the RAG prompt.
AdaptiveRAGQuestionAnswerer.init: accepts and forwards query_transformer_prompt.
Updated docstrings to document the new parameter.
Why
Enables custom query transformers (rewrite/expand/normalize) without changing server schemas or external request formats.

@szymondudycz
Copy link
Contributor

I liked the changes in the previous PR better

  • in this one the rewritten query is used not just for retrieval, but also for answering question. Having a separate query for retrieval allows it to be better fitted. I'd like to go back to the previous version, or add a flag whether the transformed query should be used just for retrieval or for answering as well.
  • in the previous PR, the query_transformer_prompt was meant to be a prompt for transforming a query, which is then passed to the llm. Instead in this one it expects a udf that transforms a query, which while more general, is harder to use without any ready to use llm based query transformer. Although it is more general, I'd go back to expecting a prompt which is then passed to the llm.

@Ch-Abhinav-Chowdary
Copy link
Author

Okay i Will do it

@CLAassistant
Copy link

CLAassistant commented Jan 22, 2026

CLA assistant check
All committers have signed the CLA.

@Ch-Abhinav-Chowdary
Copy link
Author

Status of Changes:

  1. BaseRAGQuestionAnswerer.answer_query Modification :

    • File : question_answering.py
    • Status : Completed .
    • Verification : I confirmed that the answer_query method now checks for self.query_transformer_prompt . If set, it uses the UDF to generate a rewrite prompt, calls the LLM to get the rewritten query, and uses that new query for retrieval. If not set, it defaults to the original behavior.
  2. test_base_rag_with_query_transformer_identity Addition :

    • File : test_rag.py
    • Status : Completed .
    • Verification : The test function is present. It correctly sets up a BaseRAGQuestionAnswerer with an identity_rewrite UDF and a TrueIdentityChat mock to verify that the query transformation pipeline works without altering the query content (proving compatibility).
  3. Test Execution :

    • Status : Skipped (Environment Issue) .
    • Reason : Attempting to run the tests via pytest failed because the cargo command (required to build the Pathway engine) is not available in this environment. However, the code logic and test structure have been manually verified to be correct.

    Once check the recent commit

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.

3 participants