> ## 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.

# Retrieval

> Retrieve and rerank stored chunks from the terminal.

`ragrails retrieve` embeds the query, searches the vector database, and prints the most relevant chunks. `ragrails query` uses the same retrieval path as the workflow command.

## Retrieve Chunks

```bash theme={null}
ragrails retrieve "How long do refunds take?" \
  --vector-db qdrant \
  --collection support \
  --url http://localhost:6333 \
  --provider voyage \
  --model voyage-3 \
  --top-k 10
```

Output:

```text theme={null}
Query  : How long do refunds take?
Results: 10

[1] score=0.8700 chunk_id=refund-policy-0 id=refund-policy-0
    title: Refund policy
    text : Customers can request a refund within 30 days...
```

## Rerank

Retrieve wide, rerank down. Keep `--top-k` higher than `--rerank-top-k`.

```bash theme={null}
ragrails retrieve "How long do refunds take?" \
  --vector-db qdrant --collection support --url http://localhost:6333 \
  --provider voyage --model voyage-3 \
  --top-k 20 \
  --rerank \
  --reranker voyage \
  --reranker-model rerank-2-lite \
  --rerank-top-k 5
```

## Options

| Option             | Default         | Description                                          |
| ------------------ | --------------- | ---------------------------------------------------- |
| `QUERY`            | required        | Search query.                                        |
| `--vector-db`      | `qdrant`        | `qdrant`, `qdrant_cloud`, `pinecone`, or `weaviate`. |
| `--collection`     | config or none  | Collection, index, or class name.                    |
| `--url`            | config or none  | Vector DB URL.                                       |
| `--top-k`          | `10`            | Results to retrieve.                                 |
| `--provider`       | `voyage`        | Query embedding provider.                            |
| `--model`          | `voyage-3`      | Query embedding model.                               |
| `--rerank`         | off             | Enable reranking.                                    |
| `--reranker`       | `voyage`        | Reranker provider.                                   |
| `--reranker-model` | `rerank-2-lite` | Reranker model.                                      |
| `--rerank-top-k`   | `5`             | Results to keep after reranking.                     |

<Note>Query rewriting is not exposed on `retrieve`. Use `ragrails chat --rewrite-query`, [SDK retrieval](/usage/sdk/retrieval#query-rewriting), or [REST retrieval](/usage/server/retrieval#with-query-rewriting).</Note>

<CardGroup cols={2}>
  <Card title="Query" icon="search-check" href="/usage/cli/query">Use retrieval in the query workflow.</Card>
  <Card title="Chat" icon="messages-square" href="/usage/cli/chat">Generate answers from retrieved context.</Card>
</CardGroup>
