Ë
    µŒjÒ7  ã                  ó°   — d Z ddlmZ ddlZddlZddl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 erddlmZ  ej(                  «       Z G d	„ d
e«      Zy)z'Wrapper around Epsilla vector database.é    )ÚannotationsN)ÚTYPE_CHECKINGÚAnyÚIterableÚListÚOptionalÚType©ÚDocument)Ú
Embeddings)ÚVectorStore)Úvectordbc                  ó~  — e Zd ZU dZdZded<   dZded<   dZded<   eef	 	 	 	 	 	 	 dd	„Ze	dd
„«       Z
dd„Zddd„Z	 d	 	 	 	 	 dd„Z	 d	 	 	 	 	 	 	 dd„Z	 	 	 d	 	 	 	 	 	 	 	 	 	 	 dd„Z	 d	 	 	 	 	 	 	 	 	 d d„Zeddeeedf	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d!d„«       Zedeeedf	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d"d„«       Zy)#ÚEpsillaar  
    Wrapper around Epsilla vector database.

    As a prerequisite, you need to install ``pyepsilla`` package
    and have a running Epsilla vector database (for example, through our docker image)
    See the following documentation for how to run an Epsilla vector database:
    https://epsilla-inc.gitbook.io/epsilladb/quick-start

    Args:
        client (Any): Epsilla client to connect to.
        embeddings (Embeddings): Function used to embed the texts.
        db_path (Optional[str]): The path where the database will be persisted.
                                 Defaults to "/tmp/langchain-epsilla".
        db_name (Optional[str]): Give a name to the loaded database.
                                 Defaults to "langchain_store".
    Example:
        .. code-block:: python

            from langchain_community.vectorstores import Epsilla
            from pyepsilla import vectordb

            client = vectordb.Client()
            embeddings = OpenAIEmbeddings()
            db_path = "/tmp/vectorstore"
            db_name = "langchain_store"
            epsilla = Epsilla(client, embeddings, db_path, db_name)
    Úlangchain_storeÚstrÚ_LANGCHAIN_DEFAULT_DB_NAMEz/tmp/langchain-epsillaÚ_LANGCHAIN_DEFAULT_DB_PATHÚlangchain_collectionÚ_LANGCHAIN_DEFAULT_TABLE_NAMEc                ó¼  — 	 ddl }t        ||j                  j                  |j
                  j                  j                  f«      st        dt        |«      › �«      ‚|| _
        || _        || _        t        j                  | _        | j                  j!                  ||¬«       | j                  j#                  |¬«       y# t        $ r}t        d«      |‚d}~ww xY w)z%Initialize with necessary components.r   NziCould not import pyepsilla python package. Please install pyepsilla package with `pip install pyepsilla`.zbclient should be an instance of pyepsilla.vectordb.Client or pyepsilla.cloud.client.Vectordb, got )Údb_nameÚdb_path©r   )Ú	pyepsillaÚImportErrorÚ
isinstancer   ÚClientÚcloudÚclientÚVectordbÚ	TypeErrorÚtypeÚ_clientÚ_db_nameÚ_embeddingsr   r   Ú_collection_nameÚload_dbÚuse_db)Úselfr    Ú
embeddingsr   r   r   Úes          úr/var/www/html/Fitness-lenito-AI-main/venv/lib/python3.12/site-packages/langchain_community/vectorstores/epsilla.pyÚ__init__zEpsilla.__init__4   sÙ   € ð	Ûô Ø�Y×'Ñ'×.Ñ.°	·±×0FÑ0F×0OÑ0OÐPô
ô ð8Ü8<¸V»°~ðGóð ð
 )/ˆŒØˆŒØ%ˆÔÜ '× EÑ EˆÔØ�‰×Ñ W°gÐÔ>Ø�‰×Ñ GÐÕ,øô' ò 	ÜðQóð ðûð	ús   ‚C Ã	CÃ
CÃCc                ó   — | j                   S ©N)r&   )r*   s    r-   r+   zEpsilla.embeddingsS   s   € à×ÑÐó    c                ó   — || _         y)z~
        Set default collection to use.

        Args:
            collection_name (str): The name of the collection.
        N)r'   ©r*   Úcollection_names     r-   Úuse_collectionzEpsilla.use_collectionW   s   € ð !0ˆÕr1   c                óV   — |s| j                   }| j                  j                  |«       y)zË
        Clear data in a collection.

        Args:
            collection_name (Optional[str]): The name of the collection.
                If not provided, the default collection will be used.
        N)r'   r$   Ú
drop_tabler3   s     r-   Ú
clear_datazEpsilla.clear_data`   s$   € ñ Ø"×3Ñ3ˆOØ�‰×Ñ Õ0r1   Nc                óâ   — |s| j                   }| j                  j                  ||¬«      \  }}|dk7  r8t        j	                  d|d   › �«       t        dj                  |d   «      «      ‚|d   S )a¼  Get the collection.

        Args:
            collection_name (Optional[str]): The name of the collection
                to retrieve data from.
                If not provided, the default collection will be used.
            response_fields (Optional[List[str]]): List of field names in the result.
                If not specified, all available fields will be responded.

        Returns:
            A list of the retrieved data.
        )Ú
table_nameÚresponse_fieldséÈ   zFailed to get records: Úmessageú
Error: {}.Úresult)r'   r$   ÚgetÚloggerÚerrorÚ	ExceptionÚformat)r*   r4   r;   Ústatus_codeÚresponses        r-   r@   zEpsilla.getl   s   € ñ Ø"×3Ñ3ˆOØ $§¡× 0Ñ 0Ø&¸ð !1ó !
Ñˆ�Xð ˜#ÒÜ�L‰LÐ2°8¸IÑ3FÐ2GÐHÔIÜ˜L×/Ñ/°¸Ñ0CÓDÓEÐEØ˜Ñ!Ð!r1   c                óÐ  — |st        d«      ‚t        |d   «      }dddœdddœdd	|d
œg}|�¶|D �cg c]  }|d   ‘Œ	 }}|D ]Ÿ  }|j                  «       D ]Š  \  }	}
|	|v rŒt        |
t        «      rd}nHt        |
t
        «      rd}n5t        |
t        «      rd}n"t        |
t        «      rd}nt        d|	› d�«      ‚|j                  |	|dœ«       |j                  |	«       ŒŒ Œ¡ | j                  j                  ||¬«      \  }}|dk7  rZ|dk(  rt        j                  d|› d�«       y t        j                  d|› d|d   › �«       t        dj                  |d   «      «      ‚y c c}w )NzEmbeddings list is empty.r   ÚidÚINT)ÚnameÚdataTypeÚtextÚSTRINGr+   ÚVECTOR_FLOAT)rJ   rK   Ú
dimensionsrJ   ÚFLOATÚBOOLzUnsupported data type for Ú.)Útable_fieldsr<   i™  z#Continuing with the existing table zFailed to create collection ú: r=   r>   )Ú
ValueErrorÚlenÚitemsr   r   ÚintÚfloatÚboolÚappendr$   Úcreate_tablerA   ÚinforB   rC   rD   )r*   r:   r+   Ú	metadatasÚdimÚfieldsÚfieldÚfield_namesÚmetadataÚkeyÚvalueÚd_typerE   rF   s                 r-   Ú_create_collectionzEpsilla._create_collection…   s’  € ñ ÜÐ8Ó9Ð9ä�*˜Q‘-Ó ˆà uÑ-Ø¨Ñ2Ø!¨~ÈSÑQð
ˆð
 Ð Ù6<Ó=±f¨U˜5 ›=°fˆKÐ=Û%�Ø"*§.¡.Ö"2‘J�C˜Ø˜kÑ)Ø ä! %¬Ô-Ø!)™Ü# E¬3Ô/Ø!&™Ü# E¬5Ô1Ø!(™Ü# E¬4Ô0Ø!'™ä(Ð+EÀcÀUÈ!Ð)LÓMÐMØ—M‘M¨3¸FÑ"CÔDØ×&Ñ& sÕ+ñ #3ð &ð$ !%§¡× 9Ñ 9Ø Vð !:ó !
Ñˆ�Xð ˜#ÒØ˜cÒ!Ü—‘ÐAÀ*ÀÈQÐOÕPä—‘Ø2°:°,¸bÀÈ)ÑATÐ@UÐVôô   × 3Ñ 3°H¸YÑ4GÓ HÓIÐIð ùò- >s   ±E#Fc                ó¬  — |s| j                   }n|| _         |r| j                  j                  |¬«       t        |«      }	 | j                  j                  |«      }t        |«      dk(  rt        j                  d«       g S | j                  |||¬«       |D �cg c]  }t        t        j                  «       «      ‘Œ! }	}g }
t        |	«      D ]F  \  }}|||   ||   dœ}|�"||   j!                  «       }|D ]
  \  }}|||<   Œ |
j#                  |«       ŒH | j                  j%                  ||
¬«      \  }}|dk7  r;t        j'                  d|› d	|d
   › �«       t)        dj+                  |d
   «      «      ‚|	D �cg c]  }t-        |«      ‘Œ c}S # t        $ r2 |D �cg c]  }| j                  j                  |«      ‘Œ nc c}w }}Y �Œlw xY wc c}w c c}w )a©  
        Embed texts and add them to the database.

        Args:
            texts (Iterable[str]): The texts to embed.
            metadatas (Optional[List[dict]]): Metadata dicts
                        attached to each of the texts. Defaults to None.
            collection_name (Optional[str]): Which collection to use.
                        Defaults to "langchain_collection".
                        If provided, default collection name will be set as well.
            drop_old (Optional[bool]): Whether to drop the previous collection
                        and create a new one. Defaults to False.

        Returns:
            List of ids of the added texts.
        r   r   zNothing to insert, skipping.)r:   r+   r^   ©rH   rL   r+   )r:   Úrecordsr<   zFailed to add records to rT   r=   r>   )r'   r$   Údrop_dbÚlistr&   Úembed_documentsÚNotImplementedErrorÚembed_queryrV   rA   Údebugrg   ÚhashÚuuidÚuuid4Ú	enumeraterW   r[   ÚinsertrB   rC   rD   r   )r*   Útextsr^   r4   Údrop_oldÚkwargsr+   ÚxÚ_Úidsrj   ÚindexrH   Úrecordrc   rd   re   rE   rF   s                      r-   Ú	add_textszEpsilla.add_texts±   sí  € ñ0 Ø"×3Ñ3‰Oà$3ˆDÔ!áØ�L‰L× Ñ ¨Ð Ô9ä�U“ˆð	JØ×)Ñ)×9Ñ9¸%Ó@ˆJô ˆz‹?˜aÒÜ�L‰LÐ7Ô8ØˆIà×ÑØ&°:Èð 	 ô 	
ñ ,1Ó1©5 aŒt”D—J‘J“LÕ!¨5ˆÐ1ØˆÜ" 3ž‰IˆE�2àØ˜e™Ø(¨Ñ/ñˆFð
 Ð$Ø$ UÑ+×1Ñ1Ó3�Û"*‘J�C˜Ø"'�F˜3’Kð #+à�N‰N˜6Õ"ð (ð !%§¡× 3Ñ 3Ø&°ð !4ó !
Ñˆ�Xð ˜#ÒÜ�L‰LØ+¨OÐ+<¸B¸xÈ	Ñ?RÐ>SÐTôô ˜L×/Ñ/°¸Ñ0CÓDÓEÐEÙ"%Ó&¡#˜B”�B• #Ñ&Ð&øôC #ò 	JÙCHÓIÁ5¸a˜$×*Ñ*×6Ñ6°qÕ9Á5ùÒIˆJÓIð	Jüò 2ùò, 's*   ÁF Â$GÅ9GÆG	Æ"F>Æ=G	ÇG	c                óT  ‡— |s| j                   }| j                  j                  |«      }| j                  j	                  |d||¬«      \  }}|dk7  r9t
        j                  d|d   › d�«       t        dj                  |d   «      «      ‚g d¢Št        t        ˆfd	„|d
   «      «      S )aÝ  
        Return the documents that are semantically most relevant to the query.

        Args:
            query (str): String to query the vectorstore with.
            k (Optional[int]): Number of documents to return. Defaults to 4.
            collection_name (Optional[str]): Collection to use.
                Defaults to "langchain_store" or the one provided before.
        Returns:
            List of documents that are semantically most relevant to the query
        r+   )r:   Úquery_fieldÚquery_vectorÚlimitr<   zSearch failed: r=   rR   r>   ri   c           	     ó\   •— t        | d   | D �ci c]  }|‰vsŒ|| |   “Œ c}¬«      S c c}w )NrL   )Úpage_contentrc   r
   )Úitemrd   Úexclude_keyss     €r-   Ú<lambda>z+Epsilla.similarity_search.<locals>.<lambda>  s<   ø€ œXØ!% f¡á26óÙ26¨3¸#À\Ò:Q˜˜T #™Y™°$ñõùòs   �	)
™)
r?   )r'   r&   ro   r$   ÚqueryrA   rB   rC   rD   rl   Úmap)	r*   rˆ   Úkr4   rx   r�   rE   rF   r†   s	           @r-   Úsimilarity_searchzEpsilla.similarity_search÷   s¼   ø€ ñ Ø"×3Ñ3ˆOØ×'Ñ'×3Ñ3°EÓ:ˆØ $§¡× 2Ñ 2Ø&Ø$Ø%Øð	 !3ó !
Ñˆ�Xð ˜#ÒÜ�L‰L˜?¨8°IÑ+>Ð*?¸qÐAÔBÜ˜L×/Ñ/°¸Ñ0CÓDÓEÐEâ3ˆÜÜóð ˜Ñ"óó

ð 
	
r1   c	                óR   — t        ||||¬«      }
 |
j                  |f|||dœ|	¤Ž |
S )a  Create an Epsilla vectorstore from raw documents.

        Args:
            texts (List[str]): List of text data to be inserted.
            embeddings (Embeddings): Embedding function.
            client (pyepsilla.vectordb.Client): Epsilla client to connect to.
            metadatas (Optional[List[dict]]): Metadata for each text.
                    Defaults to None.
            db_path (Optional[str]): The path where the database will be persisted.
                    Defaults to "/tmp/langchain-epsilla".
            db_name (Optional[str]): Give a name to the loaded database.
                    Defaults to "langchain_store".
            collection_name (Optional[str]): Which collection to use.
                    Defaults to "langchain_collection".
                    If provided, default collection name will be set as well.
            drop_old (Optional[bool]): Whether to drop the previous collection
                    and create a new one. Defaults to False.

        Returns:
            Epsilla: Epsilla vector store.
        )r   r   )r^   r4   rw   )r   r~   )Úclsrv   Ú	embeddingr^   r    r   r   r4   rw   rx   Úinstances              r-   Ú
from_textszEpsilla.from_texts  sG   € ôD ˜6 9°gÀwÔOˆØˆ×ÑØð	
àØ+Øñ		
ð
 ò	
ð ˆr1   c           
     ó°   — |D �	cg c]  }	|	j                   ‘Œ }
}	|D �	cg c]  }	|	j                  ‘Œ }}	 | j                  |
|f||||||dœ|¤ŽS c c}	w c c}	w )a"  Create an Epsilla vectorstore from a list of documents.

        Args:
            texts (List[str]): List of text data to be inserted.
            embeddings (Embeddings): Embedding function.
            client (pyepsilla.vectordb.Client): Epsilla client to connect to.
            metadatas (Optional[List[dict]]): Metadata for each text.
                    Defaults to None.
            db_path (Optional[str]): The path where the database will be persisted.
                    Defaults to "/tmp/langchain-epsilla".
            db_name (Optional[str]): Give a name to the loaded database.
                    Defaults to "langchain_store".
            collection_name (Optional[str]): Which collection to use.
                    Defaults to "langchain_collection".
                    If provided, default collection name will be set as well.
            drop_old (Optional[bool]): Whether to drop the previous collection
                    and create a new one. Defaults to False.

        Returns:
            Epsilla: Epsilla vector store.
        )r^   r    r   r   r4   rw   )r„   rc   r�   )r�   Ú	documentsrŽ   r    r   r   r4   rw   rx   Údocrv   r^   s               r-   Úfrom_documentszEpsilla.from_documentsL  s{   € ñB .7Ó7©Y c�×!Ó!¨YˆÐ7Ù-6Ó7©Y c�S—\“\¨Yˆ	Ð7àˆs�~‰~ØØð

ð  ØØØØ+Øñ

ð ñ

ð 
	
ùò 8ùÚ7s
   …AžA)r    r   r+   r   r   úOptional[str]r   r•   )ÚreturnzOptional[Embeddings])r4   r   r–   ÚNone)Ú )r˜   N)r4   r   r;   zOptional[List[str]]r–   z
List[dict]r0   )r:   r   r+   rl   r^   zOptional[list[dict]]r–   r—   )Nr˜   F)rv   zIterable[str]r^   úOptional[List[dict]]r4   r•   rw   úOptional[bool]rx   r   r–   ú	List[str])é   r˜   )
rˆ   r   rŠ   rX   r4   r   rx   r   r–   úList[Document])r�   úType[Epsilla]rv   r›   rŽ   r   r^   r™   r    r   r   r•   r   r•   r4   r•   rw   rš   rx   r   r–   r   )r�   rž   r’   r�   rŽ   r   r    r   r   r•   r   r•   r4   r•   rw   rš   rx   r   r–   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ú__annotations__r   r   r.   Úpropertyr+   r5   r8   r@   rg   r~   r‹   Úclassmethodr�   r”   © r1   r-   r   r      so  … ñð8 '8Ð Ó7Ø&>Ð Ó>Ø)?Ð! 3Ó?ð "<Ø!;ð-àð-ð ð-ð ð	-ð
 ó-ð> ò ó ð ó0ô
1ð QUð"Ø"ð"Ø:Mð"à	ó"ð4 TXð*JØð*JØ+/ð*JØ<Pð*Jà	ó*Jð^ +/Ø)+Ø#(ðD'àðD'ð (ðD'ð 'ð	D'ð
 !ðD'ð ðD'ð 
óD'ðN >@ð&
Øð&
Ø ð&
Ø7:ð&
ØKNð&
à	ó&
ðP ð
 +/ØØ!;Ø!;Ø)FØ#(ð*Øð*àð*ð ð*ð (ð	*ð
 ð*ð ð*ð ð*ð 'ð*ð !ð*ð ð*ð 
ò*ó ð*ðX ð
 Ø!;Ø!;Ø)FØ#(ð-
Øð-
à!ð-
ð ð-
ð ð	-
ð
 ð-
ð ð-
ð 'ð-
ð !ð-
ð ð-
ð 
ò-
ó ñ-
r1   r   )r¢   Ú
__future__r   Úloggingrr   Útypingr   r   r   r   r   r	   Úlangchain_core.documentsr   Úlangchain_core.embeddingsr   Úlangchain_core.vectorstoresr   r   r   Ú	getLoggerrA   r   r¦   r1   r-   Ú<module>r®      sD   ðÙ -å "ã Û ß E× Eå -Ý 0Ý 3áÝ"à	ˆ×	Ñ	Ó	€ôg
ˆkõ g
r1   