Skip to content

Data store

Redis data store with capability composition.

Authors

Kadek Denaya (kadek.d.r.diana@gdplabs.id)

References

[1] https://redis.io/docs/stack/search/reference/vectors/ [2] https://redis.io/docs/clients/python/

RedisDataStore(index_name, url=None, client=None)

Bases: BaseDataStore

Redis data store with fulltext capability support.

Attributes:

Name Type Description
index_name str

Name for the Redis index.

client Redis

Redis client instance.

Initialize the Redis data store.

Parameters:

Name Type Description Default
index_name str

Name of the Redis index to use.

required
url str | None

URL for Redis connection. Defaults to None. Format: redis://[[username]:[password]]@host:port/database

None
client Redis | None

Redis client instance to use. Defaults to None. in which case the url parameter will be used to create a new Redis client.

None

Raises:

Type Description
ValueError

If neither url nor client is provided, or if URL is invalid.

TypeError

If client is not a Redis instance.

ConnectionError

If Redis connection fails.

fulltext property

Access fulltext capability if registered.

This method uses the logic of its parent class to return the fulltext capability handler. This method overrides the parent class to return the RedisFulltextCapability handler for better type hinting.

Returns:

Name Type Description
RedisFulltextCapability RedisFulltextCapability

Fulltext capability handler.

Raises:

Type Description
NotRegisteredException

If fulltext capability is not registered.

supported_capabilities property

Return list of currently supported capabilities.

Returns:

Type Description
list[CapabilityType]

list[CapabilityType]: List of capability names that are supported.

vector property

Access vector capability if registered.

This method uses the logic of its parent class to return the vector capability handler. This method overrides the parent class to return the RedisVectorCapability handler for better type hinting.

Returns:

Name Type Description
RedisVectorCapability RedisVectorCapability

Vector capability handler.

Raises:

Type Description
NotRegisteredException

If vector capability is not registered.

translate_query_filter(query_filter=None)

Translate QueryFilter or FilterClause to Redis native filter syntax.

This method delegates to the existing RedisQueryTranslator in the redis.query_translator module and returns the result as a string. It uses the instance's index_name and client to detect field types for accurate Redis Search query syntax.

Examples:

from gllm_datastore.core.filters import filter as F

# Create datastore instance
datastore = RedisDataStore(index_name="my_index", url="redis://localhost:6379")

# Single FilterClause (field types detected from index schema)
clause = F.eq("metadata.status", "active")
result = datastore.translate_query_filter(clause)
# Returns: "@metadata_status:{active}" if status is a TAG field
# Returns: "@metadata_status:active" if status is a TEXT field

# QueryFilter with multiple clauses (AND condition)
filter_obj = F.and_(
    F.eq("metadata.status", "active"),
    F.gt("metadata.age", 25),
)
result = datastore.translate_query_filter(filter_obj)
# Returns: "@metadata_status:{active} @metadata_age:[(25 +inf]"

# QueryFilter with OR condition
filter_obj = F.or_(
    F.eq("metadata.status", "active"),
    F.eq("metadata.status", "pending"),
)
result = datastore.translate_query_filter(filter_obj)
# Returns: "@metadata_status:{active} | @metadata_status:{pending}"

# IN operator (produces parentheses syntax)
filter_obj = F.in_("metadata.category", ["tech", "science"])
result = datastore.translate_query_filter(filter_obj)
# Returns: "@metadata_category:(tech|science)"

# Empty filter returns None
result = datastore.translate_query_filter(None)
# Returns: None

Parameters:

Name Type Description Default
query_filter FilterClause | QueryFilter | None

The filter to translate. Can be a single FilterClause, a QueryFilter with multiple clauses. Defaults to None.

None

Returns:

Type Description
str | None

str | None: The translated filter as a Redis Search query string. Returns None if no filter is provided.

with_fulltext(index_name=None)

Configure fulltext capability and return datastore instance.

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 | None

The name of the Redis index. Defaults to None, in which case the default class attribute will be utilized.

None

Returns:

Name Type Description
RedisDataStore RedisDataStore

RedisDataStore instance for method chaining.

with_vector(em_invoker, index_name=None)

Configure vector capability and return datastore instance.

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
em_invoker BaseEMInvoker

The embedding model to perform vectorization.

required
index_name str | None

The name of the Redis index. Defaults to None, in which case the default class attribute will be utilized.

None

Returns:

Name Type Description
RedisDataStore RedisDataStore

RedisDataStore instance for method chaining.

Raises:

Type Description
ValueError

If em_invoker is not provided.