Automatic optimizations
When you execute a retriever, the planner rewrites your stage list before execution. These transformations are automatic — you don’t configure them:
The retriever is also fetched and optimized once per request, then reused across a batch — so
POST /v1/retrievers/{id}/execute/batch amortizes planning across all queries.
Inspect the plan with explain
POST /v1/retrievers/{retriever_id}/explain returns the optimized execution plan without running the query — per-stage cost and latency estimates, bottlenecks, and exactly which optimizations were applied. Pass hypothetical inputs to see how the plan changes with different parameters.
Example response
estimated_cost_credits and total_credits are legacy fields expressed in the internal ledger unit (1 credit = $0.001). Customer-facing pricing is in dollars — see Billing.How to read it
The
execution_plan reflects the optimized pipeline, not your original stage list. Compare optimization_details.original_stage_count vs optimized_stage_count to see how much the planner collapsed.Execution-plan variant
POST /v1/retrievers/{retriever_id}/execute/explain returns the same plan in a MongoDB-explain-style shape if you prefer that format. Both are read-only and never execute the query.
Typical workflow
1
Explain before you ship
Run
explain with representative inputs to see estimated cost, bottlenecks, and applied optimizations.2
Act on bottlenecks & suggestions
Reduce
top_k on high-cost searches, add a selective attribute_filter (the optimizer pushes it down), or drop low-selectivity stages.3
Verify in production
Use retriever analytics to confirm real latency and cache-hit rates match the estimate.
Related
- Multi-Stage Retrieval — how stages compose
- Feature Search — the most common bottleneck stage
- Evaluations — measure quality alongside cost
- Best Practices — caching and cost optimization

