Skip to content

Commit

Permalink
[BUG]: Removed mutable default values in Ephemeral, Persistent and Ht…
Browse files Browse the repository at this point in the history
…tp clients (#1270)

## Description of changes

*Summarize the changes made by this PR.*
 - Improvements & Bug fixes
	 - Removed mutable default settings and headers, as this seems

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

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

## Documentation Changes
N/A

This issue partly resolves - #1209 (for multiple local persistent
clients with different persist paths)
  • Loading branch information
tazarov authored Oct 24, 2023
1 parent 0552704 commit 05de6d0
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions chromadb/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Dict
from typing import Dict, Optional
import logging
from chromadb.api.client import Client as ClientCreator
from chromadb.api.client import AdminClient as AdminClientCreator
Expand Down Expand Up @@ -95,7 +95,7 @@ def get_settings() -> Settings:


def EphemeralClient(
settings: Settings = Settings(),
settings: Optional[Settings] = None,
tenant: str = DEFAULT_TENANT,
database: str = DEFAULT_DATABASE,
) -> ClientAPI:
Expand All @@ -107,14 +107,16 @@ def EphemeralClient(
tenant: The tenant to use for this client. Defaults to the default tenant.
database: The database to use for this client. Defaults to the default database.
"""
if settings is None:
settings = Settings()
settings.is_persistent = False

return ClientCreator(settings=settings, tenant=tenant, database=database)


def PersistentClient(
path: str = "./chroma",
settings: Settings = Settings(),
settings: Optional[Settings] = None,
tenant: str = DEFAULT_TENANT,
database: str = DEFAULT_DATABASE,
) -> ClientAPI:
Expand All @@ -127,6 +129,8 @@ def PersistentClient(
tenant: The tenant to use for this client. Defaults to the default tenant.
database: The database to use for this client. Defaults to the default database.
"""
if settings is None:
settings = Settings()
settings.persist_directory = path
settings.is_persistent = True

Expand All @@ -137,8 +141,8 @@ def HttpClient(
host: str = "localhost",
port: str = "8000",
ssl: bool = False,
headers: Dict[str, str] = {},
settings: Settings = Settings(),
headers: Optional[Dict[str, str]] = None,
settings: Optional[Settings] = None,
tenant: str = DEFAULT_TENANT,
database: str = DEFAULT_DATABASE,
) -> ClientAPI:
Expand All @@ -156,6 +160,11 @@ def HttpClient(
database: The database to use for this client. Defaults to the default database.
"""

if headers is None:
headers = {}
if settings is None:
settings = Settings()

settings.chroma_api_impl = "chromadb.api.fastapi.FastAPI"
settings.chroma_server_host = host
settings.chroma_server_http_port = port
Expand Down

0 comments on commit 05de6d0

Please sign in to comment.