Production_Rag / query_rewriter.py
TharaKavin's picture
Upload 17 files
6f94597 verified
Raw
History Blame Contribute Delete
871 Bytes
from typing import Optional
import config as cfg
from llm_handler import LLMHandler
_REFORMULATION_PROMPT = """Given a user question about a technical document, rewrite it into a clear, search-optimized query that will retrieve the most relevant passages.
Original question: {question}
Return ONLY the rewritten query, nothing else. Make it concise and focused on key technical terms."""
class QueryRewriter:
def __init__(self, llm: Optional[LLMHandler] = None):
self.llm = llm
def rewrite(self, question: str) -> str:
if not self.llm:
return question
try:
prompt = _REFORMULATION_PROMPT.format(question=question)
result = self.llm.generate(prompt)
if result and result.strip():
return result.strip()
except Exception:
pass
return question