# RAG.INGEST

> Chunk a document into a RAG pipeline, with optional metadata and one embedding per chunk.

URL: https://docs.hotkv.com/commands/rag-ingest/

```
RAG.INGEST pipeline doc_id text [META key value [key value ...]] [VECTORS vector [vector ...]]
```

- Group: RAG
- Complexity: O(N) where N is the length of the text
- HotKV Cloud: Performance and Scale plans
- On-Premise: requires the rag-pipeline license feature

A RAG pipeline splits your documents into chunks, keeps each chunk with the embedding you computed for it, and answers searches that combine keyword (BM25) relevance with vector similarity, all inside HotKV. `RAG.INGEST` splits `text` with the pipeline's chunking strategy
and stores the chunks under `doc_id`. Ingesting a `doc_id` that already
exists replaces all of its previous chunks.

Each chunk gets the id `doc_id:n`, where `n` counts from `0` in text
order. To find out how a document will be chunked, ingest it once without
vectors and read the reply (the chunk count), then compute one embedding per
chunk and ingest it again with `VECTORS`.

## Options

| Option | Effect |
| --- | --- |
| `META key value ...` | Metadata pairs copied onto every chunk of the document. [RAG.SEARCH](https://docs.hotkv.com/commands/rag-search/index.md) returns them and can filter on them. |
| `VECTORS vector ...` | One embedding per chunk, in chunk order. Each embedding is a single argument of comma-separated numbers (`0.12,0.98,0.44`) with the pipeline's dimensions. The number of embeddings must equal the number of chunks. |

Without `VECTORS`, the chunks are found only by keyword search.

## Return value

| Case | RESP2 | RESP3 |
| --- | --- | --- |
| Document ingested | Integer: the number of chunks stored (`0` for empty text) | Same |

Errors:

- `ERR pipeline not found, or vector count or dimensions mismatch` if the pipeline does not exist, the number of embeddings differs from the number of chunks, or an embedding has the wrong number of values.
- `ERR wrong number of arguments for 'rag.ingest' command` if the argument count is wrong.
- `NOLICENSE rag-pipeline requires a HotKV license. Contact sales@hotkv.com` if your license does not include the `rag-pipeline` feature.

## Examples

```
127.0.0.1:6379> RAG.INGEST faq doc:1 "To reset your password, click Forgot password on the login screen.\n\nBilling questions go to the billing team." META source help-center VECTORS 0.9,0.1,0.0 0.0,0.2,0.9
(integer) 2
127.0.0.1:6379> RAG.INGEST faq doc:2 "Two-factor codes expire after 30 seconds." VECTORS 0.1,0.1
(error) ERR pipeline not found, or vector count or dimensions mismatch
```

The first call uses a paragraph pipeline, so the blank line in the text
produces two chunks, `doc:1:0` and `doc:1:1`.

## Compatibility

HotKV-only command. Redis and Valkey have no equivalent.

## See also

[RAG.CREATE](https://docs.hotkv.com/commands/rag-create/index.md), [RAG.SEARCH](https://docs.hotkv.com/commands/rag-search/index.md), [RAG.STATS](https://docs.hotkv.com/commands/rag-stats/index.md), [RAG.DROP](https://docs.hotkv.com/commands/rag-drop/index.md), [RAG.LIST](https://docs.hotkv.com/commands/rag-list/index.md), [AI features guide](https://docs.hotkv.com/ai-features/index.md)