> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.trace-db.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.trace-db.com/_mcp/server.

# Explain hybrid query

POST http://127.0.0.1:8090/v1/explain
Content-Type: application/json

Current TraceDB v1 product route. This OpenAPI artifact is generated from the checked-in route manifest.

Reference: https://docs.trace-db.com/api-reference/tracedb/query/post-explain

## Authentication

- `Authorization` header (bearer token, required) — Required by gateway-managed routes; direct local engine development can use any token.

## Servers

- `http://127.0.0.1:8090` (Local tracedb-server, default)
- `https://api.trace-db.com` (Hosted TraceDB API)

## Request

### Body (application/json)

This endpoint expects a HybridQuery.

- `cursor` (string, optional, nullable) — Opaque cursor returned by the previous query page.
- `explain` (boolean, optional)
- `freshness` (string, optional)
- `graph_seed` (string, optional, nullable)
- `scalar_eq` (map from string to any, optional) — Scalar equality predicates keyed by schema scalar column.
- `table` (string, optional)
- `temporal_as_of` (integer, optional, nullable)
- `tenant_id` (string, optional)
- `text` (string, optional, nullable)
- `text_field` (string, optional, nullable) — Optional schema text-indexed column to search. When omitted, TraceDB searches all text-indexed columns for backwards-compatible fieldless queries.
- `top_k` (integer, optional)
- `vector` (list of double, optional, nullable)
- `vector_field` (string, optional, nullable) — Optional schema vector column to score. When omitted, TraceDB uses the first vector column for backwards-compatible fieldless queries.

## Response

### 200

Successful TraceDB response.

- `access_path_timings` (list of AccessPathTiming, optional)
- `access_paths` (list of AccessPathExplain, optional)
- `candidate_budget` (integer, optional)
- `deduped_candidate_count` (integer, optional)
- `dirty_feature_count` (integer, optional)
- `early_stop_reason` (string, optional, nullable)
- `exact_fallback_triggered` (boolean, optional)
- `failed_feature_count` (integer, optional)
- `final_visibility_guard_count` (integer, optional)
- `final_visibility_guard_removed` (integer, optional)
- `freshness_mode` (string, optional)
- `fusion_method` (string, optional)
- `hot_overlay_searched` (boolean, optional)
- `lexical_cache_hits` (integer, optional)
- `lexical_cache_misses` (integer, optional)
- `lexical_indexed_documents` (integer, optional)
- `lexical_scored_documents` (integer, optional)
- `materialized_count` (integer, optional)
- `missing_feature_count` (integer, optional)
- `module_versions` (list of string, optional)
- `opened_candidate_streams` (list of string, optional)
- `pending_feature_count` (integer, optional)
- `phase_timings` (list of QueryPhaseTiming, optional)
- `planner_candidates` (list of Candidate, optional)
- `policy_epoch` (integer, optional)
- `read_epoch` (integer, optional)
- `returned_count` (integer, optional)
- `scalar_filter_applied` (boolean, optional)
- `scalar_filter_predicates` (list of string, optional)
- `scalar_filter_removed_records` (integer, optional)
- `scalar_filter_visible_records` (integer, optional)
- `schema_epoch` (integer, optional)
- `segments_scanned` (integer, optional)
- `selected_strategy` (string, optional, nullable)
- `skipped_access_paths` (list of string, optional)
- `tenant_mask_visible_records` (integer, optional)
- `text_candidates` (integer, optional)
- `vector_candidates` (integer, optional)

## Errors

### 400 Bad Request Error

Bad request or validation failure.

- `code` (string, optional) — Stable machine-readable error code when available; existing clients can continue to read error.
- `error` (string, optional)

### 401 Unauthorized Error

Unauthorized gateway request.

- `code` (string, optional) — Stable machine-readable error code when available; existing clients can continue to read error.
- `error` (string, optional)

### 404 Not Found Error

Route not found.

- `code` (string, optional) — Stable machine-readable error code when available; existing clients can continue to read error.
- `error` (string, optional)

### 429 Too Many Requests Error

Gateway rate limit exceeded.

- `code` (string, optional) — Stable machine-readable error code when available; existing clients can continue to read error.
- `error` (string, optional)

### 500 Internal Server Error

Engine or gateway failure.

- `code` (string, optional) — Stable machine-readable error code when available; existing clients can continue to read error.
- `error` (string, optional)

### 502 Bad Gateway Error

Gateway upstream failure.

- `code` (string, optional) — Stable machine-readable error code when available; existing clients can continue to read error.
- `error` (string, optional)

### 503 Service Unavailable Error

Service unavailable.

- `code` (string, optional) — Stable machine-readable error code when available; existing clients can continue to read error.
- `error` (string, optional)

## Types

### AccessPathTiming

Access path timing entry.

- `access_path_id` (string, optional)
- `build_ms` (double, optional)
- `open_ms` (double, optional)

### AccessPathExplain

Access path explain entry.

- `access_path_id` (string, optional)
- `candidates` (integer, optional)
- `opened` (boolean, optional)
- `visibility_checked_before_open` (boolean, optional)

### QueryPhaseTiming

Query phase timing entry.

- `elapsed_ms` (double, optional)
- `phase` (string, optional)

### Candidate

Planner candidate explain row.

- `freshness` (string, optional)
- `record_id` (string, optional)
- `score_components` (HybridScoreComponents, optional) — Hybrid query score components.
- `score_upper_bound` (double, optional, nullable)
- `source` (string, optional)
- `version_id` (integer, optional)
- `visibility_checked` (boolean, optional)

### HybridScoreComponents

Hybrid query score components.

- `final_score` (double, optional)
- `freshness_penalty` (double, optional, nullable)
- `lexical` (double, optional, nullable)
- `relational` (double, optional, nullable)
- `vector` (double, optional, nullable)

## Examples

**Request**

```json
{}
```

**Response**

```json
{
  "access_path_timings": [
    {
      "access_path_id": "ap_12345",
      "build_ms": 12.5,
      "open_ms": 8.3
    }
  ],
  "access_paths": [
    {
      "access_path_id": "ap_12345",
      "candidates": 5,
      "opened": true,
      "visibility_checked_before_open": true
    }
  ],
  "candidate_budget": 100,
  "deduped_candidate_count": 95,
  "dirty_feature_count": 3,
  "early_stop_reason": "Reached candidate budget limit",
  "exact_fallback_triggered": false,
  "failed_feature_count": 2,
  "final_visibility_guard_count": 10,
  "final_visibility_guard_removed": 2,
  "freshness_mode": "latest",
  "fusion_method": "weighted_sum",
  "hot_overlay_searched": true,
  "lexical_cache_hits": 150,
  "lexical_cache_misses": 25,
  "lexical_indexed_documents": 10000,
  "lexical_scored_documents": 850,
  "materialized_count": 900,
  "missing_feature_count": 1,
  "module_versions": [
    "v1.4.2",
    "v2.0.1"
  ],
  "opened_candidate_streams": [
    "stream_01",
    "stream_02"
  ],
  "pending_feature_count": 4,
  "phase_timings": [
    {
      "elapsed_ms": 45.7,
      "phase": "index_scan"
    },
    {
      "elapsed_ms": 30.2,
      "phase": "scoring"
    }
  ],
  "planner_candidates": [
    {
      "freshness": "2024-06-01T12:00:00Z",
      "record_id": "rec_98765",
      "score_components": {
        "final_score": 0.92,
        "freshness_penalty": 0.05,
        "lexical": 0.4,
        "relational": 0.3,
        "vector": 0.27
      },
      "score_upper_bound": 0.95,
      "source": "vector_index",
      "version_id": 3,
      "visibility_checked": true
    }
  ],
  "policy_epoch": 42,
  "read_epoch": 105,
  "returned_count": 50,
  "scalar_filter_applied": true,
  "scalar_filter_predicates": [
    "status = 'active'",
    "region = 'us-west'"
  ],
  "scalar_filter_removed_records": 10,
  "scalar_filter_visible_records": 490,
  "schema_epoch": 7,
  "segments_scanned": 12,
  "selected_strategy": "hybrid_vector_lexical",
  "skipped_access_paths": [
    "ap_54321",
    "ap_67890"
  ],
  "tenant_mask_visible_records": 480,
  "text_candidates": 30,
  "vector_candidates": 20
}
```

**SDK Code**

```python
import requests

url = "http://127.0.0.1:8090/v1/explain"

payload = {}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'http://127.0.0.1:8090/v1/explain';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "http://127.0.0.1:8090/v1/explain"

	payload := strings.NewReader("{}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("http://127.0.0.1:8090/v1/explain")

http = Net::HTTP.new(url.host, url.port)

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("http://127.0.0.1:8090/v1/explain")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'http://127.0.0.1:8090/v1/explain', [
  'body' => '{}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("http://127.0.0.1:8090/v1/explain");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "http://127.0.0.1:8090/v1/explain")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```