mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-06-18 10:45:31 -04:00
49 lines
1.1 KiB
Python
49 lines
1.1 KiB
Python
"""
|
|
chroma_client.py
|
|
|
|
Singleton ChromaDB HTTP client.
|
|
Connects to a ChromaDB instance running as a standalone service.
|
|
"""
|
|
|
|
import os
|
|
import logging
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
_client = None
|
|
|
|
|
|
def get_chroma_client():
|
|
"""Get or create the singleton ChromaDB HTTP client.
|
|
|
|
Raises RuntimeError with a clear install hint if the `chromadb` package
|
|
is not installed — it's an optional dependency (RAG + memory vectors).
|
|
"""
|
|
global _client
|
|
if _client is not None:
|
|
return _client
|
|
|
|
try:
|
|
import chromadb
|
|
except ImportError as e:
|
|
raise RuntimeError(
|
|
"ChromaDB integration is not installed. Install the optional "
|
|
"dependency with: pip install chromadb-client"
|
|
) from e
|
|
|
|
host = os.getenv("CHROMADB_HOST", "localhost")
|
|
port = int(os.getenv("CHROMADB_PORT", "8100"))
|
|
|
|
_client = chromadb.HttpClient(host=host, port=port)
|
|
|
|
# Health check
|
|
_client.heartbeat()
|
|
logger.info(f"ChromaDB connected: {host}:{port}")
|
|
return _client
|
|
|
|
|
|
def reset_client():
|
|
"""Reset the singleton (e.g. after config change)."""
|
|
global _client
|
|
_client = None
|