import chromadb from chromadb.config import Settings from sentence_transformers import SentenceTransformer import torch import tempfile CHROMA_DIR = "chromadb_local" COLLECTION_NAME = "prompts" EMBEDDING_MODEL = "all-MiniLM-L6-v2" def get_chroma_client(): return chromadb.Client(Settings(persist_directory=CHROMA_DIR)) def get_chroma_collection(client): try: return client.get_collection(COLLECTION_NAME) except Exception: return client.create_collection(COLLECTION_NAME) def get_embedding_model(): device = "cuda" if torch.cuda.is_available() else "cpu" cache_dir = tempfile.mkdtemp() return SentenceTransformer(EMBEDDING_MODEL, device=device, cache_folder=cache_dir)