From 5bfd22b4377fd082d0d23342b148c26ea4deb43f Mon Sep 17 00:00:00 2001 From: "redisdocsapp[bot]" <177626021+redisdocsapp[bot]@users.noreply.github.com> Date: Thu, 2 Oct 2025 00:22:12 +0000 Subject: [PATCH] Update for redisvl 0.9.1 --- .../develop/ai/redisvl/api/message_history.md | 24 +- content/develop/ai/redisvl/api/query.md | 316 ++++++++++++++---- content/develop/ai/redisvl/api/schema.md | 21 +- content/develop/ai/redisvl/api/searchindex.md | 9 +- .../ai/redisvl/overview/installation.md | 28 ++ .../develop/ai/redisvl/user_guide/_index.md | 13 +- .../develop/ai/redisvl/user_guide/llmcache.md | 20 +- 7 files changed, 351 insertions(+), 80 deletions(-) diff --git a/content/develop/ai/redisvl/api/message_history.md b/content/develop/ai/redisvl/api/message_history.md index 3fc52608e0..b07787b4cd 100644 --- a/content/develop/ai/redisvl/api/message_history.md +++ b/content/develop/ai/redisvl/api/message_history.md @@ -91,7 +91,7 @@ Remove a specific exchange from the message history. * **Return type:** None -#### `get_recent(top_k=5, as_text=False, raw=False, session_tag=None)` +#### `get_recent(top_k=5, as_text=False, raw=False, session_tag=None, role=None)` Retrieve the recent message history in sequential order. @@ -103,15 +103,19 @@ Retrieve the recent message history in sequential order. prompt and response * **session_tag** (*Optional* *[* *str* *]*) – Tag of the entries linked to a specific conversation session. Defaults to instance ULID. + * **role** (*Optional* *[* *Union* *[* *str* *,* *List* *[* *str* *]* *]* *]*) – Filter messages by role(s). + Can be a single role string ("system", "user", "llm", "tool") or + a list of roles. If None, all roles are returned. * **Returns:** A single string transcription of the session : or list of strings if as_text is false. * **Return type:** Union[str, List[str]] * **Raises:** - **ValueError** – if top_k is not an integer greater than or equal to 0. + **ValueError** – if top_k is not an integer greater than or equal to 0, + or if role contains invalid values. -#### `get_relevant(prompt, as_text=False, top_k=5, fall_back=False, session_tag=None, raw=False, distance_threshold=None)` +#### `get_relevant(prompt, as_text=False, top_k=5, fall_back=False, session_tag=None, raw=False, distance_threshold=None, role=None)` Searches the message history for information semantically related to the specified prompt. @@ -134,13 +138,17 @@ context to the next LLM call. if no relevant context is found. * **raw** (*bool*) – Whether to return the full Redis hash entry or just the message. + * **role** (*Optional* *[* *Union* *[* *str* *,* *List* *[* *str* *]* *]* *]*) – Filter messages by role(s). + Can be a single role string ("system", "user", "llm", "tool") or + a list of roles. If None, all roles are returned. * **Returns:** Either a list of strings, or a list of prompts and responses in JSON containing the most relevant. * **Return type:** Union[List[str], List[Dict[str,str]] -Raises ValueError: if top_k is not an integer greater or equal to 0. +Raises ValueError: if top_k is not an integer greater or equal to 0, +: or if role contains invalid values. #### `store(prompt, response, session_tag=None)` @@ -237,7 +245,7 @@ Remove a specific exchange from the conversation history. * **Return type:** None -#### `get_recent(top_k=5, as_text=False, raw=False, session_tag=None)` +#### `get_recent(top_k=5, as_text=False, raw=False, session_tag=None, role=None)` Retrieve the recent message history in sequential order. @@ -249,13 +257,17 @@ Retrieve the recent message history in sequential order. prompt and response. * **session_tag** (*Optional* *[* *str* *]*) – Tag of the entries linked to a specific conversation session. Defaults to instance ULID. + * **role** (*Optional* *[* *Union* *[* *str* *,* *List* *[* *str* *]* *]* *]*) – Filter messages by role(s). + Can be a single role string ("system", "user", "llm", "tool") or + a list of roles. If None, all roles are returned. * **Returns:** A single string transcription of the messages : or list of strings if as_text is false. * **Return type:** Union[str, List[str]] * **Raises:** - **ValueError** – if top_k is not an integer greater than or equal to 0. + **ValueError** – if top_k is not an integer greater than or equal to 0, + or if role contains invalid values. #### `store(prompt, response, session_tag=None)` diff --git a/content/develop/ai/redisvl/api/query.md b/content/develop/ai/redisvl/api/query.md index 57e14a2d70..0caed2e168 100644 --- a/content/develop/ai/redisvl/api/query.md +++ b/content/develop/ai/redisvl/api/query.md @@ -35,8 +35,12 @@ expression. distance. Defaults to True. * **dialect** (*int* *,* *optional*) – The RediSearch query dialect. Defaults to 2. - * **sort_by** (*Optional* *[* *str* *]*) – The field to order the results by. Defaults - to None. Results will be ordered by vector distance. + * **sort_by** (*Optional* *[* *SortSpec* *]*) – The field(s) to order the results by. Can be: + - str: single field name + - Tuple[str, str]: (field_name, "ASC"|"DESC") + - List: list of fields or tuples + Note: Only the first field is used for Redis sorting. + Defaults to None. Results will be ordered by vector distance. * **in_order** (*bool*) – Requires the terms in the field to have the same order as the terms in the query filter, regardless of the offsets between them. Defaults to False. @@ -162,12 +166,20 @@ Return the query string of this query only. * **Return type:** str -#### `return_fields(*fields)` +#### `return_fields(*fields, skip_decode=None)` -Add fields to return fields. +Set the fields to return with search results. +* **Parameters:** + * **\*fields** – Variable number of field names to return. + * **skip_decode** (*str* *|* *List* *[* *str* *]* *|* *None*) – Optional field name or list of field names that should not be + decoded. Useful for binary data like embeddings. +* **Returns:** + Returns the query object for method chaining. * **Return type:** - *Query* + self +* **Raises:** + **TypeError** – If skip_decode is not a string, list, or None. #### `scorer(scorer)` @@ -233,18 +245,42 @@ phrase terms (0 means exact phrase). * **Return type:** *Query* -#### `sort_by(field, asc=True)` +#### `sort_by(sort_spec=None, asc=True)` -Add a sortby field to the query. +Set the sort order for query results. -- **field** - the name of the field to sort by -- **asc** - when True, sorting will be done in asceding order +This method supports sorting by single or multiple fields. Note that Redis Search +natively supports only a single SORTBY field. When multiple fields are specified, +only the FIRST field is used for the Redis SORTBY clause. * **Parameters:** - * **field** (*str*) - * **asc** (*bool*) + * **sort_spec** (*str* *|* *Tuple* *[* *str* *,* *str* *]* *|* *List* *[* *str* *|* *Tuple* *[* *str* *,* *str* *]* *]* *|* *None*) – Sort specification in various formats: + - str: single field name + - Tuple[str, str]: (field_name, "ASC"|"DESC") + - List: list of field names or tuples + * **asc** (*bool*) – Default sort direction when not specified (only used when sort_spec is a string). + Defaults to True (ascending). +* **Returns:** + Returns the query object for method chaining. * **Return type:** - *Query* + self +* **Raises:** + * **TypeError** – If sort_spec is not a valid type. + * **ValueError** – If direction is not "ASC" or "DESC". + +### `Examples` + +```pycon +>> query.sort_by("price") # Single field, ascending +>> query.sort_by(("price", "DESC")) # Single field, descending +>> query.sort_by(["price", "rating"]) # Multiple fields (only first used) +>> query.sort_by([("price", "DESC"), ("rating", "ASC")]) +``` + +#### `NOTE` +When multiple fields are specified, only the first field is used for sorting +in Redis. Future versions may support multi-field sorting through post-query +sorting in Python. #### `timeout(timeout)` @@ -354,8 +390,12 @@ distance threshold. distance. Defaults to True. * **dialect** (*int* *,* *optional*) – The RediSearch query dialect. Defaults to 2. - * **sort_by** (*Optional* *[* *str* *]*) – The field to order the results by. Defaults - to None. Results will be ordered by vector distance. + * **sort_by** (*Optional* *[* *SortSpec* *]*) – The field(s) to order the results by. Can be: + - str: single field name + - Tuple[str, str]: (field_name, "ASC"|"DESC") + - List: list of fields or tuples + Note: Only the first field is used for Redis sorting. + Defaults to None. Results will be ordered by vector distance. * **in_order** (*bool*) – Requires the terms in the field to have the same order as the terms in the query filter, regardless of the offsets between them. Defaults to False. @@ -478,12 +518,20 @@ Return the query string of this query only. * **Return type:** str -#### `return_fields(*fields)` +#### `return_fields(*fields, skip_decode=None)` -Add fields to return fields. +Set the fields to return with search results. +* **Parameters:** + * **\*fields** – Variable number of field names to return. + * **skip_decode** (*str* *|* *List* *[* *str* *]* *|* *None*) – Optional field name or list of field names that should not be + decoded. Useful for binary data like embeddings. +* **Returns:** + Returns the query object for method chaining. * **Return type:** - *Query* + self +* **Raises:** + **TypeError** – If skip_decode is not a string, list, or None. #### `scorer(scorer)` @@ -559,18 +607,42 @@ phrase terms (0 means exact phrase). * **Return type:** *Query* -#### `sort_by(field, asc=True)` +#### `sort_by(sort_spec=None, asc=True)` -Add a sortby field to the query. +Set the sort order for query results. -- **field** - the name of the field to sort by -- **asc** - when True, sorting will be done in asceding order +This method supports sorting by single or multiple fields. Note that Redis Search +natively supports only a single SORTBY field. When multiple fields are specified, +only the FIRST field is used for the Redis SORTBY clause. * **Parameters:** - * **field** (*str*) - * **asc** (*bool*) + * **sort_spec** (*str* *|* *Tuple* *[* *str* *,* *str* *]* *|* *List* *[* *str* *|* *Tuple* *[* *str* *,* *str* *]* *]* *|* *None*) – Sort specification in various formats: + - str: single field name + - Tuple[str, str]: (field_name, "ASC"|"DESC") + - List: list of field names or tuples + * **asc** (*bool*) – Default sort direction when not specified (only used when sort_spec is a string). + Defaults to True (ascending). +* **Returns:** + Returns the query object for method chaining. * **Return type:** - *Query* + self +* **Raises:** + * **TypeError** – If sort_spec is not a valid type. + * **ValueError** – If direction is not "ASC" or "DESC". + +### `Examples` + +```pycon +>> query.sort_by("price") # Single field, ascending +>> query.sort_by(("price", "DESC")) # Single field, descending +>> query.sort_by(["price", "rating"]) # Multiple fields (only first used) +>> query.sort_by([("price", "DESC"), ("rating", "ASC")]) +``` + +#### `NOTE` +When multiple fields are specified, only the first field is used for sorting +in Redis. Future versions may support multi-field sorting through post-query +sorting in Python. #### `timeout(timeout)` @@ -935,7 +1007,8 @@ A query for running a full text search, along with an optional filter expression * **Parameters:** * **text** (*str*) – The text string to perform the text search with. - * **text_field_name** (*str*) – The name of the document field to perform text search on. + * **text_field_name** (*Union* *[* *str* *,* *Dict* *[* *str* *,* *float* *]* *]*) – The name of the document field to perform + text search on, or a dictionary mapping field names to their weights. * **text_scorer** (*str* *,* *optional*) – The text scoring algorithm to use. Defaults to BM25STD. Options are {TFIDF, BM25STD, BM25, TFIDF.DOCNORM, DISMAX, DOCSCORE}. See [https://redis.io/docs/latest/develop/interact/search-and-query/advanced-concepts/scoring/](https://redis.io/docs/latest/develop/interact/search-and-query/advanced-concepts/scoring/) @@ -949,8 +1022,12 @@ A query for running a full text search, along with an optional filter expression Defaults to True. * **dialect** (*int* *,* *optional*) – The RediSearch query dialect. Defaults to 2. - * **sort_by** (*Optional* *[* *str* *]*) – The field to order the results by. Defaults - to None. Results will be ordered by text score. + * **sort_by** (*Optional* *[* *SortSpec* *]*) – The field(s) to order the results by. Can be: + - str: single field name + - Tuple[str, str]: (field_name, "ASC"|"DESC") + - List: list of fields or tuples + Note: Only the first field is used for Redis sorting. + Defaults to None. Results will be ordered by text score. * **in_order** (*bool*) – Requires the terms in the field to have the same order as the terms in the query filter, regardless of the offsets between them. Defaults to False. @@ -1062,12 +1139,20 @@ Return the query string of this query only. * **Return type:** str -#### `return_fields(*fields)` +#### `return_fields(*fields, skip_decode=None)` -Add fields to return fields. +Set the fields to return with search results. +* **Parameters:** + * **\*fields** – Variable number of field names to return. + * **skip_decode** (*str* *|* *List* *[* *str* *]* *|* *None*) – Optional field name or list of field names that should not be + decoded. Useful for binary data like embeddings. +* **Returns:** + Returns the query object for method chaining. * **Return type:** - *Query* + self +* **Raises:** + **TypeError** – If skip_decode is not a string, list, or None. #### `scorer(scorer)` @@ -1082,6 +1167,13 @@ Since Redis 8.0 default was changed to BM25STD. * **Return type:** *Query* +#### `set_field_weights(field_weights)` + +Set or update the field weights for the query. + +* **Parameters:** + **field_weights** (*str* *|* *Dict* *[* *str* *,* *float* *]*) – Either a single field name or dictionary of field:weight mappings + #### `set_filter(filter_expression=None)` Set the filter expression for the query. @@ -1102,18 +1194,42 @@ phrase terms (0 means exact phrase). * **Return type:** *Query* -#### `sort_by(field, asc=True)` +#### `sort_by(sort_spec=None, asc=True)` -Add a sortby field to the query. +Set the sort order for query results. -- **field** - the name of the field to sort by -- **asc** - when True, sorting will be done in asceding order +This method supports sorting by single or multiple fields. Note that Redis Search +natively supports only a single SORTBY field. When multiple fields are specified, +only the FIRST field is used for the Redis SORTBY clause. * **Parameters:** - * **field** (*str*) - * **asc** (*bool*) + * **sort_spec** (*str* *|* *Tuple* *[* *str* *,* *str* *]* *|* *List* *[* *str* *|* *Tuple* *[* *str* *,* *str* *]* *]* *|* *None*) – Sort specification in various formats: + - str: single field name + - Tuple[str, str]: (field_name, "ASC"|"DESC") + - List: list of field names or tuples + * **asc** (*bool*) – Default sort direction when not specified (only used when sort_spec is a string). + Defaults to True (ascending). +* **Returns:** + Returns the query object for method chaining. * **Return type:** - *Query* + self +* **Raises:** + * **TypeError** – If sort_spec is not a valid type. + * **ValueError** – If direction is not "ASC" or "DESC". + +### `Examples` + +```pycon +>> query.sort_by("price") # Single field, ascending +>> query.sort_by(("price", "DESC")) # Single field, descending +>> query.sort_by(["price", "rating"]) # Multiple fields (only first used) +>> query.sort_by([("price", "DESC"), ("rating", "ASC")]) +``` + +#### `NOTE` +When multiple fields are specified, only the first field is used for sorting +in Redis. Future versions may support multi-field sorting through post-query +sorting in Python. #### `timeout(timeout)` @@ -1146,6 +1262,13 @@ Ask the engine to return document search scores. * **Return type:** *Query* +#### `property field_weights: Dict[str, float]` + +Get the field weights for the query. + +* **Returns:** + Dictionary mapping field names to their weights + #### `property filter: str | `[`FilterExpression`]({{< relref "filter/#filterexpression" >}})` ` The filter expression for the query. @@ -1158,6 +1281,14 @@ Return the query parameters. Return self as the query object. +#### `property text_field_name: str | Dict[str, float]` + +Get the text field name(s) - for backward compatibility. + +* **Returns:** + Either a single field name string (if only one field with weight 1.0) + or a dictionary of field:weight mappings. + ## FilterQuery ### `class FilterQuery(filter_expression=None, return_fields=None, num_results=10, dialect=2, sort_by=None, in_order=False, params=None)` @@ -1172,7 +1303,12 @@ A query for running a filtered search with a filter expression. * **return_fields** (*Optional* *[* *List* *[* *str* *]* *]* *,* *optional*) – The fields to return. * **num_results** (*Optional* *[* *int* *]* *,* *optional*) – The number of results to return. Defaults to 10. * **dialect** (*int* *,* *optional*) – The query dialect. Defaults to 2. - * **sort_by** (*Optional* *[* *str* *]* *,* *optional*) – The field to order the results by. Defaults to None. + * **sort_by** (*Optional* *[* *SortSpec* *]* *,* *optional*) – The field(s) to order the results by. Can be: + - str: single field name (e.g., "price") + - Tuple[str, str]: (field_name, "ASC"|"DESC") (e.g., ("price", "DESC")) + - List: list of fields or tuples (e.g., ["price", ("rating", "DESC")]) + Note: Redis Search only supports single-field sorting, so only the first field is used. + Defaults to None. * **in_order** (*bool* *,* *optional*) – Requires the terms in the field to have the same order as the terms in the query filter. Defaults to False. * **params** (*Optional* *[* *Dict* *[* *str* *,* *Any* *]* *]* *,* *optional*) – The parameters for the query. Defaults to None. @@ -1276,12 +1412,20 @@ Return the query string of this query only. * **Return type:** str -#### `return_fields(*fields)` +#### `return_fields(*fields, skip_decode=None)` -Add fields to return fields. +Set the fields to return with search results. +* **Parameters:** + * **\*fields** – Variable number of field names to return. + * **skip_decode** (*str* *|* *List* *[* *str* *]* *|* *None*) – Optional field name or list of field names that should not be + decoded. Useful for binary data like embeddings. +* **Returns:** + Returns the query object for method chaining. * **Return type:** - *Query* + self +* **Raises:** + **TypeError** – If skip_decode is not a string, list, or None. #### `scorer(scorer)` @@ -1316,18 +1460,42 @@ phrase terms (0 means exact phrase). * **Return type:** *Query* -#### `sort_by(field, asc=True)` +#### `sort_by(sort_spec=None, asc=True)` -Add a sortby field to the query. +Set the sort order for query results. -- **field** - the name of the field to sort by -- **asc** - when True, sorting will be done in asceding order +This method supports sorting by single or multiple fields. Note that Redis Search +natively supports only a single SORTBY field. When multiple fields are specified, +only the FIRST field is used for the Redis SORTBY clause. * **Parameters:** - * **field** (*str*) - * **asc** (*bool*) + * **sort_spec** (*str* *|* *Tuple* *[* *str* *,* *str* *]* *|* *List* *[* *str* *|* *Tuple* *[* *str* *,* *str* *]* *]* *|* *None*) – Sort specification in various formats: + - str: single field name + - Tuple[str, str]: (field_name, "ASC"|"DESC") + - List: list of field names or tuples + * **asc** (*bool*) – Default sort direction when not specified (only used when sort_spec is a string). + Defaults to True (ascending). +* **Returns:** + Returns the query object for method chaining. * **Return type:** - *Query* + self +* **Raises:** + * **TypeError** – If sort_spec is not a valid type. + * **ValueError** – If direction is not "ASC" or "DESC". + +### `Examples` + +```pycon +>> query.sort_by("price") # Single field, ascending +>> query.sort_by(("price", "DESC")) # Single field, descending +>> query.sort_by(["price", "rating"]) # Multiple fields (only first used) +>> query.sort_by([("price", "DESC"), ("rating", "ASC")]) +``` + +#### `NOTE` +When multiple fields are specified, only the first field is used for sorting +in Redis. Future versions may support multi-field sorting through post-query +sorting in Python. #### `timeout(timeout)` @@ -1495,12 +1663,20 @@ Return the query string of this query only. * **Return type:** str -#### `return_fields(*fields)` +#### `return_fields(*fields, skip_decode=None)` -Add fields to return fields. +Set the fields to return with search results. +* **Parameters:** + * **\*fields** – Variable number of field names to return. + * **skip_decode** (*str* *|* *List* *[* *str* *]* *|* *None*) – Optional field name or list of field names that should not be + decoded. Useful for binary data like embeddings. +* **Returns:** + Returns the query object for method chaining. * **Return type:** - *Query* + self +* **Raises:** + **TypeError** – If skip_decode is not a string, list, or None. #### `scorer(scorer)` @@ -1535,18 +1711,42 @@ phrase terms (0 means exact phrase). * **Return type:** *Query* -#### `sort_by(field, asc=True)` +#### `sort_by(sort_spec=None, asc=True)` -Add a sortby field to the query. +Set the sort order for query results. -- **field** - the name of the field to sort by -- **asc** - when True, sorting will be done in asceding order +This method supports sorting by single or multiple fields. Note that Redis Search +natively supports only a single SORTBY field. When multiple fields are specified, +only the FIRST field is used for the Redis SORTBY clause. * **Parameters:** - * **field** (*str*) - * **asc** (*bool*) + * **sort_spec** (*str* *|* *Tuple* *[* *str* *,* *str* *]* *|* *List* *[* *str* *|* *Tuple* *[* *str* *,* *str* *]* *]* *|* *None*) – Sort specification in various formats: + - str: single field name + - Tuple[str, str]: (field_name, "ASC"|"DESC") + - List: list of field names or tuples + * **asc** (*bool*) – Default sort direction when not specified (only used when sort_spec is a string). + Defaults to True (ascending). +* **Returns:** + Returns the query object for method chaining. * **Return type:** - *Query* + self +* **Raises:** + * **TypeError** – If sort_spec is not a valid type. + * **ValueError** – If direction is not "ASC" or "DESC". + +### `Examples` + +```pycon +>> query.sort_by("price") # Single field, ascending +>> query.sort_by(("price", "DESC")) # Single field, descending +>> query.sort_by(["price", "rating"]) # Multiple fields (only first used) +>> query.sort_by([("price", "DESC"), ("rating", "ASC")]) +``` + +#### `NOTE` +When multiple fields are specified, only the first field is used for sorting +in Redis. Future versions may support multi-field sorting through post-query +sorting in Python. #### `timeout(timeout)` diff --git a/content/develop/ai/redisvl/api/schema.md b/content/develop/ai/redisvl/api/schema.md index cc7f43548f..b8216eeb55 100644 --- a/content/develop/ai/redisvl/api/schema.md +++ b/content/develop/ai/redisvl/api/schema.md @@ -19,7 +19,7 @@ field configurations using the following three components: -### `class IndexSchema(*, index, fields={}, version='0.1.0')` +### `class IndexSchema(*, index, fields=, version='0.1.0')` A schema definition for a search index in Redis, used in RedisVL for configuring index settings and organizing vector and metadata fields. @@ -261,7 +261,10 @@ A list of field names associated with the index schema. #### `fields: Dict[str, BaseField]` -Fields associated with the search index and their properties +Fields associated with the search index and their properties. + +Note: When creating from dict/YAML, provide fields as a list of field definitions. +The validator will convert them to a Dict[str, BaseField] internally. #### `index: IndexInfo` @@ -314,6 +317,8 @@ Each field type supports specific attributes that customize its behavior. Below - withsuffixtrie: Optimizes queries by maintaining a suffix trie. - phonetic_matcher: Enables phonetic matching. - sortable: Allows sorting on this field. +- no_index: When True, field is not indexed but can be returned in results (requires sortable=True). +- unf: Un-normalized form. When True, preserves original case for sorting (requires sortable=True). **Tag Field Attributes**: @@ -321,10 +326,18 @@ Each field type supports specific attributes that customize its behavior. Below - case_sensitive: Case sensitivity in tag matching. - withsuffixtrie: Suffix trie optimization for queries. - sortable: Enables sorting based on the tag field. +- no_index: When True, field is not indexed but can be returned in results (requires sortable=True). + +**Numeric Field Attributes**: + +- sortable: Enables sorting on the numeric field. +- no_index: When True, field is not indexed but can be returned in results (requires sortable=True). +- unf: Un-normalized form. When True, maintains original numeric representation for sorting (requires sortable=True). -**Numeric and Geo Field Attributes**: +**Geo Field Attributes**: -- Both numeric and geo fields support the sortable attribute, enabling sorting on these fields. +- sortable: Enables sorting based on the geo field. +- no_index: When True, field is not indexed but can be returned in results (requires sortable=True). **Common Vector Field Attributes**: diff --git a/content/develop/ai/redisvl/api/searchindex.md b/content/develop/ai/redisvl/api/searchindex.md index 715688e066..832b9b982a 100644 --- a/content/develop/ai/redisvl/api/searchindex.md +++ b/content/develop/ai/redisvl/api/searchindex.md @@ -275,8 +275,7 @@ Initialize from an existing search index in Redis by index name. * **redis_url** (*Optional* *[* *str* *]*) – The URL of the Redis server to connect to. * **Raises:** - * **ValueError** – If redis_url or redis_client is not provided. - * **RedisModuleVersionError** – If required Redis modules are not installed. + **ValueError** – If redis_url or redis_client is not provided. #### `classmethod from_yaml(schema_path, **kwargs)` @@ -466,7 +465,8 @@ The name of the Redis search index. #### `property prefix: str` The optional key prefix that comes before a unique key value in -forming a Redis key. +forming a Redis key. If multiple prefixes are configured, returns the +first one. #### `property storage_type: StorageType` @@ -934,7 +934,8 @@ The name of the Redis search index. #### `property prefix: str` The optional key prefix that comes before a unique key value in -forming a Redis key. +forming a Redis key. If multiple prefixes are configured, returns the +first one. #### `property storage_type: StorageType` diff --git a/content/develop/ai/redisvl/overview/installation.md b/content/develop/ai/redisvl/overview/installation.md index 3472743483..2a0c69ac84 100644 --- a/content/develop/ai/redisvl/overview/installation.md +++ b/content/develop/ai/redisvl/overview/installation.md @@ -79,3 +79,31 @@ This will also spin up the [Redis Insight GUI](https://redis.io/insight/) at `ht Redis Enterprise is a commercial offering that can be self-hosted. You can download the latest version [here](https://redis.io/downloads/). If you are considering a self-hosted Redis Enterprise deployment on Kubernetes, there is the [Redis Enterprise Operator](https://docs.redis.com/latest/kubernetes/) for Kubernetes. This will allow you to easily deploy and manage a Redis Enterprise cluster on Kubernetes. + +### Redis Sentinel + +For high availability deployments, RedisVL supports connecting to Redis through Sentinel. Use the `redis+sentinel://` URL scheme to connect: + +```python +from redisvl.index import SearchIndex + +# Connect via Sentinel +# Format: redis+sentinel://[username:password@]host1:port1,host2:port2/service_name[/db] +index = SearchIndex.from_yaml( + "schema.yaml", + redis_url="redis+sentinel://sentinel1:26379,sentinel2:26379/mymaster" +) + +# With authentication +index = SearchIndex.from_yaml( + "schema.yaml", + redis_url="redis+sentinel://user:pass@sentinel1:26379,sentinel2:26379/mymaster/0" +) +``` + +The Sentinel URL format supports: + +- Multiple sentinel hosts (comma-separated) +- Optional authentication (username:password) +- Service name (required - the name of the Redis master) +- Optional database number (defaults to 0) diff --git a/content/develop/ai/redisvl/user_guide/_index.md b/content/develop/ai/redisvl/user_guide/_index.md index c2b30f98e5..2e8d7f0843 100644 --- a/content/develop/ai/redisvl/user_guide/_index.md +++ b/content/develop/ai/redisvl/user_guide/_index.md @@ -30,12 +30,13 @@ User guides provide helpful resources for using RedisVL and its different compon * [Count Queries](hybrid_queries/#count-queries) * [Range Queries](hybrid_queries/#range-queries) * [Advanced Query Modifiers](hybrid_queries/#advanced-query-modifiers) -* [Initializing `SemanticCache`](llmcache/) -* [Basic Cache Usage](llmcache/#basic-cache-usage) -* [Customize the Distance Threshold](llmcache/#customize-the-distance-threshold) -* [Utilize TTL](llmcache/#utilize-ttl) -* [Simple Performance Testing](llmcache/#simple-performance-testing) -* [Cache Access Controls, Tags & Filters](llmcache/#cache-access-controls-tags-filters) +* [LLM Caching](llmcache/) + * [Initializing `SemanticCache`](llmcache/#initializing-semanticcache) + * [Basic Cache Usage](llmcache/#basic-cache-usage) + * [Customize the Distance Threshold](llmcache/#customize-the-distance-threshold) + * [Utilize TTL](llmcache/#utilize-ttl) + * [Simple Performance Testing](llmcache/#simple-performance-testing) + * [Cache Access Controls, Tags & Filters](llmcache/#cache-access-controls-tags-filters) * [Caching Embeddings](embeddings_cache/) * [Setup](embeddings_cache/#setup) * [Initializing the EmbeddingsCache](embeddings_cache/#initializing-the-embeddingscache) diff --git a/content/develop/ai/redisvl/user_guide/llmcache.md b/content/develop/ai/redisvl/user_guide/llmcache.md index 259d67c898..9094d4759d 100644 --- a/content/develop/ai/redisvl/user_guide/llmcache.md +++ b/content/develop/ai/redisvl/user_guide/llmcache.md @@ -1,12 +1,28 @@ --- -linkTitle: First, we will import [openai](https://platform.openai.com) to use their API for responding to user prompts. we will also create a simple `ask_openai` helper method to assist. -title: First, we will import [OpenAI](https://platform.openai.com) to use their API for responding to user prompts. We will also create a simple `ask_openai` helper method to assist. +linkTitle: LLM caching +title: LLM Caching aliases: - /integrate/redisvl/user_guide/03_llmcache weight: 03 --- +This notebook demonstrates how to use RedisVL's `SemanticCache` to cache LLM responses based on semantic similarity. Semantic caching can significantly reduce API costs and latency by retrieving cached responses for semantically similar prompts instead of making redundant API calls. + +Key features covered: +- Basic cache operations (store, check, clear) +- Customizing semantic similarity thresholds +- TTL policies for cache expiration +- Performance benchmarking +- Access controls with tags and filters for multi-user scenarios + +Prerequisites: +- Ensure `redisvl` is installed in your Python environment +- Have a running instance of [Redis Stack](https://redis.io/docs/install/install-stack/) or [Redis Cloud](https://redis.io/cloud) +- OpenAI API key for the examples + +First, we will import [OpenAI](https://platform.openai.com) to use their API for responding to user prompts. We will also create a simple `ask_openai` helper method to assist. + ```python import os