forked from marc-shade/Ollama-Workbench
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchroma_client.py
More file actions
24 lines (20 loc) · 921 Bytes
/
chroma_client.py
File metadata and controls
24 lines (20 loc) · 921 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# chroma_client.py
import os
import chromadb
from chromadb.config import Settings
def get_chroma_client(corpus_name):
corpus_path = os.path.join("corpus", corpus_name)
if not os.path.exists(corpus_path):
os.makedirs(corpus_path)
# Configure the Chroma client with the new API structure
settings = Settings(
chroma_api_impl="rest", # Can also be "sqlite" or "duckdb+parquet" based on your setup
chroma_server_host="localhost", # Replace with your Chroma server host if remote
chroma_server_port="8000", # Replace with the appropriate port
persist_directory=corpus_path # Directory to store the persistent data
)
return chromadb.Client(settings=settings)
def sanitize_collection_name(name):
sanitized_name = name.replace(" ", "_")
sanitized_name = ''.join(c for c in sanitized_name if c.isalnum() or c in ['_', '-'])
return sanitized_name