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

# Embedding

> Generate vectors for SDK chunk dictionaries.

Embedding adds vector representations to chunks so the vector database can perform semantic search. In the full SDK workflow, `rag.ingest()` embeds chunks for you. Use `rag.embed()` directly when you need to inspect vectors or control batching/model choice.

```bash theme={null}
pip install "ragrails[voyage]"
export VOYAGE_API_KEY="..."
```

```python theme={null}
from ragrails import RagRails

rag = RagRails(embedding={"provider": "voyage", "model": "voyage-3"})
```

## Embed Chunks

```python theme={null}
embedded = rag.embed(
    chunks=chunks.items,
    batch_size=64,
)
```

## Result

```python theme={null}
embedded.inputs
embedded.embedded
embedded.items
embedded.failed
embedded.errors
```

An embedded chunk keeps the chunk fields and adds `embedding`:

```json theme={null}
{
  "id": "refund-policy-0",
  "text": "Customers can request a refund within 30 days of purchase.",
  "source": "files/refund-policy.pdf",
  "metadata": {"title": "Refund policy", "chunk_index": 0},
  "embedding": [0.0132, -0.0719, 0.0241]
}
```

## Create an Embedder

```python theme={null}
embedder = rag.embedder(provider="voyage", model="voyage-3", input_type="document")
embedded = rag.embed(chunks=chunks.items, embedder=embedder)
```

Use `input_type="document"` while indexing and `input_type="query"` for retrieval. `rag.query()`, `rag.retrieve()`, and `rag.chat()` create query embedders automatically from constructor defaults.

## Override the Model

```python theme={null}
embedded = rag.embed(
    chunks=chunks.items,
    embedder=rag.embedder(model="voyage-3-large"),
    batch_size=32,
)
```

## Parameters

### `embedder()`

| Parameter    | Default                                | Description                |
| ------------ | -------------------------------------- | -------------------------- |
| `provider`   | constructor default, else `"voyage"`   | Embedding provider.        |
| `model`      | constructor default, else `"voyage-3"` | Embedding model.           |
| `input_type` | `"document"`                           | `"document"` or `"query"`. |
| `options`    | `None`                                 | Provider-specific options. |

### `embed()`

| Parameter    | Default      | Description                                    |
| ------------ | ------------ | ---------------------------------------------- |
| `chunks`     | required     | List of chunk dicts with `id` and `text`.      |
| `embedder`   | auto-created | Explicit embedding model object.               |
| `input_type` | `"document"` | Used only when `embed()` creates the embedder. |
| `batch_size` | `64`         | Chunks per embedding batch.                    |

## Next Stage

```python theme={null}
stored = rag.store(embedded_chunks=embedded.items)
```

<CardGroup cols={2}>
  <Card title="Chunking" icon="scissors" href="/usage/sdk/chunking">Create chunks.</Card>
  <Card title="Storing" icon="database" href="/usage/sdk/storing">Store embedded chunks.</Card>
</CardGroup>
