Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion python/pathway/xpacks/llm/question_answering.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,11 @@ class BaseRAGQuestionAnswerer(SummaryQuestionAnswerer):
search_topk: Top k parameter for the retrieval. Adjusts number of chunks in the context.
rerank_topk: Number of top-scoring documents to retain after reranking, when a reranker is provided.
If ``None``, reranking is disabled. Defaults to ``None``.
query_transformer: Transformer for query rewriting before retrieval.
Can be a ``pw.UDF``, callable, or ``None`` to skip query transformation.
Available options: ``pathway.xpacks.llm.prompts.prompt_query_rewrite``,
``pathway.xpacks.llm.prompts.prompt_query_rewrite_hyde``.
Defaults to ``None``.


Example:
Expand Down Expand Up @@ -523,11 +528,13 @@ def __init__(
search_topk: int = 6,
reranker: pw.UDF | None = None,
rerank_topk: int | None = None,
query_transformer: pw.UDF | Callable | None = None,
) -> None:

self.llm = llm
self.indexer = indexer
self.reranker = reranker
self.query_transformer = query_transformer

if default_llm_name is None:
default_llm_name = llm.model
Expand Down Expand Up @@ -637,7 +644,10 @@ def add_score_to_doc(doc: pw.Json, score: float) -> dict:
@pw.table_transformer
def answer_query(self, pw_ai_queries: pw.Table) -> pw.Table:
"""Answer a question based on the available information."""

if self.query_transformer is not None:
pw_ai_queries += pw_ai_queries.select(
prompt=self.query_transformer(pw.this.prompt)
)
Comment on lines +647 to +650
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

pathway.xpacks.llm.prompts.prompt_query_rewrite and `pathway.xpacks.llm.prompts.prompt_query_rewrite_hyde`` are just prompts to be sent to an llm to ask to rewrite a question for the sake of retrieval. Replacing a question to RAG with these prompt makes the RAG completely wrong

pw_ai_results = pw_ai_queries + self.indexer.retrieve_query(
pw_ai_queries.select(
metadata_filter=pw.this.filters,
Expand Down