From 3781f1ddda6a110b3750ab1cc22f3e44665cbdf4 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Wed, 21 Jun 2023 17:27:57 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A8=20refactor(loading.py):=20extract?= =?UTF-8?q?=20persist=20parameter=20from=20params=20for=20Chroma=20vector?= =?UTF-8?q?=20store=20instantiation=20=E2=9C=A8=20feat(loading.py):=20add?= =?UTF-8?q?=20persist=20parameter=20to=20Chroma=20vector=20store=20instant?= =?UTF-8?q?iation=20to=20enable=20persistence=20of=20vector=20store=20The?= =?UTF-8?q?=20persist=20parameter=20is=20now=20extracted=20from=20the=20pa?= =?UTF-8?q?rams=20dictionary=20before=20instantiating=20the=20Chroma=20vec?= =?UTF-8?q?tor=20store.=20This=20improves=20readability=20and=20reduces=20?= =?UTF-8?q?the=20complexity=20of=20the=20code.=20The=20persist=20parameter?= =?UTF-8?q?=20is=20now=20added=20to=20the=20Chroma=20vector=20store=20inst?= =?UTF-8?q?antiation=20to=20enable=20persistence=20of=20the=20vector=20sto?= =?UTF-8?q?re.=20This=20allows=20the=20vector=20store=20to=20be=20reused?= =?UTF-8?q?=20across=20multiple=20sessions,=20improving=20performance=20an?= =?UTF-8?q?d=20reducing=20the=20time=20required=20to=20load=20the=20vector?= =?UTF-8?q?=20store.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/interface/loading.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/backend/langflow/interface/loading.py b/src/backend/langflow/interface/loading.py index a765d3b9b..260104323 100644 --- a/src/backend/langflow/interface/loading.py +++ b/src/backend/langflow/interface/loading.py @@ -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):