
    Q
i                         d Z ddlmZmZ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 ddlmZmZ ddlmZ  ee          Z G d d	e
          Zd
S )z,Embeddings cache implementation for RedisVL.    )AnyDictIterableListOptionalTupleUnion)	BaseCache)
CacheEntry)convert_byteshashify)AsyncRedisClientSyncRedisClient)
get_loggerc                   N    e Zd ZU dZdZeed<   dddddi fdedee	         d	ee
         d
ee         dedeeef         f fdZdeeef         dedefdZdeeef         dedefdZ	 d9deeef         dedee         deeeef                  deeeeef         f         f
dZdeeeef                  deeeef                  fdZdefdZdeeef         dedeeeef                  fdZdedeeeef                  fdZdee         deeeeef                           fdZdeeeef                  dedeeeeef                           fdZ	 	 d:deeef         dedee         deeeef                  dee	         defd Z	 d9d!eeeef                  dee	         dee         fd"Zdeeef         dedefd#Z dedefd$Z!dee         dee         fd%Z"deeeef                  dedee         fd&Z#deeef         deddfd'Z$deddfd(Z%dee         ddfd)Z&deeeef                  deddfd*Z'deeef         dedeeeef                  fd+Z(dedeeeef                  fd,Z)dee         deeeeef                           fd-Z*deeeef                  dedeeeeef                           fd.Z+	 	 d:deeef         dedee         deeeef                  dee	         defd/Z,	 d9d!eeeef                  dee	         dee         fd0Z-dee         dee         fd1Z.deeeef                  dedee         fd2Z/dee         ddfd3Z0deeeef                  deddfd4Z1deeef         dedefd5Z2dedefd6Z3deeef         deddfd7Z4deddfd8Z5 xZ6S );EmbeddingsCachezGEmbeddings Cache for storing embedding vectors with exact key matching.F_warning_shown
embedcacheNzredis://localhost:6379namettlredis_clientasync_redis_client	redis_urlconnection_kwargsc                 V    t                                          ||||||           dS )a  Initialize an embeddings cache.

        Args:
            name (str): The name of the cache. Defaults to "embedcache".
            ttl (Optional[int]): The time-to-live for cached embeddings. Defaults to None.
            redis_client (Optional[SyncRedisClient]): Redis client instance. Defaults to None.
            redis_url (str): Redis URL for connection. Defaults to "redis://localhost:6379".
            connection_kwargs (Dict[str, Any]): Redis connection arguments. Defaults to {}.

        Raises:
            ValueError: If vector dimensions are invalid

        .. code-block:: python

            cache = EmbeddingsCache(
                name="my_embeddings_cache",
                ttl=3600,  # 1 hour
                redis_url="redis://localhost:6379"
            )
        )r   r   r   r   r   r   N)super__init__)selfr   r   r   r   r   r   	__class__s          C:\Users\Dell Inspiron 16\Desktop\tws\AgrotaPowerBi\back-agrota-powerbi\mcp-client-agrota\venv\Lib\site-packages\redisvl/extensions/cache/embeddings/embeddings.pyr   zEmbeddingsCache.__init__   sB    : 	%1/ 	 	
 	
 	
 	
 	
    content
model_namereturnc                 |    t          |t                    r|                                }t          | d|           S )aA  Generate a deterministic entry ID for the given content and model name.

        Args:
            content (bytes | str): The content that was embedded.
            model_name (str): The name of the embedding model.

        Returns:
            str: A deterministic entry ID based on the content and model name.
        :)
isinstancebyteshexr   )r   r"   r#   s      r    _make_entry_idzEmbeddingsCache._make_entry_id9   s?     gu%% 	$kkmmG'00J00111r!   c                 X    |                      ||          }|                     |          S )a  Generate a full Redis key for the given content and model name.

        Args:
            content (bytes | str): The content that was embedded.
            model_name (str): The name of the embedding model.

        Returns:
            str: The full Redis key.
        )r*   	_make_key)r   r"   r#   entry_ids       r    _make_cache_keyzEmbeddingsCache._make_cache_keyG   s+     &&w
;;~~h'''r!   	embeddingmetadatac                     |                      ||          }|                     |          }t          |||||          }||                                fS )a  Prepare data for storage in Redis

        Args:
            content (bytes | str): The content that was embedded.
            model_name (str): The name of the embedding model.
            embedding (List[float]): The embedding vector.
            metadata (Optional[Dict[str, Any]]): Optional metadata.

        Returns:
            Tuple[str, Dict[str, Any]]: A tuple of (key, entry_data)
        )r-   r"   r#   r/   r0   )r*   r,   r   to_dict)r   r"   r#   r/   r0   r-   keyentrys           r    _prepare_entry_dataz#EmbeddingsCache._prepare_entry_dataT   sb    & &&w
;;nnX&&!
 
 
 EMMOO##r!   datac                 h    |sdS t          di t          |          }|                    d          S )zProcess Redis hash data into a cache entry response.

        Args:
            data (Optional[Dict[str, Any]]): Raw Redis hash data.

        Returns:
            Optional[Dict[str, Any]]: Processed cache entry or None if no data.
        NT)exclude_none )r   r   
model_dump)r   r6   	cache_hits      r    _process_cache_dataz#EmbeddingsCache._process_cache_datar   sC      	455t!4!455	###666r!   c                 &    | j         du o| j        du S )zCheck if only async client is available (no sync client).

        Returns:
            bool: True if only async client is available (no sync client).
        FN)_owns_redis_client_redis_client)r   s    r    _should_warn_for_async_onlyz+EmbeddingsCache._should_warn_for_async_only   s     &%/ND4F$4NNr!   c                 X    |                      ||          }|                     |          S )ac  Get embedding by content and model name.

        Retrieves a cached embedding for the given content and model name.
        If found, refreshes the TTL of the entry.

        Args:
            content (bytes | str): The content that was embedded.
            model_name (str): The name of the embedding model.

        Returns:
            Optional[Dict[str, Any]]: Embedding cache entry or None if not found.

        .. code-block:: python

            embedding_data = cache.get(
                content="What is machine learning?",
                model_name="text-embedding-ada-002"
            )
        )r.   
get_by_keyr   r"   r#   r3   s       r    getzEmbeddingsCache.get   s+    0 ""7J77s###r!   r3   c                 8   |                                  r2t          j        s&t                              d           dt          _        |                                 }|                    |          }|r|                     |           |                     |          S )a  Get embedding by its full Redis key.

        Retrieves a cached embedding for the given Redis key.
        If found, refreshes the TTL of the entry.

        Args:
            key (str): The full Redis key for the embedding.

        Returns:
            Optional[Dict[str, Any]]: Embedding cache entry or None if not found.

        .. code-block:: python

            embedding_data = cache.get_by_key("embedcache:1234567890abcdef")
        zEmbeddingsCache initialized with async_redis_client only. Use async methods (aget_by_key) instead of sync methods (get_by_key).T)	r@   r   r   loggerwarning_get_redis_clienthgetallexpirer<   r   r3   clientr6   s       r    rB   zEmbeddingsCache.get_by_key   s      ++-- 	6"1 6\   26.'')) ~~c""  	KK''---r!   keysc                 2   |sg S |                                  r2t          j        s&t                              d           dt          _        |                                 }|                    d          5 }|D ]}|                    |           |                                }ddd           n# 1 swxY w Y   g }t          |          D ]J\  }}|r| 
                    ||                    |                    |                     |                     K|S )a  Get multiple embeddings by their Redis keys.

        Efficiently retrieves multiple cached embeddings in a single network roundtrip.
        If found, refreshes the TTL of each entry.

        Args:
            keys (List[str]): List of Redis keys to retrieve.

        Returns:
            List[Optional[Dict[str, Any]]]: List of embedding cache entries or None for keys not found.
            The order matches the input keys order.

        .. code-block:: python

            # Get multiple embeddings
            embedding_data = cache.mget_by_keys([
                "embedcache:key1",
                "embedcache:key2"
            ])
        zEmbeddingsCache initialized with async_redis_client only. Use async methods (amget_by_keys) instead of sync methods (mget_by_keys).TFtransactionN)r@   r   r   rF   rG   rH   pipelinerI   execute	enumeraterJ   appendr<   	r   rM   rL   rQ   r3   resultsprocessed_resultsiresults	            r    mget_by_keyszEmbeddingsCache.mget_by_keys   sr   *  	I++-- 	6"1 6`   26.''))___// 	)8 & &  %%%%&&((G		) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) "7++ 	G 	GIAv %DG$$$$$T%=%=f%E%EFFFF  s   5/B00B47B4contentsc                 V      fd|D             }|sg S                       |          S )a  Get multiple embeddings by their content and model name.

        Efficiently retrieves multiple cached embeddings in a single operation.
        If found, refreshes the TTL of each entry.

        Args:
            contents (Iterable[bytes | str]): Iterable of content that was embedded.
            model_name (str): The name of the embedding model.

        Returns:
            List[Optional[Dict[str, Any]]]: List of embedding cache entries or None for contents not found.

        .. code-block:: python

            # Get multiple embeddings
            embedding_data = cache.mget(
                contents=["What is machine learning?", "What is deep learning?"],
                model_name="text-embedding-ada-002"
            )
        c                 <    g | ]}                     |          S r9   r.   .0r"   r#   r   s     r    
<listcomp>z(EmbeddingsCache.mget.<locals>.<listcomp>  )    RRRg$$Wj99RRRr!   )rZ   r   r[   r#   rM   s   ` ` r    mgetzEmbeddingsCache.mget   sF    0 SRRRRRRR 	I   &&&r!   c                 J   |                      ||||          \  }}|                                 r2t          j        s&t                              d           dt          _        |                                 }|                    ||           |                     ||           |S )a,  Store an embedding with its content and model name.

        Args:
            content (Union[bytes, str]): The content to be embedded.
            model_name (str): The name of the embedding model.
            embedding (List[float]): The embedding vector to store.
            metadata (Optional[Dict[str, Any]]): Optional metadata to store with the embedding.
            ttl (Optional[int]): Optional TTL override for this specific entry.

        Returns:
            str: The Redis key where the embedding was stored.

        .. code-block:: python

            key = cache.set(
                content="What is machine learning?",
                model_name="text-embedding-ada-002",
                embedding=[0.1, 0.2, 0.3, ...],
                metadata={"source": "user_query"}
            )
        zqEmbeddingsCache initialized with async_redis_client only. Use async methods (aset) instead of sync methods (set).Tr   mapping)	r5   r@   r   r   rF   rG   rH   hsetrJ   	r   r"   r#   r/   r0   r   r3   cache_entryrL   s	            r    setzEmbeddingsCache.set  s    <  33ZH
 
[ ++-- 	6"1 6N   26. ''))k222 	C
r!   itemsc                    |sg S |                                  r2t          j        s&t                              d           dt          _        |                                 }g }|                    d          5 }|D ]>} | j        di |\  }}|                    |           |	                    ||           ?|
                                 ddd           n# 1 swxY w Y   |D ]}|                     ||           |S )a  Store multiple embeddings in a batch operation.

        Each item in the input list should be a dictionary with the following fields:
        - 'content': The input that was embedded
        - 'model_name': The name of the embedding model
        - 'embedding': The embedding vector
        - 'metadata': Optional metadata to store with the embedding

        Args:
            items: List of dictionaries, each containing content, model_name, embedding, and optional metadata.
            ttl: Optional TTL override for these entries.

        Returns:
            List[str]: List of Redis keys where the embeddings were stored.

        .. code-block:: python

            # Store multiple embeddings
            keys = cache.mset([
                {
                    "content": "What is ML?",
                    "model_name": "text-embedding-ada-002",
                    "embedding": [0.1, 0.2, 0.3],
                    "metadata": {"source": "user"}
                },
                {
                    "content": "What is AI?",
                    "model_name": "text-embedding-ada-002",
                    "embedding": [0.4, 0.5, 0.6],
                    "metadata": {"source": "docs"}
                }
            ])
        zsEmbeddingsCache initialized with async_redis_client only. Use async methods (amset) instead of sync methods (mset).TFrO   rf   Nr9   )r@   r   r   rF   rG   rH   rQ   r5   rT   rh   rR   rJ   	r   rl   r   rL   rM   rQ   itemr3   rj   s	            r    msetzEmbeddingsCache.msetM  si   L  	I++-- 	6"1 6P   26.''))___// 	8 = =#;4#;#C#Cd#C#C [C   3<<<<	 	 	 	 	 	 	 	 	 	 	 	 	 	 	  	" 	"CKKS!!!!s   7ACC Cc                     |                                  }|                     ||          }t          |                    |                    S )a  Check if an embedding exists for the given content and model.

        Args:
            content (bytes | str): The content that was embedded.
            model_name (str): The name of the embedding model.

        Returns:
            bool: True if the embedding exists in the cache, False otherwise.

        .. code-block:: python

            if cache.exists("What is machine learning?", "text-embedding-ada-002"):
                print("Embedding is in cache")
        )rH   r.   boolexists)r   r"   r#   rL   r3   s        r    rs   zEmbeddingsCache.exists  sD     ''))""7J77FMM#&&'''r!   c                 n    |                                  }t          |                    |                    S )a}  Check if an embedding exists for the given Redis key.

        Args:
            key (str): The full Redis key for the embedding.

        Returns:
            bool: True if the embedding exists in the cache, False otherwise.

        .. code-block:: python

            if cache.exists_by_key("embedcache:1234567890abcdef"):
                print("Embedding is in cache")
        )rH   rr   rs   r   r3   rL   s      r    exists_by_keyzEmbeddingsCache.exists_by_key  s/     ''))FMM#&&'''r!   c                    |sg S |                                  }|                    d          5 }|D ]}|                    |           |                                }ddd           n# 1 swxY w Y   d |D             S )a  Check if multiple embeddings exist by their Redis keys.

        Efficiently checks existence of multiple keys in a single operation.

        Args:
            keys (List[str]): List of Redis keys to check.

        Returns:
            List[bool]: List of boolean values indicating whether each key exists.
            The order matches the input keys order.

        .. code-block:: python

            # Check if multiple keys exist
            exists_results = cache.mexists_by_keys(["embedcache:key1", "embedcache:key2"])
        FrO   Nc                 ,    g | ]}t          |          S r9   rr   r`   rY   s     r    ra   z3EmbeddingsCache.mexists_by_keys.<locals>.<listcomp>      333V333r!   )rH   rQ   rs   rR   r   rM   rL   rQ   r3   rV   s         r    mexists_by_keyszEmbeddingsCache.mexists_by_keys  s    "  	I''))___// 	)8 % %$$$$&&((G		) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 4373333s   /A**A.1A.c                 V      fd|D             }|sg S                       |          S )a  Check if multiple embeddings exist by their contents and model name.

        Efficiently checks existence of multiple embeddings in a single operation.

        Args:
            contents (Iterable[bytes | str]): Iterable of content that was embedded.
            model_name (str): The name of the embedding model.

        Returns:
            List[bool]: List of boolean values indicating whether each embedding exists.

        .. code-block:: python

            # Check if multiple embeddings exist
            exists_results = cache.mexists(
                contents=["What is machine learning?", "What is deep learning?"],
                model_name="text-embedding-ada-002"
            )
        c                 <    g | ]}                     |          S r9   r^   r_   s     r    ra   z+EmbeddingsCache.mexists.<locals>.<listcomp>  rb   r!   )r}   rc   s   ` ` r    mexistszEmbeddingsCache.mexists  sF    . SRRRRRRR 	I ##D)))r!   c                 \    |                      ||          }|                     |           dS )al  Remove an embedding from the cache.

        Args:
            content (bytes | str): The content that was embedded.
            model_name (str): The name of the embedding model.

        .. code-block:: python

            cache.drop(
                content="What is machine learning?",
                model_name="text-embedding-ada-002"
            )
        N)r.   drop_by_keyrC   s       r    dropzEmbeddingsCache.drop  s3     ""7J77r!   c                 X    |                                  }|                    |           dS )zRemove an embedding from the cache by its Redis key.

        Args:
            key (str): The full Redis key for the embedding.

        .. code-block:: python

            cache.drop_by_key("embedcache:1234567890abcdef")
        N)rH   deleteru   s      r    r   zEmbeddingsCache.drop_by_key  s-     ''))cr!   c                     |sdS |                                  }|                    d          5 }|D ]}|                    |           |                                 ddd           dS # 1 swxY w Y   dS )al  Remove multiple embeddings from the cache by their Redis keys.

        Efficiently removes multiple embeddings in a single operation.

        Args:
            keys (List[str]): List of Redis keys to remove.

        .. code-block:: python

            # Remove multiple embeddings
            cache.mdrop_by_keys(["embedcache:key1", "embedcache:key2"])
        NFrO   )rH   rQ   r   rR   )r   rM   rL   rQ   r3   s        r    mdrop_by_keyszEmbeddingsCache.mdrop_by_keys  s      	F''))___// 	8 % %$$$$	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   /A++A/2A/c                 Z      fd|D             }|sdS                       |           dS )a6  Remove multiple embeddings from the cache by their contents and model name.

        Efficiently removes multiple embeddings in a single operation.

        Args:
            contents (Iterable[bytes | str]): Iterable of content that was embedded.
            model_name (str): The name of the embedding model.

        .. code-block:: python

            # Remove multiple embeddings
            cache.mdrop(
                contents=["What is machine learning?", "What is deep learning?"],
                model_name="text-embedding-ada-002"
            )
        c                 <    g | ]}                     |          S r9   r^   r_   s     r    ra   z)EmbeddingsCache.mdrop.<locals>.<listcomp>:  rb   r!   N)r   rc   s   ` ` r    mdropzEmbeddingsCache.mdrop(  sL    $ SRRRRRRR 	F 	4     r!   c                 h   K   |                      ||          }|                     |           d{V S )a  Async get embedding by content and model name.

        Asynchronously retrieves a cached embedding for the given content and model name.
        If found, refreshes the TTL of the entry.

        Args:
            content (bytes | str): The content that was embedded.
            model_name (str): The name of the embedding model.

        Returns:
            Optional[Dict[str, Any]]: Embedding cache entry or None if not found.

        .. code-block:: python

            embedding_data = await cache.aget(
                content="What is machine learning?",
                model_name="text-embedding-ada-002"
            )
        N)r.   aget_by_keyrC   s       r    agetzEmbeddingsCache.agetB  sC      0 ""7J77%%c*********r!   c                    K   |                                   d{V }|                    |           d{V }|r|                     |           d{V  |                     |          S )a  Async get embedding by its full Redis key.

        Asynchronously retrieves a cached embedding for the given Redis key.
        If found, refreshes the TTL of the entry.

        Args:
            key (str): The full Redis key for the embedding.

        Returns:
            Optional[Dict[str, Any]]: Embedding cache entry or None if not found.

        .. code-block:: python

            embedding_data = await cache.aget_by_key("embedcache:1234567890abcdef")
        N)_get_async_redis_clientrI   aexpirer<   rK   s       r    r   zEmbeddingsCache.aget_by_key]  s        3355555555 ^^C((((((((  	$,,s#########''---r!   c                   K   |sg S |                                   d{V }|                    d          4 d{V }|D ]}|                    |           |                                 d{V }ddd          d{V  n# 1 d{V swxY w Y   g }t	          |          D ]P\  }}|r!|                     ||                    d{V  |                    |                     |                     Q|S )a  Async get multiple embeddings by their Redis keys.

        Asynchronously retrieves multiple cached embeddings in a single network roundtrip.
        If found, refreshes the TTL of each entry.

        Args:
            keys (List[str]): List of Redis keys to retrieve.

        Returns:
            List[Optional[Dict[str, Any]]]: List of embedding cache entries or None for keys not found.
            The order matches the input keys order.

        .. code-block:: python

            # Get multiple embeddings asynchronously
            embedding_data = await cache.amget_by_keys([
                "embedcache:key1",
                "embedcache:key2"
            ])
        NFrO   )r   rQ   rI   rR   rS   r   rT   r<   rU   s	            r    amget_by_keyszEmbeddingsCache.amget_by_keysx  s     *  	I3355555555 ??u?55 	/ 	/ 	/ 	/ 	/ 	/ 	/ & &  %%%%$,,........G		/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ "7++ 	G 	GIAv ,ll47+++++++++$$T%=%=f%E%EFFFF  s   5B
BBc                 f    K    fd|D             }|sg S                       |           d{V S )a
  Async get multiple embeddings by their contents and model name.

        Asynchronously retrieves multiple cached embeddings in a single operation.
        If found, refreshes the TTL of each entry.

        Args:
            contents (Iterable[bytes | str]): Iterable of content that was embedded.
            model_name (str): The name of the embedding model.

        Returns:
            List[Optional[Dict[str, Any]]]: List of embedding cache entries or None for contents not found.

        .. code-block:: python

            # Get multiple embeddings asynchronously
            embedding_data = await cache.amget(
                contents=["What is machine learning?", "What is deep learning?"],
                model_name="text-embedding-ada-002"
            )
        c                 <    g | ]}                     |          S r9   r^   r_   s     r    ra   z)EmbeddingsCache.amget.<locals>.<listcomp>  rb   r!   N)r   rc   s   ` ` r    amgetzEmbeddingsCache.amget  s\      0 SRRRRRRR 	I ''---------r!   c                    K   |                      ||||          \  }}|                                  d{V }|                    ||           d{V  |                     ||           d{V  |S )a  Async store an embedding with its content and model name.

        Asynchronously stores an embedding with its content and model name.

        Args:
            content (bytes | str): The content that was embedded.
            model_name (str): The name of the embedding model.
            embedding (List[float]): The embedding vector to store.
            metadata (Optional[Dict[str, Any]]): Optional metadata to store with the embedding.
            ttl (Optional[int]): Optional TTL override for this specific entry.

        Returns:
            str: The Redis key where the embedding was stored.

        .. code-block:: python

            key = await cache.aset(
                content="What is machine learning?",
                model_name="text-embedding-ada-002",
                embedding=[0.1, 0.2, 0.3, ...],
                metadata={"source": "user_query"}
            )
        Nrf   )r5   r   rh   r   ri   s	            r    asetzEmbeddingsCache.aset  s      @  33ZH
 
[
 3355555555kksKk888888888 ll3$$$$$$$$$
r!   c                   K   |sg S |                                   d{V }g }|                    d          4 d{V }|D ]D} | j        di |\  }}|                    |           |                    ||           d{V  E|                                 d{V  ddd          d{V  n# 1 d{V swxY w Y   |D ]}|                     ||           d{V  |S )a  Async store multiple embeddings in a batch operation.

        Each item in the input list should be a dictionary with the following fields:
        - 'content': The content that was embedded
        - 'model_name': The name of the embedding model
        - 'embedding': The embedding vector
        - 'metadata': Optional metadata to store with the embedding

        Args:
            items: List of dictionaries, each containing content, model_name, embedding, and optional metadata.
            ttl: Optional TTL override for these entries.

        Returns:
            List[str]: List of Redis keys where the embeddings were stored.

        .. code-block:: python

            # Store multiple embeddings asynchronously
            keys = await cache.amset([
                {
                    "content": "What is ML?",
                    "model_name": "text-embedding-ada-002",
                    "embedding": [0.1, 0.2, 0.3],
                    "metadata": {"source": "user"}
                },
                {
                    "content": "What is AI?",
                    "model_name": "text-embedding-ada-002",
                    "embedding": [0.4, 0.5, 0.6],
                    "metadata": {"source": "docs"}
                }
            ])
        NFrO   rf   r9   )r   rQ   r5   rT   rh   rR   r   rn   s	            r    amsetzEmbeddingsCache.amset  s     L  	I3355555555??u?55 	% 	% 	% 	% 	% 	% 	% C C#;4#;#C#Cd#C#C [C   mmkmBBBBBBBBBB""$$$$$$$$$	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	%  	) 	)C,,sC((((((((((s   A"B33
B= B=c                 N  K   |sg S |                                   d{V }|                    d          4 d{V }|D ]}|                    |           d{V  |                                 d{V }ddd          d{V  n# 1 d{V swxY w Y   d |D             S )a7  Async check if multiple embeddings exist by their Redis keys.

        Asynchronously checks existence of multiple keys in a single operation.

        Args:
            keys (List[str]): List of Redis keys to check.

        Returns:
            List[bool]: List of boolean values indicating whether each key exists.
            The order matches the input keys order.

        .. code-block:: python

            # Check if multiple keys exist asynchronously
            exists_results = await cache.amexists_by_keys(["embedcache:key1", "embedcache:key2"])
        NFrO   c                 ,    g | ]}t          |          S r9   ry   rz   s     r    ra   z4EmbeddingsCache.amexists_by_keys.<locals>.<listcomp>H  r{   r!   )r   rQ   rs   rR   r|   s         r    amexists_by_keysz EmbeddingsCache.amexists_by_keys+  sg     "  	I3355555555??u?55 	/ 	/ 	/ 	/ 	/ 	/ 	/ + +ooc**********$,,........G		/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 4373333s   ;B


BBc                 f    K    fd|D             }|sg S                       |           d{V S )a  Async check if multiple embeddings exist by their contents and model name.

        Asynchronously checks existence of multiple embeddings in a single operation.

        Args:
            contents (Iterable[bytes | str]): Iterable of content that was embedded.
            model_name (str): The name of the embedding model.

        Returns:
            List[bool]: List of boolean values indicating whether each embedding exists.

        .. code-block:: python

            # Check if multiple embeddings exist asynchronously
            exists_results = await cache.amexists(
                contents=["What is machine learning?", "What is deep learning?"],
                model_name="text-embedding-ada-002"
            )
        c                 <    g | ]}                     |          S r9   r^   r_   s     r    ra   z,EmbeddingsCache.amexists.<locals>.<listcomp>a  rb   r!   N)r   rc   s   ` ` r    amexistszEmbeddingsCache.amexistsJ  s\      . SRRRRRRR 	I **4000000000r!   c                 f   K   |sdS |                                   d{V } |j        |  d{V  dS )a  Async remove multiple embeddings from the cache by their Redis keys.

        Asynchronously removes multiple embeddings in a single operation.

        Args:
            keys (List[str]): List of Redis keys to remove.

        .. code-block:: python

            # Remove multiple embeddings asynchronously
            await cache.amdrop_by_keys(["embedcache:key1", "embedcache:key2"])
        Nr   r   )r   rM   rL   s      r    amdrop_by_keyszEmbeddingsCache.amdrop_by_keysi  s_        	F3355555555fmT""""""""""r!   c                 j    K    fd|D             }|sdS                       |           d{V  dS )aU  Async remove multiple embeddings from the cache by their contents and model name.

        Asynchronously removes multiple embeddings in a single operation.

        Args:
            contents (Iterable[bytes | str]): Iterable of content that was embedded.
            model_name (str): The name of the embedding model.

        .. code-block:: python

            # Remove multiple embeddings asynchronously
            await cache.amdrop(
                contents=["What is machine learning?", "What is deep learning?"],
                model_name="text-embedding-ada-002"
            )
        c                 <    g | ]}                     |          S r9   r^   r_   s     r    ra   z*EmbeddingsCache.amdrop.<locals>.<listcomp>  rb   r!   N)r   rc   s   ` ` r    amdropzEmbeddingsCache.amdrop|  sb      ( SRRRRRRR 	F !!$'''''''''''r!   c                 h   K   |                      ||          }|                     |           d{V S )a  Async check if an embedding exists.

        Asynchronously checks if an embedding exists for the given content and model.

        Args:
            content (bytes | str): The content that was embedded.
            model_name (str): The name of the embedding model.

        Returns:
            bool: True if the embedding exists in the cache, False otherwise.

        .. code-block:: python

            if await cache.aexists("What is machine learning?", "text-embedding-ada-002"):
                print("Embedding is in cache")
        N)r.   aexists_by_keyrC   s       r    aexistszEmbeddingsCache.aexists  sC      " ""7J77((---------r!   c                    K   |                                   d{V }t          |                    |           d{V           S )a  Async check if an embedding exists for the given Redis key.

        Asynchronously checks if an embedding exists for the given Redis key.

        Args:
            key (str): The full Redis key for the embedding.

        Returns:
            bool: True if the embedding exists in the cache, False otherwise.

        .. code-block:: python

            if await cache.aexists_by_key("embedcache:1234567890abcdef"):
                print("Embedding is in cache")
        N)r   rr   rs   ru   s      r    r   zEmbeddingsCache.aexists_by_key  sW        3355555555&--,,,,,,,,---r!   c                 l   K   |                      ||          }|                     |           d{V  dS )a  Async remove an embedding from the cache.

        Asynchronously removes an embedding from the cache.

        Args:
            content (bytes | str): The content that was embedded.
            model_name (str): The name of the embedding model.

        .. code-block:: python

            await cache.adrop(
                content="What is machine learning?",
                model_name="text-embedding-ada-002"
            )
        N)r.   adrop_by_keyrC   s       r    adropzEmbeddingsCache.adrop  sI        ""7J77$$$$$$$$$$$r!   c                 t   K   |                                   d{V }|                    |           d{V  dS )aB  Async remove an embedding from the cache by its Redis key.

        Asynchronously removes an embedding from the cache by its Redis key.

        Args:
            key (str): The full Redis key for the embedding.

        .. code-block:: python

            await cache.adrop_by_key("embedcache:1234567890abcdef")
        Nr   ru   s      r    r   zEmbeddingsCache.adrop_by_key  sU       3355555555mmC           r!   )N)NN)7__name__
__module____qualname____doc__r   rr   __annotations__strr   intr   r   r   r   r   r	   r(   r*   r.   r   floatr   r5   r<   r@   rD   rB   rZ   r   rd   rk   rp   rs   rv   r}   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   __classcell__)r   s   @r    r   r      sl        QQ ND    !!269=1,.$
 $
$
 c]$
 /	$

 %%56$
 $
  S>$
 $
 $
 $
 $
 $
L2eE3J&7 2S 2S 2 2 2 2(uUCZ'8 (c (c ( ( ( ($ .2$ $ucz"$ $ ;	$
 4S>*$ 
sDcN"	#$ $ $ $<7T#s(^,7	$sCx.	!7 7 7 7"OT O O O O$ucz"$ $ 
$sCx.	!	$ $ $ $6!.c !.htCH~&> !. !. !. !.F/!c /!tHT#s(^4L/M /! /! /! /!b' ucz!23'AD'	htCH~&	'' ' ' 'J .2!1 1ucz"1 1 ;	1
 4S>*1 c]1 
1 1 1 1l "B BDcN#B c]B 
c	B B B BH(eE3J/ (S (T ( ( ( (&( ( ( ( ( ("4DI 4$t* 4 4 4 4>* ucz!23*AD*	d* * * *>E%*- 3 4    "s t    $s)     .!huUCZ'89 !s !t ! ! ! !4+ucz"+ + 
$sCx.	!	+ + + +6.S .Xd38n-E . . . .6(!S	 (!d8DcN;S6T (! (! (! (!T. ucz!23.AD.	htCH~&	'. . . .J .2!+ +ucz"+ + ;	+
 4S>*+ c]+ 
+ + + +` ": :DcN#: c]: 
c	: : : :x449 4d 4 4 4 4>1 ucz!231AD1	d1 1 1 1>#c #t # # # #&( ucz!23(AD(	( ( ( (8.U5#:%6 .C .D . . . .(. . . . . .&%5#4 %# %$ % % % %&!c !d ! ! ! ! ! ! ! !r!   r   N)r   typingr   r   r   r   r   r   r	   redisvl.extensions.cache.baser
   *redisvl.extensions.cache.embeddings.schemar   redisvl.redis.utilsr   r   redisvl.typesr   r   redisvl.utils.logr   r   rF   r   r9   r!   r    <module>r      s    2 2 D D D D D D D D D D D D D D D D D D 3 3 3 3 3 3 A A A A A A 6 6 6 6 6 6 6 6 ; ; ; ; ; ; ; ; ( ( ( ( ( (	H		Q! Q! Q! Q! Q!i Q! Q! Q! Q! Q!r!   