
    LKiuW                     ,   S SK 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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Jr  S SKJ r   S SK!J"r"  S SK#r#S SK$J%r%  \(       a  S SK&J'r'  \#RP                  " \)5      r*\(       a  S S	K+J,r,   " S
 S\
S   5      r-g)    )TYPE_CHECKINGOptionalUnionListcastDictAnyTuple)CollectionCommon)URICollectionMetadata	EmbeddingPyEmbeddingIncludeIndexingStatusMetadataDocumentImageWhereIDs	GetResultQueryResultID	OneOrMany	ReadLevelWhereDocumentSearchResultmaybe_cast_one_to_many)UpdateCollectionConfiguration)SearchN)Function)AttachedFunction)	ServerAPIc                      \ rS rSrS\4S jrS\4S jr     S1S\\	   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S2S\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   S3S\
\   S\
\   S\
\   SS4S jjrS \SS 4S! jr\ RB                  4S"\\"   S#\ S\#4S$ jjr$     S1S\\	   S\
\\\   \\   4      S\
\\      S	\
\\      S
\
\\      S\
\\      SS4S% jjr%     S1S\\	   S\
\\\   \\   4      S\
\\      S	\
\\      S
\
\\      S\
\\      SS4S& jjr&   S3S\
\'   S\
\   S\
\   SS4S' jjr( S4S(\)S\S)\S*\
\*\\+4      S\,S+\-4   4
S, jjr.S\SS+4S- jr/ S5S\S.\-S\-4S/ jjr0S0r1g)6
Collection)   returnc                 t    U R                   R                  U R                  U R                  U R                  S9$ )z/Return the number of records in the collection.collection_idtenantdatabase)_client_countidr+   r,   selfs    `/var/www/html/dynamic-report/venv/lib/python3.13/site-packages/chromadb/api/models/Collection.pycountCollection.count*   s3    ||""'';;]] # 
 	
    c                 t    U R                   R                  U R                  U R                  U R                  S9$ )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-   _get_indexing_statusr/   r+   r,   r0   s    r2   get_indexing_statusCollection.get_indexing_status2   s5     ||00'';;]] 1 
 	
r5   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)	a0  Add records to the collection.

Args:
    ids: Record IDs to add.
    embeddings: Embeddings to add. If None, embeddings are computed.
    metadatas: Optional metadata for each record.
    documents: Optional documents for each record.
    images: Optional images for each record.
    uris: Optional URIs for loading images.

Raises:
    ValueError: If embeddings and documents are both missing.
    ValueError: If embeddings and documents are both provided.
    ValueError: If lengths of provided fields do not match.
    ValueError: If an ID already exists.
r:   r;   r<   r=   r>   r?   r:   r;   r<   r=   r?   r*   r:   r;   r<   r=   r?   r+   r,   N)!_validate_and_prepare_add_requestr-   _addr/   r+   r,   )r1   r:   r;   r<   r=   r>   r?   add_requests           r2   addCollection.addB   s    > <<! = 
 	''E""<0!+.!+.V$;;]] 	 		
r5   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$ )a  Retrieve records from the collection.

If no filters are provided, returns records up to ``limit`` starting at
``offset``.

Args:
    ids: If provided, only return records with these IDs.
    where: A Where filter used to filter based on metadata values.
    limit: Maximum number of results to return.
    offset: Number of results to skip before returning.
    where_document: A WhereDocument filter used to filter based on K.DOCUMENT.
    include: Fields to include in results. Can contain "embeddings", "metadatas", "documents", "uris". Defaults to "metadatas" and "documents".

Returns:
    GetResult: Retrieved records and requested fields as a GetResult object.
)r:   rH   rK   rL   r:   rH   rK   rL   )	r*   r:   rH   rK   rL   rI   rJ   r+   r,   responserL   )!_validate_and_prepare_get_requestr-   _getr/   r+   r,   _transform_get_response)	r1   r:   rH   rI   rJ   rK   rL   get_requestget_resultss	            r2   getCollection.getu   s    2 <<)	 = 
 ll''''E"g&&'78	*;;]] ( 

 ++ i*@ , 
 	
r5   
   c           	          U R                  U R                  R                  U R                  UU R                  U R
                  S95      $ )zReturn the first ``limit`` records from the collection.

Args:
    limit: Maximum number of records to return.

Returns:
    GetResult: Retrieved records and requested fields.
)r*   nr+   r,   )_transform_peek_responser-   _peekr/   r+   r,   )r1   rI   s     r2   peekCollection.peek   sF     ,,LL"gg{{	  
 	
r5   )r<   r=   	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$ )
a+  Query for the K nearest neighbor records in the collection.

This is a batch query API. Multiple queries can be performed at once
by providing multiple embeddings, texts, or images.

>>> query_1 = [0.1, 0.2, 0.3]
>>> query_2 = [0.4, 0.5, 0.6]
>>> results = collection.query(
>>>     query_embeddings=[query_1, query_2],
>>>     n_results=10,
>>> )

If query_texts, query_images, or query_uris are provided, the collection's
embedding function will be used to create embeddings before querying
the API.

The `ids`, `where`, `where_document`, and `include` parameters are applied
to all queries.

Args:
    query_embeddings: Raw embeddings to query for.
    query_texts: Documents to embed and query against.
    query_images: Images to embed and query against.
    query_uris: URIs to be loaded and embedded.
    ids: Optional subset of IDs to search within.
    n_results: Number of neighbors to return per query.
    where: Metadata filter.
    where_document: Document content filter.
    include: Fields to include in results. Can contain "embeddings", "metadatas", "documents", "uris", "distances". Defaults to "metadatas", "documents", "distances".

Returns:
    QueryResult: Nearest neighbor results.

Raises:
    ValueError: If no query input is provided.
    ValueError: If multiple query input types are provided.
)	r_   r`   ra   rb   r:   rc   rH   rK   rL   r:   r;   rc   rH   rK   rL   )	r*   r:   r_   rc   rH   rK   rL   r+   r,   rN   )#_validate_and_prepare_query_requestr-   _queryr/   r+   r,   _transform_query_response)r1   r_   r`   ra   rb   r:   rc   rH   rK   rL   query_requestquery_resultss               r2   queryCollection.query   s    v @@-#%!) A 

 ++''e$*<8#K0(()9:!),;;]] , 

 --"),D . 
 	
r5   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)zUpdate collection name, metadata, or configuration.

Args:
    name: New collection name.
    metadata: New metadata for the collection.
    configuration: New configuration for the collection.
)r/   new_namenew_metadatanew_configurationr+   r,   N)_validate_modify_requestr-   _modifyr/   r+   r,   "_update_model_after_modify_success)r1   rl   rm   rn   s       r2   modifyCollection.modify  s[     	%%h/
 	ww!+;;]] 	 	
 	//Nr5   rp   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*   rp   r+   r,   )clientmodelembedding_functiondata_loader)r-   _forkr/   r+   r,   r%   _embedding_function_data_loader)r1   rp   rz   s      r2   forkCollection.fork+  s`     ""'';;]]	 # 
 <<#77))	
 	
r5   searches
read_levelc                    [        U5      nUc  / nU Vs/ s H  o@R                  U5      PM     nnU R                  R                  U R                  [        [        [           U5      U R                  U R                  US9$ s  snf )ab
  Perform hybrid search on the collection.
This is an experimental API that only works for distributed and 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.

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)

    # Skip WAL for faster queries (may miss recent uncommitted writes)
    from chromadb.api.types import ReadLevel
    result = collection.search(search, read_level=ReadLevel.INDEX_ONLY)
)r*   r   r+   r,   r   )
r   _embed_search_string_queriesr-   _searchr/   r   r   r    r+   r,   )r1   r   r   searches_listsearchembedded_searchess         r2   r   Collection.searchE  s    P /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 existing records by ID.

Records are provided in columnar format. If provided, the `embeddings`, `metadatas`, `documents`, and `uris` lists must be the same length.
Entries in each list correspond to the same record.

>>> ids = ["id1", "id2", "id3"]
>>> embeddings = [[0.1, 0.2, 0.3], [0.4, 0.5, 0.6], [0.7, 0.8, 0.9]]
>>> metadatas = [{"key": "value"}, {"key": "value"}, {"key": "value"}]
>>> documents = ["document1", "document2", "document3"]
>>> uris = ["uri1", "uri2", "uri3"]
>>> collection.update(ids, embeddings, metadatas, documents, uris)

If `embeddings` are not provided, the embeddings will be computed based on `documents` using the collection's embedding function.

Args:
    ids: Record IDs to update.
    embeddings: Updated embeddings. If None, embeddings are computed.
    metadatas: Updated metadata.
    documents: Updated documents.
    images: Updated images.
    uris: Updated URIs for loading images.
rA   r:   r;   r<   r=   r?   rB   N)$_validate_and_prepare_update_requestr-   _updater/   r+   r,   )r1   r:   r;   r<   r=   r>   r?   update_requests           r2   updateCollection.update  s    H BB! C 
 	''u%%l3$[1$[1';;]] 	 		
r5   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)	a2  Create or update records by ID.

Args:
    ids: Record IDs to upsert.
    embeddings: Embeddings to add or update. If None, embeddings are computed.
    metadatas: Metadata to add or update.
    documents: Documents to add or update.
    images: Images to add or update.
    uris: URIs for loading images.
rA   r:   r;   r<   r=   r?   rB   N)$_validate_and_prepare_upsert_requestr-   _upsertr/   r+   r,   )r1   r:   r;   r<   r=   r>   r?   upsert_requests           r2   upsertCollection.upsert  s    0 BB! C 
 	''u%%l3$[1$[1';;]] 	 		
r5   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 records by ID or filters.

All documents that match the `ids` or `where` and `where_document` filters will be deleted.

Args:
    ids: Record IDs to delete.
    where: Metadata filter.
    where_document: Document content filter.

Raises:
    ValueError: If no IDs or filters are provided.
r:   rH   rK   )r*   r:   rH   rK   r+   r,   N)$_validate_and_prepare_delete_requestr-   _deleter/   r+   r,   )r1   r:   rH   rK   delete_requests        r2   deleteCollection.delete  s`    $ BB
 	''u% ))*:;;;]] 	 	
r5   functionoutput_collectionparamsr"   c           
          [        U[        5      (       a  UR                  OUnU R                  R	                  UUU R
                  UUU R                  U R                  S9$ )aU  Attach a function to this collection.

Args:
    function: A Function enum value (e.g., STATISTICS_FUNCTION, RECORD_COUNTER_FUNCTION)
    name: Unique name for this attached function
    output_collection: Name of the collection where function output will be stored
    params: Optional dictionary with function-specific parameters

Returns:
    Tuple of (AttachedFunction, created) where created is True if newly created,
    False if already existed (idempotent request)

Example:
    >>> from chromadb.api.functions import STATISTICS_FUNCTION
    >>> attached_fn = collection.attach_function(
    ...     function=STATISTICS_FUNCTION,
    ...     name="mycoll_stats_fn",
    ...     output_collection="mycoll_stats",
    ... )
    >>> if created:
    ...     print("New function attached")
    ... else:
    ...     print("Function already existed")
)function_idrl   input_collection_idr   r   r+   r,   )
isinstancer!   valuer-   attach_functionr/   r+   r,   )r1   r   rl   r   r   r   s         r2   r   Collection.attach_function!  sX    > )38X(F(FhnnH||++# $/;;]] , 
 	
r5   c                 v    U R                   R                  UU R                  U R                  U R                  S9$ )zGet an attached function by name for this collection.

Args:
    name: Name of the attached function

Returns:
    AttachedFunction: The attached function object

Raises:
    NotFoundError: If the attached function doesn't exist
)rl   r   r+   r,   )r-   get_attached_functionr/   r+   r,   )r1   rl   s     r2   r    Collection.get_attached_functionK  s8     ||11 $;;]]	 2 
 	
r5   delete_output_collectionc                 x    U R                   R                  UU R                  UU R                  U R                  S9$ )aF  Detach a function from this collection.

Args:
    name: The name of the attached function
    delete_output_collection: Whether to also delete the output collection. Defaults to False.

Returns:
    bool: True if successful

Example:
    >>> success = collection.detach_function("my_function", delete_output_collection=True)
)rl   r   delete_outputr+   r,   )r-   detach_functionr/   r+   r,   )r1   rl   r   s      r2   r   Collection.detach_function^  s;    " ||++ $2;;]] , 
 	
r5    )NNNNN)rW   )NNN)N)F)2__name__
__module____qualname____firstlineno__intr3   r   r8   r   r   r   r   r   r   r   r   r   r   rF   r   r   r   r   rU   r\   r   rj   strr   r   rv   r   r   INDEX_AND_WALr    r   r   r   r   r   r   r!   r   r	   r
   boolr   r   r   __static_attributes__r   r5   r2   r%   r%   )   s   
s 

^ 
0 3737-1)-1
r]1
 )$+&(
1
 Ih/01
 Ih/01
 5)*1
 y~&1
 
1
j (,!%# $26'5-
im$-
 -
 }	-

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

 

H ,0(
(
 (
 	(

 c3h((
 
!4'	((
T
# 
2D 
, */

 #'
 
	
 
r5   r%   r#   ).typingr   r   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   r   r   %chromadb.api.collection_configurationr   "chromadb.execution.expression.planr    loggingchromadb.api.functionsr!   $chromadb.api.models.AttachedFunctionr"   	getLoggerr   loggerchromadb.apir#   r%   r   r5   r2   <module>r      sn    O O O A     * P 5  +E			8	$&L	
!+. L	
r5   