Client
LocalAPI Objectsโ
class LocalAPI(API)
heartbeatโ
def heartbeat() -> int
Ping the database to ensure it is alive
Returns:
The current time in milliseconds
create_collectionโ
def create_collection(name: str,
metadata: Optional[Metadata] = None,
embedding_function: Optional[Callable] = None,
get_or_create: bool = False) -> Collection
Create a new collection with the given name and metadata.
Arguments:
name
- The name of the collection to createmetadata
- Optional metadata to associate with the collectionembedding_function
- Optional function to use to embed documentsget_or_create
- If True, return the existing collection if it exists
Returns:
The newly created collection
Raises:
ValueError
- If the collection already exists and get_or_create is FalseValueError
- If the collection name is invalid
Examples:
client.create_collection("my_collection")
# collection(name="my_collection", metadata={})
client.create_collection("my_collection", metadata={"foo": "bar"})
# collection(name="my_collection", metadata={"foo": "bar"})
get_or_create_collectionโ
def get_or_create_collection(
name: str,
metadata: Optional[Metadata] = None,
embedding_function: Optional[Callable] = None) -> Collection
Get or create a collection with the given name and metadata.
Arguments:
name
- The name of the collection to get or createmetadata
- Optional metadata to associate with the collectionembedding_function
- Optional function to use to embed documents
Returns:
The collection
Examples:
client.get_or_create_collection("my_collection")
# collection(name="my_collection", metadata={})
get_collectionโ
def get_collection(
name: str,
embedding_function: Optional[Callable] = None) -> Collection
Get a collection with the given name.
Arguments:
name
- The name of the collection to getembedding_function
- Optional function to use to embed documents
Returns:
The collection
Raises:
ValueError
- If the collection does not exist
Examples:
client.get_collection("my_collection")
# collection(name="my_collection", metadata={})
list_collectionsโ
def list_collections() -> Sequence[Collection]
List all collections.
Returns:
A list of collections
Examples:
client.list_collections()
# [collection(name="my_collection", metadata={})]
delete_collectionโ
def delete_collection(name: str) -> None
Delete a collection with the given name.
Arguments:
name
- The name of the collection to delete
Raises:
ValueError
- If the collection does not exist
Examples:
client.delete_collection("my_collection")
resetโ
def reset() -> bool
Reset the database. This will delete all collections and items.
Returns:
True if the database was reset successfully
persistโ
def persist() -> bool
Persist the database to disk.
Returns:
True if the database was persisted successfully
get_versionโ
def get_version() -> str
Get the version of Chroma.
Returns:
The version of Chroma