Arag / app /core /chroma_client.py
AuthorBot
Restructure project for HF Spaces deployment
772f852
Raw
History Blame Contribute Delete
695 Bytes
"""Shared ChromaDB client factory.
Uses persistent storage on Hugging Face Spaces (/data/chroma) by default.
Set CHROMA_CLIENT_MODE=http for docker-compose with a separate ChromaDB service.
"""
import chromadb
from app.config import get_settings
_client = None
def get_chroma_client():
"""Return a cached ChromaDB client."""
global _client
if _client is None:
cfg = get_settings()
if cfg.CHROMA_CLIENT_MODE == "http":
_client = chromadb.HttpClient(
host=cfg.CHROMA_HOST,
port=cfg.CHROMA_PORT,
)
else:
_client = chromadb.PersistentClient(path=cfg.CHROMA_PERSIST_DIR)
return _client