
    3i>P                         S SK JrJrJrJrJrJrJr  S SKJ	r	  S SK
JrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJr  S SKJr  S SKJr  S SK r \ RB                  " \"5      r#\(       a  S SK$J%r%   " S S	\	S
   5      r&g)    )TYPE_CHECKINGOptionalUnionListcastDictAny)CollectionCommon)URICollectionMetadata	EmbeddingPyEmbeddingIncludeMetadataDocumentImageWhereIDs	GetResultQueryResultID	OneOrManyWhereDocumentSearchResultmaybe_cast_one_to_many)UpdateCollectionConfiguration)SearchN)	ServerAPIc                      \ rS rSrS\4S jr     S.S\\   S\\	\\
   \\   4      S\\\      S\\\      S	\\\      S
\\\      SS4S jjrSSSSSSS/4S\\\      S\\   S\\   S\\   S\\   S\S\4S jjrS/S\S\4S jjrSSSSSSSS/ SQ4	S\\	\\
   \\   4      S\\\      S\\\      S\\\      S\\\      S\S\\   S\\   S\S\4S jjr   S0S\\   S\\   S\\   SS4S jjrS\SS 4S  jrS!\\   S\4S" jr      S.S\\   S\\	\\
   \\   4      S\\\      S\\\      S	\\\      S
\\\      SS4S# jjr!     S.S\\   S\\	\\
   \\   4      S\\\      S\\\      S	\\\      S
\\\      SS4S$ jjr"   S0S\\#   S\\   S\\   SS4S% jjr$ S1S&\S'\S(\S)\\%\\&4      S\'\(\4   4
S* jjr) S2S&\S+\(S\(4S, jjr*S-r+g)3
Collection"   returnc                 t    U R                   R                  U R                  U R                  U R                  S9$ )z~The total number of embeddings added to the database

Returns:
    int: The total number of embeddings added to the database

)collection_idtenantdatabase)_client_countidr%   r&   )selfs    X/home/james-whalen/.local/lib/python3.13/site-packages/chromadb/api/models/Collection.pycountCollection.count#   s5     ||""'';;]] # 
 	
    Nids
embeddings	metadatas	documentsimagesurisc                     U R                  UUUUUUS9nU R                  R                  U R                  US   US   US   US   US   U R                  U R
                  S9  g)	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/   r0   r1   r2   r3   r4   r/   r0   r1   r2   r4   r$   r/   r0   r1   r2   r4   r%   r&   N)!_validate_and_prepare_add_requestr'   _addr)   r%   r&   )r*   r/   r0   r1   r2   r3   r4   add_requests           r+   addCollection.add0   s    F <<! = 
 	''E""<0!+.!+.V$;;]] 	 		
r.   wherelimitoffsetwhere_documentincludec                     U R                  UUUUS9nU R                  R                  U R                  US   US   US   US   UUU R                  U R
                  S9	nU R                  XS   S9$ )at  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/   r=   r@   rA   r/   r=   r@   rA   )	r$   r/   r=   r@   rA   r>   r?   r%   r&   responserA   )!_validate_and_prepare_get_requestr'   _getr)   r%   r&   _transform_get_response)	r*   r/   r=   r>   r?   r@   rA   get_requestget_resultss	            r+   getCollection.getg   s    0 <<)	 = 
 ll''''E"g&&'78	*;;]] ( 

 ++ i*@ , 
 	
r.   
   c           	          U R                  U R                  R                  U R                  UU R                  U R
                  S95      $ )zGet 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&   )_transform_peek_responser'   _peekr)   r%   r&   )r*   r>   s     r+   peekCollection.peek   sF     ,,LL"gg{{	  
 	
r.   )r1   r2   	distancesquery_embeddingsquery_textsquery_images
query_uris	n_resultsc
                     U R                  UUUUUUUUU	S9	n
U R                  R                  U R                  U
S   U
S   U
S   U
S   U
S   U
S   U R                  U R
                  S9	nU R                  XS   S	9$ )
an  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.
    query_uris: The URIs to be used with data loader. 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

)	rT   rU   rV   rW   r/   rX   r=   r@   rA   r/   r0   rX   r=   r@   rA   )	r$   r/   rT   rX   r=   r@   rA   r%   r&   rC   )#_validate_and_prepare_query_requestr'   _queryr)   r%   r&   _transform_query_response)r*   rT   rU   rV   rW   r/   rX   r=   r@   rA   query_requestquery_resultss               r+   queryCollection.query   s    Z @@-#%!) A 

 ++''e$*<8#K0(()9:!),;;]] , 

 --"),D . 
 	
r.   namemetadataconfigurationc           	          U R                  U5        U R                  R                  U R                  UUUU R                  U R
                  S9  U R                  XU5        g)zModify the collection name or metadata

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

Returns:
    None
)r)   new_namenew_metadatanew_configurationr%   r&   N)_validate_modify_requestr'   _modifyr)   r%   r&   "_update_model_after_modify_success)r*   ra   rb   rc   s       r+   modifyCollection.modify   s[      	%%h/
 	ww!+;;]] 	 	
 	//Nr.   re   c                     U R                   R                  U R                  UU R                  U R                  S9n[        U R                   UU R                  U R                  S9$ )ax  Fork the current collection under a new name. The returning collection should contain identical data to the current collection.
This is an experimental API that 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$   re   r%   r&   )clientmodelembedding_functiondata_loader)r'   _forkr)   r%   r&   r    _embedding_function_data_loader)r*   re   ro   s      r+   forkCollection.fork  s`     ""'';;]]	 # 
 <<#77))	
 	
r.   searchesc                 
   [        U5      nUc  / nU Vs/ s H  o0R                  U5      PM     nnU R                  R                  U R                  [        [        [           U5      U R                  U R                  S9$ s  snf )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)

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 = 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 = collection.search(searches)
)r$   rw   r%   r&   )
r   _embed_search_string_queriesr'   _searchr)   r   r   r   r%   r&   )r*   rw   searches_listsearchembedded_searchess        r+   r|   Collection.search*  s    | /x8 M ER
DQ&--f5M 	 
 ||##''$v,(9:;;]]	 $ 
 	
	
s   B c                     U R                  UUUUUUS9nU R                  R                  U R                  US   US   US   US   US   U R                  U R
                  S9  g)	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
r6   r/   r0   r1   r2   r4   r7   N)$_validate_and_prepare_update_requestr'   _updater)   r%   r&   )r*   r/   r0   r1   r2   r3   r4   update_requests           r+   updateCollection.updatex      2 BB! C 
 	''u%%l3$[1$[1';;]] 	 		
r.   c                     U R                  UUUUUUS9nU R                  R                  U R                  US   US   US   US   US   U R                  U R
                  S9  g)	a  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
r6   r/   r0   r1   r2   r4   r7   N)$_validate_and_prepare_upsert_requestr'   _upsertr)   r%   r&   )r*   r/   r0   r1   r2   r3   r4   upsert_requests           r+   upsertCollection.upsert  r   r.   c           	          U R                  XU5      nU R                  R                  U R                  US   US   US   U R                  U R
                  S9  g)a  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.

Returns:
    None

Raises:
    ValueError: If you don't provide either ids, where, or where_document
r/   r=   r@   )r$   r/   r=   r@   r%   r&   N)$_validate_and_prepare_delete_requestr'   _deleter)   r%   r&   )r*   r/   r=   r@   delete_requests        r+   deleteCollection.delete  s`    & BB
 	''u% ))*:;;;]] 	 	
r.   	task_nameoperator_nameoutput_collection_nameparamsc           
      |    U R                   R                  UUU R                  UUU R                  U R                  S9$ )ak  Create a recurring task that processes this collection.

Args:
    task_name: Unique name for this task instance
    operator_name: Built-in operator name (e.g., "record_counter")
    output_collection_name: Name of the collection where task output will be stored
    params: Optional dictionary with operator-specific parameters

Returns:
    tuple: (success: bool, task_id: str)

Example:
    >>> success, task_id = collection.create_task(
    ...     task_name="count_docs",
    ...     operator_name="record_counter",
    ...     output_collection_name="doc_counts",
    ...     params={"threshold": 100}
    ... )
)r   r   input_collection_idr   r   r%   r&   )r'   create_taskr)   r%   r&   )r*   r   r   r   r   s        r+   r   Collection.create_task  sA    4 ||''' $#9;;]] ( 
 	
r.   delete_outputc                 x    U R                   R                  UU R                  UU R                  U R                  S9$ )a-  Delete a task and prevent any further runs.

Args:
    task_name: Name of the task to remove
    delete_output: Whether to also delete the output collection. Defaults to False.

Returns:
    bool: True if successful

Example:
    >>> success = collection.remove_task("count_docs", delete_output=True)
)r   r   r   r%   r&   )r'   remove_taskr)   r%   r&   )r*   r   r   s      r+   r   Collection.remove_task  s;    " ||'' $';;]] ( 
 	
r.    )NNNNN)rL   )NNN)N)F),__name__
__module____qualname____firstlineno__intr,   r   r   r   r   r   r   r   r   r   r   r;   r   r   r   r   rJ   rQ   r   r_   strr   r   rk   ru   r   r   r|   r   r   r   r   r   r	   tupleboolr   r   __static_attributes__r   r.   r+   r    r    "   s   
s 
* 3737-1)-5
r]5
 )$+&(
5
 Ih/05
 Ih/05
 5)*5
 y~&5
 
5
r (,!%# $26'5,
im$,
 ,
 }	,

 ,
 !/,
 ,
 
,
\
# 
y 
2 5937/3'+!%26
G
")$+&(
G
 i12G
 y/0G
 Ys^,G
 im$G
 G
 G
 !/G
 G
( 
)G
V #15AE	OsmO -.O   =>	O
 
O@

 

4L
F#L
 
L
l 3737-1)-+
r]+
 )$+&(
+
 Ih/0+
 Ih/0+
 5)*+
 y~&+
 
+
j 3737-1)-+
r]+
 )$+&(
+
 Ih/0+
 Ih/0+
 5)*+
 y~&+
 
+
^ "!%26	
c]
 
 !/	

 

J ,0"
"
 "
 !$	"

 c3h("
 
tSy	"
N $

 
 
	
 
r.   r    r   )'typingr   r   r   r   r   r   r	   $chromadb.api.models.CollectionCommonr
   chromadb.api.typesr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   %chromadb.api.collection_configurationr   "chromadb.execution.expression.planr   logging	getLoggerr   loggerchromadb.apir   r    r   r.   r+   <module>r      s`    H H H A    & P 5 			8	$&K
!+. K
r.   