From 7da5197f35cf35cbbda3c19567521a7a7464b400 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Thu, 22 Jun 2023 22:10:29 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A8=20refactor(vector=5Fstore.py):=20r?= =?UTF-8?q?efactor=20initialize=5Fsupabase=20function=20to=20improve=20rea?= =?UTF-8?q?dability=20and=20remove=20redundant=20code=20The=20function=20n?= =?UTF-8?q?ow=20checks=20if=20"texts"=20is=20in=20the=20params=20dictionar?= =?UTF-8?q?y=20and=20renames=20it=20to=20"documents"=20for=20consistency.?= =?UTF-8?q?=20The=20"supabase=5Furl"=20and=20"supabase=5Fservice=5Fkey"=20?= =?UTF-8?q?are=20now=20removed=20from=20the=20params=20dictionary=20and=20?= =?UTF-8?q?passed=20directly=20to=20the=20create=5Fclient=20function.=20Th?= =?UTF-8?q?e=20function=20also=20removes=20the=20"documents"=20and=20"text?= =?UTF-8?q?s"=20keys=20from=20the=20params=20dictionary=20if=20there=20are?= =?UTF-8?q?=20no=20documents=20in=20the=20params.=20This=20improves=20the?= =?UTF-8?q?=20readability=20of=20the=20code=20and=20removes=20redundant=20?= =?UTF-8?q?code.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../langflow/interface/initialize/vector_store.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/backend/langflow/interface/initialize/vector_store.py b/src/backend/langflow/interface/initialize/vector_store.py index d960adb89..2f8c0c5ac 100644 --- a/src/backend/langflow/interface/initialize/vector_store.py +++ b/src/backend/langflow/interface/initialize/vector_store.py @@ -24,18 +24,20 @@ def initialize_supabase(class_object: Type[SupabaseVectorStore], params: dict): if "supabase_url" not in params or "supabase_service_key" not in params: raise ValueError("Supabase url and service key must be provided in the params") + if "texts" in params: + params["documents"] = params.pop("texts") client_kwargs = { - "supabase_url": params["supabase_url"], - "supabase_key": params["supabase_service_key"], + "supabase_url": params.pop("supabase_url"), + "supabase_key": params.pop("supabase_service_key"), } supabase: Client = create_client(**client_kwargs) if not docs_in_params(params): + params.pop("documents", None) + params.pop("texts", None) return class_object(client=supabase, **params) # If there are docs in the params, create a new index - if "texts" in params: - params["documents"] = params.pop("texts") return class_object.from_documents(client=supabase, **params)