Skip to content

Commit

Permalink
fix: Removed mutable default values in Ephemeral, Persistent and Http…
Browse files Browse the repository at this point in the history
… clients
  • Loading branch information
tazarov committed Oct 22, 2023
1 parent 019b954 commit 221fc51
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 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
import chromadb.config
from chromadb.config import Settings, System
Expand Down Expand Up @@ -55,7 +55,7 @@

is_client = False
try:
from chromadb.is_thin_client import is_thin_client # type: ignore
from chromadb.is_thin_client import is_thin_client

is_client = is_thin_client
except ImportError:
Expand Down Expand Up @@ -95,24 +95,30 @@ def get_settings() -> Settings:
return __settings


def EphemeralClient(settings: Settings = Settings()) -> API:
def EphemeralClient(settings: Optional[Settings] = None) -> API:
"""
Creates an in-memory instance of Chroma. This is useful for testing and
development, but not recommended for production use.
"""
if settings is None:
settings = Settings()
settings.is_persistent = False

return Client(settings)


def PersistentClient(path: str = "./chroma", settings: Settings = Settings()) -> API:
def PersistentClient(
path: str = "./chroma", settings: Optional[Settings] = None
) -> API:
"""
Creates a persistent instance of Chroma that saves to disk. This is useful for
testing and development, but not recommended for production use.
Args:
path: The directory to save Chroma's data to. Defaults to "./chroma".
"""
if settings is None:
settings = Settings()
settings.persist_directory = path
settings.is_persistent = True

Expand All @@ -123,8 +129,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,
) -> API:
"""
Creates a client that connects to a remote Chroma server. This supports
Expand All @@ -138,6 +144,11 @@ def HttpClient(
headers: A dictionary of headers to send to the Chroma server. Defaults to {}.
"""

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 221fc51

Please sign in to comment.