> ## Documentation Index
> Fetch the complete documentation index at: https://docs.moorcheh.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Answer (RAG)

> Retrieve context from the store and generate an answer with the local LLM.

## Overview

Run **retrieval-augmented generation (RAG)** on the local store:

1. Search using the provided **`query_vector`** (same dimension as the store).
2. Build a prompt from the top matching passages.
3. Call **Ollama** on the host with fixed model **`qwen2.5:0.5b-instruct`**.

If **no passages** pass search (empty store or nothing above `threshold` in kiosk mode), the server **does not call the LLM** and returns:

`I don't have enough information to answer that question.`

<Note>
  Requires Ollama running on the host. Start the stack with `moorcheh-edge up --with-llm` (use `--skip-ollama` for search-only). The CLI and SDK embed **`query`** locally before calling this endpoint.
</Note>

## Request body

<ParamField body="query" type="string" required>
  Original question text (included in the LLM prompt and echoed in the response).
</ParamField>

<ParamField body="query_vector" type="array" required>
  JSON array of floats used for similarity search. Length must match the store **dimension** (768 for text stores).
</ParamField>

<ParamField body="top_k" type="number" default="5">
  Number of passages to retrieve for context. Capped at **100**.
</ParamField>

<ParamField body="threshold" type="number" default="0">
  Minimum search score when `kiosk_mode` is `true`.
</ParamField>

<ParamField body="kiosk_mode" type="boolean" default="false">
  When `true`, filters retrieved passages below `threshold`.
</ParamField>

<ParamField body="header_prompt" type="string">
  Optional system instruction (replaces the default RAG system prompt).
</ParamField>

<ParamField body="footer_prompt" type="string">
  Optional instruction appended before the user question in the final user message.
</ParamField>

<ParamField body="chat_history" type="array">
  Prior turns: `[{"role": "user"|"assistant", "content": "..."}]`.
</ParamField>

<ParamField body="temperature" type="number" default="0.2">
  LLM sampling temperature (0.0–2.0).
</ParamField>

<RequestExample>
  ```bash theme={null}
  curl -X POST "http://localhost:8080/answer" \
    -H "Content-Type: application/json" \
    -d '{
      "query": "Who won the football match?",
      "query_vector": [0.01, -0.02, "... 768 floats ..."],
      "top_k": 5
    }'
  ```
</RequestExample>

<ResponseExample>
  ```json 200 - OK theme={null}
  {
    "answer": "Manchester United beat Chelsea 2-1.",
    "model": "qwen2.5:0.5b-instruct",
    "query": "Who won the football match?",
    "context_count": 1,
    "sources": [
      {
        "id": "doc-1",
        "score": 0.894123,
        "label": "Close Match",
        "text": "Manchester United beat Chelsea 2-1 in the Premier League on Saturday."
      }
    ]
  }
  ```
</ResponseExample>

## Response fields

| Field           | Description                                                   |
| --------------- | ------------------------------------------------------------- |
| `answer`        | Generated answer text                                         |
| `model`         | LLM model id (`qwen2.5:0.5b-instruct`)                        |
| `query`         | Echo of the request question                                  |
| `context_count` | Number of passages passed to the LLM                          |
| `sources`       | Search hits used as context (same shape as `/search` results) |

## Errors

| Condition                | Status | Message (example)                                                                                             |
| ------------------------ | ------ | ------------------------------------------------------------------------------------------------------------- |
| LLM not configured       | `400`  | `LLM is not configured: start Ollama on the host and run moorcheh-edge up`                                    |
| LLM unreachable or error | `400`  | `LLM request failed`                                                                                          |
| Empty store / no matches | `200`  | Fixed answer: `I don't have enough information to answer that question.` (`context_count`: 0, LLM not called) |

## Related

* [Answer stream (SSE)](/api-references/answer-stream)
* [CLI: answer](/cli/answer)
* [Python: answer\_text()](/python-client/answer)
* [Search](/api-references/search)
