
    Bvh                     p   d dl Z d dlmZmZmZmZ d dlZd dlm	Z	m
Z
mZmZ d dlmZ 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 d dlmZ d dlm Z!  ejD                  d	      d
k(  xs  ejD                  d      d
k(  Z#dZ$ G d de	e         Z% G d de	e         Z&e G d de	e                Z'e G d de	e                Z(deddfdZ)deddfdZ*deddfdZ+deddfdZ,deddfdZ-deddfdZ.d8dZ/deddfdZ0deddfdZ1deddfd Z2e jf                  ji                  e#e$!      d8d"       Z5deddfd#Z6deddfd$Z7deddfd%Z8e jf                  ji                  e#e$!      deddfd&       Z9e jf                  ji                  e#e$!      deddfd'       Z:d9d(Z;e jf                  ji                  e#e$!      deddfd)       Z<deddfd*Z=d9d+Z>deddfd,Z?deddfd-Z@deddfd.ZAdeddfd/ZBdeddfd0ZCdeddfd1ZDdeddfd2ZEdeddfd3ZFdeddfd4ZGdeddfd5ZHdeddfd6ZIdeddfd7ZJy):    N)DictAnycastList)EmbeddingFunction
EmbeddingsSpace
Embeddable)	ClientAPI)	CreateCollectionConfigurationUpdateCollectionConfiguration'load_collection_configuration_from_jsonCreateHNSWConfigurationUpdateHNSWConfigurationCreateSpannConfigurationUpdateSpannConfigurationSpannConfigurationoverwrite_spann_configuration)register_embedding_function)ClientFactories)
CollectionCHROMA_RUST_BINDINGS_TEST_ONLY1CHROMA_INTEGRATION_TEST_ONLYzPSPANN creation/modification disallowed in Rust bindings or integration test modec                   $    e Zd ZddZdedefdZy)LegacyEmbeddingFunctionreturnNc                      y N selfs    d/RAG/venv/lib/python3.12/site-packages/chromadb/test/configurations/test_collection_configuration.py__init__z LegacyEmbeddingFunction.__init__)           inputc                 n    t        t        t        j                  ddggt        j                              S N      ?       @dtyper   r   nparrayfloat32r"   r'   s     r#   __call__z LegacyEmbeddingFunction.__call__,   $    J3*RZZ HIIr&   r   N)__name__
__module____qualname__r$   r
   r   r3   r    r&   r#   r   r   (   s    Jj JZ Jr&   r   c                   :    e Zd ZddZdedefdZedefd       Z	y)LegacyEmbeddingFunctionWithNamer   Nc                      y r   r    r!   s    r#   r$   z(LegacyEmbeddingFunctionWithName.__init__1   r%   r&   r'   c                 n    t        t        t        j                  ddggt        j                              S r)   r.   r2   s     r#   r3   z(LegacyEmbeddingFunctionWithName.__call__4   r4   r&   c                       y)N	legacy_efr    r    r&   r#   namez$LegacyEmbeddingFunctionWithName.name7       r&   r5   )
r6   r7   r8   r$   r
   r   r3   staticmethodstrr?   r    r&   r#   r:   r:   0   s8    Jj JZ J #  r&   r:   c                       e Zd ZddefdZdedefdZede	fd       Z
dee	ef   fdZedee	ef   dd fd	       Zdefd
Zy)CustomEmbeddingFunctiondimc                     || _         y r   _dimr"   rE   s     r#   r$   z CustomEmbeddingFunction.__init__>   	    	r&   r'   r   c                     t        t        t        j                  dg| j                  z  gt        j
                              S )Nr*   r,   r   r   r/   r0   rH   r1   r2   s     r#   r3   z CustomEmbeddingFunction.__call__A   ,    J3%$))*;)<BJJ OPPr&   c                       y)N	custom_efr    r    r&   r#   r?   zCustomEmbeddingFunction.nameD   r@   r&   c                     d| j                   iS NrE   rG   r!   s    r#   
get_configz"CustomEmbeddingFunction.get_configH       tyy!!r&   configc                      t        | d         S NrE   rE   )rD   rT   s    r#   build_from_configz)CustomEmbeddingFunction.build_from_configK   s    &6%=99r&   c                      y)Ncosiner    r!   s    r#   default_spacez%CustomEmbeddingFunction.default_spaceO   s    r&   N)   r6   r7   r8   intr$   r
   r   r3   rA   rB   r?   r   r   rR   rY   r	   r\   r    r&   r#   rD   rD   <   s    C Qj QZ Q #  "DcN " :$sCx. :5N : :u r&   rD   c                       e Zd ZddefdZdedefdZede	fd       Z
dee	ef   fdZedee	ef   dd fd	       Zdefd
Zy)CustomEmbeddingFunction2rE   c                     || _         y r   rG   rI   s     r#   r$   z!CustomEmbeddingFunction2.__init__U   rJ   r&   r'   r   c                     t        t        t        j                  dg| j                  z  gt        j
                              S )Nr+   r,   rL   r2   s     r#   r3   z!CustomEmbeddingFunction2.__call__X   rM   r&   c                       y)N
custom_ef2r    r    r&   r#   r?   zCustomEmbeddingFunction2.name[   s    r&   c                     d| j                   iS rQ   rG   r!   s    r#   rR   z#CustomEmbeddingFunction2.get_config_   rS   r&   rT   c                      t        | d         S rV   )ra   rX   s    r#   rY   z*CustomEmbeddingFunction2.build_from_configb   s    'F5M::r&   c                      y)Nl2r    r!   s    r#   r\   z&CustomEmbeddingFunction2.default_spacef   s    r&   N)   r^   r    r&   r#   ra   ra   S   s    C Qj QZ Q #  "DcN " ;$sCx. ;5O ; ;u r&   ra   clientr   c                    | j                          | j                  dt                     }t        |j                  j
                        }|r%t        |t              r|j                  d      }|J J d|        | j                  dt                     }|j                  dgdg       |j                  dgd	
      }t        |d         d	k(  sJ yzETest creating and getting collections with legacy embedding functionstest_legacyr?   embedding_functionrp   Nzconfig: r   testids	documents   query_texts	n_resultsrs   )resetcreate_collectionr   r   _modelconfiguration_json
isinstancedictgetget_collectionaddquerylenrk   collrT   efcoll2resultss         r#   test_legacy_embedding_functionr   j   s    
LLN ##24 $ D 5T[[5S5STF*VT*ZZ,-zz)))u !!24 " E 
II3%F8I,kkvh!k<Gwu~!###r&   c                    | j                          | j                  dt                     }t        |j                  j
                        }|r%t        |t              r|j                  d      }|J J d|        | j                  dt                     }|j                  dgdg       |j                  dgd	
      }t        |d         d	k(  sJ yrm   )ry   rz   r:   r   r{   r|   r}   r~   r   r   r   r   r   r   s         r#   (test_legacy_embedding_function_with_namer      s    
LLN ##:< $ D 5T[[5S5STF*VT*ZZ,-zz)))u !!:< " E 
II3%F8I,kkvh!k<Gwu~!###r&   c                 $   | j                          dddd}| j                  d|      }t        |j                  j                        }|rt        |t              rt        t        |j                  di             }t        |j                  d            t        d      k(  sJ |j                  d	      dk(  sJ |j                  d
      dk(  sJ |j                  d      dk(  sJ |j                  d      }|J |j                         dk(  sJ yyy)z5Test creating collections with legacy metadata formatr[      
   )z
hnsw:spacezhnsw:construction_efzhnsw:Mtest_legacy_metadata)r?   metadatahnswspaceef_constructionmax_neighbors	ef_searchd   rp   Ndefault)ry   rz   r   r{   r|   r}   r~   r   r   r   rB   r?   )rk   legacy_metadatar   rT   hnsw_configr   s         r#   r   r      s   
LLN  #O
 ###  $ D 5T[[5S5STF*VT*2FJJvr4JK;??7+,H===01S888/2555{+s222ZZ,-~~wwyI%%% +vr&   c                    | j                          dddddd}|t        d      d	}| j                  d
|      }t        |j                  j
                        }|rt        |t              ryt        t        |j                  di             }|j                  di       }|j                  d      dk(  sJ |j                  d      dk(  sJ |j                  d      dk(  sJ |J yyy)z7Test creating collections with new configuration formatr[   r   r         )r   r   r   r   num_threads   rW   r   rp   test_new_configr?   configurationr   rp   r   r   r   N)ry   rD   rz   r   r{   r|   r}   r~   r   r   r   )rk   r   rT   r   loaded_configr   s         r#   test_new_configurationr      s    
LLN ,K 5!<-F
 ## $ D <&&M M482M4E4Efb4QR3R8w'833301S888/2555~~ 9}r&   c                     | j                          t        j                  t              5 }ddd}| j	                  dd|i       dt        |j                        v sJ 	 ddd       y# 1 sw Y   yxY w)	z)Test validation of invalid configurationsr[   )r   r   test_invalidr   r   zinvalid valueN)ry   pytestraises	Exceptionrz   rB   value)rk   excinfoinvalid_hnsws      r#   test_invalid_configurationsr      sm    
LLN 
y	!W!1
 	  !<0 	! 	

 #gmm"4444 
"	!	!s   4A((A1c                    | j                          dddd}| j                  dd|i      }dd	d
}d|i}|j                  |       |j                  }|rt	        |t
              r||j                  di       }t	        |t
              rY|j                  d      dk(  sJ |j                  d      dk(  sJ |j                  d      dk(  sJ |j                  d      dk(  sJ yyyy)'Test updating collection configurationsr   ru   r[   r   r   r   test_updatesr   r   r   r   )r   r   r   r   r   r   r   r      Nry   rz   modifyr|   r}   r~   r   )rk   initial_hnswr   update_hnswupdate_configr   r   s          r#   test_hnsw_configuration_updatesr      s
   
LLN -L
 ##|, $ D ,K
 	4M 	KKmK, ++MM48#''3k4(??;/2555??7+x777??#45<<<???3r999 ) 9}r&   c                    | j                         }|j                          dddd}|t        d      d}|j                  d|	       | j                         }|j	                  d
      }t        |j                  j                        }|rt        |t              rt        t        |j                  di             }|j                  d      dk(  sJ |j                  d      dk(  sJ |j                  d      dk(  sJ |j                  d      dk(  sJ |j                  d      }|J |j                         dk(  sJ yyy)z5Test configuration persistence across client restartsr[   r   r   )r   r   r   r   rW   r   test_persist_configr   r?   r   r   r   r   r   rp   NrO   )create_client_from_systemry   rD   rz   r   r   r{   r|   r}   r~   r   r   r   r?   )client_factoriesrk   r   rT   client2r   r   r   s           r#   test_configuration_persistencer     sX    779F
LLN ,K 5!<-F
 "   88:G!!" " D <&&M M482M4E4Efb4QRw'833301S888/2555{+s22234~~wwyK''' 9}r&   c                 4   | j                          dddd}| j                  dd|i      }|j                  j                  J |j                  j                  j	                  d      }|J |j	                  d	      dk(  sJ |j	                  d
      dk(  sJ y)r   r   r   r[   r   r   r   r   Nr   r   )ry   rz   r{   r|   r   )rk   r   r   r   s       r#    test_configuration_result_formatr   I  s    
LLN -L
 ##|, $ D
 ;;))555++0044V<K"""??;'2---??7#x///r&   c                    | j                          i }|t        d      d}t        r| j                  d|      }t	        |j
                  j                        }|rt        |t              rt        t        |j                  di             }|j                  d      }|j                  d      d	k(  sJ |j                  d
      dk(  sJ |j                  d      dk(  sJ |j                  d      dk(  sJ |J yyy| j                  d|      }t	        |j
                  j                        }|rt        |t              rt        t        |j                  di             }|j                  d      }|j                  d      d	k(  sJ |j                  d
      dk(  sJ |j                  d      dk(  sJ |j                  d      dk(  sJ |j                  d      dk(  sJ |j                  d      dk(  sJ |J yyy)9Test creating collections with SPANN configuration formatr   rW   spannrp   test_spann_configr   r   rp   r   ri   r   r   r   r   r   Nr   r   @   search_nprobe   write_nprobery   rD   is_spann_disabled_moderz   r   r{   r|   r}   r~   r   r   r   r   rk   spann_configrT   r   r   hnsw_config_loadedr   spann_config_loadeds           r#   test_empty_spann_configurationr   `  s/   
LLN .0L5!<-F
 ''$  ( 
 @KK**
 Zt<!%'):):62)F" ""#78B%))'2d:::%))*;<CCC%))+6#===%))/:b@@@>!> == ''$  ( 
 @KK**
 Zt<"&(-*;*;GR*H# ""#78B&**73t;;;&**+<=DDD&**;73>>>&**?;rAAA&**?;sBBB&**>:cAAA>!> ==r&   c                    | j                          ddddddd}|t        d      d}t        r| j                  d	|
      }t	        |j
                  j                        }|rt        |t              rt        t        |j                  di             }|j                  d      }|j                  d      dk(  sJ |j                  d      dk(  sJ |j                  d      dk(  sJ |j                  d      dk(  sJ |J yyy| j                  d	|
      }t	        |j
                  j                        }|rt        |t              rt        t        |j                  di             }|j                  d      }|j                  d      dk(  sJ |j                  d      dk(  sJ |j                  d      dk(  sJ |j                  d      dk(  sJ |j                  d      dk(  sJ |j                  d      dk(  sJ |J yyy)r   r[   r   r   r   r   )r   r   r   r   r   r   rW   r   r   r   r   rp   r   r   r   r   r   Nr   r   r   r   r   r   s           r#   test_spann_configurationr     sE   
LLN .L 5!<-F
 ''$  ( 
 @KK**
 Zt<!%'):):62)F" ""#78B%))'2h>>>%))*;<CCC%))+6#===%))/:b@@@>!> == ''$  ( 
 @KK**
 Zt<"&(-*;*;GR*H# ""#78B&**73x???&**+<=DDD&**;73>>>&**?;rAAA&**?;q@@@&**>:b@@@>!> ==r&   )reasonc                    | j                         }|j                          dddddd}|t        d      d}|j                  d|	       | j                         }|j	                  d
      }t        |j                  j                        }|rt        |t              rt        t        |j                  di             }|j                  d      }|j                  d      dk(  sJ |j                  d      dk(  sJ |j                  d      dk(  sJ |j                  d      dk(  sJ |j                  d      dk(  sJ |J yyy)z;Test SPANN configuration persistence across client restartsr[   r   r   r   )r   r   r   r   r   rW   r   test_persist_spann_configr   r   r   rp   r   r   r   r   r   N)r   ry   rD   rz   r   r   r{   r|   r}   r~   r   r   r   )r   rk   r   rT   r   r   r   r   s           r#   $test_spann_configuration_persistencer     sl    779F
LLN .L 5!<-F
 (  
 88:G!!( " D <&&M M484m6G6GQS6TU34(H444 12c9990B6660A555/2555~~ 9}r&   c                     | j                          ddd}ddd}t        j                  t        d      5  | j	                  d||d	
       ddd       y# 1 sw Y   yxY w)z@Test that HNSW and SPANN configurations cannot both be specifiedr[   r   )r   r   r   )r   r   z&hnsw and spann cannot both be provided)matchtest_dual_configr   r   r   N)ry   r   r   
ValueErrorrz   )rk   r   r   s      r#   'test_exclusive_hnsw_spann_configurationr     sh    
LLN ,K
 .L 
z)Q	R  ##% 	! 	
 
S	R	Rs   AAc                 :   | j                          ddi}d|i}t        r| j                  d|      }t        |j                  j
                        }|rt        |t              rt        t        |j                  di             }|j                  d      dk(  sJ |j                  d      dk(  sJ |j                  d	      dk(  sJ |j                  d
      dk(  sJ |j                  d      }|J |j                         dk(  sJ yyy| j                  d|      }t        |j                  j
                        }|rt        |t              rt        t        |j                  di             }|j                  d      dk(  sJ |j                  d      dk(  sJ |j                  d
      dk(  sJ |j                  d	      dk(  sJ |j                  d      dk(  sJ |j                  d      dk(  sJ |j                  d      }|J |j                         dk(  sJ yyy)z,Test the default values for SPANN parametersr   r[   r   test_spann_defaultsr   r   r   r   r   r   r   rp   Nr   r   r   r   r   )ry   r   rz   r   r{   r|   r}   r~   r   r   r   r?   r   r   s           r#   test_spann_default_parametersr     sZ   
LLN 	.L 	-F ''&  ( 
 @KK**
 Zt<!%'):):62)F" &))'2h>>>%))*;<CCC%))+6#===%))/:b@@@""#78B>!>779	))) == ''&  ( 
 @KK**
 Zt<"&(-*;*;GR*H# '**73x???&**+<=DDD&**?;rAAA&**;73>>>&**?;sBBB&**>:cAAA""#78B>!>779	))) ==r&   c                 t   | j                          d}t        t        j                  |            }i }|j	                  d      "t        t        |j	                  d            |d<   |j	                  d      |j	                  d      |d<   t        r| j                  d|      }t        |j                  j                        }|rt        |t              rt        t        |j	                  di             }|j	                  d      }|j	                  d      d	k(  sJ |j	                  d
      dk(  sJ |j	                  d      dk(  sJ |j	                  d      dk(  sJ |J yyy| j                  d|      }t        |j                  j                        }|rt        |t              rt        t        |j	                  di             }|j	                  d      d	k(  sJ |j	                  d      dk(  sJ |j	                  d      dk(  sJ |j	                  d
      dk(  sJ |j	                  d      dk(  sJ yyy)zCTest serializing and deserializing SPANN configuration to/from JSONaw  
    {
        "spann": {
            "space": "cosine",
            "search_nprobe": 7,
            "write_nprobe": 15,
            "ef_construction": 200,
            "ef_search": 150
        },
        "embedding_function": {
            "type": "known",
            "name": "custom_ef",
            "config": {
                "dim": 10
            }
        }
    }
    r   Nrp   test_spann_jsonr   r   r   r[   r   r   r   r   r   r      r      r      )ry   r   jsonloadsr   r   r   r   rz   r{   r|   r}   r~   r   )	rk   config_jsoncollection_configcreate_configr   r   r   r   r   s	            r#   test_spann_json_serializationr   W  se   
LLNK( @

;@WX 46MW%1!%$&7&;&;G&D"
g 12>.?.C.C /
*+ ''"' ( 
 @KK**
 Zt<!%'):):62)F" ""#78B%))'2h>>>%))*;<CCC%))+6#===%))/:b@@@>!> == ''"' ( 
 @KK**
 Zt<"&(-*;*;GR*H# '**73x???&**?;q@@@&**>:b@@@&**+<=DDD&**;73>>> ==r&   c                    | j                          dddd}| j                  dd|i      }dd	d
}d|i}|j                  |       |j                  }|rwt	        |t
              rf|j                  di       }t	        |t
              rC|j                  d      dk(  sJ |j                  d      d	k(  sJ |j                  d      dk(  sJ yyyy)z-Test updating SPANN collection configurationsr   r   r[   )r   r   r   test_spann_updatesr   r   r   r   )r   r   r   r   r   r   Nr   )rk   initial_spannr   update_spannr   r   r   s          r#    test_configuration_spann_updatesr     s     LLN /M
 ##!. $ D .L
 	4M 	KKmK, ++MM48$(("5lD)##K0C777##O4:::##G,888	 * 9}r&   c                 @   | j                          ddddddd}| j                  dd	|i
      }t        t        dd            }|j	                  |       |j
                  }|rt        |t              r|j                  d	i       }t        |t              r|j                  d      dk(  sJ |j                  d      dk(  sJ |j                  d      dk(  sJ |j                  d      dk(  sJ |j                  d      dk(  sJ |j                  d      dk(  sJ yyyy)z;Test updating SPANN configuration from JSON and applying itr   r   r[   r      r   )r   r   r   r   r   r   test_spann_json_updater   r   r   r   r   r   )r   r   r   r   r   r   r   r   N)	ry   rz   r   r   r   r|   r}   r~   r   )rk   r   r   r   r   r   s         r#   test_spann_update_from_jsonr     sN    LLN /M ##%. $ D
 2&
M 	KKmK, ++MM48$(("5lD)##K0C777##O4:::  ##G,888##$56#===##O4:::##N3r999 * 9}r&   c                  @   ddddddd} dd	d
}t        | |      }|j                  d      dk(  sJ |j                  d      d	k(  sJ |j                  d      dk(  sJ |j                  d      dk(  sJ |j                  d      dk(  sJ |j                  d      dk(  sJ y)z8Test the overwrite_spann_configuration function directlyr[   r   r   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   N)r   r   )original_configr   updated_configs      r#   "test_overwrite_spann_configurationr     s     +O /M 3?MRN o."444k*c111 g&(222n-333/0C777o."444r&   c                     | j                          ddd}| j                  dd|i      }ddi}d	d
i}||d}t        j                  t              5  |j                  |       ddd       y# 1 sw Y   yxY w)zMTest that HNSW and SPANN configurations cannot both be specified in an updater   r[   )r   r   test_exclusive_updater   r   r   r   r   r   r   r   N)ry   rz   r   r   r   r   )rk   r   r   r   r   r   s         r#   .test_exclusive_update_hnsw_spann_configurationr     s     LLN -L ##$|, $ D 	R,K 	.L 4M 
z	"-0 
#	"	"s   A--A6c                    | j                          | j                  d      }|J |j                  J t        |j                        }|J |j	                  d      }|J |j	                  d      dk(  sJ |j	                  d      dk(  sJ |j	                  d	      d
k(  sJ |j	                  d      dk(  sJ |j	                  d      dk(  sJ |j	                  d      J |j	                  d      }|J |j                         dk(  sJ y)z.Test creating a collection with default valuestest_default_creationr   Nr   r   ri   r   r   r   r   r   sync_threshold  r   rp   r   )ry   rz   r|   r   r   r?   )rk   r   rT   r   r   s        r#    test_default_collection_creationr  9  s*   
LLN##)@#AD""...4T5L5LMF**V$K"""??7#t+++??,-444???+r111??;'3...??+,444::g&&&	(	)B>>779	!!!r&   c                      dddddddddd	i d
d} t        j                  t              5  t        |        ddd       y# 1 sw Y   yxY w)z9Test that on an invalid configuration, an error is raisedri   r   r   g333333?r  )r   r   r   r   resize_factorr  NrO   knownr?   typerT   r   r   rp   )r   r   r   r   )invalid_configs    r#   test_invalid_configurationr  R  sW     " "
 
&N  
z	"/? 
#	"	"s   A  A	c           	         | j                          | j                  d      }dddi di}t        |j                  d|dd|j                  |j
                  	      }|J |j                  dk(  sJ |j                  |k(  sJ ||_        t        j                  t              5  |j                  d
gdg       ddd       t        j                  t              5  |j                  dgd       ddd       y# 1 sw Y   @xY w# 1 sw Y   yxY w)z
    When an invalid confiugration is used, collection create, get, list_collections should all pass
    Only when trying to use the collection should an error be reaised
    test_invalid_configr   rp   rO   r  r  test_invalid_config_collectionNidr?   r|   r   	dimensiontenantdatabaser   rq   rr   ru   rv   )ry   rz   CollectionModelr  r  r  r?   r|   r{   r   r   r   r   r   )rk   r   invalid_config_jsoninvalid_collections       r#   /test_collection_load_with_invalid_configurationr  h  s
   
 LLN ##)>#?D 	
 )77-.{{ )))""&FFFF004GGGG$DK	z	"cUvh/ 
# 
z	"

x1
5 
#	" 
#	" 
#	"s   !C6D6C?Dc                    | j                          dt        d      i}| j                  d|      }|j                  }|j                  }d|v sJ |j                  d      }|j                  d      }|J |J |j                  d      dk(  sJ |j                  d	      d
k(  sJ |j                         d
k(  sJ |j                         |j                  d      k(  sJ y)zHTest that configuration_json and configuration properties are consistentrp      rW   test_config_consistencyr   Nr  r  r?   rO   rT   )ry   rD   rz   r|   r   r   r?   rR   )rk   rT   r   r   config_processedef_jsonef_processeds          r#   =test_configuration_json_vs_configuration_property_consistencyr    s    LLN 	5!<-F ##& $ D ))K));... oo23G#''(<=L###;;v')));;v+---+---""$H(====r&   c                 Z   | j                          | j                  d      }|j                  }|j                  }d|v sJ |j	                  d      }|j	                  d      }|J |J |j	                  d      dk(  sJ |j	                  d      dk(  sJ |j                         dk(  sJ y)	zPTest that default configuration_json and configuration properties are consistenttest_default_config_consistencyr   rp   Nr  r  r?   r   )ry   rz   r|   r   r   r?   )rk   r   r   r  r  r  s         r#   Etest_default_configuration_json_vs_configuration_property_consistencyr!    s     LLN ##)J#KD ))K));... oo23G#''(<=L###;;v')));;v)+++)+++r&   c           
      $   | j                          | j                  d      }dddi diddddid	id
did
diddidg}t        |      D ]  \  }}t        |j                  d| |dd|j
                  |j                        }||_        |j                  |j                  k(  sJ |j                  d| k(  sJ |j                  |k(  sJ t        j                  t              5  |j                   ddd       t        j                  t              5  |j                  dgdg       ddd       t        j                  t              5  |j                  dgd       ddd       t        j                  t              5  |j!                  dgdg       ddd       t        j                  t              5  |j#                  dg       ddd        y# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   exY w# 1 sw Y   xY w)z
    Test that invalid configurations allow list_collections, get_collection to succeed,
    but fail when _embed is called (during add, query, upsert operations)
    test_invalid_operationsr   rp   nonexistent_efr  r  rE   r]   )r  rT   r   ri   r[   r  legacyr	  test_invalid_config_Nr  r   rq   rr   ru   rv   )ry   rz   	enumerater  r  r  r  r{   r?   r|   r   r   r   r   r   r   upsert_embed)rk   r   invalid_configsir
  invalid_collection_models         r#   9test_invalid_configuration_operations_succeed_until_embedr-    s    LLN ##)B#CD !(#	
 ! !*#	
 dOx(#)8"4	
%-O2 '7>#2ww's+-;;]]$
  / ww255555yy21#6666&&.888]]:& ' ]]:&HH#6(H3 ' ]]:&JJF8qJ9 ' ]]:&KKSEfXK6 ' ]]:&KK! '&? 8& '& '& '& '& '&s<   $GG!	G-?G96HG	!G*	-G6	9H	H	c                 4   | j                          | j                  ddt        d      i      }dddddid	i}||j                  _        |j
                  dk(  sJ |j                  J |j                  |k(  sJ |j                  J |j                  J t        j                  t              5  |j                  dgdg       d
d
d
       t        j                  t              5  |j                  dgd       d
d
d
       t        j                  t              5  |j                  dgdg       d
d
d
       t        j                  t              5  |j                  }d
d
d
       y
# 1 sw Y   xY w# 1 sw Y   {xY w# 1 sw Y   PxY w# 1 sw Y   y
xY w)zv
    Test that get_collection works even with invalid configurations,
    but operations that require _embed fail
    test_get_invalidrp   rj   rW   r   nonexistent_functionr  rE   r  Nrq   ztest docrr   ru   rv   )ry   rz   rD   r{   r|   r?   r  r  r  r   r   r   r   r   r(  r   )rk   
valid_collr
  _s       r#   .test_get_collection_with_invalid_configurationr3    s~   
 LLN ))+-D-KL * J 	*aj
N ,:J( ??0000==$$$((N:::(((*** 
z	"F8
|< 
# 
z	"fX; 
# 
z	"vh:,? 
# 
z	"$$ 
#	" 
#	" 
#	" 
#	" 
#	"s0   0E*'E6FF*E36E?FFc                    | j                          | j                  dt        d            }|J |j                  j	                  d      }|J |j                         dk(  sJ |j                         ddik(  sJ | j                  dt        d            }|J |j                  j	                  d      }|J |j                         dk(  sJ |j                         ddik(  sJ | j                  d	      }|j                  j	                  d      }|J |j                         dk(  sJ |j                         ddik(  sJ y)
z0Test creating a collection with no EF in config.test_no_configr]   rW   ro   Nrp   rO   rE   r   	ry   rz   rD   r   r   r?   rR   get_or_create_collectionr   rk   r   r   s      r#   test_ef_no_configr9  G  sb   
LLN##2Ia2P $ D 					 4	5B>>779###==?uaj(((**2Ia2P + D 					 4	5B>>779###==?uaj(((  &6 7D					 4	5B>>779###==?uaj(((r&   c                    | j                          | j                  dt        d      dddii      }|J |j                  j	                  d	      }|J |j                         d
k(  sJ |j                         ddik(  sJ | j                  dt        d      dddii      }|J |j                  j	                  d	      }|J |j                         d
k(  sJ |j                         ddik(  sJ | j                  d      }|j                  j	                  d	      }|J |j                         d
k(  sJ |j                         ddik(  sJ y)zATest creating a collection with EF in parameter, no EF in config. test_ef_with_config_exists_no_efr]   rW   r   r   r[   r?   rp   r   Nrp   rO   rE   r   r6  r8  s      r#   r;  r;  c  s|   
LLN##/2q923 $ D
 					 4	5B>>779###==?uaj(((**/2q923 + D
 					 4	5B>>779###==?uaj(((  &H ID					 4	5B>>779###==?uaj(((r&   c                    | j                          | j                  dt        d      ddit        d      d      }|J |j                  j	                  d	      }|J |j                         d
k(  sJ |j                         ddik(  sJ | j                  dt        d      ddit        d      d      }|J |j                  j	                  d	      }|J |j                         d
k(  sJ |j                         ddik(  sJ | j                  d      }|j                  j	                  d	      }|J |j                         d
k(  sJ |j                         ddik(  sJ y)zQTest creating a collection with EF in parameter, EF in config. They are the same."test_ef_with_config_exists_with_efr]   rW   r   r[   r   r<  Nrp   rO   rE   r   r6  r8  s      r#   (test_ef_with_config_exists_with_ef_validr?    s   
LLN##12q9h'"9a"@
 $ D 					 4	5B>>779###==?uaj(((**12q9h'"9a"@
 + D 					 4	5B>>779###==?uaj(((  &J KD					 4	5B>>779###==?uaj(((r&   c           	          | j                          t        j                  t              5  | j	                  dt        d      ddit        d      d       ddd       y# 1 sw Y   yxY w)	zRTest creating a collection with EF in parameter, EF in config. They are different.r>  r]   rW   r   r[   r   r<  N)ry   r   r   r   rz   rD   ra   rk   s    r#   1test_create_ef_with_config_exists_with_ef_invalidrB    sV    
LLN	z	"  561= (+&>1&E 	! 	
 
#	"	"   .A!!A*c           	          | j                          t        j                  t              5  | j	                  dt        d      ddit        d      d       ddd       y# 1 sw Y   yxY w)	zJTest get_or_create with EF in parameter, EF in config. They are different.r>  r]   rW   r   r[   r   r<  N)ry   r   r   r   r7  rD   ra   rA  s    r#   8test_get_or_create_ef_with_config_exists_with_ef_invalidrE    sV    
LLN	z	"''561= (+&>1&E 	( 	
 
#	"	"rC  c                     | j                          | j                  dddit        d      d       t        j                  t
              5  | j                  dt        d             d	d	d	       y	# 1 sw Y   y	xY w)
zKTest get_collection with EF in parameter, EF in config. They are different.r>  r   r[   r]   rW   r   r   ro   N)ry   rz   ra   r   r   r   r   rD   rA  s    r#   9test_get_collection_ef_with_config_exists_with_ef_invalidrG    sp     LLN
1h'":q"A
   
z	"561= 	 	
 
#	"	"s   A33A<c           	      B   | j                          | j                  dt        d            }|J |j                  j	                  d      }|J |j                         dk(  sJ |j                         ddik(  sJ t        j                  t              5  | j                  dt        d      dt        d      i	       ddd       t        j                  t              5  | j                  dt        d             ddd       y# 1 sw Y   IxY w# 1 sw Y   yxY w)
z
    After creating a collection with an embedding function,
    get_or_create should raise an error before and after retrieval, if they had provided
    a different embedding function or if it differs from the persisted one.
    'test_get_or_create_after_create_with_efr]   rW   ro   Nrp   rO   rE   r<  )ry   rz   rD   r   r   r?   rR   r   r   r   r7  ra   r8  s      r#   rI  rI    s    LLN##62q9 $ D 					 4	5B>>779###==?uaj(((	z	"'':7A>/1HQ1OP 	( 	
 
# 
z	"'':7A> 	( 	
 
#	" 
#	" 
#	"s   +D	"D	DD)r   r   r   Nr5   )Kr   typingr   r   r   r   numpyr/   chromadb.api.typesr   r   r	   r
   chromadb.apir   %chromadb.api.collection_configurationr   r   r   r   r   r   r   r   r   r   os"chromadb.utils.embedding_functionsr   chromadb.test.conftestr   chromadb.typesr   r  getenvr   skip_reason_spann_disabledr   r:   rD   ra   r   r   r   r   r   r   r   r   r   r   markskipifr   r   r   r   r   r   r   r   r  r  r  r  r!  r-  r3  r9  r;  r?  rB  rE  rG  rI  r    r&   r#   <module>rW     s    ( (   #
 
 
  	 J 2 8 BII./36 8ryy/0C7 
 W 
J/
; J	&7
&C 	 /
;  , 0<  ,$9 $ $<$Y $4 $<& &t &: 9    F5	 5d 5$":I ":$ ":J)(X0Y 04 0.4"9 4" 4"n;"Y ;"4 ;"| *3MN( O(V
I 
$ 
49*) 9* 9*xM?) M? M?` *3MN!9Y !94 !9 O!9H *3MN):	 ):d ): O):X5@ *3MN19 1 1 O1>"Y "4 "2@,)6I )6$ )6X>>	>@,,	,2G"G"	G"T-%9 -% -%`)i )D )8)Y )4 )@#)Y #)4 #)L
i 
D 

Y 
SW 


	
&
I 
$ 
r&   