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

# Retrieval (RAG)

> Splitters, end-to-end RAG, incremental indexing, cross-encoder reranking, retriever caching.

Retrieval examples enact the layers of a RAG pipeline. Sources under [`examples/retrieval/`](https://github.com/0xvasanth/cognis/tree/main/examples/retrieval).

| Name                          | Scenario                                                                                                                         | Source                                                                                         |
| ----------------------------- | -------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- |
| `retrieval_text_splitters`    | Compare `RecursiveCharSplitter`, `MarkdownSplitter`, `SentenceSplitter` on the same Markdown blog post — see how each carves it. | [src](https://github.com/0xvasanth/cognis/blob/main/examples/retrieval/text_splitters.rs)      |
| `retrieval_rag_pipeline`      | End-to-end RAG — split, embed, store, retrieve, answer with the LLM. The canonical flow.                                         | [src](https://github.com/0xvasanth/cognis/blob/main/examples/retrieval/rag_pipeline.rs)        |
| `retrieval_indexing_rag`      | Docs-site re-indexer — round 1 indexes 3 docs, edit one, round 2 only re-embeds the changed doc.                                 | [src](https://github.com/0xvasanth/cognis/blob/main/examples/retrieval/indexing_rag.rs)        |
| `retrieval_reranking`         | Vector search returns top-10; cross-encoder (LLM-judge) reranks to top-3 for the prompt.                                         | [src](https://github.com/0xvasanth/cognis/blob/main/examples/retrieval/reranking_retriever.rs) |
| `retrieval_caching_retriever` | Chat session asks the same question twice — second call returns from cache (latency drops to \~0).                               | [src](https://github.com/0xvasanth/cognis/blob/main/examples/retrieval/caching_retriever.rs)   |

## How to run

```bash theme={null}
COGNIS_PROVIDER=ollama COGNIS_OLLAMA_MODEL=llama3.1 \
  cargo run -p cognis-examples --example retrieval_rag_pipeline
```

## Pick a starting point

* **First time touching RAG?** `retrieval_rag_pipeline` is the canonical flow.
* **Re-indexing a corpus?** `retrieval_indexing_rag` — incremental updates with a `RecordManager`.
* **Improving retrieval quality?** `retrieval_reranking` adds a cross-encoder pass.

## See also

<CardGroup cols={2}>
  <Card title="Building RAG" icon="database" href="/building-rag/documents">
    The user guide for every layer.
  </Card>

  <Card title="Patterns → Code Q&A" icon="grid" href="/patterns/code-qa">
    A worked RAG over a Rust codebase.
  </Card>

  <Card title="Reranking & compression" icon="arrow-down-up-across-line" href="/building-rag/reranking">
    Why reranking matters.
  </Card>
</CardGroup>
