Skip to content

Conversation

@Ch-Abhinav-Chowdary
Copy link

Summary

  • Adds an optional query_transformer_prompt parameter to BaseRAGQuestionAnswerer to support query rewriting before retrieval.
  • Accepts any pw.UDF (e.g., prompts.prompt_query_rewrite , prompts.prompt_query_rewrite_hyde ).
  • Defaults to None (no transformation) to preserve current behavior.

Motivation

  • Query rewriting can significantly improve recall and relevance in RAG systems.
  • The codebase already includes query-rewrite prompts ( prompt_query_rewrite , prompt_query_rewrite_hyde ); this change enables using them directly in the base RAG pipeline without custom plumbing.
  • Keeps the default path unchanged for users who do not need rewriting.

Key Changes

  • python\pathway\xpacks\llm\question_answering.py

    • BaseRAGQuestionAnswerer.init : added query_transformer_prompt: pw.UDF | None = None .
    • Stored self.query_transformer_prompt .
    • answer_query : if query_transformer_prompt is set, constructs a rewrite prompt and calls the configured LLM to produce search_query ; otherwise, uses the original prompt as search_query . Retrieval now uses search_query .
    • Updated the class docstring to document the new parameter and behavior.
  • python\pathway\xpacks\llm\tests\test_rag.py

    • Added test_base_rag_with_query_transformer_identity to validate compatibility by using an identity rewrite UDF and confirming behavior remains unchanged.
@CLAassistant
Copy link

CLAassistant commented Dec 15, 2025

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@szymondudycz szymondudycz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

python\pathway\xpacks\llm\tests\test_rag.py

Added test_base_rag_with_query_transformer_identity to validate compatibility by >using an identity rewrite UDF and confirming behavior remains unchanged.

I don't see this file in the changed files

*,
default_llm_name: str | None = None,
prompt_template: str | Callable[[str, str], str] | pw.UDF = prompts.prompt_qa,
query_transformer_prompt: pw.UDF | None = None,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the docstring of this class with the description of the newly added parameter

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay i will look upon it

@zxqfd555
Copy link
Collaborator

@Ch-Abhinav-Chowdary, could you please address the comments so that we can proceed with merging your PR? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

4 participants