Vector
Redis implementation of vector similarity search capability.
This module provides a Redis implementation of the VectorCapability protocol using RedisVL AsyncSearchIndex for vector storage and similarity search.
References
[1] https://docs.redisvl.com/en/latest/user_guide/01_getting_started.html
RedisVectorCapability(index_name, client, em_invoker)
Redis implementation of VectorCapability protocol.
This class provides vector similarity search operations using RedisVL AsyncSearchIndex for vector storage and retrieval.
Attributes:
| Name | Type | Description |
|---|---|---|
index_name |
str
|
Name of the Redis index. |
client |
Redis
|
Redis async client instance. |
em_invoker |
BaseEMInvoker
|
Embedding model for vectorization. |
index |
Any
|
RedisVL AsyncSearchIndex instance. |
Initialize the Redis vector capability.
Schema will be automatically inferred from chunks when creating a new index, or auto-detected from an existing index when performing operations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index_name
|
str
|
Name of the Redis index. |
required |
client
|
Redis
|
Redis async client instance. |
required |
em_invoker
|
BaseEMInvoker
|
Embedding model for vectorization. |
required |
em_invoker
property
Returns the EM Invoker instance.
Returns:
| Name | Type | Description |
|---|---|---|
BaseEMInvoker |
BaseEMInvoker
|
The EM Invoker instance. |
clear()
async
Clear all records from the datastore.
create(data)
async
Add chunks to the vector store with automatic embedding generation.
If the index does not exist, the schema will be inferred from the chunks being created.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Chunk | list[Chunk]
|
Single chunk or list of chunks to add. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If data structure is invalid or chunk content is invalid. |
create_from_vector(chunk_vectors)
async
Add pre-computed vectors directly.
If the index does not exist, the schema will be inferred from the chunks being created.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chunk_vectors
|
list[tuple[Chunk, Vector]]
|
List of tuples containing chunks and their corresponding vectors. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If chunk content is invalid. |
delete(filters=None)
async
Delete records from the datastore.
Processes deletions in batches to avoid loading all matching documents into memory. If filters is None, no operation is performed (no-op).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filters
|
FilterClause | QueryFilter | None
|
Filters to select records to delete. Defaults to None. |
None
|
ensure_index(filterable_fields=None)
async
Ensure Redis vector index exists, creating it if necessary.
This method is idempotent - if the index already exists, it will skip creation and return early.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filterable_fields
|
list[dict[str, Any]] | None
|
List of filterable field configurations to use when creating a new index. Each field should be a dictionary with "name" and "type" keys. For example: [{"name": "metadata.category", "type": "tag"}, {"name": "metadata.score", "type": "numeric"}] If not provided and index doesn't exist, a default schema will be created with only basic fields (id, content, metadata, vector). Defaults to None. |
None
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If index creation fails. |
retrieve(query, filters=None, options=None)
async
Read records from the datastore using text-based similarity search with optional filtering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
Input text to embed and search with. |
required |
filters
|
FilterClause | QueryFilter | None
|
Query filters to apply. Defaults to None. |
None
|
options
|
QueryOptions | None
|
Query options like limit and sorting. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
list[Chunk]
|
list[Chunk]: Query results ordered by similarity score. |
retrieve_by_vector(vector, filters=None, options=None)
async
Direct vector similarity search.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vector
|
Vector
|
Query embedding vector. |
required |
filters
|
FilterClause | QueryFilter | None
|
Query filters to apply. FilterClause objects are automatically converted to QueryFilter internally. Defaults to None. |
None
|
options
|
QueryOptions | None
|
Query options like limit and sorting. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
list[Chunk]
|
list[Chunk]: List of chunks ordered by similarity score. |
update(update_values, filters=None)
async
Update existing records in the datastore.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
update_values
|
dict[str, Any]
|
Values to update. |
required |
filters
|
FilterClause | QueryFilter | None
|
Filters to select records to update. FilterClause objects are automatically converted to QueryFilter internally. Defaults to None. |
None
|