Skip to content

Commit 7b6f454

Browse files
feat: add cloud factory method to facade
1 parent 429ae22 commit 7b6f454

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

src/Api.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
class Api
3535
{
3636
public function __construct(
37-
public readonly ClientInterface $httpClient,
37+
public readonly ClientInterface $client,
3838
public readonly RequestFactoryInterface $requestFactory,
3939
public readonly StreamFactoryInterface $streamFactory,
4040
public readonly string $baseUri,
@@ -519,7 +519,7 @@ private function sendRequest(string $method, string $path, array $options = []):
519519
}
520520

521521
try {
522-
$response = $this->httpClient->sendRequest($request);
522+
$response = $this->client->sendRequest($request);
523523
} catch (ClientExceptionInterface $e) {
524524
throw new ChromaConnectionException($e->getMessage(), $e->getCode());
525525
}

src/ChromaDB.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,27 @@ public static function factory(): Factory
1919
return new Factory();
2020
}
2121

22+
/**
23+
* Creates a new factory instance configured for Chroma Cloud.
24+
*/
25+
public static function cloud(string $apiKey, ?string $tenant = null, ?string $database = null): Factory
26+
{
27+
$factory = self::factory()
28+
->withHost('https://api.trychroma.com')
29+
->withPort(8000)
30+
->withHeader('X-Chroma-Token', $apiKey);
31+
32+
if ($tenant) {
33+
$factory->withTenant($tenant);
34+
}
35+
36+
if ($database) {
37+
$factory->withDatabase($database);
38+
}
39+
40+
return $factory;
41+
}
42+
2243
/**
2344
* Resets the database. This will delete all collections and entries and
2445
* return true if the database was reset successfully.

0 commit comments

Comments
 (0)