Ë
    lQêj©T  ã                   óÈ   — d dl mZmZmZmZmZ d dlmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZ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  erd dl!m"Z"  G d„ ded	   «      Z#y
)é    )ÚTYPE_CHECKINGÚOptionalÚUnionÚListÚcast)ÚURIÚCollectionMetadataÚ	EmbeddingÚPyEmbeddingÚIncludeÚIndexingStatusÚMetadataÚDocumentÚImageÚWhereÚIDsÚ	GetResultÚQueryResultÚIDÚ	OneOrManyÚ	ReadLevelÚWhereDocumentÚSearchResultÚDeleteResultÚmaybe_cast_one_to_many)ÚCollectionCommon)ÚUpdateCollectionConfiguration)ÚSearch)ÚAsyncServerAPIc                   ó�  — e Zd Z	 	 	 	 	 d(dee   deeee   ee   f      deee	      deee
      deee      deee      ddfd	„Zej                  fd
edefd„Zdefd„Zdddddddgfdeee      dee   dee   dee   dee   dedefd„Zd)dedefd„Zddddddddg d¢f	deeee   ee   f      deee
      deee      deee      deee      dedee   dee   dedefd„Z	 	 	 d*dee   dee   dee   ddfd„Zd edd fd!„Z defd"„Z!ej                  fd#ee"   d
ede#fd$„Z$	 	 	 	 	 d(dee   deeee   ee   f      deee	      deee
      deee      deee      ddfd%„Z%	 	 	 	 	 d(dee   deeee   ee   f      deee	      deee
      deee      deee      ddfd&„Z&	 	 	 	 d+dee'   dee   dee   dee   de(f
d'„Z)y),ÚAsyncCollectionNÚidsÚ
embeddingsÚ	metadatasÚ	documentsÚimagesÚurisÚreturnc           
   ƒ   óî   K  — | j                  ||||||¬«      }| j                  j                  | j                  |d   |d   |d   |d   |d   | j                  | j
                  ¬«      ƒ d{  –—†  y7 Œ­w)	a]  Add embeddings to the data store.
        Args:
            ids: The ids of the embeddings you wish to add
            embeddings: The embeddings to add. If None, embeddings will be computed based on the documents or images using the embedding_function set for the Collection. Optional.
            metadatas: The metadata to associate with the embeddings. When querying, you can filter on this metadata. Optional.
            documents: The documents to associate with the embeddings. Optional.
            images: The images to associate with the embeddings. Optional.
            uris: The uris of the images to associate with the embeddings. Optional.

        Returns:
            None

        Raises:
            ValueError: If you don't provide either embeddings or documents
            ValueError: If the length of ids, embeddings, metadatas, or documents don't match
            ValueError: If you don't provide an embedding function and don't provide embeddings
            ValueError: If you provide both embeddings and documents
            ValueError: If you provide an id that already exists

        ©r"   r#   r$   r%   r&   r'   r"   r#   r$   r%   r'   ©Úcollection_idr"   r#   r$   r%   r'   ÚtenantÚdatabaseN)Ú!_validate_and_prepare_add_requestÚ_clientÚ_addÚidr-   r.   )Úselfr"   r#   r$   r%   r&   r'   Úadd_requests           úh/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/chromadb/api/models/AsyncCollection.pyÚaddzAsyncCollection.add#   s�   è ø€ ðD ×<Ñ<ØØ!ØØØØð =ó 
ˆð �l‰l×ÑØŸ'™'Ø˜EÑ"Ø" <Ñ0Ø! +Ñ.Ø! +Ñ.Ø˜VÑ$Ø—;‘;Ø—]‘]ð  ó 	
÷ 		
ò 		
úó   ‚A+A5Á-A3Á.A5Ú
read_levelc              ƒ   ó˜   K  — | j                   j                  | j                  | j                  | j                  |¬«      ƒ d{  –—† S 7 Œ­w)aë  Return the number of records in the collection.

        Args:
            read_level: Controls whether to read from the write-ahead log (WAL):
                - ReadLevel.INDEX_AND_WAL: Read from both the compacted index and WAL (default).
                  All committed writes will be visible.
                - ReadLevel.INDEX_ONLY: Read only from the compacted index, skipping the WAL.
                  Faster, but recent writes that haven't been compacted may not be visible.
                - ReadLevel.INDEX_AND_BOUNDED_WAL: Read from the index and up to a
                  server-configured number of WAL entries for bounded query latency.

        Returns:
            int: The total number of embeddings added to the database
        )r,   r-   r.   r8   N)r0   Ú_countr2   r-   r.   )r3   r8   s     r5   ÚcountzAsyncCollection.countY   sF   è ø€ ð —\‘\×(Ñ(ØŸ'™'Ø—;‘;Ø—]‘]Ø!ð	 )ó 
÷ 
ð 	
ð 
ús   ‚AA
ÁAÁA
c              ƒ   ó–   K  — | j                   j                  | j                  | j                  | j                  ¬«      ƒ d{  –—† S 7 Œ­w)aß  Get the indexing status of this collection.

        Returns:
            IndexingStatus: An object containing:
                - num_indexed_ops: Number of user operations that have been indexed
                - num_unindexed_ops: Number of user operations pending indexing
                - total_ops: Total number of user operations in collection
                - op_indexing_progress: Proportion of user operations that have been indexed as a float between 0 and 1
        ©r,   r-   r.   N)r0   Ú_get_indexing_statusr2   r-   r.   ©r3   s    r5   Úget_indexing_statusz#AsyncCollection.get_indexing_statuso   sC   è ø€ ð —\‘\×6Ñ6ØŸ'™'Ø—;‘;Ø—]‘]ð 7ó 
÷ 
ð 	
ð 
úó   ‚A A	ÁAÁA	ÚwhereÚlimitÚoffsetÚwhere_documentÚincludec              ƒ   ó  K  — | j                  ||||¬«      }| j                  j                  | j                  |d   |d   |d   |d   ||| j                  | j
                  ¬«	      ƒ d{  –—† }| j                  ||d   ¬«      S 7 Œ­w)	aÌ  Get embeddings and their associate data from the data store. If no ids or where filter is provided returns
        all embeddings up to limit starting at offset.

        Args:
            ids: The ids of the embeddings to get. Optional.
            where: A Where type dict used to filter results by. E.g. `{"$and": [{"color" : "red"}, {"price": {"$gte": 4.20}}]}`. Optional.
            limit: The number of documents to return. Optional.
            offset: The offset to start returning results from. Useful for paging results with limit. Optional.
            where_document: A WhereDocument type dict used to filter by the documents. E.g. `{"$contains": "hello"}`. Optional.
            include: A list of what to include in the results. Can contain `"embeddings"`, `"metadatas"`, `"documents"`. Ids are always included. Defaults to `["metadatas", "documents"]`. Optional.

        Returns:
            GetResult: A GetResult object containing the results.

        )r"   rB   rE   rF   r"   rB   rE   rF   )	r,   r"   rB   rE   rF   rC   rD   r-   r.   N©ÚresponserF   )Ú!_validate_and_prepare_get_requestr0   Ú_getr2   r-   r.   Ú_transform_get_response)	r3   r"   rB   rC   rD   rE   rF   Úget_requestÚget_resultss	            r5   ÚgetzAsyncCollection.get   s®   è ø€ ð0 ×<Ñ<ØØØ)Øð	 =ó 
ˆð !ŸL™L×-Ñ-ØŸ'™'Ø˜EÑ"Ø˜gÑ&Ø&Ð'7Ñ8Ø 	Ñ*ØØØ—;‘;Ø—]‘]ð .ó 

÷ 

ˆð ×+Ñ+Ø ¨+°iÑ*@ð ,ó 
ð 	
ð

ús   ‚A'BÁ)BÁ*Bé
   c              ƒ   ó¶   K  — | j                  | j                  j                  | j                  || j                  | j
                  ¬«      ƒ d{  –—† «      S 7 Œ­w)zÕGet the first few results in the database up to limit

        Args:
            limit: The number of results to return.

        Returns:
            GetResult: A GetResult object containing the results.
        )r,   Únr-   r.   N)Ú_transform_peek_responser0   Ú_peekr2   r-   r.   )r3   rC   s     r5   ÚpeekzAsyncCollection.peek®   sT   è ø€ ð ×,Ñ,Ø—,‘,×$Ñ$Ø"Ÿg™gØØ—{‘{ØŸ™ð	 %ó ÷ ó
ð 	
ðús   ‚AAÁAÁ	A)r$   r%   Ú	distancesÚquery_embeddingsÚquery_textsÚquery_imagesÚ
query_urisÚ	n_resultsc
              ƒ   ó&  K  — | j                  |||||||||	¬«	      }
| j                  j                  | j                  |
d   |
d   |
d   |
d   |
d   |
d   | j                  | j
                  ¬«	      ƒ d	{  –—† }| j                  ||
d   ¬
«      S 7 Œ­w)a¶  Get the n_results nearest neighbor embeddings for provided query_embeddings or query_texts.

        Args:
            query_embeddings: The embeddings to get the closes neighbors of. Optional.
            query_texts: The document texts to get the closes neighbors of. Optional.
            query_images: The images to get the closes neighbors of. Optional.
            ids: A subset of ids to search within. Optional.
            n_results: The number of neighbors to return for each query_embedding or query_texts. Optional.
            where: A Where type dict used to filter results by. E.g. `{"$and": [{"color" : "red"}, {"price": {"$gte": 4.20}}]}`. Optional.
            where_document: A WhereDocument type dict used to filter by the documents. E.g. `{"$contains": "hello"}`. Optional.
            include: A list of what to include in the results. Can contain `"embeddings"`, `"metadatas"`, `"documents"`, `"distances"`. Ids are always included. Defaults to `["metadatas", "documents", "distances"]`. Optional.

        Returns:
            QueryResult: A QueryResult object containing the results.

        Raises:
            ValueError: If you don't provide either query_embeddings, query_texts, or query_images
            ValueError: If you provide both query_embeddings and query_texts
            ValueError: If you provide both query_embeddings and query_images
            ValueError: If you provide both query_texts and query_images

        )	rW   rX   rY   rZ   r"   r[   rB   rE   rF   r"   r#   r[   rB   rE   rF   )	r,   r"   rW   r[   rB   rE   rF   r-   r.   NrH   )Ú#_validate_and_prepare_query_requestr0   Ú_queryr2   r-   r.   Ú_transform_query_response)r3   rW   rX   rY   rZ   r"   r[   rB   rE   rF   Úquery_requestÚquery_resultss               r5   ÚqueryzAsyncCollection.queryÀ   sÉ   è ø€ ðX ×@Ñ@Ø-Ø#Ø%Ø!ØØØØ)Øð Aó 

ˆð #Ÿl™l×1Ñ1ØŸ'™'Ø˜eÑ$Ø*¨<Ñ8Ø# KÑ0Ø Ñ(Ø(Ð)9Ñ:Ø! )Ñ,Ø—;‘;Ø—]‘]ð 2ó 

÷ 

ˆð ×-Ñ-Ø"¨M¸)Ñ,Dð .ó 
ð 	
ð

ús   ‚A2BÁ4BÁ5BÚnameÚmetadataÚconfigurationc              ƒ   óæ   K  — | j                  |«       | j                  j                  | j                  |||| j                  | j
                  ¬«      ƒ d{  –—†  | j                  |||«       y7 Œ­w)zëModify the collection name or metadata

        Args:
            name: The updated name for the collection. Optional.
            metadata: The updated metadata for the collection. Optional.

        Returns:
            None
        )r2   Únew_nameÚnew_metadataÚnew_configurationr-   r.   N)Ú_validate_modify_requestr0   Ú_modifyr2   r-   r.   Ú"_update_model_after_modify_success)r3   rc   rd   re   s       r5   ÚmodifyzAsyncCollection.modify  sp   è ø€ ð  	×%Ñ% hÔ/ð
 �l‰l×"Ñ"Ø�w‰wØØ!Ø+Ø—;‘;Ø—]‘]ð #ó 
÷ 	
ð 	
ð 	×/Ñ/°°hÀÕNð	
ús   ‚AA1ÁA/ÁA1rg   c              ƒ   óò   K  — | j                   j                  | j                  || j                  | j                  ¬«      ƒ d{  –—† }t        | j                   || j                  | j                  ¬«      S 7 Œ1­w)aŒ  Fork the current collection under a new name. The returning collection should contain identical data to the current collection.
        This only works for Hosted Chroma for now.

        Args:
            new_name: The name of the new collection.

        Returns:
            Collection: A new collection with the specified name and containing identical data to the current collection.
        )r,   rg   r-   r.   N)ÚclientÚmodelÚembedding_functionÚdata_loader)r0   Ú_forkr2   r-   r.   r!   Ú_embedding_functionÚ_data_loader)r3   rg   rp   s      r5   ÚforkzAsyncCollection.fork(  sn   è ø€ ð —l‘l×(Ñ(ØŸ'™'ØØ—;‘;Ø—]‘]ð	 )ó 
÷ 
ˆô Ø—<‘<ØØ#×7Ñ7Ø×)Ñ)ô	
ð 	
ð
ús   ‚AA7ÁA5Á2A7c              ƒ   ó–   K  — | j                   j                  | j                  | j                  | j                  ¬«      ƒ d{  –—† S 7 Œ­w)z¿Get the number of forks that exist for this collection.
        This only works for Hosted Chroma for now.

        Returns:
            int: The number of forks for this collection.
        r=   N)r0   Ú_fork_countr2   r-   r.   r?   s    r5   Ú
fork_countzAsyncCollection.fork_countB  sC   è ø€ ð —\‘\×-Ñ-ØŸ'™'Ø—;‘;Ø—]‘]ð .ó 
÷ 
ð 	
ð 
úrA   Úsearchesc              ƒ   ó(  K  — t        |«      }|€g }|D �cg c]  }| j                  |«      ‘Œ }}| j                  j                  | j                  t        t        t           |«      | j                  | j                  |¬«      ƒ d{  –—† S c c}w 7 Œ	­w)aÄ  Perform hybrid search on the collection.
        This is an experimental API that only works for Hosted Chroma for now.

        Args:
            searches: A single Search object or a list of Search objects, each containing:
                - where: Where expression for filtering
                - rank: Ranking expression for hybrid search (defaults to Val(0.0))
                - limit: Limit configuration for pagination (defaults to no limit)
                - select: Select configuration for keys to return (defaults to empty)
            read_level: Controls whether to read from the write-ahead log (WAL):
                - ReadLevel.INDEX_AND_WAL: Read from both the compacted index and WAL (default).
                  All committed writes will be visible.
                - ReadLevel.INDEX_ONLY: Read only from the compacted index, skipping the WAL.
                  Faster, but recent writes that haven't been compacted may not be visible.
                - ReadLevel.INDEX_AND_BOUNDED_WAL: Read from the index and up to a
                  server-configured number of WAL entries for bounded query latency.

        Returns:
            SearchResult: Column-major format response with:
                - ids: List of result IDs for each search payload
                - documents: Optional documents for each payload
                - embeddings: Optional embeddings for each payload
                - metadatas: Optional metadata for each payload
                - scores: Optional scores for each payload
                - select: List of selected keys for each payload

        Raises:
            NotImplementedError: For local/segment API implementations

        Examples:
            # Using builder pattern with Key constants
            from chromadb.execution.expression import (
                Search, Key, K, Knn, Val
            )

            # Note: K is an alias for Key, so K.DOCUMENT == Key.DOCUMENT
            search = (Search()
                .where((K("category") == "science") & (K("score") > 0.5))
                .rank(Knn(query=[0.1, 0.2, 0.3]) * 0.8 + Val(0.5) * 0.2)
                .limit(10, offset=0)
                .select(K.DOCUMENT, K.SCORE, "title"))

            # Direct construction
            from chromadb.execution.expression import (
                Search, Eq, And, Gt, Knn, Limit, Select, Key
            )

            search = Search(
                where=And([Eq("category", "science"), Gt("score", 0.5)]),
                rank=Knn(query=[0.1, 0.2, 0.3]),
                limit=Limit(offset=0, limit=10),
                select=Select(keys={Key.DOCUMENT, Key.SCORE, "title"})
            )

            # Single search
            result = await collection.search(search)

            # Multiple searches at once
            searches = [
                Search().where(K("type") == "article").rank(Knn(query=[0.1, 0.2])),
                Search().where(K("type") == "paper").rank(Knn(query=[0.3, 0.4]))
            ]
            results = await collection.search(searches)

            # Skip WAL for faster queries (may miss recent uncommitted writes)
            from chromadb.api.types import ReadLevel
            result = await collection.search(search, read_level=ReadLevel.INDEX_ONLY)
        N)r,   rz   r-   r.   r8   )
r   Ú_embed_search_string_queriesr0   Ú_searchr2   r   r   r   r-   r.   )r3   rz   r8   Úsearches_listÚsearchÚembedded_searchess         r5   r   zAsyncCollection.searchO  sœ   è ø€ ôT /¨xÓ8ˆØÐ ØˆMð ERö
Ø:@ˆD×-Ñ-¨fÕ5ð
Ðð 
ð —\‘\×)Ñ)ØŸ'™'Üœ$œv™,Ð(9Ó:Ø—;‘;Ø—]‘]Ø!ð *ó 
÷ 
ð 	
ùò	
ð
ús   ‚B–B®ABÂBÂ
Bc           
   ƒ   óî   K  — | j                  ||||||¬«      }| j                  j                  | j                  |d   |d   |d   |d   |d   | j                  | j
                  ¬«      ƒ d{  –—†  y7 Œ­w)	a‚  Update the embeddings, metadatas or documents for provided ids.

        Args:
            ids: The ids of the embeddings to update
            embeddings: The embeddings to update. If None, embeddings will be computed based on the documents or images using the embedding_function set for the Collection. Optional.
            metadatas:  The metadata to associate with the embeddings. When querying, you can filter on this metadata. Optional.
            documents: The documents to associate with the embeddings. Optional.
            images: The images to associate with the embeddings. Optional.
        Returns:
            None
        r*   r"   r#   r$   r%   r'   r+   N)Ú$_validate_and_prepare_update_requestr0   Ú_updater2   r-   r.   )r3   r"   r#   r$   r%   r&   r'   Úupdate_requests           r5   ÚupdatezAsyncCollection.updateª  ó�   è ø€ ð2 ×BÑBØØ!ØØØØð Có 
ˆð �l‰l×"Ñ"ØŸ'™'Ø˜uÑ%Ø% lÑ3Ø$ [Ñ1Ø$ [Ñ1Ø Ñ'Ø—;‘;Ø—]‘]ð #ó 	
÷ 		
ò 		
úr7   c           
   ƒ   óî   K  — | j                  ||||||¬«      }| j                  j                  | j                  |d   |d   |d   |d   |d   | j                  | j
                  ¬«      ƒ d{  –—†  y7 Œ­w)	aO  Update the embeddings, metadatas or documents for provided ids, or create them if they don't exist.

        Args:
            ids: The ids of the embeddings to update
            embeddings: The embeddings to add. If None, embeddings will be computed based on the documents using the embedding_function set for the Collection. Optional.
            metadatas:  The metadata to associate with the embeddings. When querying, you can filter on this metadata. Optional.
            documents: The documents to associate with the embeddings. Optional.

        Returns:
            None
        r*   r"   r#   r$   r%   r'   r+   N)Ú$_validate_and_prepare_upsert_requestr0   Ú_upsertr2   r-   r.   )r3   r"   r#   r$   r%   r&   r'   Úupsert_requests           r5   ÚupsertzAsyncCollection.upsert×  r†   r7   c           	   ƒ   óà   K  — | j                  ||||¬«      }| j                  j                  | j                  |d   |d   |d   |d   | j                  | j
                  ¬«      ƒ d{  –—† S 7 Œ­w)a1  Delete the embeddings based on ids and/or a where filter

        Args:
            ids: The ids of the embeddings to delete
            where: A Where type dict used to filter the delection by. E.g. `{"$and": [{"color" : "red"}, {"price": {"$gte": 4.20}}]}`. Optional.
            where_document: A WhereDocument type dict used to filter the deletion by the document content. E.g. `{"$contains": "hello"}`. Optional.
            limit: Maximum number of records to delete. Can only be used with where or where_document filters.

        Returns:
            DeleteResult: A dict containing the number of records deleted.

        Raises:
            ValueError: If you don't provide either ids, where, or where_document
            ValueError: If limit is specified without a where or where_document clause.
        )rC   r"   rB   rE   rC   )r,   r"   rB   rE   rC   r-   r.   N)Ú$_validate_and_prepare_delete_requestr0   Ú_deleter2   r-   r.   )r3   r"   rB   rE   rC   Údelete_requests         r5   ÚdeletezAsyncCollection.delete  s…   è ø€ ð, ×BÑBØ�˜¨eð Có 
ˆð —\‘\×)Ñ)ØŸ'™'Ø˜uÑ%Ø  Ñ)Ø)Ð*:Ñ;Ø  Ñ)Ø—;‘;Ø—]‘]ð *ó 
÷ 
ð 	
ð 
ús   ‚A%A.Á'A,Á(A.)NNNNN)rP   )NNN)NNNN)*Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r
   r   r   r   r   r   r6   r   ÚINDEX_AND_WALÚintr;   r   r@   r   r   r   r   rO   rU   r   rb   Ústrr	   r   rm   rv   ry   r   r   r   r…   r‹   r   r   r�   © ó    r5   r!   r!   "   s�  „ ð Ø37Ø37Ø-1Ø)-ñ4
à�r‰]ð4
ð ØØ˜)Ñ$Ø˜+Ñ&ð(ññ
ð4
ð ˜I hÑ/Ñ0ð4
ð ˜I hÑ/Ñ0ð4
ð ˜ 5Ñ)Ñ*ð4
ð �y ‘~Ñ&ð4
ð 
ó4
ðl 3<×2IÑ2Iñ 
 ið 
Ècó 
ð,
¨>ó 
ð$ (,Ø!%Ø#Ø $Ø26Ø'¨Ð5ñ-
à�i ‘mÑ$ð-
ð ˜‰ð-
ð ˜‰}ð	-
ð
 ˜‘ð-
ð ! Ñ/ð-
ð ð-
ð 
ó-
ñ^
 ð 
¨Yó 
ð2 Ø59Ø37Ø/3Ø'+ØØ!%Ø26ò
ñF
à"ØØ˜)Ñ$Ø˜+Ñ&ð(ññ
ðF
ð ˜i¨Ñ1Ñ2ðF
ð ˜y¨Ñ/Ñ0ðF
ð ˜Y s™^Ñ,ðF
ð �i ‘mÑ$ðF
ð ðF
ð ˜‰ðF
ð ! Ñ/ðF
ð ðF
ð( 
ó)F
ðT #Ø15ØAEñ	Oà�s‰mðOð Ð-Ñ.ðOð  Ð =Ñ>ð	Oð
 
óOð@
àð
ð 
ó
ð4
 #ó 
ð  !*× 7Ñ 7ñY
à˜FÑ#ðY
ð ðY
ð 
ó	Y
ðF Ø37Ø37Ø-1Ø)-ñ+
à�r‰]ð+
ð ØØ˜)Ñ$Ø˜+Ñ&ð(ññ
ð+
ð ˜I hÑ/Ñ0ð+
ð ˜I hÑ/Ñ0ð+
ð ˜ 5Ñ)Ñ*ð+
ð �y ‘~Ñ&ð+
ð 
ó+
ðj Ø37Ø37Ø-1Ø)-ñ+
à�r‰]ð+
ð ØØ˜)Ñ$Ø˜+Ñ&ð(ññ
ð+
ð ˜I hÑ/Ñ0ð+
ð ˜I hÑ/Ñ0ð+
ð ˜ 5Ñ)Ñ*ð+
ð �y ‘~Ñ&ð+
ð 
ó+
ð^ "Ø!%Ø26Ø#ñ"
à�c‰]ð"
ð ˜‰ð"
ð ! Ñ/ð	"
ð
 ˜‰}ð"
ð 
ô"
r˜   r!   r   N)$Útypingr   r   r   r   r   Úchromadb.api.typesr   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   Ú$chromadb.api.models.CollectionCommonr   Ú%chromadb.api.collection_configurationr   Ú"chromadb.execution.expression.planr   Úchromadb.apir   r!   r—   r˜   r5   ú<module>rŸ      sP   ðß =Õ =÷÷ ÷ ÷ ÷ ó õ. BÝ OÝ 5áÝ+ôD
Ð&Ð'7Ñ8õ D
r˜   