# Query an engine (/docs/knowledge/query-an-engine)
`lynk.query` runs the whole pipeline in one call. The engine searches its linked sources, writes an answer from what it finds, and returns the answer with citations and a confidence score.

## Ask a question [#ask-a-question]

This example asks one question and prints the answer:

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

    lynk = Lynk(engine_id="your-engine-id")
    result = lynk.query_sync("What is the refund window?")
    print(result.answer)
    print(result.confidence)
    ```
  </Tab>
  <Tab value="TypeScript">
    ```ts
    import { Lynk, type KnowledgeResult } from 'docklee';

    const lynk = new Lynk({ engineId: 'your-engine-id' });
    const result = (await lynk.query('What is the refund window?')) as KnowledgeResult;
    console.log(result.answer);
    console.log(result.confidence);
    ```
  </Tab>
  <Tab value="cURL">
    ```bash
    curl https://api.docklee.com/v1/engine/query \
      -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": 8,
        "query_mode": "grounded"
      }'
    ```
  </Tab>
</CodeTabs>

The answer comes back with the chunks it was drawn from:

```json
{
  "answer": "Customers can request a refund within 30 days of purchase. After 30 days, purchases can be exchanged for store credit.",
  "citations": [
    {
      "chunk_id": "c2a8f5e1-7b39-4d6c-a014-8e3f2b9d61c7",
      "page_number": 4,
      "section_title": "Refunds and returns"
    }
  ],
  "confidence": 0.93
}
```

## `query` options [#query-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 ask for this call. |
| Chunks searched | `top_k` | `topK` | `8` | How many chunks to search for, from 1 to 50. |
| Mode | `mode` | `mode` | `precise` | How strictly to stay within your sources. See [Answer modes](/docs/knowledge/answers/answer-modes). |
| Stream | `stream` | `stream` | `False` | Send the answer token by token. See [Streaming answers](/docs/knowledge/streaming-answers). |

Over HTTP, the mode field is `query_mode`.

## The result [#the-result]

| Python | TypeScript | HTTP | Description |
| --- | --- | --- | --- |
| `answer` | `answer` | `answer` | The answer, written from your sources. |
| `confidence` | `confidence` | `confidence` | How well the sources support the answer, from 0 to 1. |
| `citations` | `citations` | `citations` | The chunks the answer is based on. |

Each citation identifies a chunk with `chunk_id` (`chunkId`) and `page_number` (`pageNumber`). Over HTTP it also carries `section_title`. See [Citations and confidence](/docs/knowledge/answers/citations-and-confidence).

## When the answer isn't there [#when-the-answer-isnt-there]

In the default mode, the engine doesn't guess. If your sources don't contain the answer, it says the information isn't available, with a confidence of `0`.

<CodeTabs items={['Python', 'TypeScript']}>
  <Tab value="Python">
    ```python
    result = lynk.query_sync("What is the CEO's home address?")
    if result.confidence == 0:
        print("No answer in the knowledge base.")
    ```
  </Tab>
  <Tab value="TypeScript">
    ```ts
    const result = (await lynk.query("What is the CEO's home address?")) as KnowledgeResult;
    if (result.confidence === 0) {
      console.log('No answer in the knowledge base.');
    }
    ```
  </Tab>
</CodeTabs>

<Callout type="idea">
Show the citations in your UI. People trust an answer more when they can open the page it came from.
</Callout>

## Next steps [#next-steps]

You can get a cited answer. To show it as it's written, stream it next.

<Cards>
  <Card title="Streaming answers" href="/docs/knowledge/streaming-answers" description="Show the answer as it's written." />
  <Card title="Answer modes" href="/docs/knowledge/answers/answer-modes" description="How strictly an engine stays within your sources." />
  <Card title="Retrieve context" href="/docs/knowledge/retrieve-context" description="Get the chunks for your own model instead." />
</Cards>
