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

# Use Redis storage

The `redis` backend uses Redis as the vector store. Knowledge text is embedded by an embedding model, written to Redis via LlamaIndex, and retrieved by similarity. The index collection name equals `index`.

## When to use

* You already run a Redis instance with the **RediSearch** module enabled;
* You want Redis as a low-latency vector-search backend with persistence and multi-instance sharing.

## Dependencies

```bash lines theme={null}
pip install "veadk-python[extensions]"
```

Redis must support RediSearch (vector search).

## Usage

```python lines theme={null}
from veadk import Agent
from veadk.knowledgebase import KnowledgeBase

kb = KnowledgeBase(backend="redis", index="company_faq")
kb.add_from_text("The standard annual leave is 15 days per year, available after one year of service.")

agent = Agent(
    name="demo",
    instruction="Answer the user; when needed, use the `load_knowledgebase` tool to search the knowledge base.",
    knowledgebase=kb,
)
```

You can also pass connection config explicitly via `backend_config`:

```python lines theme={null}
from veadk.knowledgebase import KnowledgeBase
from veadk.configs.database_configs import RedisConfig

kb = KnowledgeBase(
    backend="redis",
    index="company_faq",
    backend_config={
        "index": "company_faq",
        "redis_config": RedisConfig(
            host="localhost",
            port=6379,
            password="your-password",
            db=0,
        ),
    },
)
```

## Parameters

### Constructor parameters

`backend_config` supports the following settings:

| Parameter | Type | Default | Description |
| :- | :- | :- | :- |
| `index` | `str` | No default; provided by `KnowledgeBase` | Knowledge base index name. The Redis backend imposes no naming restrictions. |
| `redis_config` | `RedisConfig` | Read automatically from `DATABASE_REDIS_*` env vars | Redis connection config. |
| `embedding_config` | `EmbeddingModelConfig` | Read automatically from `MODEL_EMBEDDING_*` env vars | Embedding model config. |

### Redis connection config

`redis_config` is a `RedisConfig` with env prefix `DATABASE_REDIS_`:

| Field | Env var | Type | Default | Description |
| :- | :- | :- | :- | :- |
| `host` | `DATABASE_REDIS_HOST` | `str` | `""` | Redis host. |
| `port` | `DATABASE_REDIS_PORT` | `int` | `6379` | Port. |
| `username` | `DATABASE_REDIS_USERNAME` | `str \| None` | `None` | Username, optional. |
| `password` | `DATABASE_REDIS_PASSWORD` | `str` | `""` | Password. |
| `db` | `DATABASE_REDIS_DB` | `int` | `0` | Database number. |
| `secret_token` | `DATABASE_REDIS_SECRET_TOKEN` | `str` | `""` | STS temporary-credential token, not yet enabled. |

### Embedding config

`embedding_config` is an `EmbeddingModelConfig` with env prefix `MODEL_EMBEDDING_`:

| Field | Env var | Type | Default | Description |
| :- | :- | :- | :- | :- |
| `name` | `MODEL_EMBEDDING_NAME` | `str` | `doubao-embedding-vision-250615` | Embedding model name. |
| `dim` | `MODEL_EMBEDDING_DIM` | `int` | `2048` | Embedding vector dimension; used to set the vector field dimension. |
| `api_base` | `MODEL_EMBEDDING_API_BASE` | `str` | `https://ark.cn-beijing.volces.com/api/v3/` | API base of the embedding service. |
| `api_key` | `MODEL_EMBEDDING_API_KEY` | `str` | Falls back to `MODEL_AGENT_API_KEY`, then an auto-fetched Ark token | Key for accessing the embedding service. |

## Environment variables

```bash lines theme={null}
# Redis connection
export DATABASE_REDIS_HOST="localhost"
export DATABASE_REDIS_PORT=6379
export DATABASE_REDIS_PASSWORD="your-password"
export DATABASE_REDIS_DB=0

# Embedding model
export MODEL_EMBEDDING_NAME="doubao-embedding-vision-250615"
export MODEL_EMBEDDING_DIM=2048
export MODEL_EMBEDDING_API_KEY="your-ark-api-key"
```

<Note>
  The vector field dimension is taken from the embedding config (`MODEL_EMBEDDING_DIM`). The Redis instance must have the RediSearch module enabled, otherwise the vector index cannot be created.
</Note>
