
    3fi                    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
mZ  G d de
      Zy)    )annotations)AnyListLiteralOptional)
Embeddings)DocArrayIndex_check_docarray_importc                      e Zd ZdZe	 	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd       Ze	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 dd       Zy)	DocArrayHnswSearchz`HnswLib` storage using `DocArray` package.

    To use it, you should have the ``docarray`` package with version >=0.32.0 installed.
    You can install it with `pip install docarray`.
    c                    t                ddlm}  | j                  d|||||||	|
|d	|} ||   |      } | ||      S )a  Initialize DocArrayHnswSearch store.

        Args:
            embedding (Embeddings): Embedding function.
            work_dir (str): path to the location where all the data will be stored.
            n_dim (int): dimension of an embedding.
            dist_metric (str): Distance metric for DocArrayHnswSearch can be one of:
                "cosine", "ip", and "l2". Defaults to "cosine".
            max_elements (int): Maximum number of vectors that can be stored.
                Defaults to 1024.
            index (bool): Whether an index should be built for this field.
                Defaults to True.
            ef_construction (int): defines a construction time/accuracy trade-off.
                Defaults to 200.
            ef (int): parameter controlling query time/accuracy trade-off.
                Defaults to 10.
            M (int): parameter that defines the maximum number of outgoing
                connections in the graph. Defaults to 16.
            allow_replace_deleted (bool): Enables replacing of deleted elements
                with new added ones. Defaults to True.
            num_threads (int): Sets the number of cpu threads to use. Defaults to 1.
            **kwargs: Other keyword arguments to be passed to the get_doc_cls method.
        r   )HnswDocumentIndex)	dimspacemax_elementsindexef_constructionefMallow_replace_deletednum_threads)work_dir )r
   docarray.indexr   _get_doc_cls)cls	embeddingr   n_dimdist_metricr   r   r   r   r   r   r   kwargsr   doc_cls	doc_indexs                   l/var/www/auto_recruiter/arenv/lib/python3.12/site-packages/langchain_community/vectorstores/docarray/hnsw.pyfrom_paramszDocArrayHnswSearch.from_params   sk    N 	 4"#"" 
%+"7#
 
 /%g.A	9i((    Nc                    |t        d      |t        d       | j                  |||fi |}|j                  ||       |S )a<  Create an DocArrayHnswSearch store and insert data.


        Args:
            texts (List[str]): Text data.
            embedding (Embeddings): Embedding function.
            metadatas (Optional[List[dict]]): Metadata for each text if it exists.
                Defaults to None.
            work_dir (str): path to the location where all the data will be stored.
            n_dim (int): dimension of an embedding.
            **kwargs: Other keyword arguments to be passed to the __init__ method.

        Returns:
            DocArrayHnswSearch Vector Store
        z&`work_dir` parameter has not been set.z#`n_dim` parameter has not been set.)texts	metadatas)
ValueErrorr$   	add_texts)r   r'   r   r(   r   r   r    stores           r#   
from_textszDocArrayHnswSearch.from_textsM   sU    2 EFF=BCC	8UEfEey9r%   )cosinei   T   
      T   )r   r   r   strr   intr   zLiteral['cosine', 'ip', 'l2']r   r3   r   boolr   r3   r   r3   r   r3   r   r4   r   r3   r    r   returnr   )NNN)r'   z	List[str]r   r   r(   zOptional[List[dict]]r   zOptional[str]r   zOptional[int]r    r   r5   r   )__name__
__module____qualname____doc__classmethodr$   r,   r   r%   r#   r   r      s     6> "&*6)6) 6) 	6)
 36) 6) 6) 6) 6) 6)  $6) 6) 6) 
6) 6)p 
 +/"&#  (	
     
 r%   r   N)
__future__r   typingr   r   r   r   langchain_core.embeddingsr   .langchain_community.vectorstores.docarray.baser	   r
   r   r   r%   r#   <module>r?      s$    " / / 0` `r%   