v5

latestOpenAPI 3.1.02026-08-025631,1012.8 MB
Retrievers

Explain Retriever Execution Plan

Get a detailed execution plan for a retriever without actually executing it. Similar to MongoDB's explain plan or SQL's EXPLAIN command, this endpoint helps you understand performance characteristics, identify bottlenecks, estimate costs, and troubleshoot retrieval issues before running expensive queries.

What This Returns:

  • Stage-by-stage execution plan (AFTER automatic optimizations)
  • Estimated costs (credits + time per stage)
  • Document flow projections (input/output counts per stage)
  • Efficiency metrics (selectivity ratios, cache likelihood)
  • Bottleneck identification (slowest/most expensive stages)
  • Optimization details (transformations applied by the optimizer)
  • Performance warnings and improvement suggestions

Key Features:

  • Cost Estimation: See how many credits and milliseconds each stage will consume
  • Bottleneck Detection: Identify which stages dominate execution time
  • Optimization Transparency: Understand how your pipeline was optimized
  • Cache Analysis: See which stages are likely to hit cache
  • Accuracy Troubleshooting: Analyze stage efficiency and document flow
  • Latency Analysis: Break down estimated duration by stage

Important: The execution_plan shows OPTIMIZED stages (after automatic transformations like filter push-down, stage fusion, and grouping optimization). Check optimization_details to understand what changed from your original configuration.

Use Cases:

  • Debug slow retrievers by identifying bottleneck stages
  • Estimate costs before running expensive queries
  • Understand how the optimizer transformed your pipeline
  • Troubleshoot accuracy issues by analyzing stage selectivity
  • Compare different retriever configurations
  • Plan budget allocation for production workloads

Example Response:

{
  "retriever_id": "ret_abc123",
  "retriever_name": "product_search",
  "execution_plan": [
    {
      "stage_index": 0,
      "stage_name": "attribute_filter",
      "stage_type": "filter",
      "estimated_input": 10000,
      "estimated_output": 5000,
      "estimated_efficiency": 0.5,
      "estimated_cost_credits": 0.01,
      "estimated_duration_ms": 20,
      "cache_likely": true,
      "optimization_notes": ["Pushed down from stage 2"],
      "warnings": []
    },
    {
      "stage_index": 1,
      "stage_name": "semantic_search",
      "stage_type": "filter",
      "estimated_input": 5000,
      "estimated_output": 100,
      "estimated_efficiency": 0.02,
      "estimated_cost_credits": 0.5,
      "estimated_duration_ms": 200,
      "cache_likely": false,
      "optimization_notes": [],
      "warnings": ["High cost stage - consider reducing limit"]
    }
  ],
  "estimated_cost": {
    "total_credits": 0.51,
    "total_duration_ms": 220
  },
  "bottleneck_stages": ["semantic_search"],
  "optimization_applied": true,
  "optimization_details": {
    "original_stage_count": 3,
    "optimized_stage_count": 2,
    "optimization_time_ms": 8.2,
    "stage_reduction_pct": 33.3,
    "decisions": [
      {
        "rule_type": "push_down_filters",
        "applied": true,
        "reason": "Moved attribute_filter before semantic_search to reduce search scope"
      }
    ]
  },
  "optimization_suggestions": [
    {
      "type": "reduce_limit",
      "stage": "semantic_search",
      "message": "Consider reducing limit to improve latency"
    }
  ]
}
post/v1/retrievers/{retriever_id}/execute/explain

Path parameters

retriever_idstring required

Retriever ID or name to explain. The execution plan will show the OPTIMIZED version after automatic transformations.

Retriever ID or name to explain. The execution plan will show the OPTIMIZED version after automatic transformations.

Request body

inputsobject

Hypothetical inputs for tailored execution plan estimation. These values are used to analyze stage behavior and estimate costs.

NOT REQUIRED - if omitted, default/representative values are used.

Common inputs:

  • 'query': Search query text (for semantic search stages)
  • 'top_k': Number of results to return (affects search scope)
  • Filter parameters: Category, price range, etc.

Examples:

  • {'query': 'laptop'} - Simple text query
  • {'query': 'laptop', 'top_k': 100} - Query with custom limit
  • {'query': 'laptop', 'category': 'electronics', 'price_max': 1000} - Query with filters

Note: Inputs are for estimation only. No actual search is performed.

Example request

{
  "description": "Explain with simple query input",
  "inputs": {
    "query": "machine learning tutorials"
  }
}

Response

Detailed execution plan with stage-by-stage cost estimates, optimization details, bottleneck identification, and performance insights. Use this to troubleshoot slow queries, estimate costs, and understand optimizer transformations.

retriever_idstring required

Unique identifier of the retriever being explained. REQUIRED.

retriever_namestring required

Human-readable name of the retriever. REQUIRED.

estimated_costobject required

Estimated total cost breakdown for executing this retriever. Contains: 'total_credits' (credit cost), 'total_duration_ms' (latency). Sum of all stage costs. Use for budget planning. REQUIRED.

optimization_suggestionsobject[]

Actionable suggestions for improving retriever performance. Each suggestion includes: 'type' (suggestion category), 'stage' (affected stage name), 'message' (human-readable description). Common types: 'reduce_limit', 'add_filter', 'reorder_stages', 'enable_cache'. OPTIONAL (empty if no suggestions).

total_estimated_stagesinteger required

Total number of stages in the optimized execution plan. This may differ from your original stage count if optimizations were applied. Compare with optimization_details.original_stage_count to see reduction. REQUIRED.

bottleneck_stagesstring[]

Names of stages expected to dominate execution time. Includes stages with duration >= 80%% of the slowest stage. Focus optimization efforts on these stages. OPTIONAL (empty if all stages have similar duration).

optimization_levelstring

Optimization level applied by the optimizer. Values: 'none' (no optimization), 'mvp' (basic optimizations), 'advanced' (all optimizations). REQUIRED.

optimization_appliedboolean

Whether automatic pipeline optimizations were applied. When true, execution_plan shows OPTIMIZED stages (after transformations like filter push-down, stage fusion, grouping optimization). When false, execution_plan matches your original configuration. Check optimization_details to see what changed. REQUIRED.

optimization_detailsobject nullable

Detailed breakdown of optimization transformations applied. Only present when optimization_applied=true.

Fields:

  • original_stage_count: Stage count before optimization
  • optimized_stage_count: Stage count after optimization
  • optimization_time_ms: Time spent on optimization (typically <100ms)
  • stage_reduction_pct: Percentage reduction in stage count
  • decisions: Array of optimization decisions

Each decision contains:

  • rule_type: Optimization rule that fired
  • applied: Whether the rule was applied
  • reason: Human-readable explanation
  • stages_before/after: Stage counts before/after this rule

Common rule types:

  • push_down_filters: Move filters earlier to reduce downstream work
  • group_by_push_down: Push grouping to database layer (10-100x faster)
  • merge_consecutive_filters: Combine adjacent filters
  • eliminate_redundant_sorts: Remove duplicate sort operations

OPTIONAL (null when optimization_applied=false).

Example response

{
  "bottleneck_stages": [
    "semantic_search"
  ],
  "description": "Simple retriever with optimization applied",
  "estimated_cost": {
    "total_credits": 0.51,
    "total_duration_ms": 220
  },
  "execution_plan": [
    {
      "cache_likely": true,
      "estimated_cost_credits": 0,
      "estimated_duration_ms": 20,
      "estimated_efficiency": 0.5,
      "estimated_input": 10000,
      "estimated_output": 5000,
      "optimization_notes": [
        "Pushed down from stage 2"
      ],
      "stage_index": 0,
      "stage_name": "attribute_filter",
      "stage_type": "filter",
      "warnings": []
    },
    {
      "cache_likely": false,
      "estimated_cost_credits": 0.5,
      "estimated_duration_ms": 200,
      "estimated_efficiency": 0.02,
      "estimated_input": 5000,
      "estimated_output": 100,
      "optimization_notes": [],
      "stage_index": 1,
      "stage_name": "semantic_search",
      "stage_type": "filter",
      "warnings": []
    }
  ],
  "optimization_applied": true,
  "optimization_details": {
    "decisions": [
      {
        "applied": true,
        "reason": "Moved attribute_filter before semantic_search",
        "rule_type": "push_down_filters"
      }
    ],
    "optimization_time_ms": 8.2,
    "optimized_stage_count": 2,
    "original_stage_count": 3,
    "stage_reduction_pct": 33.3
  },
  "optimization_level": "mvp",
  "optimization_suggestions": [
    {
      "message": "Consider reducing limit to improve latency",
      "stage": "semantic_search",
      "type": "reduce_limit"
    }
  ],
  "retriever_id": "ret_abc123",
  "retriever_name": "product_search",
  "total_estimated_stages": 2
}