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

# How RAG Works

> The whole pipeline in plain terms, in 5 minutes.

RAG (Retrieval-Augmented Generation) gives an LLM the right facts at answer time. Instead of relying on what the model memorized, you retrieve relevant passages from your own content and hand them to the model.

Ragrails runs that as a pipeline:

<CodeGroup>
  ```Example theme={null}
  content → chunks → embeddings → vector store → retrieval → answer
  ```
</CodeGroup>

## The pipeline, stage by stage

<Steps>
  <Step title="Ingest">
    Pull in your raw content (scraped websites, documents, or API responses) and normalize it into clean text.
  </Step>

  <Step title="Chunk">
    Split each document into small, focused passages.
    <Note>**Why:** search works best on focused passages, not whole files. Chunking lets a query match the one paragraph that answers it instead of a 50-page PDF.</Note>
  </Step>

  <Step title="Embed">
    Convert each chunk into a vector, a list of numbers that captures meaning.
    <Note>**Why:** vectors let *"how do I get my money back"* match a chunk titled *"Refund policy"* even with no shared words.</Note>
  </Step>

  <Step title="Store">
    Save the vectors in a vector database so they can be searched fast.
  </Step>

  <Step title="Retrieve">
    Embed the user's question the same way, then find the closest chunks by meaning.
  </Step>

  <Step title="Answer">
    Hand those chunks to an LLM as context. The model answers grounded in your data.
  </Step>
</Steps>

## Core terms

| Term             | Plain meaning                                                                     |
| ---------------- | --------------------------------------------------------------------------------- |
| **Chunk**        | A small passage of a document, sized for search.                                  |
| **Embedding**    | Text turned into numbers that capture meaning. Similar meaning → similar numbers. |
| **Vector store** | A database built to search embeddings by similarity (Qdrant, Pinecone, Weaviate). |
| **Retrieval**    | Finding the chunks most relevant to a query.                                      |
| **Reranking**    | A second, smarter pass that reorders retrieved chunks by true relevance.          |
| **Grounding**    | Forcing the LLM to answer from retrieved chunks, not its own memory.              |

## When you need capabilities

The basic pipeline works out of the box. Reach for these when you hit the matching problem:

| Symptom                                 | Feature                                                          | What it does                                                       |
| --------------------------------------- | ---------------------------------------------------------------- | ------------------------------------------------------------------ |
| Top results are off-target              | [Reranking](/features/retrieval)                                 | Re-reads top candidates and reorders by relevance.                 |
| Chat follow-ups return nothing          | [Query rewriting](/features/chat)                                | Expands *"what about the second one?"* into a standalone question. |
| Long chats get slow or expensive        | [History compaction](/features/chat)                             | Summarizes old turns, keeps recent ones.                           |
| *"Thanks!"* triggers a pointless search | [Intent routing](/features/chat)                                 | Skips retrieval for small talk.                                    |
| Crawls partly fail                      | [Dead-letter queue](/usage/sdk/extraction#dead-letter-queue-dlq) | Records failures so you retry only those.                          |

## Next

<CardGroup cols={2}>
  <Card title="Quickstart" icon="zap" href="/getting-started/quickstart">Build it now.</Card>
  <Card title="Features" icon="layers" href="/features/overview">Tune each stage.</Card>
</CardGroup>
