Spaces:
Build error
Build error
File size: 1,313 Bytes
f51bb92 |
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 |
from langchain_community.vectorstores import Chroma
from modules.vectorstore.base import VectorStoreBase
import os
class ChromaVectorStore(VectorStoreBase):
def __init__(self, config):
self.config = config
self._init_vector_db()
def _init_vector_db(self):
self.chroma = Chroma()
def create_database(self, document_chunks, embedding_model):
self.vectorstore = self.chroma.from_documents(
documents=document_chunks,
embedding=embedding_model,
persist_directory=os.path.join(
self.config["vectorstore"]["db_path"],
"db_"
+ self.config["vectorstore"]["db_option"]
+ "_"
+ self.config["vectorstore"]["model"],
),
)
def load_database(self, embedding_model):
self.vectorstore = Chroma(
persist_directory=os.path.join(
self.config["vectorstore"]["db_path"],
"db_"
+ self.config["vectorstore"]["db_option"]
+ "_"
+ self.config["vectorstore"]["model"],
),
embedding_function=embedding_model,
)
return self.vectorstore
def as_retriever(self):
return self.vectorstore.as_retriever()
|