Allow disabling rewrite/rerank stages per query
Problem
The SDK's 3-stage query pipeline (rewrite → rerank → generate) delivers high-quality answers for complex multi-hop questions, but costs 3x in LLM calls and adds ~1s latency. For simple factual queries, this overhead is unnecessary.
Users have no way to opt out of individual stages per-query.
Proposed API
# Full pipeline (default) — best for complex questions
result = await rag.completion(question)
# Skip rewrite for simple lookups
result = await rag.completion(question, rewrite=False)
# Skip rerank for latency-sensitive paths
result = await rag.completion(question, rerank=False)
# Minimal: retrieve + generate only (1 LLM call, like Neo4j's default)
result = await rag.completion(question, rewrite=False, rerank=False)
Context
- The demo benchmark shows 3 LLM calls per question vs Neo4j's 1
- Average latency is 2.8s — much of it from the extra LLM round-trips
- Multi-hop and numeric questions benefit from the full pipeline; simple factual questions don't
- This would let users tune cost/quality tradeoff per-query
Priority
Medium — important for production latency and cost optimization.
I'd like to pick this up. Before writing code I checked main (ec84726), and part of the request already seems possible per query:
- Rewrite is already opt-in.
completion(..., rewrite_question_with_history=False)is the default, and the rewrite call only runs whenhistoryis passed and the flag isTrue(api/main.py, step 1 ofcompletion()). - External rerank is already opt-in.
completion(..., reranker=None)is the default, andretrieve()only callsreranker.rerank()when one is passed. - What still runs on every query is inside
MultiPathRetrieval.search():- the keyword-extraction LLM call (
_extract_keywords, step 1); - the cosine rerank (step 8). This one makes no LLM call. It only re-embeds candidates when stored chunk embeddings cover less than 90% of them.
- the keyword-extraction LLM call (
So a default completion() today makes 2 LLM calls (keywords + answer), not 3. The one per-query lever left is the keyword-extraction call.
Proposed change, with defaults unchanged:
await rag.completion(question, llm_keywords=False) # stopword keywords only -> 1 LLM call
await rag.retrieve(question, llm_keywords=False)
The flag would reach MultiPathRetrieval through the per-call Context, so the RetrievalStrategy.search(query, ctx) signature stays the same and custom strategies can ignore it. I'd add mocked unit tests asserting the LLM call count with the flag on and off, plus a docs/CHANGELOG entry. Optionally I'd also add chunk_rerank=False to keep candidate order and skip the fallback re-embedding.
CONTRIBUTING asks for the 85% benchmark and maintainer sign-off before committing. I can't run the FalkorDB + LLM benchmark locally. The defaults wouldn't change, so the default benchmark path is untouched. Would you like this as a PR, and does the flag name and Context plumbing work for you? If the existing opt-ins already cover what you had in mind, I'm also happy to send a short docs note instead.