langchain.vectorstores.redis.filters.RedisFilterExpression¶

class langchain.vectorstores.redis.filters.RedisFilterExpression(_filter: Optional[str] = None, operator: Optional[RedisFilterOperator] = None, left: Optional[RedisFilterExpression] = None, right: Optional[RedisFilterExpression] = None)[source]¶

A logical expression of RedisFilterFields.

RedisFilterExpressions can be combined using the & and | operators to create complex logical expressions that evaluate to the Redis Query language.

This presents an interface by which users can create complex queries without having to know the Redis Query language.

Filter expressions are not initialized directly. Instead they are built by combining RedisFilterFields using the & and | operators.

Examples

>>> from langchain.vectorstores.redis import RedisTag, RedisNum
>>> brand_is_nike = RedisTag("brand") == "nike"
>>> price_is_under_100 = RedisNum("price") < 100
>>> filter = brand_is_nike & price_is_under_100
>>> print(str(filter))
(@brand:{nike} @price:[-inf (100)])

Methods

__init__([_filter, operator, left, right])

format_expression(left, right, operator_str)

__init__(_filter: Optional[str] = None, operator: Optional[RedisFilterOperator] = None, left: Optional[RedisFilterExpression] = None, right: Optional[RedisFilterExpression] = None)[source]¶
static format_expression(left: RedisFilterExpression, right: RedisFilterExpression, operator_str: str) str[source]¶