org.llm4s.vectorstore.redis

Members list

Type members

Classlikes

final case class RedisConfig

What RedisVectorStore needs to reach 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 the valkey-search module.

What RedisVectorStore needs to reach 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 the valkey-search module.

Load it from configuration with org.llm4s.config.RedisVectorStoreConfigLoader, which reads llm4s.vectorstore.redis, or build one in code:

val config = RedisConfig("redis.example.com")
 .withTls(true)
 .withPassword("secret")
 .withIndex("docs")

The store checks it with RedisConfig#validate when it is built. toString never prints the password.

Value parameters

algorithm

the vector index structure the index is created with

database

the logical database (SELECT); Redis Query Engine indexes only database 0 on most servers

dimensions

the vector size the index is created with; when unset, the size of the first record upserted. A record of another size is refused before it is sent.

distanceMetric

the distance the index is created with

host

the server's host name or address

index

the search index's name (FT.CREATE)

keyPrefix

the prefix of every record's hash key; unset means "<index>:". Two stores must not share a prefix.

password

the password (AUTH); unset means no authentication

port

the server's port

timeout

how long connecting and each command may take

tls

whether to connect over TLS. Without it the password crosses the network in clear text, which is acceptable only on a trusted network.

username

the ACL user; unset means the default user

Attributes

Companion
object
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
object RedisConfig

Attributes

Companion
class
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
enum RedisDistanceMetric(val wireName: String)

The distance a Redis VECTOR field is indexed with, fixed when the index is created.

The distance a Redis VECTOR field is indexed with, fixed when the index is created.

Redis reports a distance (lower is closer); RedisVectorStore turns it into a org.llm4s.vectorstore.ScoredRecord score in [0, 1], higher meaning closer: 1 - distance / 2 for RedisDistanceMetric.Cosine (the cosine distance lies in [0, 2], so this is (1 + cosine) / 2) and for RedisDistanceMetric.InnerProduct ((1 + dot) / 2, in [0, 1] for unit-length vectors), and 1 / (1 + distance) for RedisDistanceMetric.L2. Scores are clamped to [0, 1].

Value parameters

wireName

the value of the field's DISTANCE_METRIC attribute

Attributes

Companion
object
Supertypes
trait Enum
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Attributes

Companion
enum
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
enum RedisVectorAlgorithm(val wireName: String)

The index structure of a Redis VECTOR field, fixed when the index is created.

The index structure of a Redis VECTOR field, fixed when the index is created.

Value parameters

wireName

the algorithm's name in FT.CREATE

Attributes

Companion
object
Supertypes
trait Enum
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Attributes

Companion
enum
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
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.

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
Supertypes
trait VectorStore
class Object
trait Matchable
class Any

Attributes

Companion
class
Supertypes
class Object
trait Matchable
class Any
Self type