22
33declare (strict_types=1 );
44
5-
65namespace Codewithkyrian \ChromaDB ;
76
87use Codewithkyrian \ChromaDB \Exceptions \ChromaConnectionException ;
98use Codewithkyrian \ChromaDB \Exceptions \ChromaException ;
109use Codewithkyrian \ChromaDB \Models \Collection ;
1110use Codewithkyrian \ChromaDB \Models \Database ;
1211use Codewithkyrian \ChromaDB \Models \Tenant ;
13- use Codewithkyrian \ChromaDB \Requests \AddEmbeddingRequest ;
12+ use Codewithkyrian \ChromaDB \Requests \AddItemsRequest ;
1413use Codewithkyrian \ChromaDB \Requests \CreateCollectionRequest ;
1514use Codewithkyrian \ChromaDB \Requests \CreateDatabaseRequest ;
1615use Codewithkyrian \ChromaDB \Requests \CreateTenantRequest ;
17- use Codewithkyrian \ChromaDB \Requests \DeleteEmbeddingRequest ;
16+ use Codewithkyrian \ChromaDB \Requests \DeleteItemsRequest ;
1817use Codewithkyrian \ChromaDB \Requests \GetEmbeddingRequest ;
19- use Codewithkyrian \ChromaDB \Requests \QueryEmbeddingRequest ;
18+ use Codewithkyrian \ChromaDB \Requests \QueryItemsRequest ;
2019use Codewithkyrian \ChromaDB \Requests \UpdateCollectionRequest ;
21- use Codewithkyrian \ChromaDB \Requests \UpdateEmbeddingRequest ;
20+ use Codewithkyrian \ChromaDB \Requests \UpdateItemsRequest ;
2221use Codewithkyrian \ChromaDB \Requests \UpdateTenantRequest ;
2322use Codewithkyrian \ChromaDB \Responses \GetItemsResponse ;
2423use Codewithkyrian \ChromaDB \Responses \QueryItemsResponse ;
2827use Psr \Http \Client \ClientExceptionInterface ;
2928
3029/**
31- * Client for ChromaDB API (v.0.1.0)
30+ * Client for ChromaDB API
3231 */
3332class Api
3433{
35-
3634 public function __construct (
3735 public readonly Client $ httpClient ,
3836 ) {}
@@ -58,15 +56,15 @@ public function getUserIdentity(): array
5856 * @param string $database The database name.
5957 * @param string $tenant The tenant name.
6058 */
61- public function getCollectionByCrn (string $ crn ): Collection
59+ public function getCollectionByCrn (string $ crn, string $ database , string $ tenant ): Collection
6260 {
6361 try {
6462 $ response = $ this ->httpClient ->get ("/api/v2/collections/ {$ crn }" );
6563 } catch (ClientExceptionInterface $ e ) {
6664 $ this ->handleChromaApiException ($ e );
6765 }
6866
69- return Collection::make (json_decode ($ response ->getBody ()->getContents (), true ));
67+ return Collection::make (json_decode ($ response ->getBody ()->getContents (), true ), $ this , $ database , $ tenant );
7068 }
7169
7270 /**
@@ -288,7 +286,7 @@ public function listCollections(string $database, string $tenant, ?int $limit =
288286
289287 $ result = json_decode ($ response ->getBody ()->getContents (), true );
290288
291- return array_map (fn (array $ item ) => Collection::make ($ item ), $ result );
289+ return array_map (fn (array $ item ) => Collection::make ($ item, $ this , $ database , $ tenant ), $ result );
292290 }
293291
294292 /**
@@ -312,7 +310,7 @@ public function createCollection(string $database, string $tenant, CreateCollect
312310
313311 $ result = json_decode ($ response ->getBody ()->getContents (), true );
314312
315- return Collection::make ($ result );
313+ return Collection::make ($ result, $ this , $ database , $ tenant );
316314 }
317315
318316 /**
@@ -334,7 +332,7 @@ public function getCollection(string $collectionId, string $database, string $te
334332
335333 $ result = json_decode ($ response ->getBody ()->getContents (), true );
336334
337- return Collection::make ($ result );
335+ return Collection::make ($ result, $ this , $ database , $ tenant );
338336 }
339337
340338 /**
@@ -398,9 +396,9 @@ public function countCollections(string $database, string $tenant): int
398396 * @param string $collectionId The UUID of the collection to add items to.
399397 * @param string $database The database name to add items to.
400398 * @param string $tenant The tenant ID to add items to.
401- * @param AddEmbeddingRequest $request The request to add items to the collection.
399+ * @param AddItemsRequest $request The request to add items to the collection.
402400 */
403- public function addCollectionItems (string $ collectionId , string $ database , string $ tenant , AddEmbeddingRequest $ request ): void
401+ public function addCollectionItems (string $ collectionId , string $ database , string $ tenant , AddItemsRequest $ request ): void
404402 {
405403 try {
406404 $ this ->httpClient ->post ("/api/v2/tenants/ $ tenant/databases/ $ database/collections/ $ collectionId/add " , [
@@ -437,9 +435,9 @@ public function countCollectionItems(string $collectionId, string $database, str
437435 * @param string $collectionId The UUID of the collection to update items in.
438436 * @param string $database The database name to update items in.
439437 * @param string $tenant The tenant ID to update items in.
440- * @param UpdateEmbeddingRequest $request The request to update items in the collection.
438+ * @param UpdateItemsRequest $request The request to update items in the collection.
441439 */
442- public function updateCollectionItems (string $ collectionId , string $ database , string $ tenant , UpdateEmbeddingRequest $ request ): void
440+ public function updateCollectionItems (string $ collectionId , string $ database , string $ tenant , UpdateItemsRequest $ request ): void
443441 {
444442 try {
445443 $ this ->httpClient ->post ("/api/v2/tenants/ $ tenant/databases/ $ database/collections/ $ collectionId/update " , [
@@ -456,9 +454,9 @@ public function updateCollectionItems(string $collectionId, string $database, st
456454 * @param string $collectionId The UUID of the collection to upsert items in.
457455 * @param string $database The database name to upsert items in.
458456 * @param string $tenant The tenant ID to upsert items in.
459- * @param AddEmbeddingRequest $request The request to upsert items in the collection.
457+ * @param AddItemsRequest $request The request to upsert items in the collection.
460458 */
461- public function upsertCollectionItems (string $ collectionId , string $ database , string $ tenant , AddEmbeddingRequest $ request ): void
459+ public function upsertCollectionItems (string $ collectionId , string $ database , string $ tenant , AddItemsRequest $ request ): void
462460 {
463461 try {
464462 $ this ->httpClient ->post ("/api/v2/tenants/ $ tenant/databases/ $ database/collections/ $ collectionId/upsert " , [
@@ -470,7 +468,7 @@ public function upsertCollectionItems(string $collectionId, string $database, st
470468 }
471469
472470 /**
473- * Retrieves records from a collection by ID or metadata filter.
471+ * Retrieves items from a collection by ID or metadata filter.
474472 *
475473 * @param string $collectionId The UUID of the collection to get items from.
476474 * @param string $database The database name to get items from.
@@ -494,7 +492,15 @@ public function getCollectionItems(string $collectionId, string $database, strin
494492 return GetItemsResponse::from ($ result );
495493 }
496494
497- public function deleteCollectionItems (string $ collectionId , string $ database , string $ tenant , DeleteEmbeddingRequest $ request ): void
495+ /**
496+ * Deletes items from a collection by ID or metadata filter.
497+ *
498+ * @param string $collectionId The UUID of the collection to delete items from.
499+ * @param string $database The database name to delete items from.
500+ * @param string $tenant The tenant ID to delete items from.
501+ * @param DeleteItemsRequest $request The request to delete items from the collection.
502+ */
503+ public function deleteCollectionItems (string $ collectionId , string $ database , string $ tenant , DeleteItemsRequest $ request ): void
498504 {
499505 try {
500506 $ this ->httpClient ->post ("/api/v2/tenants/ $ tenant/databases/ $ database/collections/ $ collectionId/delete " , [
@@ -511,11 +517,11 @@ public function deleteCollectionItems(string $collectionId, string $database, st
511517 * @param string $collectionId The UUID of the collection to query.
512518 * @param string $database The database name to query the collection in.
513519 * @param string $tenant The tenant ID to query the collection in.
514- * @param QueryEmbeddingRequest $request The request to query the collection.
520+ * @param QueryItemsRequest $request The request to query the collection.
515521 *
516522 * @return QueryItemsResponse
517523 */
518- public function queryCollectionItems (string $ collectionId , string $ database , string $ tenant , QueryEmbeddingRequest $ request ): QueryItemsResponse
524+ public function queryCollectionItems (string $ collectionId , string $ database , string $ tenant , QueryItemsRequest $ request ): QueryItemsResponse
519525 {
520526 try {
521527 $ response = $ this ->httpClient ->post ("/api/v2/tenants/ $ tenant/databases/ $ database/collections/ $ collectionId/query " , [
0 commit comments