🔨 refactor(loading.py): extract persist parameter from params for Chroma vector store instantiation

 feat(loading.py): add persist parameter to Chroma vector store instantiation to enable persistence of vector store
The persist parameter is now extracted from the params dictionary before instantiating the Chroma vector store. This improves readability and reduces the complexity of the code. The persist parameter is now added to the Chroma vector store instantiation to enable persistence of the vector store. This allows the vector store to be reused across multiple sessions, improving performance and reducing the time required to load the vector store.
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-06-21 17:27:57 -03:00
commit 3781f1ddda

View file

@ -160,13 +160,19 @@ def instantiate_vectorstore(class_object, params):
)
# Chroma requires all metadata values to not be None
if class_object.__name__ == "Chroma":
persist = params.pop("persist", False)
for doc in params["documents"]:
if doc.metadata is None:
doc.metadata = {}
for key, value in doc.metadata.items():
if value is None:
doc.metadata[key] = ""
return class_object.from_documents(**params)
vector_store = class_object.from_documents(**params)
if persist:
vector_store.persist()
else:
vector_store = class_object.from_documents(**params)
return vector_store
def instantiate_documentloader(class_object, params):