Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
spikechroma committed Aug 21, 2024
1 parent ad43937 commit 6eb54ca
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 32 deletions.
9 changes: 8 additions & 1 deletion chromadb/api/models/AsyncCollection.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,14 @@ async def update(
ids, embeddings, metadatas, documents, images, uris
)

await self._client._update(self.id, embedding_set["ids"], cast(Embeddings, embedding_set["embeddings"]), embedding_set["metadatas"], embedding_set["documents"], embedding_set["uris"])
await self._client._update(
self.id,
embedding_set["ids"],
cast(Embeddings, embedding_set["embeddings"]),
embedding_set["metadatas"],
embedding_set["documents"],
embedding_set["uris"],
)

async def upsert(
self,
Expand Down
12 changes: 9 additions & 3 deletions chromadb/api/models/Collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def add(
images,
uris,
)

self._client._add(
embedding_set["ids"],
self.id,
Expand All @@ -89,7 +89,6 @@ def add(
embedding_set["documents"],
embedding_set["uris"],
)


def get(
self,
Expand Down Expand Up @@ -262,7 +261,14 @@ def update(
ids, embeddings, metadatas, documents, images, uris
)

self._client._update(self.id, embedding_set["ids"], cast(Embeddings, embedding_set["embeddings"]), embedding_set["metadatas"], embedding_set["documents"], embedding_set["uris"])
self._client._update(
self.id,
embedding_set["ids"],
cast(Embeddings, embedding_set["embeddings"]),
embedding_set["metadatas"],
embedding_set["documents"],
embedding_set["uris"],
)

def upsert(
self,
Expand Down
45 changes: 17 additions & 28 deletions chromadb/api/models/CollectionCommon.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ def _update_model_after_modify_success(
self._model["name"] = name
if metadata:
self._model["metadata"] = metadata

def _process_add_request(
self,
ids: OneOrMany[ID],
Expand All @@ -439,8 +439,7 @@ def _process_add_request(
documents: Optional[OneOrMany[Document]],
images: Optional[OneOrMany[Image]] = None,
uris: Optional[OneOrMany[URI]] = None,
) -> EmbeddingSet:

) -> EmbeddingSet:
unpacked_embedding_set = self._unpack_embedding_set(
ids,
embeddings,
Expand Down Expand Up @@ -472,14 +471,14 @@ def _process_add_request(
unpacked_embedding_set["images"],
unpacked_embedding_set["uris"],
)

return {
"ids": unpacked_embedding_set["ids"],
"embeddings": prepared_embeddings,
"metadatas": unpacked_embedding_set["metadatas"],
"metadatas": unpacked_embedding_set["metadatas"],
"documents": unpacked_embedding_set["documents"],
"images": unpacked_embedding_set["images"],
"uris": unpacked_embedding_set["uris"],
"uris": unpacked_embedding_set["uris"],
}

def _prepare_update_request(
Expand All @@ -488,19 +487,14 @@ def _prepare_update_request(
documents: Optional[Documents],
images: Optional[Images],
) -> Embeddings:

if embeddings is None:
if documents is not None:
embeddings = self._embed(
input=documents
)
embeddings = self._embed(input=documents)
elif images is not None:
embeddings = self._embed(
input=images
)
embeddings = self._embed(input=images)

return cast(Embeddings, embeddings)

def _process_update_request(
self,
ids: OneOrMany[ID],
Expand All @@ -513,7 +507,7 @@ def _process_update_request(
metadatas: Optional[OneOrMany[Metadata]],
documents: Optional[OneOrMany[Document]],
images: Optional[OneOrMany[Image]],
uris: Optional[OneOrMany[URI]]
uris: Optional[OneOrMany[URI]],
) -> EmbeddingSet:
unpacked_embedding_set = self._unpack_embedding_set(
ids, embeddings, metadatas, documents, images, uris
Expand All @@ -534,20 +528,20 @@ def _process_update_request(
unpacked_embedding_set["uris"],
require_embeddings_or_data=False,
)

prepared_embeddings = self._prepare_update_request(
normalized_embeddings,
unpacked_embedding_set["documents"],
unpacked_embedding_set["images"],
)

return {
"ids": unpacked_embedding_set["ids"],
"embeddings": prepared_embeddings,
"metadatas": unpacked_embedding_set["metadatas"],
"metadatas": unpacked_embedding_set["metadatas"],
"documents": unpacked_embedding_set["documents"],
"images": unpacked_embedding_set["images"],
"uris": unpacked_embedding_set["uris"],
"uris": unpacked_embedding_set["uris"],
}

def _prepare_upsert_request(
Expand All @@ -556,16 +550,11 @@ def _prepare_upsert_request(
documents: Optional[Documents],
images: Optional[Images],
) -> Embeddings:

if embeddings is None:
if documents is not None:
embeddings = self._embed(
input=documents
)
embeddings = self._embed(input=documents)
elif images is not None:
embeddings = self._embed(
input=images
)
embeddings = self._embed(input=images)

return cast(Embeddings, embeddings)

Expand Down Expand Up @@ -612,10 +601,10 @@ def _process_upsert_request(
return {
"ids": unpacked_embedding_set["ids"],
"embeddings": prepared_embeddings,
"metadatas": unpacked_embedding_set["metadatas"],
"metadatas": unpacked_embedding_set["metadatas"],
"documents": unpacked_embedding_set["documents"],
"images": unpacked_embedding_set["images"],
"uris": unpacked_embedding_set["uris"],
"uris": unpacked_embedding_set["uris"],
}

# TODO: Rename this function
Expand Down

0 comments on commit 6eb54ca

Please sign in to comment.