# Retrieve context (/docs/knowledge/retrieve-context)
Sometimes your own model should write the answer, because you've tuned its prompt, picked its provider, or need it to follow your app's format. `lynk.retrieve` runs the search and ranking without writing an answer, and returns the chunks for your model to use.

<Callout type="info" title="Retrieve context when...">
- You run your own model and prompt.
- You want to combine Docklee's context with other context in one prompt.
- You need the source text itself, not a summary.
</Callout>

## Retrieve chunks [#retrieve-chunks]

This example retrieves the top chunks for one question:

<CodeTabs>
  <Tab value="Python">
    ```python
    from docklee import Lynk

    lynk = Lynk(engine_id="your-engine-id")
    chunks = lynk.retrieve_sync("What is the refund window?", top_k=5)
    for chunk in chunks:
        print(chunk.chunk_id, chunk.content)
    ```
  </Tab>
  <Tab value="TypeScript">
    ```ts
    import { Lynk } from 'docklee';

    const lynk = new Lynk({ engineId: 'your-engine-id' });
    const chunks = await lynk.retrieve('What is the refund window?', { topK: 5 });
    for (const chunk of chunks) {
      console.log(chunk.chunkId, chunk.content);
    }
    ```
  </Tab>
  <Tab value="cURL">
    ```bash
    curl https://api.docklee.com/v1/engine/retrieve \
      -H "Authorization: Bearer $DOCKLEE_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{"engine_id": "your-engine-id", "query": "What is the refund window?", "top_k": 5}'
    ```
  </Tab>
</CodeTabs>

The chunks come back best match first, from vector and OKF sources alike:

```json
{
  "chunks": [
    {
      "chunk_id": "c2a8f5e1-7b39-4d6c-a014-8e3f2b9d61c7",
      "content": "Customers can request a refund within 30 days of purchase.",
      "metadata": {"policy": "refunds"}
    },
    {
      "chunk_id": "7e3b9a04-1f6c-4d25-8b97-2a5e0c8d1f63",
      "content": "After 30 days, purchases can be exchanged for store credit.",
      "metadata": {"policy": "refunds"}
    }
  ]
}
```

## `retrieve` options [#retrieve-options]

| Option | Python | TypeScript | Default | Description |
| --- | --- | --- | --- | --- |
| Question | `question` | first argument | none | The question, in plain words. |
| Engine | `engine_id` | `engineId` | `DOCKLEE_ENGINE_ID` | The engine to search for this call. |
| Result count | `top_k` | `topK` | `8` | How many chunks to return, from 1 to 100. |

Your plan can cap `top_k` lower than the range above.

## The chunk [#the-chunk]

| Python | TypeScript | Description |
| --- | --- | --- |
| `chunk_id` | `chunkId` | The chunk's ID. |
| `content` | `content` | The chunk's text. |
| `metadata` | `metadata` | The metadata stored with the chunk, such as what you passed to `capture`. |

## Build a prompt [#build-a-prompt]

Number the chunks so your model can cite them back to you:

<CodeTabs items={['Python', 'TypeScript']}>
  <Tab value="Python">
    ```python
    chunks = lynk.retrieve_sync(question, top_k=5)
    context = "\n\n".join(f"[{i}] {chunk.content}" for i, chunk in enumerate(chunks, 1))
    prompt = (
        "Answer from the sources below. Cite them by number. "
        "If they don't contain the answer, say so.\n\n"
        f"{context}\n\nQuestion: {question}"
    )
    ```
  </Tab>
  <Tab value="TypeScript">
    ```ts
    const chunks = await lynk.retrieve(question, { topK: 5 });
    const context = chunks.map((chunk, i) => `[${i + 1}] ${chunk.content}`).join('\n\n');
    const prompt =
      "Answer from the sources below. Cite them by number. If they don't contain the answer, say so.\n\n" +
      `${context}\n\nQuestion: ${question}`;
    ```
  </Tab>
</CodeTabs>

<Callout type="idea">
Retrieve from an engine and recall from a memory space in the same turn. Put both in one prompt, and your model can answer from your content and remember the user at the same time.
</Callout>

## Next steps [#next-steps]

Your model has the context. See how the two engine sources work together next.

<Cards>
  <Card title="Vector and OKF together" href="/docs/knowledge/retrieval/vector-and-okf" description="How an engine merges both kinds of source." />
  <Card title="Query an engine" href="/docs/knowledge/query-an-engine" description="Let Docklee write the answer instead." />
  <Card title="Recall memory" href="/docs/memory/recall-memory" description="Add what you know about the user." />
</Cards>
