> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mixpeek.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Retrievers

> Create and execute a retriever: input schema, stages, metadata filters, pagination, batch execution, caching, typeahead and publishing.

A retriever is a saved search pipeline. It names the collections it reads, declares the inputs a caller sends in `input_schema`, and runs a list of [stages](https://docs.mixpeek.com/docs/retrieve/stages.md) in order: a search, then filters, sorts, reducers and enrichments. You create it once and execute it with new inputs on every request. Each run returns `documents`, a `status` and a `warnings` array.

## Create a retriever

This retriever runs one feature search over a collection named `products` that uses the text extractor. It takes one input, `query`.

```bash cURL theme={null}
curl -sS -X POST "https://api.mixpeek.com/v1/retrievers" \
  -H "Authorization: Bearer $MIXPEEK_API_KEY" \
  -H "X-Namespace: $NAMESPACE_ID" \
  -H "Content-Type: application/json" \
  -d '{
    "retriever_name": "product_search",
    "collection_identifiers": ["products"],
    "input_schema": {
      "query": {"type": "text", "required": true}
    },
    "stages": [
      {
        "stage_name": "search",
        "stage_type": "filter",
        "config": {
          "stage_id": "feature_search",
          "parameters": {
            "searches": [
              {
                "feature_uri": "mixpeek://text_extractor@v1/multilingual_e5_large_instruct_v1",
                "query": {"input_mode": "text", "value": "{{INPUT.query}}"},
                "top_k": 100
              }
            ],
            "final_top_k": 20
          }
        }
      }
    ]
  }'
```

```python Python theme={null}
import os
import requests

HEADERS = {
    "Authorization": f"Bearer {os.environ['MIXPEEK_API_KEY']}",
    "X-Namespace": os.environ["NAMESPACE_ID"],
}

body = {
    "retriever_name": "product_search",
    "collection_identifiers": ["products"],
    "input_schema": {"query": {"type": "text", "required": True}},
    "stages": [
        {
            "stage_name": "search",
            "stage_type": "filter",
            "config": {
                "stage_id": "feature_search",
                "parameters": {
                    "searches": [
                        {
                            "feature_uri": "mixpeek://text_extractor@v1/multilingual_e5_large_instruct_v1",
                            "query": {"input_mode": "text", "value": "{{INPUT.query}}"},
                            "top_k": 100,
                        }
                    ],
                    "final_top_k": 20,
                },
            },
        }
    ],
}

resp = requests.post("https://api.mixpeek.com/v1/retrievers", headers=HEADERS, json=body)
resp.raise_for_status()
print(resp.json()["retriever_id"])
```

```javascript JavaScript theme={null}
const body = {
  retriever_name: "product_search",
  collection_identifiers: ["products"],
  input_schema: { query: { type: "text", required: true } },
  stages: [
    {
      stage_name: "search",
      stage_type: "filter",
      config: {
        stage_id: "feature_search",
        parameters: {
          searches: [
            {
              feature_uri: "mixpeek://text_extractor@v1/multilingual_e5_large_instruct_v1",
              query: { input_mode: "text", value: "{{INPUT.query}}" },
              top_k: 100,
            },
          ],
          final_top_k: 20,
        },
      },
    },
  ],
};

const res = await fetch("https://api.mixpeek.com/v1/retrievers", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.MIXPEEK_API_KEY}`,
    "X-Namespace": process.env.NAMESPACE_ID,
    "Content-Type": "application/json",
  },
  body: JSON.stringify(body),
});
const retriever = await res.json();
console.log(retriever.retriever_id);
```

Save the returned `retriever_id` as `RETRIEVER_ID`. If the `feature_uri` does not match an index in your collections, the error lists the `available_feature_uris`; copy one from there or from `vector_indexes[].feature_uri` on `GET /v1/collections/{collection_id}`. Full schema: [Create retriever](https://docs.mixpeek.com/docs/api-reference/retrievers/create-retriever.md).

## Execute a retriever

```bash cURL theme={null}
curl -sS -X POST "https://api.mixpeek.com/v1/retrievers/$RETRIEVER_ID/execute" \
  -H "Authorization: Bearer $MIXPEEK_API_KEY" \
  -H "X-Namespace: $NAMESPACE_ID" \
  -H "Content-Type: application/json" \
  -d '{"inputs": {"query": "wireless earbuds"}, "limit": 10}'
```

```python Python theme={null}
import os
import requests

resp = requests.post(
    f"https://api.mixpeek.com/v1/retrievers/{os.environ['RETRIEVER_ID']}/execute",
    headers={
        "Authorization": f"Bearer {os.environ['MIXPEEK_API_KEY']}",
        "X-Namespace": os.environ["NAMESPACE_ID"],
    },
    json={"inputs": {"query": "wireless earbuds"}, "limit": 10},
)
run = resp.json()
print(run["status"], run["warnings"])
for doc in run["documents"]:
    print(doc["document_id"], doc["score"])
```

```javascript JavaScript theme={null}
const res = await fetch(
  `https://api.mixpeek.com/v1/retrievers/${process.env.RETRIEVER_ID}/execute`,
  {
    method: "POST",
    headers: {
      Authorization: `Bearer ${process.env.MIXPEEK_API_KEY}`,
      "X-Namespace": process.env.NAMESPACE_ID,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({ inputs: { query: "wireless earbuds" }, limit: 10 }),
  },
);
const run = await res.json();
console.log(run.status, run.warnings);
for (const doc of run.documents) console.log(doc.document_id, doc.score);
```

The execute body also takes `filters` (merged with the stages' filters), `pagination`, `skip_cache` and `explain`. See [Execute retriever](https://docs.mixpeek.com/docs/api-reference/retrievers/execute-retriever.md).

## Read the response

Read `documents`, check `status`, and print `warnings`. A run that times out or skips a stage still answers HTTP 200, with `status: "degraded"` and an entry in `warnings`, so a short or empty `documents` can come from the degradation. A clean run returns `status: "completed"`, and then an empty `documents` is a genuine no-match. Its `warnings` still carries one notice that the deprecated `results` field is no longer returned, unless you pass `?include_legacy_results=true`; any other entry is a real problem.

| Field | What it holds |
| - | - |
| `documents` | The results, each with `document_id`, `collection_id`, `score` and its fields. `results` is a deprecated alias and is absent by default. |
| `status` | `completed`, `degraded`, `failed`, `processing` or `pending`. |
| `warnings` | Problems that did not stop the run, such as a filter on an unindexed field. |
| `degraded` | When `status` is `degraded`: what was skipped, why, and what to do. |
| `limits` | Every cap that clamped the request. Absent when nothing was capped. |
| `stage_statistics` | `stages.<stage_name>` timing, document counts, `cache_hit` and stage metadata. |
| `pagination` | The page you got and how to fetch the next one. |
| `budget` | `credits_used`, `time_elapsed_ms`, `llm_calls`. A plain text search and a cache hit read `0.0` credits. |
| `interpretation` | What the platform did with your inputs, including `ignored_input_keys` and `relaxations`. |

A non-empty `interpretation.relaxations` means a filter condition was dropped because its input was absent, so the results are broader than the filter you wrote. `ignored_input_keys` lists inputs no stage reads. The most common cause of an empty result is a wrong `feature_uri`.

Media URLs such as `thumbnail_url` and `video_segment_url` are signed per request and expire after 24 hours. Re-run the query for fresh ones instead of storing them.

## Input schema

`input_schema` is a flat dict that maps each input name to its definition. Do not wrap it in a JSON Schema object such as `{"type": "object", "properties": ...}`; the API refuses that shape. Stages read inputs as `{{INPUT.name}}`.

| Key | Meaning |
| - | - |
| `type` | Required. `string`, `text`, `number`, `integer`, `float`, `boolean`, `object`, `array`, `date`, `datetime`, `image`, `audio`, `video`, `pdf`, `excel` or `document_reference`. |
| `required` | Defaults to `false`. |
| `default` | Used when the caller omits the input. |
| `description`, `examples` | Shown in generated UIs and apps. |
| `enum` | Restricts the value to a fixed set. |
| `items`, `properties` | Nested definitions for `array` and `object`. |

There is no `vector` type. Declare a precomputed embedding as `array` with `items` of type `float`: `{"embedding": {"type": "array", "items": {"type": "float"}, "required": true}}`. A [`feature_search`](https://docs.mixpeek.com/docs/retrieve/stages#feature-search) query reads it with `{"input_mode": "vector", "value": "{{INPUT.embedding}}"}`.

An input name the retriever does not declare returns 400 before any stage runs, with `accepted_fields` in the error. A missing required input returns 422. `session_id` and `user_id` are accepted on every retriever without being declared.

## Stages and templates

Each stage is `{"stage_name", "stage_type", "config": {"stage_id", "parameters"}}`. `stage_name` is your label, `stage_id` picks the stage, and `stage_type` is optional because the API infers it from `stage_id`. [Stages](https://docs.mixpeek.com/docs/retrieve/stages.md) lists every stage with its parameters.

Stage parameters accept Jinja2 templates with double braces. Namespaces are case-insensitive.

| Namespace | Holds | Example |
| - | - | - |
| `INPUT` | The caller's inputs | `{{INPUT.query}}` |
| `DOC` | The current document, in per-document stages | `{{DOC.metadata.category}}` |
| `CONTEXT` | Execution state and aliased stage outputs | `{{CONTEXT.budget_remaining}}` |
| `STAGE` | Earlier stages' outputs | `{{STAGE.search.top_score}}` |

`PATCH /v1/retrievers/{retriever_id}` replaces the stage list on an unpublished retriever. A published retriever's stages are fixed; clone it to change them.

## Filters

A metadata filter is a tree of `AND`, `OR` and `NOT` groups whose leaves are `field`/`operator`/`value` conditions. The same shape works in a stage's `pre_filters`, in the execute body's `filters`, in [`attribute_filter`](https://docs.mixpeek.com/docs/retrieve/stages#attribute-filter), and in conditional `when` blocks.

```json Filter for published video or audio that is not restricted theme={null}
{
  "AND": [
    {"field": "metadata.status", "operator": "eq", "value": "published"},
    {"OR": [
      {"field": "metadata.type", "operator": "eq", "value": "video"},
      {"field": "metadata.type", "operator": "eq", "value": "audio"}
    ]},
    {"NOT": [
      {"field": "metadata.restricted", "operator": "eq", "value": true}
    ]}
  ]
}
```

Put a stage filter in `pre_filters`, beside `parameters` inside `config`. The vector store applies it during the search. `post_filters` is accepted on every stage and never applied, so a predicate there returns unfiltered results with no warning.

Filtered fields need a payload index (`keyword`, `integer`, `float`, `bool`, `datetime`, `text` or `geo`), set in the namespace's `payload_indexes`; see [Namespaces](https://docs.mixpeek.com/docs/manage/namespaces.md). A filter on an unindexed field adds a `warnings` entry. System fields and `_internal.*` are indexed for you. A filter the API cannot compile returns 422 naming the node, for example `AND[0].NOT[0]`.

> [accordion] Operators
>
> | Operator | Matches |
> | - | - |
> | `eq`, `ne` | Equal, not equal |
> | `gt`, `gte`, `lt`, `lte` | Ranges. Pass RFC 3339 strings for dates. |
> | `in`, `nin` | Value in or not in a list |
> | `exists`, `is_null` | Field present, field null (value `true` or `false`) |
> | `contains`, `text` | Substring of a string. On an array field: equal to one element. |
> | `starts_with`, `ends_with`, `regex` | String prefix, suffix, pattern |
> | `words` | Every word appears as a whole word, matched on its English stem |
> | `phrase` | The words appear in order |
> | `geo_radius` | Within `radius` meters of `center`: `{"center": {"lat": 40.758, "lon": -73.9855}, "radius": 15000}` |
> | `geo_bounding_box` | Inside `top_left` and `bottom_right` corners |
> | `geo_polygon` | Inside `{"exterior": {"points": [...]}}`, 3 points or more |
>
> String operators match without regard to case by default. `eq`, `ne`, `in` and `nin` always compare exactly. In [`attribute_filter`](https://docs.mixpeek.com/docs/retrieve/stages#attribute-filter), set `case_insensitive` to make those compare without case too. A location is `{"lat", "lon"}` or a GeoJSON `[lon, lat]` array, longitude first.

> [accordion] Lineage aliases
>
> | Alias | Resolves to | Use it for |
> | - | - | - |
> | `from_object` | `_internal.lineage.root_object_id` | Everything derived from one bucket object |
> | `from_bucket` | `_internal.lineage.root_bucket_id` | Everything derived from one bucket |
> | `from_document` | `_internal.lineage.source_document_id` | Direct children of one document |
> | `from_collection` | `_internal.lineage.source_collection_id` | Documents whose parent sits in one collection |

> [accordion] Templates and missing inputs
>
> A value can be a template such as `{{INPUT.max_price}}`. When the input is absent, the condition is removed, the run continues, and `interpretation.relaxations` plus `warnings` say so. A bare condition or a list of conditions is read as an `AND` group. An empty filter (`{}` or `{"AND": []}`) means no filter.

> [accordion] Every \_internal field you can filter on
>
> ### Every `_internal` field
>
> This table is generated from the server's field registry, so it is the complete, authoritative set. If a name is not here, Mixpeek does not write it under `_internal`. Filter on the **field / alias** column; the storage path is shown so you can address a nested value explicitly.
>
> **Identity**
>
> | Field / alias | Storage path | Filtering |
> | - | - | - |
> | `document_id` | `_internal.document_id` | `eq`, `in`; system-owned, rejected if you send it on write |
> | `collection_id` | `_internal.collection_id` | `eq`, `in`; system-owned, rejected if you send it on write |
>
> **Timestamps**
>
> | Field / alias | Storage path | Filtering |
> | - | - | - |
> | `created_at` | `_internal.created_at` | `eq` and range operators (`gte`/`lte`/`gt`/`lt`). Pass RFC 3339 strings as bounds |
> | `updated_at` | `_internal.updated_at` | `eq` and range operators (`gte`/`lte`/`gt`/`lt`). Pass RFC 3339 strings as bounds |
>
> **Lineage**
>
> | Field / alias | Storage path | Filtering |
> | - | - | - |
> | `root_object_id` · aliases `from_object` | `_internal.lineage.root_object_id` | `eq`, `in` |
> | `root_bucket_id` · aliases `from_bucket` | `_internal.lineage.root_bucket_id` | `eq`, `in` |
> | `source_type` | `_internal.lineage.source_type` | `eq`, `in` |
> | `source_object_id` | `_internal.lineage.source_object_id` | `eq`, `in` |
> | `source_document_id` · aliases `from_document` | `_internal.lineage.source_document_id` | `eq`, `in` |
> | `source_collection_id` · aliases `from_collection` | `_internal.lineage.source_collection_id` | `eq`, `in` |
> | `lineage_path` | `_internal.lineage.path` | `eq`, `in` |
> | `lineage_chain` | `_internal.lineage.chain` | `eq`, `in` |
> | `bucket_id` | `_internal.lineage.root_bucket_id` | `eq`, `in` |
> | `object_id` | `_internal.lineage.source_object_id` | `eq`, `in` |
> | `processing_tier` | n/a (not stored) | not stored anywhere; a filter on it matches nothing |
> | `parent_document_id` | n/a (not stored) | not stored anywhere; a filter on it matches nothing |
>
> **System metadata**
>
> | Field / alias | Storage path | Filtering |
> | - | - | - |
> | `modality` | `_internal.modality` | `eq`, `in` |
> | `mime_type` | `_internal.mime_type` | `eq`, `in` |
> | `size_bytes` | `_internal.size_bytes` | `eq`, `in` |
> | `content_hash` | `_internal.content_hash` | `eq`, `in`; system-owned, rejected if you send it on write |
> | `metadata` | `_internal.metadata` | `eq`, `in` |
> | `archive` | `_internal.archive` | filter by the exact dotted path only (the bare name is a real customer field name, so it is not auto-resolved) |
>
> **Blobs**
>
> | Field / alias | Storage path | Filtering |
> | - | - | - |
> | `source_blobs` | `_internal.source_blobs` | `eq`, `in` |
> | `document_blobs` | `_internal.document_blobs` | `eq`, `in` |
>
> **Provenance**
>
> | Field / alias | Storage path | Filtering |
> | - | - | - |
> | `source_details` | `_internal.source_details` | `eq`, `in` |
> | `provenance` | `_internal.provenance` | filter by the exact dotted path only (the bare name is a real customer field name, so it is not auto-resolved) |
> | `source_url` | `_internal.processing.source_url` | filter by the exact dotted path only (the bare name is a real customer field name, so it is not auto-resolved) |
> | `object_key_source` | `_internal.processing.object_key_source` | filter by the exact dotted path only (the bare name is a real customer field name, so it is not auto-resolved) |
> | `detected_mime_type` | `_internal.processing.detected_mime_type` | filter by the exact dotted path only (the bare name is a real customer field name, so it is not auto-resolved) |
> | `processing_history` | `_internal.processing.history` | filter by the exact dotted path only (the bare name is a real customer field name, so it is not auto-resolved) |
> | `taxonomy_lineage` | `_internal.processing.taxonomy_lineage` | filter by the exact dotted path only (the bare name is a real customer field name, so it is not auto-resolved) |
> | `last_health_check` | `_internal.processing.last_health_check` | filter by the exact dotted path only (the bare name is a real customer field name, so it is not auto-resolved) |
> | `include_processing_history` | `_internal.processing.include_history` | filter by the exact dotted path only (the bare name is a real customer field name, so it is not auto-resolved) |
>
> **Tenancy**
>
> | Field / alias | Storage path | Filtering |
> | - | - | - |
> | `internal_id` | `_internal.internal_id` | `eq`, `in`; system-owned, rejected if you send it on write |
> | `namespace_id` | `_internal.namespace_id` | `eq`, `in`; system-owned, rejected if you send it on write |
>
> **Access control**
>
> | Field / alias | Storage path | Filtering |
> | - | - | - |
> | `_acl` | `_internal._acl` | `eq`, `in`; system-owned, rejected if you send it on write |

## Pagination

Pass a `pagination` object with a `method` on the execute request. Without it, the run uses cursor pagination sized to the pipeline's `final_top_k`, or 10 when no stage declares one. `limit` is a shorthand for the page size.

| Method | Keys (default) | Use it for |
| - | - | - |
| `cursor` | `limit` (10), `cursor` | Stable iteration |
| `offset` | `page_size` (10), `page_number` (1) | Numbered pages |
| `keyset` | `limit` (10), `after` | Browsing with a sort key |
| `scroll` | `limit` (100), `scroll_id`, `scroll_ttl` (300) | Deep exports |

`offset` takes `page_size` and `page_number`. An unknown key inside `pagination` returns 422 listing the valid keys. Pagination values do not accept templates.

## Batch execution

`POST /v1/retrievers/{retriever_id}/execute/batch` runs up to 16 `queries`, each with its own `inputs` and `filters`, against one retriever. The retriever is planned once for the batch. `concurrency` (default 5, up to 20) sets the parallel runs. With `"stream": true` the results arrive as Server-Sent Events as each query finishes, tagged with `query_index`, and a keepalive comment every 15 seconds.

```bash Execute three queries in one call theme={null}
curl -sS -X POST "https://api.mixpeek.com/v1/retrievers/$RETRIEVER_ID/execute/batch" \
  -H "Authorization: Bearer $MIXPEEK_API_KEY" \
  -H "X-Namespace: $NAMESPACE_ID" \
  -H "Content-Type: application/json" \
  -d '{"queries": [{"inputs": {"query": "red sneakers"}}, {"inputs": {"query": "rain jacket"}}, {"inputs": {"query": "wool socks"}}], "concurrency": 3}'
```

## Execute without saving

`POST /v1/retrievers/execute` runs `stages`, `collection_identifiers`, `input_schema` and `inputs` in one call and stores no retriever. It accepts `filters`, `pagination`, `limit` and `budget_limits`. Use it to try a pipeline, then save the one that works. See [Execute ad-hoc retriever](https://docs.mixpeek.com/docs/api-reference/adhoc-retrievers/execute-adhoc-retriever.md).

## Caching

Responses and stage outputs are cached with no setup. A response cache hit skips the whole pipeline and returns `cached_at`; a stage cache hit skips that stage and sets `cache_hit` in `stage_statistics`. Cache keys include each collection's index signature, so new ingestion invalidates them.

| Control | Where | Effect |
| - | - | - |
| `skip_cache: true` | Execute body | Runs every stage fresh. Results are still written to the cache. |
| `cache_behavior` | Stage parameters | `auto` (default), `disabled`, or `aggressive` for non-deterministic stages. |
| `cache_ttl_seconds` | Stage parameters | Entry lifetime. Unset uses LRU eviction. |
| Update the retriever | `PATCH /v1/retrievers/{retriever_id}` | The next run reads nothing cached. No route clears the cache directly. |

Hit rates are at `GET /v1/analytics/retrievers/{retriever_id}/cache-performance`.

## Explain a run

Mixpeek rewrites your stage list before it runs: it pushes filters into the vector store, merges compatible stages and runs independent work in parallel. Write stages in the order that reads best.

| Call | Runs the query | Tells you |
| - | - | - |
| `POST /v1/retrievers/{retriever_id}/execute/explain` | No | The optimized plan, per-stage cost and latency estimates, `bottleneck_stages`, and which rewrites fired |
| Execute with `"explain": true` | Yes | What this run did, inline in `explain_plan` |
| `GET /v1/retrievers/{retriever_id}/executions/{execution_id}/profile` | No | What a past run did. Only runs executed with `explain: true` have a profile. |

See [Explain retriever execution plan](https://docs.mixpeek.com/docs/api-reference/retrievers/explain-retriever-execution-plan.md).

## Write results to a collection

Add `target_collection_id` to an execute request to store each result as a document in that collection, with its fields, its stored vectors and lineage back to the execution. Running again into the same collection updates those documents in place. A collection can also fill itself from a saved retriever with a `retriever_transform`; see [Collections and features](https://docs.mixpeek.com/docs/extract/collections.md).

## Search as you type

`GET /v1/retrievers/typeahead?q=wir&fields=metadata.brand` returns prefix suggestions from field values, collection names and the caller's recent searches. `limit` (default 10, up to 50) applies per source, so one response can hold 30 entries. At most 5 `fields` are read, and each needs a keyword index. A source that fails is named in `warnings` and the others still answer. See [Typeahead](https://docs.mixpeek.com/docs/api-reference/retrievers/typeahead.md).

## Publish a retriever and add the search widget

`POST /v1/retrievers/{retriever_id}/publish` with a `public_name` gives the retriever a public URL and a slug. `display_config` on the retriever controls the hosted page's inputs, result fields and layout. The `@mixpeek/search-js` React component searches a published retriever:

```bash Install the search widget theme={null}
npm install @mixpeek/search-js
```

```tsx Add the widget to a React app theme={null}
import { MixpeekSearch } from "@mixpeek/search-js";
import "@mixpeek/search-js/styles.css";

export default function App() {
  return <MixpeekSearch projectKey="my-search" placeholder="Search..." theme="auto" />;
}
```

`projectKey` is the `public_name`, or a `ret_sk_` key together with a `retrieverSlug` prop. Users open it with Cmd+K or Ctrl+K. `enableAIAnswer` needs an `agent_search` or `rag_prepare` stage in the retriever. See [Publish retriever](https://docs.mixpeek.com/docs/api-reference/published-retrievers/publish-retriever.md) and [Apps](https://docs.mixpeek.com/docs/tools/apps.md) for hosted search pages.

## Related

* [Stages](https://docs.mixpeek.com/docs/retrieve/stages.md): every stage, its parameters and an example
* [Tune relevance](https://docs.mixpeek.com/docs/retrieve/relevance.md): fusion, interactions, evaluations
* [Monitoring and troubleshooting](https://docs.mixpeek.com/docs/production/monitoring.md): retriever analytics and empty results
* [Templates](https://docs.mixpeek.com/docs/templates/overview.md): deployable retrievers for common use cases


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.