Skip to main content

Crate rig_redis_vectorstore

Crate rig_redis_vectorstore 

Source
Expand description

Redis vector store integration for Rig.

Provides a RedisVectorStore that implements Rig’s VectorStoreIndex and InsertDocuments traits using RediSearch’s vector similarity search (FT.SEARCH).

§Prerequisites

The RediSearch index must be created before using this store. The expected schema is:

  • A HASH-based index with the specified prefix
  • A document field of type TEXT (stores serialized JSON)
  • An embedded_text field of type TEXT (stores the source text)
  • A vector field (configurable name) of type VECTOR with FLOAT32 elements
  • Optionally, additional fields for metadata filtering (TAG, NUMERIC, etc.)

§Distance Metric

The metric is configurable via RedisVectorStore::with_distance_metric and must match the index’s DISTANCE_METRIC. DistanceMetric::Cosine (the default), DistanceMetric::L2, and DistanceMetric::InnerProduct are supported. Returned distances are converted to similarity scores (higher = more similar) per metric; see DistanceMetric. Use RedisVectorStore::validate_index to confirm the index agrees with the configured metric.

§Metadata Filtering

To enable filtering on document fields during search, configure metadata fields via RedisVectorStore::with_metadata_fields. These fields are extracted from the serialized document JSON during insertion and written as separate hash fields, making them available for RediSearch filter queries. Your index schema must declare these fields with appropriate types (TAG, NUMERIC, TEXT) for filters to work.

§Limitations

  • Single-node only. Inserts are pipelined across multiple keys, which is not compatible with Redis Cluster (CROSSSLOT). Cluster support is a planned follow-up.
  • Key prefix must match the index PREFIX, otherwise inserted documents are stored but never indexed.
  • Multiple embeddings per document produce multiple independently searchable hashes, so a single logical document may appear more than once in results.

Both RESP2 and RESP3 FT.SEARCH reply shapes are parsed.

§Example

use rig_redis_vectorstore::RedisVectorStore;

let store = RedisVectorStore::new(
    embedding_model,
    redis_client,
    "my_index".into(),
    "embedding".into(),
)
.await?
.with_key_prefix("doc:".to_string())
.with_metadata_fields(vec!["category".to_string(), "price".to_string()]);

Re-exports§

pub use filter::Filter;

Modules§

filter
Redis-specific filter types for RediSearch FT.SEARCH queries.

Structs§

RedisVectorStore
Redis vector store implementation using RediSearch vector similarity search.

Enums§

DistanceMetric
RediSearch vector distance metric. Determines how the returned distance is converted to a similarity score (higher = more similar).
MetadataFieldType
RediSearch field type for a metadata field declared via RedisVectorStore::create_index.