1414use Codewithkyrian \ChromaDB \Requests \CreateDatabaseRequest ;
1515use Codewithkyrian \ChromaDB \Requests \CreateTenantRequest ;
1616use Codewithkyrian \ChromaDB \Requests \DeleteItemsRequest ;
17+ use Codewithkyrian \ChromaDB \Requests \ForkCollectionRequest ;
1718use Codewithkyrian \ChromaDB \Requests \GetEmbeddingRequest ;
1819use Codewithkyrian \ChromaDB \Requests \QueryItemsRequest ;
1920use Codewithkyrian \ChromaDB \Requests \UpdateCollectionRequest ;
@@ -38,8 +39,7 @@ public function __construct(
3839 public readonly StreamFactoryInterface $ streamFactory ,
3940 public readonly string $ baseUri ,
4041 public readonly array $ headers = [],
41- ) {
42- }
42+ ) {}
4343
4444 /**
4545 * Retrieves the current user's identity, tenant, and databases.
@@ -288,6 +288,27 @@ public function updateCollection(string $collectionId, string $database, string
288288 ]);
289289 }
290290
291+ /**
292+ * Forks an existing collection.
293+ *
294+ * @param string $collectionId The UUID of the collection to fork.
295+ * @param string $database The database name to fork the collection from.
296+ * @param string $tenant The tenant ID to fork the collection from.
297+ * @param ForkCollectionRequest $request The request to fork the collection.
298+ *
299+ * @return Collection
300+ */
301+ public function forkCollection (string $ collectionId , string $ database , string $ tenant , ForkCollectionRequest $ request ): Collection
302+ {
303+ $ response = $ this ->sendRequest ('POST ' , "/api/v2/tenants/ $ tenant/databases/ $ database/collections/ $ collectionId/fork " , [
304+ 'json ' => $ request ->toArray ()
305+ ]);
306+
307+ $ result = json_decode ($ response ->getBody ()->getContents (), true );
308+
309+ return Collection::fromArray ($ result , $ this , $ database , $ tenant );
310+ }
311+
291312 /**
292313 * Deletes a collection in a given database.
293314 *
@@ -313,7 +334,6 @@ public function countCollections(string $database, string $tenant): int
313334 $ response = $ this ->sendRequest ('GET ' , "/api/v2/tenants/ $ tenant/databases/ $ database/collections_count " );
314335
315336 return json_decode ($ response ->getBody ()->getContents (), true );
316-
317337 }
318338
319339 /**
@@ -392,7 +412,7 @@ public function getCollectionItems(string $collectionId, string $database, strin
392412 $ response = $ this ->sendRequest ('POST ' , "/api/v2/tenants/ $ tenant/databases/ $ database/collections/ $ collectionId/get " , [
393413 'json ' => $ request ->toArray (),
394414 ]);
395-
415+
396416 $ result = json_decode ($ response ->getBody ()->getContents (), true );
397417
398418 return GetItemsResponse::fromArray ($ result );
0 commit comments