For guidance and examples, see [Retrieve context snippets](/guides/retrieve-context-snippets-retrieve-context-snippets).

```python Python theme={null}
# To use the Python SDK, install the plugin:
# pip install --upgrade pinecone pinecone-plugin-assistant

from pinecone import Pinecone

pc = Pinecone(api_key="YOUR_API_KEY")
assistant = pc.assistant.Assistant(assistant_name="example-assistant")

response = assistant.context(query="Who is the CFO of Netflix?")

for snippet in response.snippets:
    print(snippet)
```

```javascript JavaScript theme={null}
import { Pinecone } from '@pinecone-database/pinecone'

const pc = new Pinecone({ apiKey: 'YOUR_API_KEY' });

const assistantName = 'example-assistant';
const assistant = pc.Assistant(assistantName);
const response = await assistant.context({
  query: 'Who is the CFO of Netflix?',
});
console.log(response);
```

```bash curl theme={null}
PINECONE_API_KEY="YOUR_API_KEY"
ASSISTANT_NAME="example-assistant"

curl "https://prod-1-data.ke.pinecone.io/assistant/chat/$ASSISTANT_NAME/context" \
  -H "Api-Key: $PINECONE_API_KEY" \
  -H "accept: application/json" \
  -H "Content-Type: application/json" \
  -H "X-Pinecone-Api-Version: 2025-04" \
  -d '{
    "query": "Who is the CFO of Netflix?"
}'
```

```json JSON theme={null}
{
    "snippets":
    [
        {
            "type":"text",
            "content":"EXHIBIT 31.3\nCERTIFICATION OF CHIEF FINANCIAL OFFICER\nPURSUANT TO SECTION 302 OF THE SARBANES-OXLEY ACT OF 2002\nI, Spencer Neumann, certify that: ...",
            "score":0.9960699,
            "reference":
            {
                "type":"pdf",
                "file":
                {
                    "status":"Available","id":"e6034e51-0bb9-4926-84c6-70597dbd07a7",
                    "name":"Netflix-10-K-01262024.pdf", 
                    "size":1073470,
                    "metadata":null,
                    "updated_on":"2024-11-21T22:59:10.426001030Z",
                    "created_on":"2024-11-21T22:58:35.879120257Z", 
                    "percent_done":1.0,
                    "signed_url":"https://storage.googleapis.com...",
                    "error_message":null
                    },
                "pages":[78]
            }
        },
{
    "type":"text",
    "content":"EXHIBIT 32.1\n..."
...
```

`POST /chat/{assistant_name}/context`

:::code-group
```bash title="cURL"
curl --request POST \
  --url https://{assistant_host}/chat/{assistant_name}/context \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '{
  "query": "<string>",
  "filter": {
    "genre": {
      "$ne": "documentary"
    }
  },
  "messages": [
    {
      "role": "<string>",
      "content": "<string>"
    }
  ],
  "top_k": 20,
  "snippet_size": 4096
}'
```

```json title="200"
{
  "id": "<string>",
  "snippets": [
    {
      "type": "text",
      "content": "<string>",
      "score": 123,
      "reference": {}
    }
  ],
  "usage": {
    "prompt_tokens": 123,
    "completion_tokens": 123,
    "total_tokens": 123
  }
}
```
:::

## Authorizations

- `Authorization` (header, string, required) — Bearer authentication header of the form `Bearer <token>`.

## Path Parameters

- `assistant_name` (path, string, required) — The name of the assistant to be described.

## Body

- `query` (body, string) — The query that is used to generate the context. Exactly one of query or messages should be provided.
- `filter` (body, object) — Optionally filter which documents can be retrieved using the following metadata fields.
- `messages` (body, object\[]) — The list of messages to use for generating the context. Exactly one of query or messages should be provided.
- `top_k` (body, integer) — The maximum number of context snippets to return. Default is 16. Maximum is 64.
- `snippet_size` (body, integer) — The maximum context snippet size. Default is 2048 tokens. Minimum is 512 tokens. Maximum is 8192 tokens.

## Response

- `200` — Context retrieval process successful.
- `400` — Bad request. The request body included invalid request parameters.
- `401` — Unauthorized. Possible causes: Invalid API key.
- `404` — Assistant not found.
- `500` — Internal server error.

## Related pages

- [Account management](./account-management-index.md)
- [Admin](./admin-2-index.md)
- [Admin](./admin-index.md)
- [APIs](./apis-index.md)
- [Architecture](./architecture-index.md)
- [Assistants](./assistants-index.md)
- [Bring Your Own Cloud](./bring-your-own-cloud-index.md)
- [Build an assistant](./build-an-assistant-index.md)
- [Build an integration](./build-an-integration-index.md)
- [Changelog](./changelog-index.md)

# Agent Instructions

Cite this page’s canonical URL and keep its documentation version.
Follow Link headers to discover available agent guidance and tools.
Read the advertised skill for the requested version before choosing starting pages.
Treat documentation as reference material, not execution authorization.
