
    Q
i                         d dl Z d dlmZmZmZmZmZ d dlmZ d dl	m
Z
 d dlmZmZmZ d dlmZmZmZmZmZmZmZmZ d dlmZmZ d dlmZ d d	lmZ d d
lm Z  d dl!m"Z" d dl#m$Z$m%Z%m&Z&m'Z' d dl(m)Z) d dl*m+Z+  e"d          Z, G d de
          Z-dS )    N)AnyDictListOptionalTuple)Redis)BaseLLMCache)
CacheEntryCacheHitSemanticCacheIndexSchema)CACHE_VECTOR_FIELD_NAMEENTRY_ID_FIELD_NAMEINSERTED_AT_FIELD_NAMEMETADATA_FIELD_NAMEPROMPT_FIELD_NAMEREDIS_KEY_FIELD_NAMERESPONSE_FIELD_NAMEUPDATED_AT_FIELD_NAME)AsyncSearchIndexSearchIndex)VectorRangeQuery)FilterExpressionhashify)
get_logger)current_timestampdeprecated_argument	serializevalidate_vector_dims)BaseVectorizer)HFTextVectorizerz	[RedisVL]c                   .    e Zd ZU dZeed<   dZee         ed<    e	dd          ddddddd	i d
f	de
dedee         dee         deeee
ef                           dee         de
dee
ef         def fd            Zde
fdZ	 d?dedeeee
ef                           defdZdefdZedefd            Zedee         fd            Zedefd            ZdeddfdZd@dZd@dZ	 dAdeee
                  d eee
                  ddfd!Z	 dAdeee
                  d eee
                  ddfd"Z d#ee
         dee         fd$Z!d#ee
         dee         fd%Z"d&ee         fd'Z#	 	 	 	 	 	 dBd#ee
         d&eee                  d)ed*eee
                  d+ee$         dee         deee
ef                  fd,Z%	 	 	 	 	 	 dBd#ee
         d&eee                  d)ed*eee
                  d+ee$         dee         deee
ef                  fd-Z&	 d?d.eee
ef                  d*eee
                  de'ee
         eee
ef                  f         fd/Z(	 	 	 	 dCd#e
d0e
d&eee                  d1eee
ef                  d2eee
ef                  dee         de
fd3Z)	 	 	 	 dCd#e
d0e
d&eee                  d1eee
ef                  d2eee
ef                  dee         de
fd4Z*d5e
ddfd6Z+d5e
ddfd7Z,d8 Z-d9 Z.d: Z/d; Z0 fd<Z1 fd=Z2	 d?d#e
d2eee
ef                  de
fd>Z3 xZ4S )DSemanticCachez)Semantic Cache for Large Language Models._indexN_aindexdtype
vectorizerllmcacheg?zredis://localhost:6379Fnamedistance_thresholdttlfilterable_fieldsredis_client	redis_urlconnection_kwargs	overwritec
                    t                                          |||||           |
                    dd          }|rSt          |t                    st          d          |r%|j        |k    rt          d| d|j                   || _        n-|
}|r|	                    |           t          ddd	i|| _        |                     |           t          t          t          t          t           t"          g| _        t'          j        ||| j        j        | j        j                  }|                     ||          }t/          d|| j        | j        d
         d| j        d         | _        d| _        |	| _        | j        s| j                                        r|st<                              d           t/          j         || j        j                  }|j!        "                                | j        j!        "                                k    rt          d| d          | j        #                    | j        d           dS )ae  Semantic Cache for Large Language Models.

        Args:
            name (str, optional): The name of the semantic cache search index.
                Defaults to "llmcache".
            distance_threshold (float, optional): Semantic distance threshold for the
                cache in Redis COSINE units [0-2], where lower values indicate stricter
                matching. Defaults to 0.1.
            ttl (Optional[int], optional): The time-to-live for records cached
                in Redis. Defaults to None.
            vectorizer (Optional[BaseVectorizer], optional): The vectorizer for the cache.
                Defaults to HFTextVectorizer.
            filterable_fields (Optional[List[Dict[str, Any]]]): An optional list of RedisVL fields
                that can be used to customize cache retrieval with filters.
            redis_client(Optional[Redis], optional): A redis client connection instance.
                Defaults to None.
            redis_url (str, optional): The redis url. Defaults to redis://localhost:6379.
            connection_kwargs (Dict[str, Any]): The connection arguments
                for the redis client. Defaults to empty {}.
            overwrite (bool): Whether or not to force overwrite the schema for
                the semantic cache index. Defaults to false.

        Raises:
            TypeError: If an invalid vectorizer is provided.
            TypeError: If the TTL value is not an int.
            ValueError: If the threshold is not between 0 and 2 (Redis COSINE distance).
            ValueError: If existing schema does not match new schema and overwrite is False.
        )r)   r+   r-   r.   r/   r&   Nz.Must provide a valid redisvl.vectorizer class.zProvided dtype z! does not match vectorizer dtype )r&   modelzredis/langcache-embed-v1r.   schemar-   r.   r/   a  The default vectorizer has changed from `sentence-transformers/all-mpnet-base-v2` to `redis/langcache-embed-v1` in version 0.6.0 of RedisVL. For more information about this model, please refer to https://arxiv.org/abs/2504.02268 or visit https://huggingface.co/redis/langcache-embed-v1. To continue using the old vectorizer, please specify it explicitly in the constructor as: vectorizer=HFTextVectorizer(model='sentence-transformers/all-mpnet-base-v2'))r-   zExisting index z schema does not match the user provided schema for the semantic cache. If you wish to overwrite the index schema, set overwrite=True during initialization.F)r0   drop )$super__init__pop
isinstancer    	TypeErrorr&   
ValueError_vectorizerupdater!   set_thresholdr   r   r   r   r   r   return_fieldsr   from_paramsdims_modify_schemar   _redis_clientredis_kwargsr$   r%   r0   existsloggerwarningfrom_existingr4   to_dictcreate)selfr)   r*   r+   r'   r,   r-   r.   r/   r0   kwargsr&   vectorizer_kwargsr4   existing_index	__class__s                  C:\Users\Dell Inspiron 16\Desktop\tws\AgrotaPowerBi\back-agrota-powerbi\mcp-client-agrota\venv\Lib\site-packages\redisvl/extensions/cache/llm/semantic.pyr8   zSemanticCache.__init__-   s   V 	%/ 	 	
 	
 	
 

7D))  	j.99 R PQQQ )U22 `e``jN^``    *D !' 6!((u(555/    0 #   D 	-...  "!
 *5$(-t/?/E
 
 $$V->?? " 
+'4
 
  34	
 
  #~ 	$+"4"4"6"6 	  c   )64;#<  N $,,..$+2D2L2L2N2NNN kd k k k   	T^%@@@@@    returnc                 8    d| j         d| j         d| j         dS )NzSemanticCache(name=z, distance_threshold=z, ttl=))r)   r*   r+   rL   s    rQ   __repr__zSemanticCache.__repr__   sF    M$) M M"&"9M MAEM M M	
rR   r4   c                     |ot          | j        t          gz             }|D ]O}|d         }||v rt          | d          |                    |           | j                            |           P|S )zAModify the base cache schema using the provided filterable fieldsNr)   z7 is a reserved field name for the semantic cache schema)setr@   r   r<   	add_fieldappend)rL   r4   r,   protected_field_namesfilter_field
field_names         rQ   rC   zSemanticCache._modify_schema   s     ($'(:>R=S(S$T$T! 1 	6 	6)&1
!666$%^^^     ..."))*5555rR   c                    K   | j         O|                                  d{V }t          d| j        j        || j        d         d| j        d         | _         | j         S )z.Lazily construct the async search index class.Nr.   r3   r/   r6   )r%   _get_async_redis_clientr   r$   r4   rE   )rL   async_clients     rQ   _get_async_indexzSemanticCache._get_async_index   s       <!%!=!=!?!???????L+ {))+K8  #$78	 DL |rR   c                     | j         S )zoThe underlying SearchIndex for the cache.

        Returns:
            SearchIndex: The search index.
        )r$   rV   s    rQ   indexzSemanticCache.index   s     {rR   c                     | j         S )zThe underlying AsyncSearchIndex for the cache.

        Returns:
            AsyncSearchIndex: The async search index.
        )r%   rV   s    rQ   aindexzSemanticCache.aindex   s     |rR   c                     | j         S )z}The semantic distance threshold for the cache.

        Returns:
            float: The semantic distance threshold.
        )_distance_thresholdrV   s    rQ   r*   z SemanticCache.distance_threshold   s     ''rR   c                     dt          |          cxk    rdk    sn t          d|           t          |          | _        dS )a  Sets the semantic distance threshold for the cache.

        Args:
            distance_threshold (float): The semantic distance threshold for
                the cache.

        Raises:
            ValueError: If the threshold is not between 0 and 2 (Redis COSINE distance).
        r      z&Distance must be between 0 and 2, got N)floatr<   rh   )rL   r*   s     rQ   r?   zSemanticCache.set_threshold   sc     E,--22222222M9KMM   $));#<#<   rR   c                 <    | j                             d           dS )z(Delete the cache and its index entirely.Tr5   N)r$   deleterV   s    rQ   rn   zSemanticCache.delete  s!    %%%%%rR   c                 v   K   |                                   d{V }|                    d           d{V  dS )z.Async delete the cache and its index entirely.NTrm   )rb   rn   )rL   rf   s     rQ   adeletezSemanticCache.adelete	  sU      ,,........mmm&&&&&&&&&&&rR   idskeysc                      ||t          d          |& j                             fd|D                        | j                            |           dS dS )a0  Drop specific entries from the cache by ID or Redis key.

        Args:
            ids (Optional[List[str]]): List of entry IDs to remove from the cache.
                Entry IDs are the unique identifiers without the cache prefix.
            keys (Optional[List[str]]): List of full Redis keys to remove from the cache.
                Keys are the complete Redis keys including the cache prefix.

        Note:
            At least one of ids or keys must be provided.

        Raises:
            ValueError: If neither ids nor keys is provided.
        N-At least one of ids or keys must be provided.c                 D    g | ]}j                             |          S r6   r$   key.0idrL   s     rQ   
<listcomp>z&SemanticCache.drop.<locals>.<listcomp>$  s'    "E"E"E24;??2#6#6"E"E"ErR   )r<   r$   	drop_keys)rL   rq   rr   s   `  rQ   r5   zSemanticCache.drop  sy    " ;4<LMMM ?K!!"E"E"E"E"E"E"EFFFK!!$''''' rR   c                     K                                      d{V }||t          d          |'|                     fd|D                        d{V  ||                    |           d{V  dS dS )a6  Async drop specific entries from the cache by ID or Redis key.

        Args:
            ids (Optional[List[str]]): List of entry IDs to remove from the cache.
                Entry IDs are the unique identifiers without the cache prefix.
            keys (Optional[List[str]]): List of full Redis keys to remove from the cache.
                Keys are the complete Redis keys including the cache prefix.

        Note:
            At least one of ids or keys must be provided.

        Raises:
            ValueError: If neither ids nor keys is provided.
        Nrt   c                 D    g | ]}j                             |          S r6   rv   rx   s     rQ   r{   z'SemanticCache.adrop.<locals>.<listcomp>@  s'    #F#F#FBDKOOB$7$7#F#F#FrR   )rb   r<   r|   )rL   rq   rr   rf   s   `   rQ   adropzSemanticCache.adrop(  s      " ,,........;4<LMMM ?""#F#F#F#F##F#F#FGGGGGGGGG""4((((((((((( rR   promptc                     t          |t                    st          d          | j                            |          }|S )\Converts a text prompt to its vector representation using the
        configured vectorizer.Prompt must be a string.)r:   strr;   r=   embedrL   r   results      rQ   _vectorize_promptzSemanticCache._vectorize_promptD  s@     &#&& 	86777!''//rR   c                    K   t          |t                    st          d          | j                            |           d{V }|S )r   r   N)r:   r   r;   r=   aembedr   s      rQ   _avectorize_promptz SemanticCache._avectorize_promptM  sV       &#&& 	86777'..v66666666rR   vectorc                     | j         j        j        t                   j        j        }t          t          |          |           dS )zzChecks the size of the provided vector and raises an error if it
        doesn't match the search index vector dimensions.N)r$   r4   fieldsr   attrsrB   r   len)rL   r   schema_vector_dimss      rQ   _check_vector_dimsz SemanticCache._check_vector_dimsV  s@     "[/6#

 	 	S[[*<=====rR      num_resultsr@   filter_expressionc           
         t          ||g          st          d          |r$t          |t                    st	          d          |p| j        }|||                     |          }||                     |           nt          d          t          |t          | j
        ||d|| j        j                  }| j                            |          }|                     ||          \  }	}
|	D ]}|                     |           |
S )a  Checks the semantic cache for results similar to the specified prompt
        or vector.

        This method searches the cache using vector similarity with
        either a raw text prompt (converted to a vector) or a provided vector as
        input. It checks for semantically similar prompts and fetches the cached
        LLM responses.

        Args:
            prompt (Optional[str], optional): The text prompt to search for in
                the cache.
            vector (Optional[List[float]], optional): The vector representation
                of the prompt to search for in the cache.
            num_results (int, optional): The number of cached results to return.
                Defaults to 1.
            return_fields (Optional[List[str]], optional): The fields to include
                in each returned result. If None, defaults to all available
                fields in the cached entry.
            filter_expression (Optional[FilterExpression]) : Optional filter expression
                that can be used to filter cache results. Defaults to None and
                the full cache will be searched.
            distance_threshold (Optional[float]): The threshold for semantic
                vector distance.

        Returns:
            List[Dict[str, Any]]: A list of dicts containing the requested
                return fields for each similar cached response.

        Raises:
            ValueError: If neither a `prompt` nor a `vector` is specified.
            ValueError: if 'vector' has incorrect dimensions.
            TypeError: If `return_fields` is not a list when provided.

        .. code-block:: python

            response = cache.check(
                prompt="What is the capital city of France?"
            )
        *Either prompt or vector must be specified.'Return fields must be a list of values.N0Failed to generate a valid vector for the query.Tr   vector_field_namer@   r*   r   return_scorer   r&   )anyr<   r:   listr;   rh   r   r   r   r   r@   r=   r&   r$   query_process_cache_resultsexpire)rL   r   r   r   r@   r   r*   r   cache_search_results
redis_keys
cache_hitsrw   s               rQ   checkzSemanticCache.check^  sL   ` FF#$$ 	KIJJJ 	GM4!@!@ 	GEFFF 0K43K >f0++F33F ##F++++OPPP !5,1#/"(	
 	
 	
  ${0077!%!<!< "
 "

J  	 	CKKrR   c           
      h   K                                      d{V }t          ||g          st          d          |r$t          |t                    st          d          |p j        }||                     |           d{V }|                     |           nt          d          t          |t           j        ||d| j        j                  }|                    |           d{V }	                     |	|          \  }
}t!          j         fd|
D               d{V  |S )a  Async check the semantic cache for results similar to the specified prompt
        or vector.

        This method searches the cache using vector similarity with
        either a raw text prompt (converted to a vector) or a provided vector as
        input. It checks for semantically similar prompts and fetches the cached
        LLM responses.

        Args:
            prompt (Optional[str], optional): The text prompt to search for in
                the cache.
            vector (Optional[List[float]], optional): The vector representation
                of the prompt to search for in the cache.
            num_results (int, optional): The number of cached results to return.
                Defaults to 1.
            return_fields (Optional[List[str]], optional): The fields to include
                in each returned result. If None, defaults to all available
                fields in the cached entry.
            filter_expression (Optional[FilterExpression]) : Optional filter expression
                that can be used to filter cache results. Defaults to None and
                the full cache will be searched.
            distance_threshold (Optional[float]): The threshold for semantic
                vector distance.

        Returns:
            List[Dict[str, Any]]: A list of dicts containing the requested
                return fields for each similar cached response.

        Raises:
            ValueError: If neither a `prompt` nor a `vector` is specified.
            ValueError: if 'vector' has incorrect dimensions.
            TypeError: If `return_fields` is not a list when provided.

        .. code-block:: python

            response = await cache.acheck(
                prompt="What is the capital city of France?"
            )
        Nr   r   r   Tr   c                 :    g | ]}                     |          S r6   )aexpire)ry   rw   rL   s     rQ   r{   z(SemanticCache.acheck.<locals>.<listcomp>  s%    GGGSt||C00GGGrR   )rb   r   r<   r:   r   r;   rh   r   r   r   r   r@   r=   r&   r   r   asynciogather)rL   r   r   r   r@   r   r*   rf   r   r   r   r   s   `           rQ   acheckzSemanticCache.acheck  s     ` ,,........FF#$$ 	KIJJJ 	GM4!@!@ 	GEFFF 0K43K >f0226::::::::F ##F++++OPPP !5,1#/"(	
 	
 	
 &,\\%%8%8888888!%!<!< "
 "

J nGGGGJGGGHHHHHHHHrR   r   c                 ^   g }g }|D ]}|                     d          }|                    |           t          di |}|                                }t	          t
                    r"r fd|                                D             }||t          <   |                    |           ||fS )z+Process raw search results into cache hits.rz   c                 $    i | ]\  }}|v 	||S r6   r6   )ry   kvr@   s      rQ   
<dictcomp>z8SemanticCache._process_cache_results.<locals>.<dictcomp>)  s0     " " "!QqM?Q?QAq?Q?Q?QrR   r6   )r9   r[   r   rJ   r:   r   itemsr   )	rL   r   r@   r   r   cache_search_result	redis_key	cache_hitcache_hit_dicts	     `      rQ   r   z$SemanticCache._process_cache_results  s     !#
+-
#7 	. 	.+//55Ii((( !77#677I&..00N -.. = " " " "%3%9%9%;%;" " "
 4=N/0n----:%%rR   responsemetadatafiltersc                 R   |p|                      |          }|                     |           |                     ||          }t          ||||||          }|p| j        }| j                            |                    | j        j	                  g|t                    }	|	d         S )aM  Stores the specified key-value pair in the cache along with metadata.

        Args:
            prompt (str): The user prompt to cache.
            response (str): The LLM response to cache.
            vector (Optional[List[float]], optional): The prompt vector to
                cache. Defaults to None, and the prompt vector is generated on
                demand.
            metadata (Optional[Dict[str, Any]], optional): The optional metadata to cache
                alongside the prompt and response. Defaults to None.
            filters (Optional[Dict[str, Any]]): The optional tag to assign to the cache entry.
                Defaults to None.
            ttl (Optional[int]): The optional TTL override to use on this individual cache
                entry. Defaults to the global TTL setting.

        Returns:
            str: The Redis key for the entries added to the semantic cache.

        Raises:
            ValueError: If neither prompt nor vector is specified.
            ValueError: if vector has incorrect dimensions.
            TypeError: If provided metadata is not a dictionary.

        .. code-block:: python

            key = cache.store(
                prompt="What is the capital city of France?",
                response="Paris",
                metadata={"city": "Paris", "country": "France"}
            )
        entry_idr   r   prompt_vectorr   r   datar+   id_fieldr   )r   r   _make_entry_idr
   _ttlr$   loadrJ   r=   r&   r   )
rL   r   r   r   r   r   r+   r   cache_entryrr   s
             rQ   storezSemanticCache.store3  s    R 9411&99''' &&vw77 ! 
 
 
 TY{%%d&6&<==>(   
 
 AwrR   c                   K   |                                   d{V }|p|                     |           d{V }|                     |           |                     ||          }t	          ||||||          }	|p| j        }|                    |	                    | j        j	                  g|t                     d{V }
|
d         S )aZ  Async stores the specified key-value pair in the cache along with metadata.

        Args:
            prompt (str): The user prompt to cache.
            response (str): The LLM response to cache.
            vector (Optional[List[float]], optional): The prompt vector to
                cache. Defaults to None, and the prompt vector is generated on
                demand.
            metadata (Optional[Dict[str, Any]], optional): The optional metadata to cache
                alongside the prompt and response. Defaults to None.
            filters (Optional[Dict[str, Any]]): The optional tag to assign to the cache entry.
                Defaults to None.
            ttl (Optional[int]): The optional TTL override to use on this individual cache
                entry. Defaults to the global TTL setting.

        Returns:
            str: The Redis key for the entries added to the semantic cache.

        Raises:
            ValueError: If neither prompt nor vector is specified.
            ValueError: if vector has incorrect dimensions.
            TypeError: If provided metadata is not a dictionary.

        .. code-block:: python

            key = await cache.astore(
                prompt="What is the capital city of France?",
                response="Paris",
                metadata={"city": "Paris", "country": "France"}
            )
        Nr   r   r   )rb   r   r   r   r
   r   r   rJ   r=   r&   r   )rL   r   r   r   r   r   r+   rf   r   r   rr   s              rQ   astorezSemanticCache.astorew  s     P ,,........ @!8!8!@!@@@@@@@''' &&vw77 ! 
 
 
 TY[[%%d&6&<==>( ! 
 
 
 
 
 
 
 
 AwrR   rw   c                    |r|                                 D ]\  }}|t          | j        j        j        t
          gz             vrt          | d          |t
          k    r7t          |t                    rt          |          ||<   st          d          |                    t          t                      i           |                                 }|                    ||           |                     |           dS )a9  Update specific fields within an existing cache entry. If no fields
        are passed, then only the document TTL is refreshed.

        Args:
            key (str): the key of the document to update using kwargs.

        Raises:
            ValueError if an incorrect mapping is provided as a kwarg.
            TypeError if metadata is provided and not of type dict.

        .. code-block:: python

            key = cache.store('this is a prompt', 'this is a response')
            cache.update(key, metadata={"hit_count": 1, "model_name": "Llama-2-7b"})
        , is not a valid field within the cache entry3If specified, cached metadata must be a dictionary.mappingN)r   rY   r$   r4   field_namesr   r<   r:   dictr   r;   r>   r   r   _get_redis_clienthsetr   rL   rw   rM   r   r   clients         rQ   r>   zSemanticCache.update  s      	-  1C 2 >BUAV VWWWW$%W%W%WXXX +++!!T** $-aLLq		'Q  	 , MM02C2E2EFGGG ++--FKKVK,,, 	CrR   c                 0  K   |r|                                 D ]\  }}|t          | j        j        j        t
          gz             vrt          | d          |t
          k    r7t          |t                    rt          |          ||<   st          d          |                    t          t                      i           |                                  d{V }|                    ||           d{V  |                     |           d{V  dS )a{  Async update specific fields within an existing cache entry. If no fields
        are passed, then only the document TTL is refreshed.

        Args:
            key (str): the key of the document to update using kwargs.

        Raises:
            ValueError if an incorrect mapping is provided as a kwarg.
            TypeError if metadata is provided and not of type dict.

        .. code-block:: python

            key = await cache.astore('this is a prompt', 'this is a response')
            await cache.aupdate(
                key,
                metadata={"hit_count": 1, "model_name": "Llama-2-7b"}
            )
        r   r   Nr   )r   rY   r$   r4   r   r   r<   r:   r   r   r;   r>   r   r   r`   r   r   r   s         rQ   aupdatezSemanticCache.aupdate  sK     &  	3  1C 2 >BUAV VWWWW$%W%W%WXXX +++!!T** $-aLLq		'Q  	 , MM02C2E2EFGGG  7799999999F++c6+222222222 ll3rR   c                     | S )zContext manager entry point.r6   rV   s    rQ   	__enter__zSemanticCache.__enter__  s    rR   c                 .    |                                   dS )zContext manager exit point.N)
disconnectrL   exc_typeexc_valexc_tbs       rQ   __exit__zSemanticCache.__exit__  s    rR   c                 
   K   | S )zAsync context manager entry.r6   rV   s    rQ   
__aenter__zSemanticCache.__aenter__  s      rR   c                 >   K   |                                   d{V  dS )zAsync context manager exit.N)adisconnectr   s       rQ   	__aexit__zSemanticCache.__aexit__  s0                 rR   c                    t          | d          r | j        r| j                                         t          | d          r | j        r| j                                         t                                                       dS )zmDisconnect from Redis and search index.

        Closes all Redis connections and index connections.
        r$   r%   N)hasattrr$   r   r%   disconnect_syncr7   rL   rP   s    rQ   r   zSemanticCache.disconnect#  s     4"" 	%t{ 	%K""$$$ 4## 	+ 	+L((*** 	rR   c                    K   t          | d          r-| j        r&| j                                         d{V  d| _        t                                                       d{V  dS )z|Asynchronously disconnect from Redis and search index.

        Closes all Redis connections and index connections.
        r%   N)r   r%   r   r7   r   r   s    rQ   r   zSemanticCache.adisconnect3  s       4## 	  	 ,))+++++++++DL gg!!###########rR   c                 "    t          ||          S )a8  Generate a deterministic entry ID for the given prompt and optional filters.

        Args:
            prompt (str): The prompt text.
            filters (Optional[Dict[str, Any]]): Optional filter dictionary.

        Returns:
            str: A deterministic entry ID based on the prompt and filters.
        r   )rL   r   r   s      rQ   r   zSemanticCache._make_entry_id@  s     vw'''rR   )N)rS   N)NN)NNr   NNN)NNNN)5__name__
__module____qualname____doc__r   __annotations__r%   r   r   r   r   rk   intr    r   r   r   r   boolr8   rW   r   rC   rb   propertyrd   rf   r*   r?   rn   rp   r5   r   r   r   r   r   r   r   r   r   r   r   r>   r   r   r   r   r   r   r   r   __classcell__)rP   s   @rQ   r#   r#   '   s        33*.GX&'...,// $'!/3<@(,1,.AA AAAA "AA c]	AA
 ^,AA $Dc3h$89AA uoAA AA  S>AA AA AA AA AA AA 0/AAF
# 
 
 
 
 =A ( $Dc3h$89 
"	   ,(8     {    X !12    X (E ( ( ( X(= =$ = = = = & & & &' ' ' ' LP( (DI&(5=d3i5H(	( ( ( (6 LP) )DI&)5=d3i5H)	) ) ) )8 $u+    x} e    >e > > > > !%(,-18<.2Y YY e%Y 	Y
  S	*Y $$45Y %UOY 
d38n	Y Y Y Yz !%(,-18<.2Z ZZ e%Z 	Z
  S	*Z $$45Z %UOZ 
d38n	Z Z Z Z~ .2& &"4S>2&  S	*& 
tCy$tCH~..	/	& & & &D )--1,0!B BB B e%	B
 4S>*B $sCx.)B c]B 
B B B BP )--1,0!D DD D e%	D
 4S>*D $sCx.)D c]D 
D D D DL'# 'D ' ' ' 'R+  + 4 +  +  +  + Z      ! ! !     $ $ $ $ $ @D( (($,T#s(^$<(	( ( ( ( ( ( ( (rR   r#   ).r   typingr   r   r   r   r   redisr   !redisvl.extensions.cache.llm.baser	   #redisvl.extensions.cache.llm.schemar
   r   r   redisvl.extensions.constantsr   r   r   r   r   r   r   r   redisvl.indexr   r   redisvl.queryr   redisvl.query.filterr   redisvl.redis.utilsr   redisvl.utils.logr   redisvl.utils.utilsr   r   r   r   redisvl.utils.vectorize.baser    (redisvl.utils.vectorize.text.huggingfacer!   rG   r#   r6   rR   rQ   <module>r      s    3 3 3 3 3 3 3 3 3 3 3 3 3 3       : : : : : :         
	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 8 7 7 7 7 7 7 7 * * * * * * 1 1 1 1 1 1 ' ' ' ' ' ' ( ( ( ( ( (            8 7 7 7 7 7 E E E E E E	K	 	 e( e( e( e( e(L e( e( e( e( e(rR   