Spaces:
Runtime error
Runtime error
File size: 1,088 Bytes
e7ece9c |
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 |
from chromadb import Client, ClientAPI
class Chroma:
"""
Chroma class to instantiate a vector db in memory.
"""
def __init__(self, default_database: str = "default", first_collection_name: str = "test", top_k: int = 1):
self.api: ClientAPI = Client()
self.collection_pointer = self.api.create_collection(first_collection_name)
self.top_k = top_k
def new_collection(self, name: str, **kwargs):
try:
self.api.create_collection(name, **kwargs)
except Exception as e:
print(e)
def add_data_to(self, data):
try:
self.collection_pointer.add(
embeddings=data.get("embeddings"),
documents=data.get("contents"),
metadatas=data.get("metadatas"),
ids=data.get("ids")
)
except Exception as e:
print(e)
def switch_collection(self, new_pointer: str):
try:
self.collection_pointer = self.api.get_collection(new_pointer)
except Exception as e:
print(e) |