Build a RAG support flow: rewrite ambiguous follow-ups, retrieve relevant documents, produce grounded answers with citations, and refuse unsupported claims.
Full problem description visible. Upgrade to unlock the editor, test cases, and solution.
Implement support_pipeline(query, history, retrieve_fn, answer_fn).
- query is the current user question (string).
- history is a list of previous user messages (strings), oldest first.
- If query has fewer than 5 words AND history is non-empty, rewrite the
query by prepending the last history message: f"{history[-1]} {query}".
Otherwise use the query as-is.
- Call retrieve_fn(rewritten_query) to get a list of doc dicts. Each doc has
{"id": str, "content": str, "score": float}.
- Filter out docs where score < 0.5.
- If no docs remain after filtering, return
{"answer": "I cannot answer this from the available documentation.", "citations": [], "confidence": 0.0}.
- Otherwise call answer_fn(rewritten_query, filtered_docs). It returns
{"text": str, "citations": [str]}.
- Compute confidence = min(1.0, max_score) using the highest score among
the filtered docs.
- Return {"answer": result["text"], "citations": result["citations"], "confidence": confidence}.
₹999/monthLimited period launch pricing.
Get the full problem statement, test cases, interactive editor, solution explanation, and visual diagram.
def support_pipeline(query, history, retrieve_fn, answer_fn):
"""Run a RAG support pipeline: rewrite, retrieve, filter, answer."""Rewrite, retrieve, filter, answer pipeline
Already have Pro access? Sign in