
    Q
i                     V    d Z ddlmZmZmZmZ ddlmZ ddlm	Z	  G d de          Z
dS )zBase LLM cache interface for RedisVL.

This module defines the abstract base interface for LLM caches, which store
prompt-response pairs with semantic retrieval capabilities.
    )AnyDictListOptional)	BaseCache)FilterExpressionc                       e Zd ZdZddedee         f fdZddZddZ		 	 	 	 	 	 dd
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         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dedee
e                  deeeef                  deeeef                  dee         defdZ	 	 	 	 dd
ededee
e                  deeeef                  deeeef                  dee         defdZdeddfdZdeddfdZ xZS )BaseLLMCachezBase abstract LLM cache interface.

    This class defines the core functionality for caching LLM responses
    with semantic similarity search capabilities.
    Nnamettlc                 @     t                      j        d||d| dS )a   Initialize an LLM cache.

        Args:
            name (str): The name of the cache.
            ttl (Optional[int]): The time-to-live for cached responses. Defaults to None.
            **kwargs: Additional arguments passed to the parent class.
        )r   r   N )super__init__)selfr   r   kwargs	__class__s       C:\Users\Dell Inspiron 16\Desktop\tws\AgrotaPowerBi\back-agrota-powerbi\mcp-client-agrota\venv\Lib\site-packages\redisvl/extensions/cache/llm/base.pyr   zBaseLLMCache.__init__   s/     	6d66v66666    returnc                     t           )z(Delete the cache and its index entirely.NotImplementedErrorr   s    r   deletezBaseLLMCache.delete   s    !!r   c                    K   t           )z.Async delete the cache and its index entirely.r   r   s    r   adeletezBaseLLMCache.adelete"         !!r      promptvectornum_resultsreturn_fieldsfilter_expressiondistance_thresholdc                     t           )a  Check the cache for semantically similar prompts.

        Args:
            prompt (Optional[str]): The text prompt to search for in the cache.
            vector (Optional[List[float]]): Vector representation to search for.
            num_results (int): Number of results to return. Defaults to 1.
            return_fields (Optional[List[str]]): Fields to return in results.
            filter_expression (Optional[FilterExpression]): Optional filter to apply.
            distance_threshold (Optional[float]): Override for semantic distance threshold.

        Returns:
            List[Dict[str, Any]]: List of matching cache entries.
        r   r   r    r!   r"   r#   r$   r%   s          r   checkzBaseLLMCache.check&   
    , "!r   c                    K   t           )z7Async check the cache for semantically similar prompts.r   r'   s          r   acheckzBaseLLMCache.acheck>          "!r   responsemetadatafiltersc                     t           )a  Store a prompt-response pair in the cache.

        Args:
            prompt (str): The user prompt to cache.
            response (str): The LLM response to cache.
            vector (Optional[List[float]]): Optional embedding vector.
            metadata (Optional[Dict[str, Any]]): Optional metadata.
            filters (Optional[Dict[str, Any]]): Optional filters for retrieval.
            ttl (Optional[int]): Optional TTL override.

        Returns:
            str: The Redis key for the cached entry.
        r   r   r    r-   r!   r.   r/   r   s          r   storezBaseLLMCache.storeJ   r)   r   c                    K   t           )z0Async store a prompt-response pair in the cache.r   r1   s          r   astorezBaseLLMCache.astoreb   r,   r   keyc                     t           )zUpdate specific fields within an existing cache entry.

        Args:
            key (str): The key of the document to update.
            **kwargs: Field-value pairs to update.
        r   r   r5   r   s      r   updatezBaseLLMCache.updaten   s
     "!r   c                    K   t           )z<Async update specific fields within an existing cache entry.r   r7   s      r   aupdatezBaseLLMCache.aupdatew   r   r   )N)r   N)NNr   NNN)NNNN)__name__
__module____qualname____doc__strr   intr   r   r   r   floatr   r   r   r(   r+   r2   r4   r8   r:   __classcell__)r   s   @r   r
   r
      s*        7 7S 7x} 7 7 7 7 7 7" " " "" " " " !%(,-18<.2" "" e%" 	"
  S	*" $$45" %UO" 
d38n	" " " "4 !%(,-18<.2
" 
"
" e%
" 	
"
  S	*
" $$45
" %UO
" 
d38n	
" 
" 
" 
"  )--1,0!" "" " e%	"
 4S>*" $sCx.)" c]" 
" " " "8 )--1,0!
" 
"
" 
" e%	
"
 4S>*
" $sCx.)
" c]
" 

" 
" 
" 
""# "D " " " "" "4 " " " " " " " "r   r
   N)r>   typingr   r   r   r   redisvl.extensions.cache.baser   redisvl.query.filterr   r
   r   r   r   <module>rF      s     - , , , , , , , , , , , 3 3 3 3 3 3 1 1 1 1 1 1l" l" l" l" l"9 l" l" l" l" l"r   