Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
File size: 1,464 Bytes
79269c4 5407e1f 79269c4 cb13c5d 79269c4 cb13c5d 79269c4 |
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 |
import logging
import os
import platform
from typing import Literal
import chromadb
from dotenv import load_dotenv
os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "1"
from chromadb.config import Settings
# Set up logging
logging.basicConfig(
level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s"
)
logger = logging.getLogger(__name__)
load_dotenv()
os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "1"
# Set up logging
logging.basicConfig(
level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s"
)
logger = logging.getLogger(__name__)
load_dotenv()
CHROMA_CLIENT = None
def get_save_path() -> Literal["chroma/"] | Literal["/data/chroma/"]:
path = "chroma/" if platform.system() == "Darwin" else "/data/chroma/"
logger.info(f"Using save path: {path}")
return path
def get_chroma_client():
global CHROMA_CLIENT
if CHROMA_CLIENT is None:
SAVE_PATH = get_save_path()
CHROMA_CLIENT = chromadb.PersistentClient(
path=SAVE_PATH,
settings=Settings(anonymized_telemetry=False, is_persistent=True),
)
return CHROMA_CLIENT
def get_collection(chroma_client, embedding_function, collection_name):
logger.info(f"Getting or creating collection: {collection_name}")
return chroma_client.create_collection(
name=collection_name,
get_or_create=True,
embedding_function=embedding_function,
metadata={"hnsw:space": "cosine"},
)
|