# RAG API (https://intelliask.mt/docs/configuration/rag_api)

The **RAG API** powers IntelliAsk's **chat-with-files**. When a user uploads a
document, the RAG API splits it into chunks, embeds those chunks with a configurable
embeddings provider, and stores the vectors in a vector database (PostgreSQL +
pgvector by default). At query time it embeds the question, retrieves the most
relevant chunks, and passes them to the model so the answer is grounded in the
user's documents.

It runs as a separate **FastAPI + LangChain** service (`rag-api`) alongside the
IntelliAsk app. For the end-user feature, see
[Features → RAG API](/docs/features/rag_api).

<Callout type="info" title="RAG is optional and disabled by default">
  The RAG API needs a working **embeddings provider** — without one, `rag-api`
  crash-loops on start — so the stack ships it **disabled**. `intelliask provision`
  asks whether to enable it and points you at the embeddings setup first. Turn it on
  once configured with:

  ```bash
  intelliask module enable rag
  ```

  and off again with `intelliask module disable rag`. The app runs fine without it;
  RAG features are simply unavailable until it is enabled.
</Callout>

## Configuration lives in the service reference

This page is just an overview. All RAG settings are environment variables in
`config/.env`, read by the container under the **same name**. The complete,
authoritative reference is under **Services → RAG API**:

<Cards>
  <Card title="RAG API (service reference)" href="/docs/services/rag_api">
    What it is, how indexing/retrieval works, and how it is wired into the stack.
  </Card>
  <Card title="Configuration" href="/docs/services/rag_api/configuration">
    Every non-embeddings variable — server, authentication, vector database
    (pgvector and MongoDB Atlas), chunking, batching, document processing, and
    logging.
  </Card>
  <Card title="Embeddings providers" href="/docs/services/rag_api/embeddings">
    The full provider matrix — OpenAI, Azure, HuggingFace (local + TEI), Ollama,
    Google GenAI, VertexAI, and AWS Bedrock — with each provider's keys and models.
  </Card>
  <Card title="Deploy → Components → RAG API" href="/docs/quick_start/components/rag">
    How the service is wired into the Compose stack: image tag, resource limits,
    the shared database keys, and update steps.
  </Card>
</Cards>

## Before you enable it

Provisioning already sets up the **database credentials** the RAG API shares with
the bundled [Vector DB](/docs/quick_start/components/vectordb). What you must supply
is the **embeddings provider**: pick one, then fill the matching keys in
`config/.env` (and, if needed, `config/rag.compose.yml`) following the
[Embeddings providers](/docs/services/rag_api/embeddings) reference.

At minimum, set:

```bash filename="config/.env"
EMBEDDINGS_PROVIDER=azure   # openai | azure | huggingface | huggingfacetei | ollama | google_genai | vertexai | bedrock
EMBEDDINGS_MODEL=text-embedding-3-small
# ...plus the provider's credentials (see the Embeddings reference)
```

<Callout type="warning" title="Don't change the model on a populated store">
  The embedding dimension is fixed per model (e.g. 1536 for `text-embedding-3-small`,
  384 for `all-MiniLM-L6-v2`). Changing `EMBEDDINGS_MODEL` after documents are indexed
  makes existing vectors incompatible — keep it stable or plan a full re-index.
</Callout>

Then enable and start the service:

```bash
intelliask module enable rag
```

Run `intelliask env doctor` first to confirm the variables are wired between
`config/.env` and the compose files.

