Skip to content

Commit 83febf3

Browse files
BlackyDrumCodeWithKyrian
authored andcommitted
Update to chromadb api v2
1 parent 53bb269 commit 83febf3

File tree

3 files changed

+60
-101
lines changed

3 files changed

+60
-101
lines changed

docker-compose.yml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
version: '3.9'
1+
version: "3.9"
22

33
services:
44
chroma_wo_auth:
5-
image: 'chromadb/chroma:0.5.0'
5+
image: "chromadb/chroma:1.0.8"
66
ports:
7-
- '8000:8000'
7+
- "8000:8000"
88

99
chroma_w_auth:
10-
image: 'chromadb/chroma:0.5.0'
10+
image: "chromadb/chroma:1.0.8"
1111
ports:
12-
- '8001:8000'
12+
- "8001:8000"
1313
environment:
14-
CHROMA_SERVER_AUTHN_CREDENTIALS: 'test-token'
15-
CHROMA_SERVER_AUTHN_PROVIDER: 'chromadb.auth.token_authn.TokenAuthenticationServerProvider'
14+
CHROMA_SERVER_AUTHN_CREDENTIALS: "authToken"
15+
CHROMA_SERVER_AUTHN_PROVIDER: "chromadb.auth.token_authn.TokenAuthenticationServerProvider"
16+
CHROMA_AUTH_TOKEN_TRANSPORT_HEADER: "Authorization"

src/Generated/ChromaApiClient.php

Lines changed: 35 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,12 @@ class ChromaApiClient
3434

3535
public function __construct(
3636
public readonly Client $httpClient,
37-
)
38-
{
39-
}
37+
) {}
4038

4139
public function root(): array
4240
{
4341
try {
44-
$response = $this->httpClient->get('/api/v1');
42+
$response = $this->httpClient->get('/api/v2');
4543
} catch (ClientExceptionInterface $e) {
4644
$this->handleChromaApiException($e);
4745
}
@@ -52,7 +50,7 @@ public function root(): array
5250
public function version(): string
5351
{
5452
try {
55-
$response = $this->httpClient->get('/api/v1/version');
53+
$response = $this->httpClient->get('/api/v2/version');
5654

5755
// remove the quo
5856
return trim($response->getBody()->getContents(), '"');
@@ -64,7 +62,7 @@ public function version(): string
6462
public function heartbeat(): array
6563
{
6664
try {
67-
$response = $this->httpClient->get('/api/v1/heartbeat');
65+
$response = $this->httpClient->get('/api/v2/heartbeat');
6866
} catch (ClientExceptionInterface $e) {
6967
$this->handleChromaApiException($e);
7068
}
@@ -74,7 +72,7 @@ public function heartbeat(): array
7472
public function preFlightChecks(): mixed
7573
{
7674
try {
77-
$response = $this->httpClient->get('/api/v1/pre-flight-checks');
75+
$response = $this->httpClient->get('/api/v2/pre-flight-checks');
7876
} catch (ClientExceptionInterface $e) {
7977
$this->handleChromaApiException($e);
8078
}
@@ -85,11 +83,8 @@ public function preFlightChecks(): mixed
8583
public function createDatabase(string $tenant, CreateDatabaseRequest $request): void
8684
{
8785
try {
88-
$this->httpClient->post('/api/v1/databases', [
89-
'json' => $request->toArray(),
90-
'query' => [
91-
'tenant' => $tenant,
92-
]
86+
$this->httpClient->post("/api/v2/tenants/$tenant/databases", [
87+
'json' => $request->toArray()
9388
]);
9489
} catch (ClientExceptionInterface $e) {
9590
$this->handleChromaApiException($e);
@@ -99,11 +94,7 @@ public function createDatabase(string $tenant, CreateDatabaseRequest $request):
9994
public function getDatabase(string $database, string $tenant): Database
10095
{
10196
try {
102-
$response = $this->httpClient->get("/api/v1/databases/$database", [
103-
'query' => [
104-
'tenant' => $tenant,
105-
]
106-
]);
97+
$response = $this->httpClient->get("/api/v2/tenants/$tenant/databases/$database");
10798
} catch (ClientExceptionInterface $e) {
10899
$this->handleChromaApiException($e);
109100
}
@@ -116,7 +107,7 @@ public function getDatabase(string $database, string $tenant): Database
116107
public function createTenant(CreateTenantRequest $request): void
117108
{
118109
try {
119-
$this->httpClient->post('/api/v1/tenants', [
110+
$this->httpClient->post('/api/v2/tenants', [
120111
'json' => $request->toArray(),
121112
]);
122113
} catch (ClientExceptionInterface $e) {
@@ -127,27 +118,21 @@ public function createTenant(CreateTenantRequest $request): void
127118
public function getTenant(string $tenant): ?Tenant
128119
{
129120
try {
130-
$response = $this->httpClient->get("/api/v1/tenants/$tenant");
121+
$response = $this->httpClient->get("/api/v2/tenants/$tenant");
131122

132123
$result = json_decode($response->getBody()->getContents(), true);
133124

134125
return Tenant::make($result);
135126
} catch (ClientExceptionInterface $e) {
136127
$this->handleChromaApiException($e);
137128
}
138-
139129
}
140130

141131

142132
public function listCollections(string $database, string $tenant): array
143133
{
144134
try {
145-
$response = $this->httpClient->get('/api/v1/collections', [
146-
'query' => [
147-
'database' => $database,
148-
'tenant' => $tenant,
149-
]
150-
]);
135+
$response = $this->httpClient->get("/api/v2/tenants/$tenant/databases/$database/collections");
151136
} catch (ClientExceptionInterface $e) {
152137
$this->handleChromaApiException($e);
153138
}
@@ -162,14 +147,9 @@ public function listCollections(string $database, string $tenant): array
162147
public function createCollection(string $database, string $tenant, CreateCollectionRequest $request): Collection
163148
{
164149
try {
165-
$response = $this->httpClient->post('/api/v1/collections', [
166-
'json' => $request->toArray(),
167-
'query' => [
168-
'database' => $database,
169-
'tenant' => $tenant,
170-
]
150+
$response = $this->httpClient->post("/api/v2/tenants/$tenant/databases/$database/collections", [
151+
'json' => $request->toArray()
171152
]);
172-
173153
} catch (ClientExceptionInterface $e) {
174154
$this->handleChromaApiException($e);
175155
}
@@ -182,12 +162,7 @@ public function createCollection(string $database, string $tenant, CreateCollect
182162
public function getCollection(string $collectionId, string $database, string $tenant): Collection
183163
{
184164
try {
185-
$response = $this->httpClient->get("/api/v1/collections/$collectionId", [
186-
'query' => [
187-
'database' => $database,
188-
'tenant' => $tenant,
189-
]
190-
]);
165+
$response = $this->httpClient->get("/api/v2/tenants/$tenant/databases/$database/collections/$collectionId");
191166
} catch (ClientExceptionInterface $e) {
192167
$this->handleChromaApiException($e);
193168
}
@@ -197,10 +172,10 @@ public function getCollection(string $collectionId, string $database, string $te
197172
return Collection::make($result);
198173
}
199174

200-
public function updateCollection(string $collectionId, UpdateCollectionRequest $request): void
175+
public function updateCollection(string $collectionId, string $database, string $tenant, UpdateCollectionRequest $request): void
201176
{
202177
try {
203-
$response = $this->httpClient->put("/api/v1/collections/$collectionId", [
178+
$response = $this->httpClient->put("/api/v2/tenants/$tenant/databases/$database/collections/$collectionId", [
204179
'json' => $request->toArray(),
205180
]);
206181
} catch (ClientExceptionInterface $e) {
@@ -211,54 +186,49 @@ public function updateCollection(string $collectionId, UpdateCollectionRequest $
211186
public function deleteCollection(string $collectionId, string $database, string $tenant): void
212187
{
213188
try {
214-
$this->httpClient->delete("/api/v1/collections/$collectionId", [
215-
'query' => [
216-
'database' => $database,
217-
'tenant' => $tenant,
218-
]
219-
]);
189+
$this->httpClient->delete("/api/v2/tenants/$tenant/databases/$database/collections/$collectionId");
220190
} catch (ClientExceptionInterface $e) {
221191
$this->handleChromaApiException($e);
222192
}
223193
}
224194

225-
public function add(string $collectionId, AddEmbeddingRequest $request): void
195+
public function add(string $collectionId, string $database, string $tenant, AddEmbeddingRequest $request): void
226196
{
227197
try {
228-
$this->httpClient->post("/api/v1/collections/$collectionId/add", [
198+
$this->httpClient->post("/api/v2/tenants/$tenant/databases/$database/collections/$collectionId/add", [
229199
'json' => $request->toArray(),
230200
]);
231201
} catch (ClientExceptionInterface $e) {
232202
$this->handleChromaApiException($e);
233203
}
234204
}
235205

236-
public function update(string $collectionId, UpdateEmbeddingRequest $request): void
206+
public function update(string $collectionId, string $database, string $tenant, UpdateEmbeddingRequest $request): void
237207
{
238208
try {
239-
$this->httpClient->post("/api/v1/collections/$collectionId/update", [
209+
$this->httpClient->post("/api/v2/tenants/$tenant/databases/$database/collections/$collectionId/update", [
240210
'json' => $request->toArray(),
241211
]);
242212
} catch (ClientExceptionInterface $e) {
243213
$this->handleChromaApiException($e);
244214
}
245215
}
246216

247-
public function upsert(string $collectionId, AddEmbeddingRequest $request): void
217+
public function upsert(string $collectionId, string $database, string $tenant, AddEmbeddingRequest $request): void
248218
{
249219
try {
250-
$this->httpClient->post("/api/v1/collections/$collectionId/upsert", [
220+
$this->httpClient->post("/api/v2/tenants/$tenant/databases/$database/collections/$collectionId/upsert", [
251221
'json' => $request->toArray(),
252222
]);
253223
} catch (ClientExceptionInterface $e) {
254224
$this->handleChromaApiException($e);
255225
}
256226
}
257227

258-
public function get(string $collectionId, GetEmbeddingRequest $request): GetItemsResponse
228+
public function get(string $collectionId, string $database, string $tenant, GetEmbeddingRequest $request): GetItemsResponse
259229
{
260230
try {
261-
$response = $this->httpClient->post("/api/v1/collections/$collectionId/get", [
231+
$response = $this->httpClient->post("/api/v2/tenants/$tenant/databases/$database/collections/$collectionId/get", [
262232
'json' => $request->toArray(),
263233
]);
264234
} catch (ClientExceptionInterface $e) {
@@ -270,32 +240,32 @@ public function get(string $collectionId, GetEmbeddingRequest $request): GetItem
270240
return GetItemsResponse::from($result);
271241
}
272242

273-
public function delete(string $collectionId, DeleteEmbeddingRequest $request): void
243+
public function delete(string $collectionId, string $database, string $tenant, DeleteEmbeddingRequest $request): void
274244
{
275245
try {
276-
$this->httpClient->post("/api/v1/collections/$collectionId/delete", [
246+
$this->httpClient->post("/api/v2/tenants/$tenant/databases/$database/collections/$collectionId/delete", [
277247
'json' => $request->toArray(),
278248
]);
279249
} catch (ClientExceptionInterface $e) {
280250
$this->handleChromaApiException($e);
281251
}
282252
}
283253

284-
public function count(string $collectionId): int
254+
public function count(string $collectionId, string $database, string $tenant): int
285255
{
286256
try {
287-
$response = $this->httpClient->get("/api/v1/collections/$collectionId/count");
257+
$response = $this->httpClient->get("/api/v2/tenants/$tenant/databases/$database/collections/$collectionId/count");
288258
} catch (ClientExceptionInterface $e) {
289259
$this->handleChromaApiException($e);
290260
}
291261

292262
return json_decode($response->getBody()->getContents(), true);
293263
}
294264

295-
public function getNearestNeighbors(string $collectionId, QueryEmbeddingRequest $request): QueryItemsResponse
265+
public function getNearestNeighbors(string $collectionId, string $database, string $tenant, QueryEmbeddingRequest $request): QueryItemsResponse
296266
{
297267
try {
298-
$response = $this->httpClient->post("/api/v1/collections/$collectionId/query", [
268+
$response = $this->httpClient->post("/api/v2/tenants/$tenant/databases/$database/collections/$collectionId/query", [
299269
'json' => $request->toArray(),
300270
]);
301271
} catch (ClientExceptionInterface $e) {
@@ -310,7 +280,7 @@ public function getNearestNeighbors(string $collectionId, QueryEmbeddingRequest
310280
public function reset(): bool
311281
{
312282
try {
313-
$response = $this->httpClient->post('/api/v1/reset');
283+
$response = $this->httpClient->post('/api/v2/reset');
314284
} catch (ClientExceptionInterface $e) {
315285
$this->handleChromaApiException($e);
316286
}
@@ -342,8 +312,8 @@ private function handleChromaApiException(\Exception|ClientExceptionInterface $e
342312
if (preg_match(
343313
'/^(?P<error_type>\w+)\((?P<message>.*)\)$/',
344314
$error['error'] ?? '',
345-
$matches)
346-
) {
315+
$matches
316+
)) {
347317
if (isset($matches['message'])) {
348318
$error_type = $matches['error_type'] ?? 'UnknownError';
349319
$message = $matches['message'];
@@ -383,4 +353,4 @@ private function handleChromaApiException(\Exception|ClientExceptionInterface $e
383353

384354
throw new ChromaException($e->getMessage(), $e->getCode());
385355
}
386-
}
356+
}

0 commit comments

Comments
 (0)