RedisVectorStore

org.llm4s.vectorstore.redis.RedisVectorStore
See theRedisVectorStore companion object
final class RedisVectorStore extends VectorStore

A org.llm4s.vectorstore.VectorStore over one search index of a Redis server with the Redis Query Engine (Redis Stack, or Redis 8 and later), or of a Valkey server with valkey-search.

Each record is a hash at <keyPrefix><id> (see RedisConfig#effectivePrefix). The index is created on the first upsert if it does not exist (FT.CREATE ... ON HASH), with a VECTOR field sized to RedisConfig#dimensions (or to the first record) using the configured RedisVectorAlgorithm and RedisDistanceMetric. search is a KNN query whose metadata filter is a pre-filter, so topK results come back when that many match; count and list are filter queries, list sorted by write order.

Metadata is indexed as TAG values (see RedisQueries for the encoding), so every org.llm4s.vectorstore.MetadataFilter case is a query clause: Equals and In match entries, HasKey matches keys, Contains is a wildcard pattern (w'...', Redis Query Engine 2.6 or later; valkey-search does not support it) and And, Or and Not combine clauses. A wildcard expands to at most the server's maximum number of terms (search-max-prefix-expansions, 200 by default), so Contains over a key with more distinct values than that may miss records.

Reads of an index that does not exist yet answer as an empty store. deleteByPrefix and clear() walk the store's keys with SCAN; clear() also drops the index, which the next upsert creates again. Every operation returns a Result: a connection failure is a org.llm4s.error.NetworkError or a org.llm4s.error.TimeoutError, refused credentials an org.llm4s.error.AuthenticationError, and any other error reply a org.llm4s.error.ProcessingError carrying the server's message.

A search reply is limited by the server's search-max-search-results (10,000 by default), so list's offset + limit and search's topK may not exceed it. The store connects to one standalone server, not to a cluster.

The valkey-search in Valkey 9.0 answers only vector queries: there, search (with any filter but Contains) and the operations by ID or key work, while count and stats over an existing index, list and deleteByFilter are refused with the server's message.

Attributes

Companion
object
Graph
Supertypes
trait VectorStore
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

override def clear(): Result[Unit]

Clear all records from the store.

Clear all records from the store.

Attributes

Returns

Success or error

Definition Classes
override def close(): Unit

Closes the connection pool when this store created it; a connection passed in belongs to the caller.

Closes the connection pool when this store created it; a connection passed in belongs to the caller.

Attributes

Definition Classes
override def count(filter: Option[MetadataFilter]): Result[Long]

Count total records in the store.

Count total records in the store.

Value parameters

filter

Optional metadata filter

Attributes

Returns

Record count

Definition Classes
override def delete(id: String): Result[Unit]

Delete a record by its ID.

Delete a record by its ID.

Value parameters

id

The record identifier

Attributes

Returns

Success or error

Definition Classes
override def deleteBatch(ids: Seq[String]): Result[Unit]

Delete multiple records by their IDs.

Delete multiple records by their IDs.

Value parameters

ids

The record identifiers

Attributes

Returns

Success or error

Definition Classes
override def deleteByFilter(filter: MetadataFilter): Result[Long]

Delete all records matching a metadata filter.

Delete all records matching a metadata filter.

Value parameters

filter

The metadata filter

Attributes

Returns

Number of records deleted

Definition Classes
override def deleteByPrefix(idPrefix: String): Result[Long]

Delete all records with IDs starting with the given prefix.

Delete all records with IDs starting with the given prefix.

Value parameters

prefix

The ID prefix to match

Attributes

Returns

Number of records deleted

Definition Classes
override def get(id: String): Result[Option[VectorRecord]]

Retrieve a record by its ID.

Retrieve a record by its ID.

Value parameters

id

The record identifier

Attributes

Returns

The record if found

Definition Classes
override def getBatch(ids: Seq[String]): Result[Seq[VectorRecord]]

Retrieve multiple records by their IDs.

Retrieve multiple records by their IDs.

Value parameters

ids

The record identifiers

Attributes

Returns

The found records (missing IDs are silently skipped)

Definition Classes
override def list(limit: Int, offset: Int, filter: Option[MetadataFilter]): Result[Seq[VectorRecord]]

List records with pagination.

List records with pagination.

Value parameters

filter

Optional metadata filter

limit

Maximum records to return

offset

Number of records to skip

Attributes

Returns

Records in insertion order

Definition Classes
override def search(queryVector: Array[Float], topK: Int, filter: Option[MetadataFilter]): Result[Seq[ScoredRecord]]

Search for similar vectors using cosine similarity.

Search for similar vectors using cosine similarity.

Value parameters

filter

Optional metadata filter

queryVector

The query embedding

topK

Number of results to return

Attributes

Returns

Matching records with similarity scores

Definition Classes
override def stats(): Result[VectorStoreStats]

Get statistics about the vector store.

Get statistics about the vector store.

Attributes

Returns

Store statistics

Definition Classes
override def upsert(record: VectorRecord): Result[Unit]

Store a vector record.

Store a vector record.

If a record with the same ID exists, it will be replaced.

Value parameters

record

The record to store

Attributes

Returns

Success or error

Definition Classes
override def upsertBatch(records: Seq[VectorRecord]): Result[Unit]

Store multiple vector records in a batch.

Store multiple vector records in a batch.

More efficient than individual upserts for bulk operations.

Value parameters

records

The records to store

Attributes

Returns

Success or error

Definition Classes

Concrete fields