Skip to content

Commit

Permalink
[CLN]: Clean up small nits (#1489)
Browse files Browse the repository at this point in the history
## Description of changes

*Summarize the changes made by this PR.*
 - Improvements & Bug fixes
	 - Removed redeclaration of EmbeddingFunction and DataLoader
	 - Removed unused imports
	 - Added doc strings
	 - Removed redeclaration of typevars L/D

## Test plan
*How are these changes tested?*

- [x] Tests pass locally with `pytest` for python

## Documentation Changes
N/A
  • Loading branch information
tazarov authored Dec 18, 2023
1 parent 889569c commit 096e018
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 21 deletions.
4 changes: 4 additions & 0 deletions chromadb/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def create_collection(
embedding_function: Optional function to use to embed documents.
Uses the default embedding function if not provided.
get_or_create: If True, return the existing collection if it exists.
data_loader: Optional function to use to load records (documents, images, etc.)
Returns:
Collection: The newly created collection.
Expand Down Expand Up @@ -129,9 +130,11 @@ def get_collection(
) -> Collection:
"""Get a collection with the given name.
Args:
id: The UUID of the collection to get. Id and Name are simultaneously used for lookup if provided.
name: The name of the collection to get
embedding_function: Optional function to use to embed documents.
Uses the default embedding function if not provided.
data_loader: Optional function to use to load records (documents, images, etc.)
Returns:
Collection: The collection
Expand Down Expand Up @@ -165,6 +168,7 @@ def get_or_create_collection(
provided and not None. If the collection does not exist, the
new collection will be created with the provided metadata.
embedding_function: Optional function to use to embed documents
data_loader: Optional function to use to load records (documents, images, etc.)
Returns:
The collection
Expand Down
19 changes: 1 addition & 18 deletions chromadb/api/types.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Optional, Sequence, Union, TypeVar, List, Dict, Any, Tuple, cast
from typing import Optional, Union, TypeVar, List, Dict, Any, Tuple, cast
from numpy.typing import NDArray
import numpy as np
from typing_extensions import Literal, TypedDict, Protocol
Expand Down Expand Up @@ -145,20 +145,10 @@ def maybe_cast_one_to_many_image(target: OneOrMany[Image]) -> Images:
D = TypeVar("D", bound=Embeddable, contravariant=True)


class EmbeddingFunction(Protocol[D]):
def __call__(self, input: D) -> Embeddings:
...


Loadable = List[Optional[Image]]
L = TypeVar("L", covariant=True, bound=Loadable)


class DataLoader(Protocol[L]):
def __call__(self, uris: Sequence[Optional[URI]]) -> L:
...


class GetResult(TypedDict):
ids: List[ID]
embeddings: Optional[List[Embedding]]
Expand Down Expand Up @@ -189,10 +179,6 @@ class IndexMetadata(TypedDict):
time_created: float


Embeddable = Union[Documents, Images]
D = TypeVar("D", bound=Embeddable, contravariant=True)


class EmbeddingFunction(Protocol[D]):
def __call__(self, input: D) -> Embeddings:
...
Expand All @@ -214,9 +200,6 @@ def validate_embedding_function(
)


L = TypeVar("L", covariant=True)


class DataLoader(Protocol[L]):
def __call__(self, uris: URIs) -> L:
...
Expand Down
3 changes: 0 additions & 3 deletions chromadb/server/fastapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
from fastapi.routing import APIRoute
from fastapi import HTTPException, status
from uuid import UUID

import chromadb
from chromadb.api.models.Collection import Collection
from chromadb.api.types import GetResult, QueryResult
from chromadb.auth import (
Expand All @@ -30,7 +28,6 @@
attr_from_resource_object,
)
from chromadb.config import DEFAULT_DATABASE, DEFAULT_TENANT, Settings, System
import chromadb.server
import chromadb.api
from chromadb.api import ServerAPI
from chromadb.errors import (
Expand Down

0 comments on commit 096e018

Please sign in to comment.