55use Codewithkyrian \ChromaDB \ChromaDB ;
66use Codewithkyrian \ChromaDB \Embeddings \EmbeddingFunction ;
77use Codewithkyrian \ChromaDB \Generated \Exceptions \ChromaDimensionalityException ;
8+ use Codewithkyrian \ChromaDB \Generated \Exceptions \ChromaException ;
89use Codewithkyrian \ChromaDB \Generated \Exceptions \ChromaTypeException ;
910use Codewithkyrian \ChromaDB \Generated \Exceptions \ChromaValueException ;
11+ use Codewithkyrian \ChromaDB \Generated \Exceptions \ChromaInvalidArgumentException ;
12+ use Codewithkyrian \ChromaDB \Generated \Exceptions \ChromaNotFoundException ;
1013use Codewithkyrian \ChromaDB \Resources \CollectionResource ;
1114
1215beforeEach (function () {
@@ -90,7 +93,7 @@ public function generate(array $texts): array
9093
9194it ('throws a value error when getting a collection that does not exist ' , function () {
9295 $ this ->client ->getCollection ('test_collection_2 ' );
93- })->throws (ChromaValueException ::class, ' Collection test_collection_2 does not exist. ' );
96+ })->throws (ChromaNotFoundException ::class);
9497
9598it ('can modify a collection name or metadata ' , function () {
9699 $ this ->collection ->modify ('test_collection_2 ' , ['test ' => 'test_2 ' ]);
@@ -101,14 +104,13 @@ public function generate(array $texts): array
101104 ->toBe ('test_collection_2 ' )
102105 ->and ($ collection ->metadata )
103106 ->toMatchArray (['test ' => 'test_2 ' ]);
104-
105107});
106108
107109it ('can delete a collection ' , function () {
108110 $ this ->client ->deleteCollection ('test_collection ' );
109111
110112 expect (fn () => $ this ->client ->getCollection ('test_collection ' ))
111- ->toThrow (ChromaValueException ::class);
113+ ->toThrow (ChromaNotFoundException ::class);
112114});
113115
114116it ('can delete all collections ' , function () {
@@ -131,7 +133,7 @@ public function generate(array $texts): array
131133
132134it ('throws a value error when deleting a collection that does not exist ' , function () {
133135 $ this ->client ->deleteCollection ('test_collection_2 ' );
134- })->throws (ChromaValueException ::class, ' Collection test_collection_2 does not exist. ' );
136+ })->throws (ChromaNotFoundException ::class);
135137
136138it ('can add single embeddings to a collection ' , function () {
137139 $ ids = ['test1 ' ];
@@ -149,7 +151,7 @@ public function generate(array $texts): array
149151 $ metadatas = [['test ' => 'test ' ]];
150152
151153 $ this ->collection ->add ($ ids , $ embeddings , $ metadatas );
152- })->throws (ChromaTypeException ::class);
154+ })->throws (ChromaException ::class);
153155
154156it ('can add single text documents to a collection ' , function () {
155157 $ ids = ['test1 ' ];
@@ -179,7 +181,7 @@ public function generate(array $texts): array
179181 $ metadatas = [['test ' => 'test2 ' ]];
180182
181183 $ this ->collection ->add ($ ids , $ embeddings , $ metadatas );
182- })->throws (ChromaDimensionalityException ::class, 'Embedding dimension 11 does not match collection dimensionality 10 ' );
184+ })->throws (ChromaInvalidArgumentException ::class, 'Collection expecting embedding with dimension of 10, got 11 ' );
183185
184186it ('can upsert single embeddings to a collection ' , function () {
185187 $ ids = ['test1 ' ];
@@ -294,7 +296,7 @@ public function generate(array $texts): array
294296 ];
295297
296298 $ this ->collection ->add ($ ids , $ embeddings , $ metadatas );
297- })->throws (ChromaDimensionalityException ::class);
299+ })->throws (ChromaInvalidArgumentException ::class);
298300
299301it ('can add batch documents to a collection ' , function () {
300302 $ ids = ['test1 ' , 'test2 ' , 'test3 ' ];
@@ -344,7 +346,6 @@ public function generate(array $texts): array
344346
345347 expect ($ peekResponse ->ids )
346348 ->toMatchArray (['test1 ' , 'test2 ' ]);
347-
348349});
349350
350351it ('can query a collection ' , function () {
@@ -370,7 +371,6 @@ public function generate(array $texts): array
370371 ->toMatchArray (['test1 ' , 'test2 ' ])
371372 ->and ($ queryResponse ->distances [0 ])
372373 ->toMatchArray ([0.0 , 0.0 ]);
373-
374374});
375375
376376it ('can get a collection by id ' , function () {
@@ -457,8 +457,8 @@ public function generate(array $texts): array
457457 nResults: 1
458458 );
459459
460- expect ($ queryResponse ->ids [0 ])
461- ->toMatchArray (['test1 ' ]);
460+ expect ($ queryResponse ->ids [0 ][ 0 ] )
461+ ->toBeIn (['test1 ' , ' test2 ' , ' test3 ' ]);
462462});
463463
464464it ('throws a value error when getting a collection by where with an invalid operator ' , function () {
@@ -483,7 +483,7 @@ public function generate(array $texts): array
483483 'some ' => ['$invalid ' => 'metadata1 ' ]
484484 ]
485485 );
486- })->throws (ChromaValueException ::class);
486+ })->throws (ChromaException ::class);
487487
488488it ('can delete a collection by id ' , function () {
489489 $ ids = ['test1 ' , 'test2 ' , 'test3 ' ];
@@ -531,4 +531,4 @@ public function generate(array $texts): array
531531 );
532532
533533 expect ($ this ->collection ->count ())->toBe (2 );
534- });
534+ });
0 commit comments