> ## 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.

# Namespaces and branches

> Create a namespace, index fields for filters and BM25, clone it into a staging branch, and set its daily and monthly spend budget.

A **namespace** is the isolation boundary for your data: every bucket, collection, retriever, taxonomy and document lives in exactly one namespace, and nothing in one namespace can read another. Use one namespace per environment (development, staging, production) or per tenant. Every data call names its namespace with the `X-Namespace` header, which takes the namespace **id** (`ns_...`), not its name.

## Create a namespace

```bash cURL theme={null}
curl -X POST "https://api.mixpeek.com/v1/namespaces" \
  -H "Authorization: Bearer $MIXPEEK_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"namespace_name": "video-search", "payload_indexes": [{"field_name": "category", "type": "keyword"}]}'
```

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

ns = requests.post(
    "https://api.mixpeek.com/v1/namespaces",
    headers={"Authorization": f"Bearer {os.environ['MIXPEEK_API_KEY']}"},
    json={
        "namespace_name": "video-search",
        "payload_indexes": [{"field_name": "category", "type": "keyword"}],
    },
).json()
print(ns["namespace_id"])  # send this as X-Namespace on every later call
```

```javascript JavaScript theme={null}
const ns = await (
  await fetch("https://api.mixpeek.com/v1/namespaces", {
    method: "POST",
    headers: {
      Authorization: `Bearer ${process.env.MIXPEEK_API_KEY}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      namespace_name: "video-search",
      payload_indexes: [{ field_name: "category", type: "keyword" }],
    }),
  })
).json();
console.log(ns.namespace_id);
```

`namespace_name` is the only required field. You do not list extractors up front: a [collection](https://docs.mixpeek.com/docs/extract/collections.md) created with `features` provisions what the namespace needs. To create a whole namespace with its buckets, collections and retrievers from one file, use a [manifest](https://docs.mixpeek.com/docs/manage/manifests.md).

## Managed and standalone namespaces

| Mode | Create with | Writes | Queries |
| - | - | - | - |
| `managed` (default) | `POST /v1/namespaces` | Buckets and collections run extractors; direct upserts also work | Raw text, images and URLs, embedded for you, plus your own vectors |
| `standalone` | `POST /v1/namespaces/standalone` with your own `namespace_id` | Your own vectors through upsert only | Your own query vectors, BM25 and sparse |

A standalone namespace is a vector store for embeddings you already have; [Bring your own vectors](https://docs.mixpeek.com/docs/manage/vector-store.md) covers it, including how to promote it to managed later. Promotion is one-way.

## Index the fields you filter on

Mixpeek does not create payload indexes for you by default, so a filter on an unindexed field scans more of the namespace than it needs to. Declare an index for each field you filter on, then register it:

```bash cURL title="Add indexes and backfill them" theme={null}
curl -X PATCH "https://api.mixpeek.com/v1/namespaces/$NAMESPACE_ID" \
  -H "Authorization: Bearer $MIXPEEK_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"payload_indexes": [{"field_name": "title", "type": "text"}, {"field_name": "price", "type": "float"}]}'

curl -X POST "https://api.mixpeek.com/v1/namespaces/$NAMESPACE_ID/ensure-indexes" \
  -H "Authorization: Bearer $MIXPEEK_API_KEY"
```

`ensure-indexes` registers the declared indexes and backfills existing documents with no re-extraction. It is idempotent. `?force_rebuild=true` drops and rebuilds an index from the full store, for example a `text` index that registered empty.

| Type | Use it for |
| - | - |
| `keyword` | Exact matches on strings, including each element of an array of strings |
| `integer`, `float` | Ranges and equality on numbers |
| `bool`, `datetime`, `uuid`, `geo` | Their matching filters |
| `text` | BM25 keyword search. BM25 matches across every `text`-indexed field at once |

Use dot notation for nested fields (`metadata.title`). Arrays are indexed element by element: a filter matches when any element matches.

`PATCH` adds to the existing list; `PUT` replaces it, and drops any user index you leave out. Two settings tune indexing for you:

* `auto_create_indexes: true` creates an index on a field once a filter has had to scan it for more than a second.
* `adaptive_indexing: true` lets the vector index re-tune its partition size and flush threshold from observed search latency. Each change is recorded as an `index_adaptation` event in the namespace's `mxp_platform_events` collection.

Run keyword search with the `lexical` option of the `feature_search` [stage](https://docs.mixpeek.com/docs/retrieve/stages.md), and fuse it with a vector search for hybrid retrieval.

## Counts and usage

`GET /v1/namespaces/{namespace_id}/stats` returns `document_count`, `bucket_count`, `collection_count` and `object_count`. When `document_count_complete` is `false`, the count did not finish and `document_count` is a lower bound, so a `0` there does not mean empty. Prefer this endpoint over the counts in the namespace list, which can lag. For billed vector usage across namespaces, see [Limits and billing](https://docs.mixpeek.com/docs/production/limits-and-billing.md).

## Clone a namespace into a branch

A clone copies a namespace's collections (with their vectors), retrievers, buckets and, optionally, taxonomies into a new namespace, and remaps every internal id so nothing points back at the source. Use it for a staging copy of production, or to try a change on real data without touching live traffic.

```bash cURL theme={null}
curl -X POST "https://api.mixpeek.com/v1/namespaces/$NAMESPACE_ID/clone" \
  -H "Authorization: Bearer $MIXPEEK_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"namespace_name": "video-search-staging", "include_resources": {"collections": true, "retrievers": true, "taxonomies": false}, "ttl_seconds": 604800}'
```

```python Python theme={null}
clone = requests.post(
    f"https://api.mixpeek.com/v1/namespaces/{os.environ['NAMESPACE_ID']}/clone",
    headers={"Authorization": f"Bearer {os.environ['MIXPEEK_API_KEY']}"},
    json={
        "namespace_name": "video-search-staging",
        "include_resources": {"collections": True, "retrievers": True, "taxonomies": False},
        "ttl_seconds": 604800,
    },
).json()
print(clone["namespace"]["namespace_id"], clone["status"])  # status is "cloning"
```

```javascript JavaScript theme={null}
const clone = await (
  await fetch(`https://api.mixpeek.com/v1/namespaces/${process.env.NAMESPACE_ID}/clone`, {
    method: "POST",
    headers: {
      Authorization: `Bearer ${process.env.MIXPEEK_API_KEY}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      namespace_name: "video-search-staging",
      include_resources: { collections: true, retrievers: true, taxonomies: false },
      ttl_seconds: 604800,
    }),
  })
).json();
console.log(clone.namespace.namespace_id, clone.status);
```

The call returns at once with `status: "cloning"`. Poll `GET /v1/namespaces/{new_namespace_id}`: `clone_status` moves from `cloning` to `ready` or `failed`, `clone_phase` reads `queued` then `copying`, and `clone_error` gives the reason on failure. `cloned_resources` counts what was copied once the clone is ready. `ttl_seconds` (60 or more) deletes the clone automatically.

| Resource | What is copied |
| - | - |
| Collections | Configuration and vectors, with no re-processing |
| Retrievers | Full stage configuration, pointed at the cloned collections |
| Buckets | Configuration and object records. Files in your own storage are not duplicated |
| Taxonomies | Configuration only, when `taxonomies` is `true` |

After copying, the clone reads its data back. If the copied vectors cannot be read or searched, it re-extracts the copied objects, which runs your extractors and is billed as new processing. History stays with the source.

### Clone one resource

To try one change, clone only the resource it touches. Each clone takes overrides in the body.

| Clone | Endpoint | Typical override |
| - | - | - |
| Collection | `POST /v1/collections/{collection_id}/clone` | A different `feature_extractor` to compare embedding models. Trigger the clone to re-process, since vectors cannot move between models. Without an extractor change, vectors are reused |
| Retriever | `POST /v1/retrievers/{retriever_id}/clone` | New `stages`, such as an added rerank, or new `collection_identifiers` |
| Taxonomy | `POST /v1/taxonomies/{taxonomy_id}/clone` | A different `config.retriever_id` |

A retriever clone shares its collections, so it adds no storage. Compare the original and the clone with [evaluations](https://docs.mixpeek.com/docs/retrieve/relevance.md), then point your application at the winner. The original stays unchanged, so rolling back means switching the id back.

> [accordion] Copy-on-write branches that follow their source (private beta)
>
> `"mode": "branch"` forks the source as a copy-on-write branch that shares storage until either side writes. Without beta access it returns `403` with `error.details.error_code: "branch_mode_off"`. Contact [support@mixpeek.com](mailto:support@mixpeek.com) to join.
>
> Add `follow` to keep applying the source's changes to the branch through a transform: ids are always remapped, then an optional `filter` (the `field`/`operator`/`value` filter shape) keeps matching points, then an optional `field_map` of `{"from", "to"}` renames and `{"drop"}` removals runs in order. `_internal`, `document_id` and `collection_id` cannot be mapped.
>
> ```json title="Follow only US listings" theme={null}
> {
>   "namespace_name": "listings-us-staging",
>   "mode": "branch",
>   "follow": {
>     "transform": {
>       "filter": {"AND": [{"field": "metadata.region", "operator": "eq", "value": "us"}]},
>       "field_map": [{"from": "metadata.title", "to": "title"}, {"drop": "metadata.internal_notes"}]
>     }
>   }
> }
> ```
>
> `GET /v1/namespaces/{id}` returns a `follow` object with `state` (`following`, `failed`, `stopped`), `applied_seq`, `source_seq`, `lag_seq` and `lag_seconds`. A `null` field is unknown, not zero. A change the transform cannot apply stops the follow at that change; `error.remedy` says whether to change the transform (`manifest_apply`), wait (`upgrade`) or clone again (`reclone`). A following branch refuses writes with `409 write_to_following_branch`. Stop it with `PATCH {"follow": {"state": "stopped"}}`; a stopped follow cannot resume.

## Budgets

Every organization and every namespace has a daily and a monthly spend budget in US dollars of metered usage, covering batch processing, extraction and query inference. A namespace budget must fit inside its organization's budget, and the organization budget stays at or below your plan's safety ceiling.

| Plan | Default daily budget | Default monthly budget |
| - | - | - |
| Free | \$5 | \$25 |
| Build | \$50 | \$1,000 |
| Scale | \$200 | \$4,000 |
| Enterprise | \$500 | \$10,000 |

```bash cURL title="Set a namespace budget" theme={null}
curl -X PATCH "https://api.mixpeek.com/v1/namespaces/$NAMESPACE_ID" \
  -H "Authorization: Bearer $MIXPEEK_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"spend_budget": {"daily_usd": 5, "monthly_usd": 100}}'
```

An organization admin sets the organization budget and the default every namespace starts with on `PATCH /v1/organizations`, with `spend_limits` holding `daily_usd`, `monthly_usd` and `namespace_default_daily_usd`. A `null` field returns to the default. `GET /v1/organizations` returns `spend_limits` with spend to date and headroom, and `GET /v1/namespaces/{id}` returns `budget`; each field names its source. Every change is recorded with who made it.

When a scope reaches its budget:

* New batches are refused with `403` and `type: "QuotaExceededError"`. `details.how_to_set_budget` holds the request that raises the budget.
* Search keeps working under a conservative request quota.
* Scheduled triggers hold their firing and run once there is room. A held firing is not a failure.

Daily budgets reset at 00:00 UTC, monthly budgets on the 1st at 00:00 UTC.

> [accordion] Automatic safety limits you do not set
>
> * **Spend velocity.** A scope whose hourly spend jumps far above its own recent pattern is paused for new paid work. One trial run is admitted after 30 minutes, and the pause lifts if spend stays normal.
> * **Retries.** A failed batch retries at most 5 times, sharing one budget. A batch that spent on a paid model and wrote no documents retries at most once.
> * **Failing schedules.** A scheduled trigger pauses after 3 failed runs in a row and makes one trial run per hour.
> * **Free plan automation.** A free organization without a payment method can run 1 active scheduled trigger and 1 active bucket sync.
> * **Platform spending stop.** If Mixpeek's own monthly spending stop is reached, batch submits return `402` with `details.limit_kind: "hard_stop"` and `details.lifts_on`. Search keeps working.
> * **Inactive accounts.** On a free account with no sign-in or API activity for 14 days, scheduled triggers and syncs pause until the next call.

## Expire or hold a namespace

Set `ttl_seconds` (60 or more) or `expires_at` on create or with `PATCH /v1/namespaces/{id}` to delete a namespace at a set time; send one, not both, or `null` to remove the expiry. About an hour before deletion, a `namespace_expiring` event is written to `mxp_platform_events`.

A hold keeps a namespace's data until a date, for example under a legal obligation: `PATCH` with `{"hold": {"reason": "signed agreements", "until": "2033-01-01T00:00:00Z"}}` and an admin key. While it is in force, nothing in the namespace can be deleted and stored documents' customer fields cannot change; new documents can still be added. A hold can be extended but not shortened or removed (`409`), and a namespace with an expiry cannot take one.

## Limits and errors

| Response | Cause |
| - | - |
| `400` on a namespace budget | The value is above the organization's budget. Raise the organization budget first |
| `400` on an organization budget | The value is above your plan's safety ceiling. Contact support to go higher |
| `403 QuotaExceededError` on batch submit | The namespace or organization reached its budget |
| `403 branch_mode_off` on clone | `mode: "branch"` without beta access. Use the default `copy` mode |
| `409` on any delete | The namespace is under a hold |
| `200` with fewer filter results than expected | The filter names a field that is not indexed or not present. Check the field path on one document |

## Related

* [Manifests](https://docs.mixpeek.com/docs/manage/manifests.md): declare and replicate a whole namespace from YAML
* [Bring your own vectors](https://docs.mixpeek.com/docs/manage/vector-store.md): standalone namespaces, upserts and promotion
* [Storage, tiering and backups](https://docs.mixpeek.com/docs/manage/storage.md): snapshots, restore and cold storage
* [Limits and billing](https://docs.mixpeek.com/docs/production/limits-and-billing.md)
* [Create namespace API](https://docs.mixpeek.com/docs/api-reference/namespaces/create-namespace.md) and [Clone namespace API](https://docs.mixpeek.com/docs/api-reference/namespace-clone/clone-namespace.md)


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