-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart_chroma.py
More file actions
72 lines (61 loc) · 2.2 KB
/
Copy pathstart_chroma.py
File metadata and controls
72 lines (61 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
"""
start_chroma.py -- Starts ChromaDB as an HTTP server on localhost:8000
Works with ChromaDB 1.x (tested on 1.5.9)
Usage:
python start_chroma.py
"""
import os
import sys
# Fix Windows console encoding issues
if sys.platform == "win32":
import io
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8", errors="replace")
sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding="utf-8", errors="replace")
HOST = "0.0.0.0"
PORT = 8000
PERSIST_DIR = "./chroma_data"
os.makedirs(PERSIST_DIR, exist_ok=True)
try:
import uvicorn
except ImportError:
print("[ERROR] uvicorn is not installed. Run: pip install uvicorn")
sys.exit(1)
try:
import chromadb
print(f"ChromaDB version: {chromadb.__version__}")
except ImportError:
print("[ERROR] chromadb is not installed. Run: pip install chromadb")
sys.exit(1)
# --- ChromaDB 1.x (uses chromadb.app + FastAPI) ---------------------------
try:
from chromadb.server.fastapi import FastAPI as ChromaFastAPI
settings = chromadb.Settings(
is_persistent=True,
persist_directory=PERSIST_DIR,
anonymized_telemetry=False,
)
server = ChromaFastAPI(settings)
print(f"[OK] ChromaDB 1.x server starting on http://localhost:{PORT}")
print(f" Data directory : {os.path.abspath(PERSIST_DIR)}")
print(f" Press Ctrl+C to stop")
uvicorn.run(server.app(), host=HOST, port=PORT, log_level="info")
sys.exit(0)
except ImportError as e:
print(f"[WARN] chromadb.server.fastapi not available: {e}")
# --- ChromaDB 0.4/0.5 fallback -------------------------------------------
try:
from chromadb.app import create_app
settings = chromadb.Settings(
is_persistent=True,
persist_directory=PERSIST_DIR,
anonymized_telemetry=False,
)
app = create_app(settings)
print(f"[OK] ChromaDB 0.4/0.5 server starting on http://localhost:{PORT}")
uvicorn.run(app, host=HOST, port=PORT, log_level="info")
sys.exit(0)
except (ImportError, AttributeError) as e:
print(f"[WARN] chromadb.app.create_app not available: {e}")
print("[ERROR] Could not find a compatible ChromaDB server entrypoint.")
print(" Try: pip install chromadb uvicorn --upgrade")
sys.exit(1)