Skip to content

Commit

Permalink
Add to fastapi
Browse files Browse the repository at this point in the history
  • Loading branch information
HammadB committed Oct 23, 2023
1 parent 5baf290 commit 6bcb1fd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions chromadb/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,11 +390,11 @@ def max_batch_size(self) -> int:

@override
def set_tenant_and_database(self, tenant: str, database: str) -> None:
self._validate_tenant_database(database, self.tenant)
self._validate_tenant_database(tenant=tenant, database=database)
self.tenant = tenant
self.database = database

def _validate_tenant_database(self, database: str, tenant: str) -> None:
def _validate_tenant_database(self, tenant: str, database: str) -> None:
try:
self._admin_client.get_tenant(name=tenant)
except Exception:
Expand Down
21 changes: 21 additions & 0 deletions chromadb/server/fastapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

import logging
from chromadb.telemetry import ServerContext, Telemetry
from chromadb.types import Database, Tenant

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -142,13 +143,27 @@ def __init__(self, settings: Settings):
response_model=None,
)

self.router.add_api_route(
"/api/v1/databases/{database}",
self.get_database,
methods=["GET"],
response_model=None,
)

self.router.add_api_route(
"/api/v1/tenants",
self.create_tenant,
methods=["POST"],
response_model=None,
)

self.router.add_api_route(
"/api/v1/tenants/{tenant}",
self.get_tenant,
methods=["GET"],
response_model=None,
)

self.router.add_api_route(
"/api/v1/collections",
self.list_collections,
Expand Down Expand Up @@ -245,9 +260,15 @@ def create_database(
) -> None:
return self._api.create_database(database.name, tenant)

def get_database(self, database: str, tenant: str = DEFAULT_TENANT) -> Database:
return self._api.get_database(database, tenant)

def create_tenant(self, tenant: CreateTenant) -> None:
return self._api.create_tenant(tenant.name)

def get_tenant(self, tenant: str) -> Tenant:
return self._api.get_tenant(tenant)

def list_collections(
self, tenant: str = DEFAULT_TENANT, database: str = DEFAULT_DATABASE
) -> Sequence[Collection]:
Expand Down

0 comments on commit 6bcb1fd

Please sign in to comment.