Orchestrate a research pipeline: search, extract, and synthesize while preserving source identities and handling empty or partial results.
Full problem description visible. Upgrade to unlock the editor, test cases, and solution.
Implement research_assistant(query, search_fn, extract_fn, synthesize_fn).
- Call search_fn(query) to retrieve a list of source dicts. Each source has
{"id": str, "content": str}.
- If search returns an empty list, return {"error": "no sources found", "sources": []}.
- For each source with non-empty content, call extract_fn(source) to get extracted data.
- If extract_fn returns None, skip that source entirely.
- Each successful extraction must preserve its source identity:
{"source_id": source["id"], "data": <extracted_value>}.
- Collect all successful extractions into an extracted list.
- If no extractions succeeded, return {"error": "no data extracted", "sources": sources}.
- Otherwise call synthesize_fn(extracted) to produce the final synthesis.
- Return {"result": synthesis, "sources": sources, "extracted": extracted, "source_count": len(sources)}.
₹999/monthLimited period launch pricing.
Get the full problem statement, test cases, interactive editor, solution explanation, and visual diagram.
def research_assistant(query, search_fn, extract_fn, synthesize_fn):
"""Run a research pipeline: search, extract, and synthesize."""Extract sources, synthesize, return structured dict
Already have Pro access? Sign in