Skip to content

Commit 7db63a9

Browse files
author
Sicheng Pan
committed
Wire up APIs
1 parent 11ebbac commit 7db63a9

File tree

6 files changed

+83
-38
lines changed

6 files changed

+83
-38
lines changed

Diff for: chromadb/api/__init__.py

+18-18
Original file line numberDiff line numberDiff line change
@@ -92,23 +92,6 @@ def _modify(
9292
"""
9393
pass
9494

95-
@abstractmethod
96-
def _fork(
97-
self,
98-
collection_id: UUID,
99-
new_name: str
100-
) -> CollectionModel:
101-
"""[Internal] Fork the current collection under a new name. The returning collection should contain identical data to the current collection.
102-
This is an experimental API that only works for Hosted Chroma for now.
103-
104-
Args:
105-
new_name: The name of the new collection.
106-
107-
Returns:
108-
Collection: A new collection with the specified name and containing identical data to the current collection.
109-
"""
110-
pass
111-
11295
@abstractmethod
11396
def delete_collection(
11497
self,
@@ -478,6 +461,24 @@ def get_or_create_collection(
478461
"""
479462
pass
480463

464+
@abstractmethod
465+
def _fork(
466+
self,
467+
collection_id: UUID,
468+
new_name: str
469+
) -> Collection:
470+
"""[Internal] Fork the current collection under a new name. The returning collection should contain identical data to the current collection.
471+
This is an experimental API that only works for Hosted Chroma for now.
472+
473+
Args:
474+
new_name: The name of the new collection.
475+
476+
Returns:
477+
Collection: A new collection with the specified name and containing identical data to the current collection.
478+
"""
479+
pass
480+
481+
481482
@abstractmethod
482483
def set_tenant(self, tenant: str, database: str = DEFAULT_DATABASE) -> None:
483484
"""Set the tenant and database for the client. Raises an error if the tenant or
@@ -654,7 +655,6 @@ def _modify(
654655
pass
655656

656657
@abstractmethod
657-
@override
658658
def _fork(
659659
self,
660660
collection_id: UUID,

Diff for: chromadb/api/async_api.py

+21-18
Original file line numberDiff line numberDiff line change
@@ -86,23 +86,6 @@ async def _modify(
8686
"""
8787
pass
8888

89-
@abstractmethod
90-
async def _fork(
91-
self,
92-
collection_id: UUID,
93-
new_name: str
94-
) -> CollectionModel:
95-
"""[Internal] Fork the current collection under a new name. The returning collection should contain identical data to the current collection.
96-
This is an experimental API that only works for Hosted Chroma for now.
97-
98-
Args:
99-
new_name: The name of the new collection.
100-
101-
Returns:
102-
Collection: A new collection with the specified name and containing identical data to the current collection.
103-
"""
104-
pass
105-
10689
@abstractmethod
10790
async def delete_collection(
10891
self,
@@ -472,6 +455,27 @@ async def get_or_create_collection(
472455
"""
473456
pass
474457

458+
@abstractmethod
459+
async def _fork(
460+
self,
461+
collection_id: UUID,
462+
new_name: str,
463+
embedding_function: Optional[
464+
EmbeddingFunction[Embeddable]
465+
] = ef.DefaultEmbeddingFunction(), # type: ignore
466+
data_loader: Optional[DataLoader[Loadable]] = None,
467+
) -> AsyncCollection:
468+
"""[Internal] Fork the current collection under a new name. The returning collection should contain identical data to the current collection.
469+
This is an experimental API that only works for Hosted Chroma for now.
470+
471+
Args:
472+
new_name: The name of the new collection.
473+
474+
Returns:
475+
Collection: A new collection with the specified name and containing identical data to the current collection.
476+
"""
477+
pass
478+
475479
@abstractmethod
476480
async def set_tenant(self, tenant: str, database: str = DEFAULT_DATABASE) -> None:
477481
"""Set the tenant and database for the client. Raises an error if the tenant or
@@ -648,7 +652,6 @@ async def _modify(
648652
pass
649653

650654
@abstractmethod
651-
@override
652655
async def _fork(
653656
self,
654657
collection_id: UUID,

Diff for: chromadb/api/async_client.py

+21
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,27 @@ async def _modify(
268268
database=self.database,
269269
)
270270

271+
@override
272+
async def _fork(
273+
self,
274+
collection_id: UUID,
275+
new_name: str,
276+
embedding_function: Optional[
277+
EmbeddingFunction[Embeddable]
278+
] = ef.DefaultEmbeddingFunction(), # type: ignore
279+
data_loader: Optional[DataLoader[Loadable]] = None,
280+
) -> AsyncCollection:
281+
model = await self._server._fork(
282+
collection_id=collection_id,
283+
new_name=new_name,
284+
)
285+
return AsyncCollection(
286+
client=self._server,
287+
model=model,
288+
embedding_function=embedding_function,
289+
data_loader=data_loader,
290+
)
291+
271292
@override
272293
async def delete_collection(
273294
self,

Diff for: chromadb/api/async_fastapi.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ async def _fork(
410410
) -> CollectionModel:
411411
resp_json = await self._make_request(
412412
"post",
413-
f"/tenants/{tenant}/databases/{database}/collections/{id}/fork",
413+
f"/tenants/{tenant}/databases/{database}/collections/{collection_id}/fork",
414414
json={"new_name": new_name},
415415
)
416416
model = CollectionModel.from_json(resp_json)

Diff for: chromadb/api/client.py

+21
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,27 @@ def _modify(
235235
new_configuration=new_configuration,
236236
)
237237

238+
@override
239+
def _fork(
240+
self,
241+
collection_id: UUID,
242+
new_name: str,
243+
embedding_function: Optional[
244+
EmbeddingFunction[Embeddable]
245+
] = ef.DefaultEmbeddingFunction(), # type: ignore
246+
data_loader: Optional[DataLoader[Loadable]] = None,
247+
) -> Collection:
248+
model = self._server._fork(
249+
collection_id=collection_id,
250+
new_name=new_name,
251+
)
252+
return Collection(
253+
client=self._server,
254+
model=model,
255+
embedding_function=embedding_function,
256+
data_loader=data_loader,
257+
)
258+
238259
@override
239260
def delete_collection(
240261
self,

Diff for: chromadb/api/fastapi.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ def _fork(
363363
"""Forks a collection"""
364364
resp_json = self._make_request(
365365
"post",
366-
f"/tenants/{tenant}/databases/{database}/collections/{id}/fork",
366+
f"/tenants/{tenant}/databases/{database}/collections/{collection_id}/fork",
367367
json={"new_name": new_name},
368368
)
369369
model = CollectionModel.from_json(resp_json)

0 commit comments

Comments
 (0)