
    dhm/                        S SK Jr  S SKrS SKrS SKJrJrJrJrJ	r	  S SK
rS SKJr  S SKJr  S SKJr  \R$                  " \5      r " S S\5      rg)	    )annotationsN)AnyIterableListOptionalType)Document)
Embeddings)VectorStorec                  x   \ rS rSr% SrSrS\S'        S             SS jjr\SS j5       r	   S           SS	 jjr
SS
 jr S       SS jjr\         S                         SS jj5       r\         S                         SS jj5       rSrg)AtlasDB   a  `Atlas` vector store.

 Atlas is the `Nomic's` neural database and `rhizomatic` instrument.

To use, you should have the ``nomic`` python package installed.

Example:
    .. code-block:: python

            from langchain_community.vectorstores import AtlasDB
            from langchain_community.embeddings.openai import OpenAIEmbeddings

            embeddings = OpenAIEmbeddings()
            vectorstore = AtlasDB("my_project", embeddings.embed_query)
atlas_idstr_ATLAS_DEFAULT_ID_FIELDNc           	     (    SSK nSSK Jn  Uc  [        S5      eUR	                  U5        X l        Sn	U R
                  b  Sn	U" UUU	UU[        R                  S9U l        U R                  R                  5         g! [         a    [        S5      ef = f)	a  
Initialize the Atlas Client

Args:
    name (str): The name of your project. If the project already exists,
        it will be loaded.
    embedding_function (Optional[Embeddings]): An optional function used for
        embedding your data. If None, data will be embedded with
        Nomic's embed model.
    api_key (str): Your nomic API key
    description (str): A description for your project.
    is_public (bool): Whether your project is publicly accessible.
        True by default.
    reset_project_if_exists (bool): Whether to reset this project if it
        already exists. Default False.
        Generally useful during development and testing.
r   N)AtlasProjectzRCould not import nomic python package. Please install it with `pip install nomic`.z/No API key provided. Sign up at atlas.nomic.ai!text	embedding)namedescriptionmodality	is_publicreset_project_if_existsunique_id_field)
nomicr   ImportError
ValueErrorlogin_embedding_functionr   r   project_latest_project_state)
selfr   embedding_functionapi_keyr   r   r   r   r   r   s
             ^/var/www/html/shao/venv/lib/python3.13/site-packages/langchain_community/vectorstores/atlas.py__init__AtlasDB.__init__"   s    4	* ?NOOG#5 ##/"H $#$;#;;
 	**,1  	> 	s   
A; ;Bc                    U R                   $ )N)r    )r#   s    r&   
embeddingsAtlasDB.embeddingsY   s    '''    c           	        Ub1  [        U5      S:  a"  SUS   R                  5       ;   a  [        S5      e[        U5      nUc-  U Vs/ sH!  n[	        [
        R                  " 5       5      PM#     nnU R                  Gb  U R                  R                  U5      n[        R                  " U5      nUc5  [        U5       V	Vs/ sH  u  p[        R                  X9   SX   0PM     n
n	nO=[        [        U5      5       H#  n	X9   X)   [        R                  '   X   X)   S'   M%     Un
U R                  R!                  / [        R                  U
S9  U R                  R#                  5          U R                  R%                  XS9  SSS5        OUc3  [        U5       V	Vs/ sH  u  pSU[        R                  X9   0PM     n
n	nO4[        U5       H#  u  pXU	   S'   X9   X)   [        R                  '   M%     Un
U R                  R!                  / [        R                  U
S9  U R                  R#                  5          U R                  R'                  U
5        SSS5        U(       ab  [        U R                  R(                  5      S:  a?  U R                  R#                  5          U R                  R+                  5         SSS5        U$ U$ s  snf s  snn	f ! , (       d  f       N= fs  snn	f ! , (       d  f       N= f! , (       d  f       U$ = f)a  Run more texts through the embeddings and add to the vectorstore.

Args:
    texts (Iterable[str]): Texts to add to the vectorstore.
    metadatas (Optional[List[dict]], optional): Optional list of metadatas.
    ids (Optional[List[str]]): An optional list of ids.
    refresh(bool): Whether or not to refresh indices with the updated data.
        Default True.
Returns:
    List[str]: List of IDs of the added texts.
Nr   r   z#Cannot accept key text in metadata!)id_fielddata)r*   r/   )lenkeysr   listr   uuiduuid4r    embed_documentsnpstack	enumerater   r   ranger!   _validate_map_data_inputswait_for_project_lockadd_embeddingsadd_textindicesrebuild_maps)r#   texts	metadatasidsrefreshkwargs__embeddingsr*   ir/   r   s               r&   	add_textsAtlasDB.add_texts]   s   * !I")A,++--BCCU;.34e3tzz|$eC4 ##/22BB5IK+.J  !*% 0 0 44cffehO 0  
 s9~.ADGFIL!@!@A+08IL( / !LL22W<<4 3  335++z+M 65   $-U#3#3 T7#B#BCFK#3  
  )/GA+0aL(DGFIL!@!@A  0 !LL22W<<4 3  335%%d+ 6 4<<''(1,\\779LL--/ : 
s
_ 5 65
 65
 :9 
s6   'K #K'K!K"7K(K9
K(
K69
Lc                    U R                   R                  5          U R                   R                  " S0 UD6sSSS5        $ ! , (       d  f       g= f)zCreates an index in your project.

See
https://docs.nomic.ai/atlas_api.html#nomic.project.AtlasProject.create_index
for full detail.
N )r!   r;   create_index)r#   rD   s     r&   rL   AtlasDB.create_index   s5     \\//1<<,,6v6 211s   A
Ac           	        U R                   c  [        S5      eU R                   R                  U/5      S   n[        R                  " U5      R                  SS5      nU R                  R                  5          U R                  R                  S   R                  XRS9u  pgU R                  R                  US   S9nSSS5        [        W5       V	V
s/ sH  u  p[        WU	   S   X   S	9PM     nn	n
U$ ! , (       d  f       N>= fs  sn
n	f )
zRun similarity search with AtlasDB

Args:
    query (str): Query text to search for.
    k (int): Number of results to return. Defaults to 4.

Returns:
    List[Document]: List of documents most similar to the query text.
NzBAtlasDB requires an embedding_function for text similarity search!r      )queriesk)rB   r   )page_contentmetadata)r    NotImplementedErrorr5   r6   arrayreshaper!   r;   projectionsvector_searchget_datar8   r	   )r#   queryrR   rD   
_embeddingr   	neighborsrE   r/   rG   neighbordocss               r&   similarity_searchAtlasDB.similarity_search   s    ##+%T  --==ugFqI
HHZ(00B7	\\//1<<33A6DD! E LI <<((Yq\(:D	 2  )3
3 $q'&/DGD3 	 
  21
s   8AC5D5
Dc           	     <   Ub  Uc  [        S5      eUS-   SS.nU
b  U
R                  5        H	  u  pXU'   M     U " UUUSUU	S9nUR                  R                  5          UR	                  XUS9  UR
                  " S	0 UD6  SSS5        U$ ! , (       d  f       U$ = f)
a  Create an AtlasDB vectorstore from a raw documents.

Args:
    texts (List[str]): The list of texts to ingest.
    name (str): Name of the project to create.
    api_key (str): Your nomic API key,
    embedding (Optional[Embeddings]): Embedding function. Defaults to None.
    metadatas (Optional[List[dict]]): List of metadatas. Defaults to None.
    ids (Optional[List[str]]): Optional list of document IDs. If None,
        ids will be auto created
    description (str): A description for your project.
    is_public (bool): Whether your project is publicly accessible.
        True by default.
    reset_project_if_exists (bool): Whether to reset this project if it
        already exists. Default False.
        Generally useful during development and testing.
    index_kwargs (Optional[dict]): Dict of kwargs for index creation.
        See https://docs.nomic.ai/atlas_api.html

Returns:
    AtlasDB: Nomic's neural database and finest rhizomatic instrument
N$`name` and `api_key` cannot be None._indexr   )r   indexed_fieldA description for your project)r$   r%   r   r   r   )r@   rA   rB   rK   )r   itemsr!   r;   rH   rL   )clsr@   r   rA   rB   r   r%   r   r   r   index_kwargsrD   all_index_kwargsrR   vatlasDBs                   r&   
from_textsAtlasDB.from_texts   s    J <7?CDD %)8OfM#$**,&'# - (8$;
 __224ECH  4#34 5  54 s   #B
Bc                    Ub  Uc  [        S5      eU Vs/ sH  oR                  PM     nnU Vs/ sH  oR                  PM     nnU R                  UUUUUUUUU	U
S9
$ s  snf s  snf )a  Create an AtlasDB vectorstore from a list of documents.

Args:
    name (str): Name of the collection to create.
    api_key (str): Your nomic API key,
    documents (List[Document]): List of documents to add to the vectorstore.
    embedding (Optional[Embeddings]): Embedding function. Defaults to None.
    ids (Optional[List[str]]): Optional list of document IDs. If None,
        ids will be auto created
    description (str): A description for your project.
    is_public (bool): Whether your project is publicly accessible.
        True by default.
    reset_project_if_exists (bool): Whether to reset this project if
        it already exists. Default False.
        Generally useful during development and testing.
    index_kwargs (Optional[dict]): Dict of kwargs for index creation.
        See https://docs.nomic.ai/atlas_api.html

Returns:
    AtlasDB: Nomic's neural database and finest rhizomatic instrument
rc   )
r   r%   r@   r   rA   rB   r   r   r   ri   )r   rS   rT   rm   )rh   	documentsr   rB   r   r%   persist_directoryr   r   r   ri   rD   docr@   rA   s                  r&   from_documentsAtlasDB.from_documents  s    H <7?CDD-67Yc!!Y7-67Yc\\Y	7~~#$;%  
 	
 87s
   AA#)r    r!   )NNrf   TF)r   r   r$   Optional[Embeddings]r%   Optional[str]r   r   r   boolr   rw   returnNone)rx   ru   )NNT)r@   zIterable[str]rA   Optional[List[dict]]rB   Optional[List[str]]rC   rw   rD   r   rx   	List[str])rD   r   rx   r   )   )r[   r   rR   intrD   r   rx   List[Document])	NNNNNrf   TFN)rh   Type[AtlasDB]r@   r|   r   ru   rA   rz   rB   r{   r   rv   r%   rv   r   r   r   rw   r   rw   ri   Optional[dict]rD   r   rx   r   )rh   r   rp   r   r   ru   rB   r{   r   rv   r%   rv   rq   rv   r   r   r   rw   r   rw   ri   r   rD   r   rx   r   )__name__
__module____qualname____firstlineno____doc__r   __annotations__r'   propertyr*   rH   rL   r`   classmethodrm   rs   __static_attributes__rK   r,   r&   r   r      sj     $.S-
 48!%;(-5-5- 15- 	5-
 5- 5- "&5- 
5-n ( ( +/#'LL (L !	L
 L L 
L\7      	 
 
 D  +/*.#'"!%;(-'+999 (9 (	9
 !9 9 9 9 9 "&9 %9 9 
9 9v  +/#'"!%+/;(-'+2
2
!2
 (2
 !	2

 2
 2
 )2
 2
 2
 "&2
 %2
 2
 
2
 2
r,   r   )
__future__r   loggingr3   typingr   r   r   r   r   numpyr6   langchain_core.documentsr	   langchain_core.embeddingsr
   langchain_core.vectorstoresr   	getLoggerr   loggerr   rK   r,   r&   <module>r      s>    "   6 6  - 0 3			8	$w
k w
r,   