Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@ jobs:

services:
chroma-wo-auth:
image: chromadb/chroma:0.5.0
image: chromadb/chroma:1.0.8
ports:
- 8000:8000

chroma-w-auth:
image: chromadb/chroma:0.5.0
image: chromadb/chroma:1.0.8
ports:
- 8001:8000
env:
CHROMA_SERVER_AUTHN_CREDENTIALS: 'test-token'
CHROMA_SERVER_AUTHN_PROVIDER: 'chromadb.auth.token_authn.TokenAuthenticationServerProvider'
CHROMA_AUTH_TOKEN_TRANSPORT_HEADER: 'Authorization'

steps:
- name: Checkout
Expand Down
15 changes: 8 additions & 7 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
version: '3.9'
version: "3.9"

services:
chroma_wo_auth:
image: 'chromadb/chroma:0.5.0'
image: "chromadb/chroma:1.0.8"
ports:
- '8000:8000'
- "8000:8000"

chroma_w_auth:
image: 'chromadb/chroma:0.5.0'
image: "chromadb/chroma:1.0.8"
ports:
- '8001:8000'
- "8001:8000"
environment:
CHROMA_SERVER_AUTHN_CREDENTIALS: 'test-token'
CHROMA_SERVER_AUTHN_PROVIDER: 'chromadb.auth.token_authn.TokenAuthenticationServerProvider'
CHROMA_SERVER_AUTHN_CREDENTIALS: "test-token"
CHROMA_SERVER_AUTHN_PROVIDER: "chromadb.auth.token_authn.TokenAuthenticationServerProvider"
CHROMA_AUTH_TOKEN_TRANSPORT_HEADER: "Authorization"
100 changes: 35 additions & 65 deletions src/Generated/ChromaApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,12 @@ class ChromaApiClient

public function __construct(
public readonly Client $httpClient,
)
{
}
) {}

public function root(): array
{
try {
$response = $this->httpClient->get('/api/v1');
$response = $this->httpClient->get('/api/v2');
} catch (ClientExceptionInterface $e) {
$this->handleChromaApiException($e);
}
Expand All @@ -52,7 +50,7 @@ public function root(): array
public function version(): string
{
try {
$response = $this->httpClient->get('/api/v1/version');
$response = $this->httpClient->get('/api/v2/version');

// remove the quo
return trim($response->getBody()->getContents(), '"');
Expand All @@ -64,7 +62,7 @@ public function version(): string
public function heartbeat(): array
{
try {
$response = $this->httpClient->get('/api/v1/heartbeat');
$response = $this->httpClient->get('/api/v2/heartbeat');
} catch (ClientExceptionInterface $e) {
$this->handleChromaApiException($e);
}
Expand All @@ -74,7 +72,7 @@ public function heartbeat(): array
public function preFlightChecks(): mixed
{
try {
$response = $this->httpClient->get('/api/v1/pre-flight-checks');
$response = $this->httpClient->get('/api/v2/pre-flight-checks');
} catch (ClientExceptionInterface $e) {
$this->handleChromaApiException($e);
}
Expand All @@ -85,11 +83,8 @@ public function preFlightChecks(): mixed
public function createDatabase(string $tenant, CreateDatabaseRequest $request): void
{
try {
$this->httpClient->post('/api/v1/databases', [
'json' => $request->toArray(),
'query' => [
'tenant' => $tenant,
]
$this->httpClient->post("/api/v2/tenants/$tenant/databases", [
'json' => $request->toArray()
]);
} catch (ClientExceptionInterface $e) {
$this->handleChromaApiException($e);
Expand All @@ -99,11 +94,7 @@ public function createDatabase(string $tenant, CreateDatabaseRequest $request):
public function getDatabase(string $database, string $tenant): Database
{
try {
$response = $this->httpClient->get("/api/v1/databases/$database", [
'query' => [
'tenant' => $tenant,
]
]);
$response = $this->httpClient->get("/api/v2/tenants/$tenant/databases/$database");
} catch (ClientExceptionInterface $e) {
$this->handleChromaApiException($e);
}
Expand All @@ -116,7 +107,7 @@ public function getDatabase(string $database, string $tenant): Database
public function createTenant(CreateTenantRequest $request): void
{
try {
$this->httpClient->post('/api/v1/tenants', [
$this->httpClient->post('/api/v2/tenants', [
'json' => $request->toArray(),
]);
} catch (ClientExceptionInterface $e) {
Expand All @@ -127,27 +118,21 @@ public function createTenant(CreateTenantRequest $request): void
public function getTenant(string $tenant): ?Tenant
{
try {
$response = $this->httpClient->get("/api/v1/tenants/$tenant");
$response = $this->httpClient->get("/api/v2/tenants/$tenant");

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

return Tenant::make($result);
} catch (ClientExceptionInterface $e) {
$this->handleChromaApiException($e);
}

}


public function listCollections(string $database, string $tenant): array
{
try {
$response = $this->httpClient->get('/api/v1/collections', [
'query' => [
'database' => $database,
'tenant' => $tenant,
]
]);
$response = $this->httpClient->get("/api/v2/tenants/$tenant/databases/$database/collections");
} catch (ClientExceptionInterface $e) {
$this->handleChromaApiException($e);
}
Expand All @@ -162,14 +147,9 @@ public function listCollections(string $database, string $tenant): array
public function createCollection(string $database, string $tenant, CreateCollectionRequest $request): Collection
{
try {
$response = $this->httpClient->post('/api/v1/collections', [
'json' => $request->toArray(),
'query' => [
'database' => $database,
'tenant' => $tenant,
]
$response = $this->httpClient->post("/api/v2/tenants/$tenant/databases/$database/collections", [
'json' => $request->toArray()
]);

} catch (ClientExceptionInterface $e) {
$this->handleChromaApiException($e);
}
Expand All @@ -182,12 +162,7 @@ public function createCollection(string $database, string $tenant, CreateCollect
public function getCollection(string $collectionId, string $database, string $tenant): Collection
{
try {
$response = $this->httpClient->get("/api/v1/collections/$collectionId", [
'query' => [
'database' => $database,
'tenant' => $tenant,
]
]);
$response = $this->httpClient->get("/api/v2/tenants/$tenant/databases/$database/collections/$collectionId");
} catch (ClientExceptionInterface $e) {
$this->handleChromaApiException($e);
}
Expand All @@ -197,10 +172,10 @@ public function getCollection(string $collectionId, string $database, string $te
return Collection::make($result);
}

public function updateCollection(string $collectionId, UpdateCollectionRequest $request): void
public function updateCollection(string $collectionId, string $database, string $tenant, UpdateCollectionRequest $request): void
{
try {
$response = $this->httpClient->put("/api/v1/collections/$collectionId", [
$response = $this->httpClient->put("/api/v2/tenants/$tenant/databases/$database/collections/$collectionId", [
'json' => $request->toArray(),
]);
} catch (ClientExceptionInterface $e) {
Expand All @@ -211,54 +186,49 @@ public function updateCollection(string $collectionId, UpdateCollectionRequest $
public function deleteCollection(string $collectionId, string $database, string $tenant): void
{
try {
$this->httpClient->delete("/api/v1/collections/$collectionId", [
'query' => [
'database' => $database,
'tenant' => $tenant,
]
]);
$this->httpClient->delete("/api/v2/tenants/$tenant/databases/$database/collections/$collectionId");
} catch (ClientExceptionInterface $e) {
$this->handleChromaApiException($e);
}
}

public function add(string $collectionId, AddEmbeddingRequest $request): void
public function add(string $collectionId, string $database, string $tenant, AddEmbeddingRequest $request): void
{
try {
$this->httpClient->post("/api/v1/collections/$collectionId/add", [
$this->httpClient->post("/api/v2/tenants/$tenant/databases/$database/collections/$collectionId/add", [
'json' => $request->toArray(),
]);
} catch (ClientExceptionInterface $e) {
$this->handleChromaApiException($e);
}
}

public function update(string $collectionId, UpdateEmbeddingRequest $request): void
public function update(string $collectionId, string $database, string $tenant, UpdateEmbeddingRequest $request): void
{
try {
$this->httpClient->post("/api/v1/collections/$collectionId/update", [
$this->httpClient->post("/api/v2/tenants/$tenant/databases/$database/collections/$collectionId/update", [
'json' => $request->toArray(),
]);
} catch (ClientExceptionInterface $e) {
$this->handleChromaApiException($e);
}
}

public function upsert(string $collectionId, AddEmbeddingRequest $request): void
public function upsert(string $collectionId, string $database, string $tenant, AddEmbeddingRequest $request): void
{
try {
$this->httpClient->post("/api/v1/collections/$collectionId/upsert", [
$this->httpClient->post("/api/v2/tenants/$tenant/databases/$database/collections/$collectionId/upsert", [
'json' => $request->toArray(),
]);
} catch (ClientExceptionInterface $e) {
$this->handleChromaApiException($e);
}
}

public function get(string $collectionId, GetEmbeddingRequest $request): GetItemsResponse
public function get(string $collectionId, string $database, string $tenant, GetEmbeddingRequest $request): GetItemsResponse
{
try {
$response = $this->httpClient->post("/api/v1/collections/$collectionId/get", [
$response = $this->httpClient->post("/api/v2/tenants/$tenant/databases/$database/collections/$collectionId/get", [
'json' => $request->toArray(),
]);
} catch (ClientExceptionInterface $e) {
Expand All @@ -270,32 +240,32 @@ public function get(string $collectionId, GetEmbeddingRequest $request): GetItem
return GetItemsResponse::from($result);
}

public function delete(string $collectionId, DeleteEmbeddingRequest $request): void
public function delete(string $collectionId, string $database, string $tenant, DeleteEmbeddingRequest $request): void
{
try {
$this->httpClient->post("/api/v1/collections/$collectionId/delete", [
$this->httpClient->post("/api/v2/tenants/$tenant/databases/$database/collections/$collectionId/delete", [
'json' => $request->toArray(),
]);
} catch (ClientExceptionInterface $e) {
$this->handleChromaApiException($e);
}
}

public function count(string $collectionId): int
public function count(string $collectionId, string $database, string $tenant): int
{
try {
$response = $this->httpClient->get("/api/v1/collections/$collectionId/count");
$response = $this->httpClient->get("/api/v2/tenants/$tenant/databases/$database/collections/$collectionId/count");
} catch (ClientExceptionInterface $e) {
$this->handleChromaApiException($e);
}

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

public function getNearestNeighbors(string $collectionId, QueryEmbeddingRequest $request): QueryItemsResponse
public function getNearestNeighbors(string $collectionId, string $database, string $tenant, QueryEmbeddingRequest $request): QueryItemsResponse
{
try {
$response = $this->httpClient->post("/api/v1/collections/$collectionId/query", [
$response = $this->httpClient->post("/api/v2/tenants/$tenant/databases/$database/collections/$collectionId/query", [
'json' => $request->toArray(),
]);
} catch (ClientExceptionInterface $e) {
Expand All @@ -310,7 +280,7 @@ public function getNearestNeighbors(string $collectionId, QueryEmbeddingRequest
public function reset(): bool
{
try {
$response = $this->httpClient->post('/api/v1/reset');
$response = $this->httpClient->post('/api/v2/reset');
} catch (ClientExceptionInterface $e) {
$this->handleChromaApiException($e);
}
Expand Down Expand Up @@ -342,8 +312,8 @@ private function handleChromaApiException(\Exception|ClientExceptionInterface $e
if (preg_match(
'/^(?P<error_type>\w+)\((?P<message>.*)\)$/',
$error['error'] ?? '',
$matches)
) {
$matches
)) {
if (isset($matches['message'])) {
$error_type = $matches['error_type'] ?? 'UnknownError';
$message = $matches['message'];
Expand Down Expand Up @@ -383,4 +353,4 @@ private function handleChromaApiException(\Exception|ClientExceptionInterface $e

throw new ChromaException($e->getMessage(), $e->getCode());
}
}
}
3 changes: 2 additions & 1 deletion src/Generated/Exceptions/ChromaException.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public static function throwSpecific(string $message, string $type, int $code)
'DimensionalityError' => new ChromaDimensionalityException($message, $code),
'InvalidCollection' => new ChromaInvalidCollectionException($message, $code),
'TypeError' => new ChromaTypeException($message, $code),
'InvalidArgumentError' => new ChromaInvalidArgumentException($message, $code),
default => new self($message, $code),
};
}
Expand All @@ -34,4 +35,4 @@ public static function inferTypeFromMessage(string $message): string
default => 'UnknownError',
};
}
}
}
8 changes: 8 additions & 0 deletions src/Generated/Exceptions/ChromaInvalidArgumentException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

declare(strict_types=1);


namespace Codewithkyrian\ChromaDB\Generated\Exceptions;

class ChromaInvalidArgumentException extends ChromaException {}
Loading