
    _j(                    h   d dl mZmZmZmZmZmZmZmZm	Z	 d dl
Z
d dlZd dlmZmZ d dl
mZmZmZ d dlmZ d dlmZ d dlmZ d dlmZ d d	l
mZm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( d dl)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/ d dl0m1Z1 d dl0m2Z2m3Z3m4Z4m5Z5 d dl6m7Z7m8Z8m9Z9m:Z: d dl;m<Z< d dl=m>Z>m?Z?m@Z@mAZAmBZB d dlCmDZD d dlEmFZF d dlGmHZH d dlImJZJmKZKmLZLmMZMmNZNmOZOmPZPmQZQmRZR d dlSmTZT d dlUZUd dlVmWZW d dlXmYZYmZZ[ d dl\m]Z] d dl^m_Z_ d dl`maZambZb d dlcmdZdmeZe d dlfmgZgmhZhmiZimjZj d d l`mkZl  eUjm        en          Zod! Zpd"ed#dfd$Zqd%ed&eegef         d#efd'Zrd%ed&eegef         d#efd(Zsd%ed&eegef         d#efd)Zt ed*e%d+,          Zud-eeu         d.ed#eufd/Zv G d0 d1e
jw                  Zx G d2 d3eH          ZdS )4    )	AnyCallablecastDictSequenceOptionalTypeTypeVarTupleN)	to_threadCapacityLimiter)FastAPIResponseRequest)get_openapi)CORSMiddlewareORJSONResponse)APIRoute)HTTPExceptionstatus)wraps).load_update_collection_configuration_from_json.load_create_collection_configuration_from_json?create_collection_configuration_from_legacy_collection_metadataCreateCollectionConfiguration)	BaseModel)__version__)DeleteResult	Embedding	GetResultQueryResult
Embeddingsconvert_list_embeddings_to_np)UserIdentity)AuthzActionAuthzResourceServerAuthenticationProviderServerAuthorizationProvider)DEFAULT_DATABASEDEFAULT_TENANTSettingsSystem)	ServerAPI)ChromaErrorInvalidDimensionExceptionInvalidHTTPVersionRateLimitError
QuotaError)QuotaEnforcer)AsyncRateLimitEnforcer)Server)	AddEmbeddingCreateDatabaseCreateTenantDeleteEmbeddingGetEmbeddingQueryEmbeddingCreateCollectionUpdateCollectionUpdateEmbedding)Headers)ServerStartEvent)fastapi_json_responsestring_to_uuid)trace)instrument_fastapi)DatabaseTenant)ServerContextProductTelemetryClient)OpenTelemetryClientOpenTelemetryGranularityadd_attributes_to_current_spantrace_method)
Collectionc                 h     t                     dt          dt          dt          f fd            }|S )Nargskwargsreturnc                  d   K   | d         } |j                                       | i | d {V S )Nr   )_async_rate_limit_enforcer
rate_limit)rP   rQ   selffuncs      ]/var/www/FlaskApp/flask-venv/lib/python3.11/site-packages/chromadb/server/fastapi/__init__.pywrapperzrate_limit.<locals>.wrapper^   sH      AwET4??EEtVvVVVVVVVVV    )r   r   )rW   rY   s   ` rX   rU   rU   ]   sV    
4[[WS WC WC W W W W W [W NrZ   apprR   c                 x    | j         D ]1}t          |t                    r|j        d|j        v rdndz   |_        2dS )z
    Simplify operation IDs so that generated API clients have simpler function
    names.
    Should be called only after all routes have been added.
    v2z-v2z-v1N)routes
isinstancer   namepathoperation_id)r[   routes     rX    use_route_names_as_operation_idsrd   f   sW      W WeX&& 	W!&
8J8JuuPU!VEW WrZ   request	call_nextc                    K   t          j                                                    j        } ||            d {V }t	          |d          |j        d<   |S )NxzChroma-Trace-Id)rD   get_current_spanget_span_contexttrace_idformatheaders)re   rf   rk   responses       rX   #add_trace_id_to_response_middlewarero   q   sc       %''88::CHYw''''''''H*03*?*?H&'OrZ   c                   K   	  ||            d {V S # t           $ r}t          |          cY d }~S d }~wt          $ r+}t          dt	          |          dd          cY d }~S d }~wt
          $ r+}t          dt	          |          dd          cY d }~S d }~wt          $ rD}t                              |           t          dt          |          id          cY d }~S d }~ww xY w)NInvalidArgumentError)errormessage  )contentstatus_coderr     )
r/   rB   
ValueErrorr   str	TypeError	Exceptionlogger	exceptionrepr)re   rf   es      rX   catch_exceptions_middlewarer   z   s}     KYw''''''''' ( ( ($Q'''''''' 
 
 
4QHH
 
 
 	
 	
 	
 	
 	
 	
  
 
 
4QHH
 
 
 	
 	
 	
 	
 	
 	
  K K KwQ&8cJJJJJJJJJKsM    
C*3C*C*  A& C*&C*3 BC*C*&9C%C*%C*c                    K   | j                             d          }|dvrt          d| d           ||            d {V S )Nhttp_version)z1.12zHTTP version z is not supported)scopegetr1   )re   rf   r   s      rX   check_http_version_middlewarer      sd       =$$^44L<'' !P!P!P!PQQQ7#########rZ   DT)boundcontravariantmodeldatac                 x    	 |                      |          S # t          $ r |                     |          cY S w xY w)z1Used for backward compatibility with Pydantic 1.x)model_validateAttributeError	parse_obj)r   r   s     rX   validate_modelr      sN    %##D))) % % %t$$$$$%s    99c                   0     e Zd Zdedededdf fdZ xZS )ChromaAPIRouterra   rP   rQ   rR   Nc                 B   d|v o|d          dt           dt          ffd} ||          |d<    t                      j        |g|R i | |                    d          r|d d         }n|dz   } ||          |d<    t                      j        |g|R i | d S )Ninclude_in_schemara   rR   c                 6     o|                      d           S )N/)endswith)ra   exclude_from_schemas    rX   r   z8ChromaAPIRouter.add_api_route.<locals>.include_in_schema   s     **E4==3E3E/EErZ   r   )ry   boolsuperadd_api_router   )rV   ra   rP   rQ   r   r   	__class__s        @rX   r   zChromaAPIRouter.add_api_route   s   
  6)M&9L2M.M 		FC 	FD 	F 	F 	F 	F 	F 	F '8&7&=&="#d4T444V444== 	9DD#:D&7&7&=&="#d4T444V44444rZ   )__name__
__module____qualname__ry   r   r   __classcell__)r   s   @rX   r   r      sY        5# 5c 5S 5T 5 5 5 5 5 5 5 5 5 5rZ   r   c                      e Zd ZdefdZdeeef         fdZde	e
         deeef         fdZd{dZd{d	Zdej        fd
ZdededefdZdeeef         fdZdededefdZdeeef         fdZdefdZdeddfdZ edej                  ede de!de"e         de"e         de"e         ddfd                        Z# edej                  de de!de"e         de"e         de"e         ddfd            Z$ edej                  dede%fd            Z& edej                  dededdfd            Z' ed ej                  ded!edede(fd"            Z) ed#ej                  ded!ededdfd$            Z* ed%ej                  deddfd&            Z+ ed'ej                  dedede,fd(            Z- ed)ej                  	 	 d|deded*e"e         d+e"e         de.e(         f
d,            Z/ ed-ej                  	 	 d|deded!ed*e"e         d+e"e         de.e0         fd.            Z1 ed/ej                  deded!edefd0            Z2 ed1ej                  deded!ede0fd2            Z3 ed3ej                  deded!ed4ede0f
d5            Z4 ed6ej                  deded!ed7ede0f
d8            Z5 ed9ej                  ded!ed7ededdf
d:            Z6 ed;ej                  ded4eded!eddf
d<            Z7 ed=ej                  ededed!ed7edeeef         f
d>                        Z8 ed?ej                  ededed!ed7ed@edeeef         fdA                        Z9 edBej                  ededed!ed7ede:f
dC                        Z; edDej                  ededed!ed7eddf
dE                        Z< edFej                  ededed!ed7eddf
dG                        Z= edHej                  ed7eded!edede>f
dI                        Z? edJej                  ed7eded!edede@f
dK                        ZA edLej                  ededed!ed7edef
dM                        ZB edNej                  edede:fdO                        ZC edPej                  eded!ed7ededeDf
dQ                        ZEdeeef         fdRZFd{dSZG edTej                  ede de!de"e         de"e         de"e         deHe"e         e"e         f         fdU                        ZIde de!de"e         de"e         de"e         deHe"e         e"e         f         fdVZJ edWej                  eeKfdededdfdX                        ZL edYej                  eeKfdededede(fdZ                        ZM ed[ej                  ededdfd\                        ZN ed]ej                  ededede,fd^                        ZO ed_ej                  eddeKePfded*e"e         d+e"e         dedede.e0         fd`                        ZQ edaej                  eeKePfdedededefdb                        ZR edcej                  eeKePfdededede0fdd                        ZS edeej                  eeKePfded4ededede0f
df                        ZT edgej                  ed7ededdfdh                        ZU ediej                  eeKePfded4edededdf
dj                        ZV edkej                  eded7ede:fdl                        ZW edmej                  ded7eddfdn            ZX edoej                  eded7eddfdp                        ZY edqej                  ed7edede>fdr                        ZZ edsej                  ed7edede@fdt                        Z[ eduej                  eded7edefdv                        Z\ edwej                  edede:fdx                        Z] edyej                  ed7ededeDfdz                        Z^dS )}r   settingsc                    t           j        t          _        t	          j        dt                    | _        t          |          | _	        | j	        
                    t                    | _        i | _        | j        | j        _        | j                            t"                    | _        t'          |j                  | _        | j	                            t,                    | _        | j	                                          | j                            d          t4                      | j                            d          t6                      | j                            d          t8                     | j                            t<          dg|j        dg           | j                             tB          | j"                   | j                             tF          | j$                   | j	                            tJ                    | _&         | j        '                    d          | j(                   d | _)        |j*        r$| j	                            tV                    | _)        d | _,        |j-        r$| j	                            t\                    | _,        t_                      | _0        | 1                                 | 2                                 | j        3                    | j0                   ti          | j                   tk          | j                   | j	        
                    t                    }|6                    to                                 d S )NT)debugdefault_response_classhttp*)allow_headersallow_originsallow_methodsshutdown)8rH   FASTAPIrI   SERVER_CONTEXTfastapir   r   _appr-   _systeminstancer.   _api_extra_openapi_schemasgenerate_openapiopenapirequirerJ   _opentelemetry_clientr   chroma_server_thread_pool_size_capacity_limiterr4   _quota_enforcerstart
middlewarer   r   ro   add_middlewarer    chroma_server_cors_allow_originsadd_exception_handlerr3   quota_exception_handlerr2   rate_limit_exception_handlerr5   rT   on_eventr   authn_providerchroma_server_authn_providerr(   authz_providerchroma_server_authz_providerr)   r   routersetup_v1_routessetup_v2_routesinclude_routerrd   rE   capturerA   )rV   r   telemetry_clients      rX   __init__zFastAPI.__init__   s   0=0E-O$~VVV	h''#|44Y??	68# 1	%)Y%6%67J%K%K"!03"
 "
  $|33MBB$	V$$%BCCC$	V$$%@AAA$	V$$%HIII	  %"C%	 	! 	
 	
 	
 		''
D4PQQQ	''D=	
 	
 	
 +/,*>*>?U*V*V'&	:&&t}555"0 	U"&,"6"67S"T"TD"0 	T"&,"6"67R"S"SD%''	  ---(33349%%%<001GHH  !1!3!344444rZ   rR   c                     t          d| j        j        t                    }| j                                        D ]\  }}||d         d         |<   |S )z_Used instead of the default openapi() generation handler to include manually-populated schemas.Chroma)titler^   version
componentsschemas)r   r   r^   chromadb_versionr   items)rV   schemakeyvalues       rX   r   zFastAPI.generate_openapi   sd    !,9#$"
 "
 "
 5;;== 	9 	9JC38F< +C00rZ   request_modelc                     |                     d          }d|v r*|d                                         D ]\  }}|| j        |<   ddd|iiddi}|S )	Nz#/components/schemas/{model})ref_templatez$defsrequestBodyzapplication/jsonr   T)ru   required)model_json_schemar   r   )rV   r   r   r   r   openapi_extras         rX   !get_openapi_extras_for_body_modelz)FastAPI.get_openapi_extras_for_body_model  s     007 1 
 
 f$Wo3355 9 9
U38+C00 .60BC  
 rZ   Nc           
      	   | j                             d| j        dg           | j                             d| j        dg           | j                             d| j        dg           | j                             d| j        dg           | j                             d| j        dg           | j                             d	| j        dgd 
           | j                             d| j        dgd | 	                    t                               | j                             d| j        dgd 
           | j                             d| j        dgd 
           | j                             d| j        dgd | 	                    t                               | j                             d| j        dgd 
           | j                             d| j        dgd 
           | j                             d| j        dgd 
           | j                             d| j        dgd 
           | j                             d| j        dgd | 	                    t(                               | j                             d| j        dgt,          j        d | 	                    t0                               | j                             d| j        dgd | 	                    t4                               | j                             d| j        dgd | 	                    t0                               | j                             d| j        dgd | 	                    t:                               | j                             d| j        dgt>          | 	                    t@                               | j                             d| j!        dgd 
           | j                             d| j"        dgd | 	                    tF                               | j                             d| j$        dgd 
           | j                             d| j%        dgd | 	                    tL                               | j                             d| j'        dgd 
           | j                             d| j(        dgd 
           | j                             d | j)        dgd 
           | j                             d!| j*        dgd 
           d S )"Nz/api/v2GETmethodsz/api/v2/resetPOSTz/api/v2/versionz/api/v2/heartbeatz/api/v2/pre-flight-checksz/api/v2/auth/identityr   response_modelz"/api/v2/tenants/{tenant}/databasesr   r   r   z2/api/v2/tenants/{tenant}/databases/{database_name}DELETEz/api/v2/tenantsz/api/v2/tenants/{tenant}z>/api/v2/tenants/{tenant}/databases/{database_name}/collectionszD/api/v2/tenants/{tenant}/databases/{database_name}/collections_countzR/api/v2/tenants/{tenant}/databases/{database_name}/collections/{collection_id}/addr   rv   r   r   zU/api/v2/tenants/{tenant}/databases/{database_name}/collections/{collection_id}/updatezU/api/v2/tenants/{tenant}/databases/{database_name}/collections/{collection_id}/upsertzR/api/v2/tenants/{tenant}/databases/{database_name}/collections/{collection_id}/getzU/api/v2/tenants/{tenant}/databases/{database_name}/collections/{collection_id}/deletezT/api/v2/tenants/{tenant}/databases/{database_name}/collections/{collection_id}/countzT/api/v2/tenants/{tenant}/databases/{database_name}/collections/{collection_id}/query)r   zP/api/v2/tenants/{tenant}/databases/{database_name}/collections/{collection_name}zN/api/v2/tenants/{tenant}/databases/{database_name}/collections/{collection_id}PUTz_/api/v2/tenants/{tenant}/databases/{database_name}/collections/{collection_id}/functions/attachzh/api/v2/tenants/{tenant}/databases/{database_name}/collections/{collection_id}/functions/{function_name}zT/api/v2/tenants/{tenant}/databases/{database_name}/collections/by-id/{collection_id})+r   r   rootresetr   	heartbeatpre_flight_checksget_user_identitycreate_databaser   r8   get_databasedelete_databasecreate_tenantr9   
get_tenantlist_databaseslist_collectionscount_collectionscreate_collectionr=   addr   HTTP_201_CREATEDr7   updater?   upsertr   r;   deleter   r:   countget_nearest_neighborsr<   get_collectionupdate_collectionr>   delete_collectionattach_functionget_attached_functionget_collection_by_idrV   s    rX   r   zFastAPI.setup_v2_routes  s   !!)TY!HHH!!/4:x!PPP!!"3T\E7!SSS!!"5t~PUw!WWW!!')?% 	" 	
 	
 	
 	!!#"G	 	" 	
 	
 	
 	!!0 H@@PP 	" 	
 	
 	
 	!!@G	 	" 	
 	
 	
 	!!@ J	 	" 	
 	
 	
 	!!H@@NN 	" 	
 	
 	
 	!!&OG	 	" 	
 	
 	
 	!!0G	 	" 	
 	
 	
 	!!L!G	 	" 	
 	
 	
 	!!R"G	 	" 	
 	
 	
 	!!L"H@@AQRR 	" 	
 	
 	
 	!!`HH/@@NN 	" 	
 	
 	
 	!!cKH@@QQ 	" 	
 	
 	
 	!!cKH@@NN 	" 	
 	
 	
 	!!`HH@@NN 	" 	
 	
 	
 	!!cKH'@@QQ 	" 	
 	
 	
 	!!bJG	 	" 	
 	
 	
 	!!b&H@@, A   	" 	
 	
 	
 	!!^G	 	" 	
 	
 	
 	!!\"G@@AQRR 	" 	
 	
 	
 	!!^"J	 	" 	
 	
 	
 	!!m H	 	" 	
 	
 	
 	!!v&G	 	" 	
 	
 	
 	!!b%G	 	" 	
 	
 	
 	
 	
rZ   c                 8    | j                                          d S N)r   stopr  s    rX   r   zFastAPI.shutdown  s    rZ   c                     | j         S r
  )r   r  s    rX   r[   zFastAPI.app  s
    yrZ   re   excc                 ,   K   t          dddi          S )Ni  rs   zRate limit exceeded.rv   ru   r   rV   re   r  s      rX   r   z$FastAPI.rate_limit_exception_handler  s+        67
 
 
 	
rZ   c                 8    d| j                                         iS )Nznanosecond heartbeat)r   r   r  s    rX   r   zFastAPI.root  s    &	(;(;(=(=>>rZ   c                 P   K   t          dd|                                i          S )Nrt   rs   r  )r   rs   r  s      rX   r   zFastAPI.quota_exception_handler  s2       .
 
 
 	
rZ   c                 .   K   |                                  S r
  )r   r  s    rX   r   zFastAPI.heartbeat  s      yy{{rZ   c                 8   K   | j                                         S r
  )r   get_versionr  s    rX   r   zFastAPI.version  s      y$$&&&rZ   c                 @    | j                             d|i           dS )zU
        Set context about the request on any components that might need it.
        re   )contextN)r   set_contextrV   re   s     rX   _set_request_contextzFastAPI._set_request_context  s)     	(()W1E(FFFFFrZ   auth_requestrm   actiontenantdatabase
collectionc                 J   K   t          j        | j        g|||||fR   d {V S r
  )r   run_syncsync_auth_requestrV   rm   r  r  r  r  s         rX   r  zFastAPI.auth_request  s[       '"
 vvx<
 
 
 
 
 
 
 
 
 	
rZ   zFastAPI.sync_auth_requestc                     | j         st          |||d           dS | j                             t          |                    }| j        sdS t          |||          }| j                            |||           t          |||d           dS )z
        Authenticates and authorizes the request based on the given headers
        and other parameters. If the request cannot be authenticated or cannot
        be authorized (with the configured providers), raises an HTTP 401.
        r  r  r  N)r   rL   authenticate_or_raisedictr   r'   authorize_or_raise)rV   rm   r  r  r  r  user_identityauthz_resources           rX   r"  zFastAPI.sync_auth_request  s    " " 	*$ (",    F+AA$w--PP" 	F&!
 
 
 	..}fnUUU& $( 	
 	
 	
 	rZ   zFastAPI.get_user_identityc                     K    j         st          dt          t          g          S t	          t          t          j         fd           d {V           S )N )user_idr  	databasesc                      t          t          j                                      t	           j                            S r
  )r   r(   r   r&  r'  rm   )re   rV   s   rX   <lambda>z+FastAPI.get_user_identity.<locals>.<lambda>7  s4    0$2E ''W_(=(=>> rZ   )r   r%   r+   r*   r   r   r!  r  s   ``rX   r   zFastAPI.get_user_identity*  s      
 " 	>>N=O    $? ? ? ? ?       
 
 	
rZ   zFastAPI.create_databasec                     K   dt           dt          dt          dd f fd}t          j        ||j                                         d {V  j                   d {V  d S )Nr  rm   raw_bodyrR   c                    t          t          t          j        |                    }                    |t
          j        | |j        d                                           j	        
                    |j        |           S )Nre   )r   r8   orjsonloadsr"  r&   CREATE_DATABASEr`   r  r   r   )r  rm   r2  dbre   rV   s       rX   process_create_databasez8FastAPI.create_database.<locals>.process_create_databaseC  s      X0F0FGGB ""+   %%g%6669,,RWf===rZ   limiterry   r@   bytesr   r!  rm   bodyr   rV   re   r  r9  s   ``  rX   r   zFastAPI.create_database=  s      	>	>")	>5:	>	> 	> 	> 	> 	> 	> 	>$  #O,,..      *
 
 
 	
 	
 	
 	
 	
 	
 	
 	
 	
rZ   zFastAPI.get_databasedatabase_namec           	         K   |                      |j        t          j        ||d            d {V  t	          t
          t          j        | j        j	        ||| j
                   d {V           S Nr:  )r  rm   r&   GET_DATABASEr   rF   r   r!  r   r   r   rV   re   r@  r  s       rX   r   zFastAPI.get_database]  s       O$
 
 	
 	
 	
 	
 	
 	
 	
 $	&.	        
 
 	
rZ   zFastAPI.delete_databasec                    K   |                      |j        t          j        ||d            d {V  t	          j        | j        j        ||| j                   d {V  d S rB  )	r  rm   r&   DELETE_DATABASEr   r!  r   r   r   rD  s       rX   r   zFastAPI.delete_databasew  s       O'
 
 	
 	
 	
 	
 	
 	
 	
  I%*	
 
 
 	
 	
 	
 	
 	
 	
 	
 	
 	
rZ   zFastAPI.create_tenantc                     K   dt           dt          dd f fd}t          j        |||                                 d {V  j                   d {V  d S )Nre   r2  rR   c                     t          t          t          j        |                    }                    | j        t          j        |j        d d            j	        
                    |j                  S r
  )r   r9   r5  r6  r"  rm   r&   CREATE_TENANTr`   r   r   )re   r2  r  rV   s      rX   process_create_tenantz4FastAPI.create_tenant.<locals>.process_create_tenant  sf    #L&,x2H2HIIF "")   9**6;777rZ   r:  r   r=  r   r!  r>  r   rV   re   rJ  s   `  rX   r   zFastAPI.create_tenant  s      
	87 	8e 	8 	8 	8 	8 	8 	8 	8  !,,..      *	
 
 
 	
 	
 	
 	
 	
 	
 	
 	
 	
rZ   zFastAPI.get_tenantc                    K   |                      |j        t          j        |d d            d {V  t	          t
          t          j        | j        j	        || j
                   d {V           S rB  )r  rm   r&   
GET_TENANTr   rG   r   r!  r   r   r   )rV   re   r  s      rX   r   zFastAPI.get_tenant  s       O"
 
 	
 	
 	
 	
 	
 	
 	
 $	$.        
 
 	
rZ   zFastAPI.list_databaseslimitoffsetc           
         K   |                      |j        t          j        |d d            d {V  t	          t
          t                   t          j        | j	        j
        |||| j                   d {V           S rB  )r  rm   r&   LIST_DATABASESr   r   rF   r   r!  r   r   r   )rV   re   r  rO  rP  s        rX   r   zFastAPI.list_databases  s       O&
 
 	
 	
 	
 	
 	
 	
 	
 X$	(.        	
 	
 		
rZ   zFastAPI.list_collectionsc                 *   K   dt           t                   dt           t                   dt          dt          dt          t                   f
 fd}t          t          t                   t          j        ||||| j                   d {V           }|S )NrO  rP  r  r@  rR   c                                          j        t          j        ||d                                           t          d|i           j                            ||| |          S )Nr4  r  )r  r  rO  rP  )r"  rm   r&   LIST_COLLECTIONSr  rL   r   r   )rO  rP  r  r@  re   rV   s       rX   process_list_collectionsz:FastAPI.list_collections.<locals>.process_list_collections  s     "",   %%g%666*Hf+=>>>9--U6 .   rZ   r:  )	r   intry   r   CollectionModelr   r   r!  r   )rV   re   r  r@  rO  rP  rV  api_collection_modelss   ``      rX   r   zFastAPI.list_collections  s      	C=	*23-	AD	UX	o&	 	 	 	 	 	 	& !%_%$(.        
!
 
!
 %$rZ   zFastAPI.count_collectionsc           	        K   |                      |j        t          j        ||d            d {V  t	          d|i           t          t          t          j        | j	        j
        ||| j                   d {V           S Nr  r:  )r  rm   r&   COUNT_COLLECTIONSrL   r   rW  r   r!  r   r   r   )rV   re   r  r@  s       rX   r   zFastAPI.count_collections  s       O)
 
 	
 	
 	
 	
 	
 	
 	
 	'&'9:::$	+.	        
 
 	
rZ   zFastAPI.create_collectionc                     K   dt           dt          dt          dt          dt          f
 fd}t	          t          t          j        |||||                                 d {V  j                   d {V           }|S )Nre   r  r  r2  rR   c                    t          t          t          j        |                    }|j        s|j        rt          |j                  }nd }nt          |j                  }                    | j	        t          j        |||j                                       |            t          d|i           j                            |j        ||j        |j        ||          S )Nr4  r  r`   configurationmetadataget_or_creater  r  )r   r=   r5  r6  r`  ra  r   r   r"  rm   r&   CREATE_COLLECTIONr`   r  rL   r   r   rb  )re   r  r  r2  creater`  rV   s         rX   process_create_collectionz<FastAPI.create_collection.<locals>.process_create_collection)  s     $$4fl86L6LMMF' ? )W"O  "M %)MM N(! !
 ""-   %%g%666*Hf+=>>>9..[+$2! /   rZ   r:  	r   ry   r=  rX  r   r   r!  r>  r   )rV   re   r  r@  re  api_collection_models   `     rX   r   zFastAPI.create_collection"  s      &	&	&)&	58&	DI&	&	 &	 &	 &	 &	 &	P  $$)llnn$$$$$$.        
 
 
 
 $#rZ   zFastAPI.get_collectioncollection_namec           
      
  K   |                      |j        t          j        |||           d {V  t	          d|i           t          t          t          j        | j	        j
        |||| j                   d {V           }|S r[  )r  rm   r&   GET_COLLECTIONrL   r   rX  r   r!  r   r  r   )rV   re   r  r@  rh  rg  s         rX   r  zFastAPI.get_collection^  s       O&
 
 	
 	
 	
 	
 	
 	
 	
 	'&'9:::#$	(.        	 
 	 
 $#rZ   zFastAPI.get_collection_by_idcollection_idc           
      $  K   |                      |j        t          j        |||           d {V  t	          d|i           t          t          t          j        | j	        j
        t          |          ||| j                   d {V           }|S r[  )r  rm   r&   rj  rL   r   rX  r   r!  r   r  _uuidr   )rV   re   r  r@  rk  rg  s         rX   r  zFastAPI.get_collection_by_id}  s       O&
 
 	
 	
 	
 	
 	
 	
 	
 	'&'9:::#$	.m$$.        	 
 	 
 $#rZ   zFastAPI.update_collectionc                     K   dt           dt          dt          dd f fd}t          j        ||||                                 d {V  j                   d {V  d S )Nre   rk  r2  rR   c                    t          t          t          j        |                    }                    | j        t          j        |           |j        sd nt          |j                  }
                    |            t          di           j                            t          |          |j        |j        |          S )Nr4  r  )idnew_namenew_metadatanew_configurationr  r  )r   r>   r5  r6  r"  rm   r&   UPDATE_COLLECTIONrs  r   r  rL   r   _modifyrm  rq  rr  )re   rk  r2  r   r`  r@  rV   r  s        rX   process_update_collectionz<FastAPI.update_collection.<locals>.process_update_collection  s     $$4fl86L6LMMF""-   /C,   %%g%666*Hf+=>>>9$$''#0"/& %   rZ   r:  r   ry   r=  r   r!  r>  r   )rV   r  r@  rk  re   rv  s   ```   rX   r  zFastAPI.update_collection  s      		-0	<A		 	 	 	 	 	 	 	<  %,,..      *
 
 
 	
 	
 	
 	
 	
 	
 	
 	
 	
rZ   zFastAPI.delete_collectionc                    K   |                      |j        t          j        |||           d {V  t	          d|i           t          j        | j        j        |||| j	                   d {V  d S r[  )
r  rm   r&   DELETE_COLLECTIONrL   r   r!  r   r  r   )rV   re   rh  r  r@  s        rX   r  zFastAPI.delete_collection  s       O)
 
 	
 	
 	
 	
 	
 	
 	
 	'&'9::: I'*
 
 
 	
 	
 	
 	
 	
 	
 	
 	
 	
rZ   zFastAPI.attach_functionc                    K   	 dt           dt          dt          t          t          f         f fd}|                                 d {V }t          j        ||| j                   d {V S # t          $ r  w xY w)Nre   r2  rR   c           	         t          j        |          }
                    | j        t          j        	           
                    |            |                    d          }|                    d          }|                    d          }|                    d          }
j        	                    ||t                    ||	          }dt          |j                  |j        |j        |j        |j        diS )	Nr4  r`   function_idoutput_collectionparams)r|  r`   input_collection_idr}  r~  r  r  attached_functionrp  r`   function_namer}  r~  )r5  r6  r"  rm   r&   rt  r  r   r   r  rm  ry   rp  r`   r  r}  r~  )re   r2  r>  r`   r|  r}  r~  attached_fnrk  r@  rV   r  s           rX   process_attach_functionz8FastAPI.attach_function.<locals>.process_attach_function  s    |H--&&O1!!   ))'):::xx''"hh}55$(HH-@$A$A!(++"i77 +(-m(<(<&7!!* 8   (!+.11 + 0)4)B-8-J"-"4* * rZ   r:  )
r   r=  r   ry   r   r>  r   r!  r   r{   )rV   re   r  r@  rk  r  r2  s   ` ```  rX   r  zFastAPI.attach_function  s      1	% %,1%c3h% % % % % % % % %N %\\^^++++++H"+'.	           	 	 		s   A,A5 5BzFastAPI.get_attached_functionr  c                 \  K   |                      |j        t          j        |||           d {V  t	          d|i           t          j        | j        j        |t          |          ||| j
                   d {V }dt          |j                  |j        |j        |j        |j        diS )Nr  r:  r  r  )r  rm   r&   rj  rL   r   r!  r   r  rm  r   ry   rp  r`   r  r}  r~  )rV   re   r  r@  rk  r  r  s          rX   r  zFastAPI.get_attached_function   s       O&
 
 	
 	
 	
 	
 	
 	
 	
 	'&'9:::%.I+-  *
 
 
 
 
 
 
 
 
  +.))#(!,!:%0%B%," "
 	
rZ   zFastAPI.addc           	      H   K   	 dt           dt          dt          f fd}t          t          t	          j        |||                                 d {V  j                   d {V           S # t          $ r#}t          dt          |                    d }~ww xY w)Nre   r2  rR   c           
         t          t          t          j        |                    }                    | j        t          j                                       |            t          di           j
                            t                    |j        t          t          |j        rt#          |j                  nd           |j        |j        |j                  S Nr4  r  )rk  ids
embeddings	metadatas	documentsurisr  r  )r   r7   r5  r6  r"  rm   r&   ADDr  rL   r   _addrm  r  r   r#   r  r$   r  r  r  )re   r2  r   rk  r@  rV   r  s      rX   process_addz FastAPI.add.<locals>.process_addR  s    $\6<3I3IJJ&&OO!!   ))'):::.&/ABBBy~~"'"6"6#">"5cnEEE!	    "m!m!* &   rZ   r:  rw   rv   detailr   r=  r   r   r   r!  r>  r   r0   r   ry   )rV   re   r  r@  rk  r  r   s   ` ```  rX   r   zFastAPI.addG  s     (	@W  $         8 (!,,..(((((( 2	           ) 	@ 	@ 	@CA????	@s   A+A4 4
B!>BB!zFastAPI.updatec                     K   dt           dt          dt          f fd}t          j        |||                                 d {V  j                   d {V  d S )Nre   r2  rR   c           
         t          t          t          j        |                    }                    | j        t          j                                       |            t          di           j
                            t                    |j        |j        rt          |j                  nd |j        |j        |j                  S r  )r   r?   r5  r6  r"  rm   r&   UPDATEr  rL   r   _updaterm  r  r  r$   r  r  r  )re   r2  r   rk  r@  rV   r  s      rX   process_updatez&FastAPI.update.<locals>.process_update  s    #OV\(5K5KLLF """   %%g%666*Hf+=>>>9$$#M22J$89JKKK * *[& %   rZ   r:  r   r=  r   r   r!  r>  r   )rV   re   r  r@  rk  r  s   ` ``` rX   r   zFastAPI.updatez  s      	G 	u 	 	 	 	 	 	 	 	 	 	6  ,,..      *	
 
 
 	
 	
 	
 	
 	
 	
 	
 	
 	
rZ   zFastAPI.upsertc                     K   dt           dt          dt          f fd}t          j        |||                                 d {V  j                   d {V  d S )Nre   r2  rR   c           
         t          t          t          j        |                    }                    | j        t          j                                       |            t          di           j
                            t                    |j        t          t          |j        rt#          |j                  nd           |j        |j        |j                  S r  )r   r7   r5  r6  r"  rm   r&   UPSERTr  rL   r   _upsertrm  r  r   r#   r  r$   r  r  r  )re   r2  r   rk  r@  rV   r  s      rX   process_upsertz&FastAPI.upsert.<locals>.process_upsert  s    #L&,x2H2HIIF """   %%g%666*Hf+=>>>9$$#M22J(1&2CDDD	  !* *[& %   rZ   r:  r  )rV   re   r  r@  rk  r  s   ` ``` rX   r   zFastAPI.upsert  s      	G 	u 	 	 	 	 	 	 	 	 	 	<  ,,..      *	
 
 
 	
 	
 	
 	
 	
 	
 	
 	
 	
rZ   zFastAPI.getc           	      $   K   dt           dt          dt          f fd}t          t          t	          j        |||                                 d {V  j                   d {V           }|d         d |d         D             |d<   |S )Nre   r2  rR   c                    t          t          t          j        |                    }                    | j        t          j                                       |            t          di           j
                            t                    |j        |j        |j        |j        |j        |j        	  	        S )Nr4  r  )	rk  r  whererO  rP  where_documentincluder  r  )r   r;   r5  r6  r"  rm   r&   r   r  rL   r   _getrm  r  r  rO  rP  r  r  )re   r2  r   rk  r@  rV   r  s      rX   process_getz FastAPI.get.<locals>.process_get  s     v|H/E/EFFC""   %%g%666*Hf+=>>>9>>#M22Giiz"1& " 
 
 
rZ   r:  r  c                 \    g | ])}t          t          |                                          *S  r   r    tolist.0	embeddings     rX   
<listcomp>zFastAPI.get.<locals>.<listcomp>  >     ( ( ( Y	**1133( ( (rZ   r   r=  r!   r   r   r!  r>  r   )rV   rk  r  r@  re   r  
get_results   ````   rX   r   zFastAPI.get  s      	 	E 	i 	 	 	 	 	 	 	 	 	0 $llnn$$$$$$.	        
 

 l#/( (!+L!9( ( (J|$
 rZ   zFastAPI.deletec                     K   dt           dt          dt          f fd}t          j        |||                                 d {V  j                   d {V S )Nre   r2  rR   c           	      t   t          t          t          j        |                    }                    | j        t          j                                       |            t          di           j
                            t                    |j        |j        |j        |j                  S )Nr4  r  )rk  r  r  r  rO  r  r  )r   r:   r5  r6  r"  rm   r&   r   r  rL   r   _deleterm  r  r  r  rO  )re   r2  r   rk  r@  rV   r  s      rX   process_deletez&FastAPI.delete.<locals>.process_delete  s    #OV\(5K5KLLF"""   %%g%666*Hf+=>>>9$$#M22Jl%4l& %   rZ   r:  r   r=  r   r   r!  r>  r   )rV   rk  r  r@  re   r  s   ````  rX   r   zFastAPI.delete  s      	G 	u 	 	 	 	 	 	 	 	 	 	, ',,..      *	
 
 
 
 
 
 
 
 
 	
rZ   zFastAPI.countc           
         K   |                      |j        t          j        |||           d {V  t	          d|i           t          t          t          j        | j	        j
        t          |          ||| j                   d {V           S r[  )r  rm   r&   COUNTrL   r   rW  r   r!  r   _countrm  r   )rV   re   r  r@  rk  s        rX   r   zFastAPI.count,  s       O
 
 	
 	
 	
 	
 	
 	
 	
 	'&'9:::$	 m$$.        	
 	
 		
rZ   zFastAPI.resetc                    K   |                      |j        t          j        d d d            d {V  t	          t
          t          j        | j        j	        | j
                   d {V           S rB  )r  rm   r&   RESETr   r   r   r!  r   r   r   r  s     rX   r   zFastAPI.resetJ  s       O
 
 	
 	
 	
 	
 	
 	
 	
 $	.        
 
 	
rZ   zFastAPI.get_nearest_neighborsc           	      d   K   t          dt          j                  dt          dt          dt
          f fd            }t          t
          t          j        |||	                                 d {V  j
                   d {V           }|d         d |d         D             |d<   |S )	Nzinternal.get_nearest_neighborsre   r2  rR   c           
         t          t          t          j        |                    }                    | j        t          j                                       |            t          di           j
                            t                    t          t          |j        rt!          |j                  nd           |j        |j        |j        |j                  S )Nr4  r  )rk  query_embeddings	n_resultsr  r  r  r  r  )r   r<   r5  r6  r"  rm   r&   QUERYr  rL   r   _queryrm  r   r#   r  r$   r  r  r  r  )re   r2  queryrk  r@  rV   r  s      rX   process_queryz4FastAPI.get_nearest_neighbors.<locals>.process_queryj  s     #>6<3I3IJJE ""!   %%g%666*Hf+=>>>9###M22!%-1%2HIII	" "  /k$3& $   rZ   r:  r  c                 &    g | ]}d  |D             S )c                 \    g | ])}t          t          |                                          *S r  r  r  s     rX   r  z<FastAPI.get_nearest_neighbors.<locals>.<listcomp>.<listcomp>  .    MMMi++2244MMMrZ   r  r  results     rX   r  z1FastAPI.get_nearest_neighbors.<locals>.<listcomp>  7     & & & NMfMMM& & &rZ   )rM   rK   	OPERATIONr   r=  r"   r   r   r!  r>  r   )rV   r  r@  rk  re   r  nnresults   ````   rX   r  zFastAPI.get_nearest_neighborsa  s      
,.F.P

 

	7 	e 	 	 	 	 	 	 	 	 	

 

	< $llnn$$$$$$.	        
 
 L!-& &&|4& & &H\"
 rZ   c                     K   dt           t          t          f         f fd}t          t           t          t          f         t	          j        | j                   d {V           S )NrR   c                  :    d j                                         iS )Nmax_batch_size)r   get_max_batch_sizer  s   rX   process_pre_flight_checksz<FastAPI.pre_flight_checks.<locals>.process_pre_flight_checks  s      $)">">"@"@ rZ   r:  )r   ry   r   r   r   r!  r   )rV   r  s   ` rX   r   zFastAPI.pre_flight_checks  s      	4S> 	 	 	 	 	 	
 cN$).        
 
 	
rZ   c           
      @   | j                             d| j        dg           | j                             d| j        dg           | j                             d| j        dg           | j                             d| j        dg           | j                             d| j        dg           | j                             d	| j        dgd |                     t                    
           | j                             d| j
        dgd            | j                             d| j        dgd |                     t                    
           | j                             d| j        dgd            | j                             d| j        dgd            | j                             d| j        dgd            | j                             d| j        dgd |                     t"                    
           | j                             d| j        dgt&          j        d |                     t*                               | j                             d| j        dgd |                     t.                    
           | j                             d| j        dgd |                     t*                    
           | j                             d| j        dgd |                     t4                    
           | j                             d| j        dgt8          |                     t:                    
           | j                             d| j        dgd            | j                             d| j        dgd |                     t@                    
           | j                             d| j!        dgd            | j                             d| j"        dgd |                     tF                    
           | j                             d| j$        dgd            d S )Nz/api/v1r   r   z/api/v1/resetr   z/api/v1/versionz/api/v1/heartbeatz/api/v1/pre-flight-checksz/api/v1/databasesr   z/api/v1/databases/{database}r   z/api/v1/tenantsz/api/v1/tenants/{tenant}z/api/v1/collectionsz/api/v1/count_collectionsz'/api/v1/collections/{collection_id}/addr   z*/api/v1/collections/{collection_id}/updatez*/api/v1/collections/{collection_id}/upsertz'/api/v1/collections/{collection_id}/getz*/api/v1/collections/{collection_id}/deletez)/api/v1/collections/{collection_id}/countz)/api/v1/collections/{collection_id}/queryz%/api/v1/collections/{collection_name}z#/api/v1/collections/{collection_id}r   r   )%r   r   r   r   r   r   r   create_database_v1r   r8   get_database_v1create_tenant_v1r9   get_tenant_v1list_collections_v1count_collections_v1create_collection_v1r=   add_v1r   r   r7   	update_v1r?   	upsert_v1get_v1r;   	delete_v1r   r:   count_v1get_nearest_neighbors_v1r<   get_collection_v1update_collection_v1r>   delete_collection_v1r  s    rX   r   zFastAPI.setup_v1_routes  s   !!)TY!HHH!!/4:x!PPP!!"3T\E7!SSS!!"5t~PUw!WWW!!')?% 	" 	
 	
 	
 	!!#H@@PP 	" 	
 	
 	
 	!!* G	 	" 	
 	
 	
 	!!!H@@NN 	" 	
 	
 	
 	!!&G	 	" 	
 	
 	
 	!!!$G	 	" 	
 	
 	
 	!!'%G	 	" 	
 	
 	
 	!!!%H@@AQRR 	" 	
 	
 	
 	!!5KH/@@NN 	" 	
 	
 	
 	!!8NH@@QQ 	" 	
 	
 	
 	!!8NH@@NN 	" 	
 	
 	
 	!!5KH@@NN 	" 	
 	
 	
 	!!8NH'@@QQ 	" 	
 	
 	
 	!!7MG	 	" 	
 	
 	
 	!!7)H@@PP 	" 	
 	
 	
 	!!3"G	 	" 	
 	
 	
 	!!1%G@@AQRR 	" 	
 	
 	
 	!!3%J	 	" 	
 	
 	
 	
 	
rZ   /auth_and_get_tenant_and_database_for_request_v1c                 N   K   t          j        | j        |||||           d{V S )a  
        Authenticates and authorizes the request based on the given headers
        and other parameters. If the request cannot be authenticated or cannot
        be authorized (with the configured providers), raises an HTTP 401.

        If the request is authenticated and authorized, returns the tenant and
        database to be used for the request. These will differ from the passed
        tenant and database if and only if:
        - The request is authenticated
        - chroma_overwrite_singleton_tenant_database_access_from_auth = True
        - The passed tenant or database are None or default_{tenant, database}
            (can be overwritten separately)
        - The user has access to a single tenant and/or single database.
        N)r   r!  1sync_auth_and_get_tenant_and_database_for_requestr#  s         rX   ,auth_and_get_tenant_and_database_for_requestz4FastAPI.auth_and_get_tenant_and_database_for_request.  sP      6 'B
 
 
 
 
 
 
 
 	
rZ   c                    | j         st          |||d           ||fS | j                             t          |                    }| j                             |          \  }}|r|t
          k    r|r|}|r|t          k    r|r|}| j        s||fS t          |||          }	| j        	                    |||	           t          |||d           ||fS )Nr%  )
r   rL   r&  r'  'singleton_tenant_database_if_applicabler+   r*   r   r'   r(  )
rV   rm   r  r  r  r  r)  
new_tenantnew_databaser*  s
             rX   r  z9FastAPI.sync_auth_and_get_tenant_and_database_for_requestT  s;    " 	&*$ (",    H%%+AA$w--PP
 GGVV	
  	 &N22
2F 	$H(888l8#H" 	&H%%&!
 
 
 	..}fnUUU& $( 	
 	
 	
 !!rZ   zFastAPI.create_database_v1c                     K   dt           dt          dt          dd f fd}t          j        |||j        |                                 d {V  j                   d {V  d S )Nr  rm   r2  rR   c                    t          t          t          j        |                    }                    |t
          j        | |j        d           \  }}|r|} |r||_        j        	                    |j        |           S r
  )
r   r8   r5  r6  r  r&   r7  r`   r   r   )r  rm   r2  r8  maybe_tenantmaybe_databaserV   s         rX   r9  z;FastAPI.create_database_v1.<locals>.process_create_database  s      X0F0FGGB FF+ 	  &% )(9,,RWf===rZ   r:  r<  r?  s   `   rX   r  zFastAPI.create_database_v1  s      	>	>")	>5:	>	> 	> 	> 	> 	> 	>.  #O,,..      *
 
 
 	
 	
 	
 	
 	
 	
 	
 	
 	
rZ   zFastAPI.get_database_v1c           	         K   |                      |j        t          j        ||d            d {V \  }}|r|}|r|}t	          t
          t          j        | j        j	        ||| j
                   d {V           S rB  )r  rm   r&   rC  r   rF   r   r!  r   r   r   )rV   re   r  r  r  r  s         rX   r  zFastAPI.get_database_v1  s       CCO$
 
 
 
 
 
 
 
	
  	"!F 	&%H$	&.	        
 
 	
rZ   zFastAPI.create_tenant_v1c                     K   dt           dt          dd f fd}t          j        |||                                 d {V  j                   d {V  d S )Nre   r2  rR   c                    t          t          t          j        |                    }                    | j        t          j        |j        d d           \  }}|r||_        j	        
                    |j                  S r
  )r   r9   r5  r6  r  rm   r&   rI  r`   r   r   )re   r2  r  r  _rV   s        rX   rJ  z7FastAPI.create_tenant_v1.<locals>.process_create_tenant  sv    #L&,x2H2HIIF #TT) OL!  +*9**6;777rZ   r:  rK  rL  s   `  rX   r  zFastAPI.create_tenant_v1  s      	87 	8e 	8 	8 	8 	8 	8 	8 	8   !,,..      *	
 
 
 	
 	
 	
 	
 	
 	
 	
 	
 	
rZ   zFastAPI.get_tenant_v1c                    K   |                      |j        t          j        |d d            d {V \  }}|r|}t	          t
          t          j        | j        j	        || j
                   d {V           S rB  )r  rm   r&   rN  r   rG   r   r!  r   r   r   )rV   re   r  r  r  s        rX   r  zFastAPI.get_tenant_v1  s       !% Q QO"!
 !
 
 
 
 
 
 
a  	"!F$	$.        
 
 	
rZ   zFastAPI.list_collections_v1c                   K   |                      |j        t          j        ||d            d {V \  }}|r|}|r|}t	          t
          t                   t          j        | j	        j
        ||||| j                   d {V           }|S rB  )r  rm   r&   rU  r   r   rX  r   r!  r   r   r   )	rV   re   rO  rP  r  r  r  r  rY  s	            rX   r  zFastAPI.list_collections_v1  s       CCO(
 
 
 
 
 
 
 
	
  	"!F 	&%H $_%$	*.        
!
 
!
 %$rZ   zFastAPI.count_collections_v1c           	         K   |                      |j        t          j        ||d            d {V \  }}|r|}|r|}t	          t
          t          j        | j        j	        ||| j
                   d {V           S rB  )r  rm   r&   r\  r   rW  r   r!  r   r   r   )rV   re   r  r  r  r  s         rX   r  zFastAPI.count_collections_v1*  s       CCO)
 
 
 
 
 
 
 
	
  	"!F 	&%H$	+.	        
 
 	
rZ   zFastAPI.create_collection_v1c                     K   dt           dt          dt          dt          dt          f
 fd}t	          t          t          j        |||||                                 d {V  j                   d {V           }|S )Nre   r  r  r2  rR   c                 r   t          t          t          j        |                    }|j        st                      nt          |j                  }                    | j        t          j
        |||j                  \  }}|r|}|r|}j                            |j        ||j        |j        ||          S )Nr_  )r   r=   r5  r6  r`  r   r   r  rm   r&   rc  r`   r   r   ra  rb  )	re   r  r  r2  rd  r`  r  r  rV   s	           rX   re  z?FastAPI.create_collection_v1.<locals>.process_create_collectionS  s     $$4fl86L6LMMF +-///C(   FF- 	  &% *)9..[+$2! /   rZ   r:  rf  )rV   re   r  r  re  rg  s   `     rX   r  zFastAPI.create_collection_v1K  s      #	#	&)#	58#	DI#	#	 #	 #	 #	 #	 #	J  $$)llnn$$$$$$.        
 
 
 
 $#rZ   zFastAPI.get_collection_v1c                     K                         |j        t          j                   d {V \  }}|r||r| fd} |             d {V S )Nc            
         K   t          t          t          j        j        j        j                   d {V           } | S rB  )r   rX  r   r!  r   r  r   )rg  rh  r  rV   r  s    rX   innerz(FastAPI.get_collection_v1.<locals>.inner  sl      #'(I,# 2        	$ 	$  ('rZ   )r  rm   r&   rj  )rV   re   rh  r  r  r  r  r  s   ` ```   rX   r  zFastAPI.get_collection_v1  s       CCO&
 
 
 
 
 
 
 
	
  	"!F 	&%H	( 	( 	( 	( 	( 	( 	( 	( UWW}}}}}}rZ   zFastAPI.update_collection_v1c                     K   dt           dt          dt          dd f fd}t          j        ||||                                 d {V  j                   d {V  d S )Nre   rk  r2  rR   c                 F   t          t          t          j        |                    }                    | j        t          j        d d |           |j        sd nt          |j                  }j
                            t          |          |j        |j        |          S )N)rp  rq  rr  rs  )r   r>   r5  r6  r  rm   r&   rt  rs  r   r   ru  rm  rq  rr  )re   rk  r2  r   r`  rV   s        rX   rv  z?FastAPI.update_collection_v1.<locals>.process_update_collection  s     $$4fl86L6LMMFBB-   /C,   9$$''#0"/	 %   rZ   r:  rw  )rV   rk  re   rv  s   `   rX   r  zFastAPI.update_collection_v1  s      		-0	<A		 	 	 	 	 	4  %,,..      *
 
 
 	
 	
 	
 	
 	
 	
 	
 	
 	
rZ   zFastAPI.delete_collection_v1c                    K   |                      |j        t          j        |||           d {V \  }}|r|}|r|}t	          j        | j        j        |||| j                   d {V  d S rB  )	r  rm   r&   ry  r   r!  r   r  r   )rV   re   rh  r  r  r  r  s          rX   r  zFastAPI.delete_collection_v1  s       CCO)
 
 
 
 
 
 
 
	
  	"!F 	&%H I'*
 
 
 	
 	
 	
 	
 	
 	
 	
 	
 	
rZ   zFastAPI.add_v1c           	      @   K   	 dt           dt          dt          f fd}t          t          t	          j        |||                                 d {V  j                   d {V           S # t          $ r#}t          dt          |                    d }~ww xY w)Nre   r2  rR   c           
         t          t          t          j        |                    }                    | j        t          j        d d            j        	                    t                    |j        t          t          |j        rt          |j                  nd           |j        |j        |j                  S N)rk  r  r  r  r  r  )r   r7   r5  r6  r  rm   r&   r  r   r  rm  r  r   r#   r  r$   r  r  r  )re   r2  r   rk  rV   s      rX   r  z#FastAPI.add_v1.<locals>.process_add  s    $\6<3I3IJJFFOO!   y~~"'"6"6#">"5cnEEE!	    "m!m &   rZ   r:  rw   r  r  )rV   re   rk  r  r   s   ` `  rX   r  zFastAPI.add_v1  s      $	@W  $       0 (!,,..(((((( 2	           ) 	@ 	@ 	@CA????	@s   A)A0 0
B:BBzFastAPI.update_v1c                     K   dt           dt          dt          f fd}t          j        |||                                 d {V  j                   d {V  d S )Nre   r2  rR   c                 Z   t          t          t          j        |                    }                    | j        t          j        d d            j        	                    t                    |j        |j        rt          |j                  nd |j        |j        |j                  S r  )r   r?   r5  r6  r  rm   r&   r  r   r  rm  r  r  r$   r  r  r  )re   r2  r   rk  rV   s      rX   r  z)FastAPI.update_v1.<locals>.process_update(  s    #OV\(5K5KLLF BB"   9$$#M22J$89JKKK * *[ % 	 	 	rZ   r:  r  )rV   re   rk  r  s   ` ` rX   r  zFastAPI.update_v1"  s      	G 	u 	 	 	 	 	 	 	 	.  ,,..      *	
 
 
 	
 	
 	
 	
 	
 	
 	
 	
 	
rZ   zFastAPI.upsert_v1c                     K   dt           dt          dt          f fd}t          j        |||                                 d {V  j                   d {V  d S )Nre   r2  rR   c           
         t          t          t          j        |                    }                    | j        t          j        d d            j        	                    t                    |j        t          t          |j        rt          |j                  nd           |j        |j        |j                  S r  )r   r7   r5  r6  r  rm   r&   r  r   r  rm  r  r   r#   r  r$   r  r  r  )re   r2  r   rk  rV   s      rX   r  z)FastAPI.upsert_v1.<locals>.process_upsertM  s    #L&,x2H2HIIF BB"   9$$#M22J(1&2CDDD	  !* *[ %   rZ   r:  r  )rV   re   rk  r  s   ` ` rX   r  zFastAPI.upsert_v1F  s      	G 	u 	 	 	 	 	 	 	 	4  ,,..      *	
 
 
 	
 	
 	
 	
 	
 	
 	
 	
 	
rZ   zFastAPI.get_v1c           	         K   dt           dt          dt          f fd}t          t          t	          j        |||                                 d {V  j                   d {V           }|d         d |d         D             |d<   |S )Nre   r2  rR   c           	      :   t          t          t          j        |                    }                    | j        t          j        d d            j        	                    t                    |j        |j        |j        |j        |j        |j                  S )N)rk  r  r  rO  rP  r  r  )r   r;   r5  r6  r  rm   r&   r   r   r  rm  r  r  rO  rP  r  r  )re   r2  r   rk  rV   s      rX   r  z#FastAPI.get_v1.<locals>.process_getu  s     v|H/E/EFFCBB   9>>#M22Giiz"1 "   rZ   r:  r  c                 \    g | ])}t          t          |                                          *S r  r  r  s     rX   r  z"FastAPI.get_v1.<locals>.<listcomp>  r  rZ   r  )rV   rk  re   r  r  s   ``   rX   r  zFastAPI.get_v1n  s      	 	E 	i 	 	 	 	 	 	 	( $llnn$$$$$$.	        
 

 l#/( (!+L!9( ( (J|$
 rZ   zFastAPI.delete_v1c                     K   dt           dt          dt          f fd}t          j        |||                                 d {V  j                   d {V S )Nre   r2  rR   c                 "   t          t          t          j        |                    }                    | j        t          j        d d            j        	                    t                    |j        |j        |j        |j                  S )N)rk  r  r  r  rO  )r   r:   r5  r6  r  rm   r&   r   r   r  rm  r  r  r  rO  )re   r2  r   rk  rV   s      rX   r  z)FastAPI.delete_v1.<locals>.process_delete  s    #OV\(5K5KLLFBB"   9$$#M22Jl%4l %   rZ   r:  r  )rV   rk  re   r  s   ``  rX   r  zFastAPI.delete_v1  s      	G 	u 	 	 	 	 	 	 	 	$ ',,..      *	
 
 
 
 
 
 
 
 
 	
rZ   zFastAPI.count_v1c           	         K   |                      |j        t          j        d d |           d {V  t	          t
          t          j        | j        j	        t          |          | j                   d {V           S rB  )r  rm   r&   r  r   rW  r   r!  r   r  rm  r   )rV   re   rk  s      rX   r  zFastAPI.count_v1  s       ??O
 
 	
 	
 	
 	
 	
 	
 	
 $	 m$$.        
 
 	
rZ   zFastAPI.reset_v1c                    K   |                      |j        t          j        d d d            d {V  t	          t
          t          j        | j        j	        | j
                   d {V           S rB  )r  rm   r&   r  r   r   r   r!  r   r   r   r  s     rX   reset_v1zFastAPI.reset_v1  s       ??O
 
 	
 	
 	
 	
 	
 	
 	
 $	.        
 
 	
rZ   z FastAPI.get_nearest_neighbors_v1c           	         K   dt           dt          dt          f fd}t          t          t	          j        |||                                 d {V  j                   d {V           }|d         d |d         D             |d<   |S )Nre   r2  rR   c           	         t          t          t          j        |                    }                    | j        t          j        d d            j        	                    t                    t          t          |j        rt          |j                  nd           |j        |j        |j        |j                  S )N)rk  r  r  r  r  r  )r   r<   r5  r6  r  rm   r&   r  r   r  rm  r   r#   r  r$   r  r  r  r  )re   r2  r  rk  rV   s      rX   r  z7FastAPI.get_nearest_neighbors_v1.<locals>.process_query  s    ">6<3I3IJJE BB!   9###M22!%-1%2HIII	" "  /k$3 $   rZ   r:  r  c                 &    g | ]}d  |D             S )c                 \    g | ])}t          t          |                                          *S r  r  r  s     rX   r  z?FastAPI.get_nearest_neighbors_v1.<locals>.<listcomp>.<listcomp>	  r  rZ   r  r  s     rX   r  z4FastAPI.get_nearest_neighbors_v1.<locals>.<listcomp>	  r  rZ   )r   r=  r"   r   r   r!  r>  r   )rV   rk  re   r  r  s   ``   rX   r  z FastAPI.get_nearest_neighbors_v1  s      	7 	e 	 	 	 	 	 	 	 	4 $llnn$$$$$$.	        
 
 L!-& &&|4& & &H\"
 rZ   )rR   N)NN)_r   r   r   r,   r   r   ry   r   r   r	   r   r   r   r   r   r   r[   r   r2   r   r   rW  r   r3   r   r   r   r  rM   rK   r  rU   r@   r&   r   r  r"  r%   r   r   rF   r   r   r   rG   r   r   r   rX  r   r   r   r  r  r  r  r  r  r   r   r   r   r!   r   r   r   r   r   r"   r  r   r   r   r  r  r+   r  r  r  r  r*   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rZ   rX   r   r      sn       45 45 45 45 45l$sCx.    !!W	c3h   $j
 j
 j
 j
X   W_    

%3
	
 
 
 
?d38n ? ? ? ?

%/
	
 
 
 
c3h    's ' ' ' 'GG G G G G G \ *  

 
 	

 3-
 SM
 

 
 
 Z	 

 \# * ** * 	*
 3-* SM* 
* * *	 *X \-/G/QRR

 

 
 
 SR
$ \+-E-OPP

 
 
	
 
 
 QP
> \(*B*LMM

 
 	

 

 
 
 NM
2 \+-E-OPP

 
 	

 

 
 
 QP
, \)+C+MNN

 

 
 
 ON
2 \&(@(JKK

 
 
	
 
 
 LK
. \*,D,NOO
  $ $
 

 
 }	

 
 
(	
 
 
 PO
6 \,.F.PQQ  $ $'% '%'% '% 	'%
 }'% '% 
/	"'% '% '% RQ'%R \-/G/QRR

 
 	

 

 
 
 SR
6 \-/G/QRR9$9$ 9$ 	9$
 
9$ 9$ 9$ SR9$v \*,D,NOO$$ $ 	$
 $ 
$ $ $ PO$< \02J2TUU$$ $ 	$
 $ 
$ $ $ VU$< \-/G/QRR+
+
 +
 	+

 +
 
+
 +
 +
 SR+
Z \-/G/QRR

 
 	

 
 

 
 
 SR
2 \+-E-OPP88 8 	8
 8 
c3h8 8 8 Z QP8t \13K3UVV#
#
 #
 	#

 #
 #
 
c3h#
 #
 #
 Z WV#
J \-!9!CDD/@/@ /@ 	/@
 /@ 
/@ /@ /@ Z ED/@b \"$<$FGG'
'
 '
 	'

 '
 
'
 '
 '
 Z HG'
R \"$<$FGG*
*
 *
 	*

 *
 
*
 *
 *
 Z HG*
X \-!9!CDD// / 	/
 / 
/ / / Z ED/b \"$<$FGG"
"
 "
 	"

 "
 
"
 "
 "
 Z HG"
H \/#;#EFF

 
 	

 
 

 
 
 Z GF
8 \/#;#EFF

 

 
 
 Z GF
* \13K3UVV88 8 	8
 8 
8 8 8 Z WV8t
c3h 
 
 
 
"~
 ~
 ~
 ~
@ \9 *  

 
 	

 3-
 SM
 
x}hsm+	,
 
 
 Z	 

B/"/" /" 	/"
 3-/" SM/" 
x}hsm+	,/" /" /" /"b \.0H0RSS %"
 "
"
 "
 
	"
 "
 "
 Z TS"
H \+-E-OPP
 %	
 

 
 	

 

 
 
 Z QP
> \,.F.PQQ

 

 
 
 Z RQ
6 \)+C+MNN

 
 
	
 
 
 Z ON
0 \/1I1STT  $ $$(#% #%#% }#% 	#%
 #% #% 
/	"#% #% #% Z UT#%J \02J2TUU %(	
 

 
 	

 

 
 
 Z VU
> \02J2TUU %(	6$ 6$6$ 6$ 	6$
 
6$ 6$ 6$ Z VU6$p \-/G/QRR
 %(# ## # 	#
 # 
# # # Z SR#J \02J2TUU%
%
 %
 
	%
 %
 %
 Z VU%
N \02J2TUU
 %(
 

 
 	

 
 

 
 
 Z VU
< \"$<$FGG)@)@ )@ 
	)@ )@ )@ Z HG)@V \%'?'IJJ!
!
 !
 
	!
 !
 !
 KJ!
F \%'?'IJJ$
$
 $
 
	$
 $
 $
 Z KJ$
L \"$<$FGG)) ) 
	) ) ) Z HG)V \%'?'IJJ

 
 
	
 
 
 Z KJ
< \$&>&HII

 
 
	
 
 
 Z JI
, \$&>&HII

 

 
 
 Z JI
( \*,D,N  // / 
	/ / / Z / / /rZ   r   )ytypingr   r   r   r   r   r   r	   r
   r   r   r5  anyior   r   r   _FastAPIr   r   fastapi.openapi.utilsr   fastapi.middleware.corsr   fastapi.responsesr   fastapi.routingr   r   r   	functoolsr   %chromadb.api.collection_configurationr   r   r   r   pydanticr   chromadbr   r   chromadb.api.typesr   r    r!   r"   r#   r$   chromadb.authr%   r&   r'   r(   r)   chromadb.configr*   r+   r,   r-   chromadb.apir.   chromadb.errorsr/   r0   r1   r2   r3   chromadb.quotar4   chromadb.rate_limitr5   chromadb.serverr6   chromadb.server.fastapi.typesr7   r8   r9   r:   r;   r<   r=   r>   r?   starlette.datastructuresr@   logging!chromadb.telemetry.product.eventsrA   chromadb.utils.fastapirB   rC   rm  opentelemetryrD   (chromadb.telemetry.opentelemetry.fastapirE   chromadb.typesrF   rG   chromadb.telemetry.productrH   rI    chromadb.telemetry.opentelemetryrJ   rK   rL   rM   rN   rX  	getLoggerr   r|   rU   rd   ro   r   r   r   r   	APIRouterr   r  rZ   rX   <module>r/     s  
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
          ; : : : : : : : : : - - - - - - 2 2 2 2 2 2 , , , , , , $ $ $ $ $ $ ) ) ) ) ) ) ) )                        4 4 4 4 4 4                ' & & & & &            O N N N N N N N N N N N " " " " " "              ) ( ( ( ( ( 6 6 6 6 6 6 " " " " " "
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 - , , , , ,  > > > > > > Q Q Q Q Q Q Q Q       G G G G G G + + + + + + + + L L L L L L L L            9 8 8 8 8 8		8	$	$  W( Wt W W W W!)7)S.!9   KK!)7)S.!9KK K K K,$$!)7)S.!9$$ $ $ $ GCy555%$q' % % % % % %5 5 5 5 5g' 5 5 58\! \! \! \! \!f \! \! \! \! \!rZ   