> For a complete page index of the Captain API documentation, fetch https://docs.filesearch.dev/llms.txt?excludeSpec=true

# Update Chunk Metadata

PATCH https://api.filesearch.dev/v3/collections/{collection_name}/chunks/{chunk_id}/metadata
Content-Type: application/json

Merge updates into the custom metadata object attached to a chunk.

Reference: https://docs.filesearch.dev/reference/v3/documents/chunk/metadata/update

## Request

### Path parameters

- `collection_name` (string, required)
- `chunk_id` (string, required)

### Body (application/json)

This endpoint expects an UpdateChunkMetadataRequestV3.

- `custom_metadata` (map from string to any, optional) — The custom metadata object. Keys that Captain uses for its own chunk attributes are reserved and rejected with 400.
- `metadata` (map from string to any, optional, deprecated) — Deprecated alias for `custom_metadata`.

## Response

### 200

Update Chunk Metadata response.

- `chunk_id` (string, required)
- `custom_metadata` (map from string to any, optional) — The stored custom metadata object.
- `updated_at` (string, optional, nullable)
- `filterable` (boolean, optional, default: false) — True when the metadata also reached the search index, so query filters can match it. False when the metadata is stored but filters may not match it yet.
- `metadata` (map from string to any, optional, deprecated) — Deprecated alias for `custom_metadata`; carries the same object.

## Errors

### 401 Unauthorized Error

Missing or invalid authentication.

- `error` (string, required) — Error kind. `HTTP_ERROR` for errors raised by the route.
- `message` (string, required) — What went wrong.
- `path` (string, required) — The request path.
- `status_code` (integer, optional) — The HTTP status code.

### 403 Forbidden Error

API key cannot write to this collection.

- `error` (string, required) — Error kind. `HTTP_ERROR` for errors raised by the route.
- `message` (string, required) — What went wrong.
- `path` (string, required) — The request path.
- `status_code` (integer, optional) — The HTTP status code.

### 404 Not Found Error

Collection not found.

- `error` (string, required) — Error kind. `HTTP_ERROR` for errors raised by the route.
- `message` (string, required) — What went wrong.
- `path` (string, required) — The request path.
- `status_code` (integer, optional) — The HTTP status code.

## Examples

**Request**

```json
{}
```

**Response**

```json
{
  "chunk_id": "chunk_agri_report_001",
  "updated_at": "2024-05-22T14:31:00Z",
  "metadata": {
    "review_status": "peer_reviewed",
    "topic": "agriculture",
    "owner": "research-team",
    "priority": "high"
  }
}
```

**SDK Code**

```python
import json
import requests
import uuid

BASE_URL = "https://api.filesearch.dev"
API_KEY = "your_api_key"
COLLECTION_NAME = "my_documents"
CHUNK_ID = "doc_abc123:0"

headers = {
    "Authorization": f"Bearer {API_KEY}",
    "Content-Type": "application/json",
    "Idempotency-Key": str(uuid.uuid4()),
}

response = requests.patch(
    f"{BASE_URL}/v3/collections/{COLLECTION_NAME}/chunks/{CHUNK_ID}/metadata",
    headers=headers,
    json={
    "metadata": {}
},
    timeout=30.0
)

print(json.dumps(response.json(), indent=2))
```

```typescript
const BASE_URL = "https://api.filesearch.dev";

const API_KEY = "your_api_key";

const collection_name = "my_documents";

const chunk_id = "doc_abc123:0";

const headers = {
  Authorization: `Bearer ${API_KEY}`,
  "Content-Type": "application/json",
  "Idempotency-Key": crypto.randomUUID(),
};

const response = await fetch(`${BASE_URL}/v3/collections/${collection_name}/chunks/${chunk_id}/metadata`, {
  method: "PATCH",
  headers,
  body: JSON.stringify({
    "metadata": {}
  }),
});

const data = await response.json();
console.log(JSON.stringify(data, null, 2));
```