From 8feaa3b937d99c4f23c4ac8ca0885f55201585a5 Mon Sep 17 00:00:00 2001 From: Edwin Jose Date: Thu, 12 Sep 2024 14:38:45 -0400 Subject: [PATCH 1/7] feat(Weaviate): Enforce capitalized index name - Add get_valid_index_name method to ensure index name is capitalized - Update index_name input with info about capitalization requirement - Implement capitalization check before creating vector store - Remove type ignore comment for weaviate import Ref: https://forum.weaviate.io/t/feature-or-bug-first-letter-of-class-name-gets-capitalized/1203 --- .../components/vectorstores/Weaviate.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/backend/base/langflow/components/vectorstores/Weaviate.py b/src/backend/base/langflow/components/vectorstores/Weaviate.py index 94266720cb4..ea93f6eb068 100644 --- a/src/backend/base/langflow/components/vectorstores/Weaviate.py +++ b/src/backend/base/langflow/components/vectorstores/Weaviate.py @@ -1,6 +1,6 @@ from typing import List -import weaviate # type: ignore +import weaviate from langchain_community.vectorstores import Weaviate from langflow.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store @@ -19,7 +19,12 @@ class WeaviateVectorStoreComponent(LCVectorStoreComponent): inputs = [ StrInput(name="url", display_name="Weaviate URL", value="http://localhost:8080", required=True), SecretStrInput(name="api_key", display_name="API Key", required=False), - StrInput(name="index_name", display_name="Index Name", required=True), + StrInput( + name="index_name", + display_name="Index Name", + required=True, + info="Please use capitalized index name. Weaviate requires the index name to be capitalized.", + ), StrInput(name="text_key", display_name="Text Key", value="text", advanced=True), MultilineInput(name="search_query", display_name="Search Query"), DataInput( @@ -37,6 +42,13 @@ class WeaviateVectorStoreComponent(LCVectorStoreComponent): ), BoolInput(name="search_by_text", display_name="Search By Text", advanced=True), ] + index_name: str + + def get_valid_index_name(self, client: weaviate.Client, index_name: str) -> str: + capitalized_name = index_name.capitalize() + if index_name != capitalized_name: + raise ValueError(f"Weaviate requires the index name to be capitalized. Use: {capitalized_name}") + return capitalized_name @check_cached_vector_store def build_vector_store(self) -> Weaviate: @@ -46,6 +58,8 @@ def build_vector_store(self) -> Weaviate: else: client = weaviate.Client(url=self.url) + self.index_name = self.get_valid_index_name(client, self.index_name) + documents = [] for _input in self.ingest_data or []: if isinstance(_input, Data): From 0e9113184fdc12bb4d1da5157fe6d56f81fd3066 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Fri, 27 Sep 2024 16:09:14 +0000 Subject: [PATCH 2/7] [autofix.ci] apply automated fixes --- .../base/langflow/components/vectorstores/Weaviate.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/backend/base/langflow/components/vectorstores/Weaviate.py b/src/backend/base/langflow/components/vectorstores/Weaviate.py index d086c5f2635..bdb12392c3c 100644 --- a/src/backend/base/langflow/components/vectorstores/Weaviate.py +++ b/src/backend/base/langflow/components/vectorstores/Weaviate.py @@ -1,7 +1,4 @@ - -from typing import List - -import weaviate +import weaviate from langchain_community.vectorstores import Weaviate from langflow.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store From 5a699cc05e5386935dd8080a5d36eb815e8d23bc Mon Sep 17 00:00:00 2001 From: Edwin Jose Date: Fri, 27 Sep 2024 12:16:25 -0400 Subject: [PATCH 3/7] updated the component --- .../langflow/components/vectorstores/Weaviate.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/backend/base/langflow/components/vectorstores/Weaviate.py b/src/backend/base/langflow/components/vectorstores/Weaviate.py index d086c5f2635..a8de19ef140 100644 --- a/src/backend/base/langflow/components/vectorstores/Weaviate.py +++ b/src/backend/base/langflow/components/vectorstores/Weaviate.py @@ -1,7 +1,4 @@ - -from typing import List - -import weaviate +import weaviate from langchain_community.vectorstores import Weaviate from langflow.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store @@ -24,7 +21,7 @@ class WeaviateVectorStoreComponent(LCVectorStoreComponent): name="index_name", display_name="Index Name", required=True, - info="Please use capitalized index name. Weaviate requires the index name to be capitalized.", + info="Requires capitalized index name.", ), StrInput(name="text_key", display_name="Text Key", value="text", advanced=True), MultilineInput(name="search_query", display_name="Search Query"), @@ -43,11 +40,10 @@ class WeaviateVectorStoreComponent(LCVectorStoreComponent): ), BoolInput(name="search_by_text", display_name="Search By Text", advanced=True), ] - index_name: str - def get_valid_index_name(self, client: weaviate.Client, index_name: str) -> str: - capitalized_name = index_name.capitalize() - if index_name != capitalized_name: + def get_valid_index_name(self, client: weaviate.Client) -> str: + capitalized_name = self.index_name.capitalize() + if self.index_name != capitalized_name: raise ValueError(f"Weaviate requires the index name to be capitalized. Use: {capitalized_name}") return capitalized_name @@ -59,7 +55,7 @@ def build_vector_store(self) -> Weaviate: else: client = weaviate.Client(url=self.url) - self.index_name = self.get_valid_index_name(client, self.index_name) + self.index_name = self.get_valid_index_name(client) documents = [] for _input in self.ingest_data or []: From eca151117e9a1707c92d69087b1d795ba551cbdc Mon Sep 17 00:00:00 2001 From: Edwin Jose Date: Fri, 27 Sep 2024 15:47:53 -0400 Subject: [PATCH 4/7] Update Weaviate.py --- src/backend/base/langflow/components/vectorstores/Weaviate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/base/langflow/components/vectorstores/Weaviate.py b/src/backend/base/langflow/components/vectorstores/Weaviate.py index a8de19ef140..0fc83dfc2c4 100644 --- a/src/backend/base/langflow/components/vectorstores/Weaviate.py +++ b/src/backend/base/langflow/components/vectorstores/Weaviate.py @@ -41,7 +41,7 @@ class WeaviateVectorStoreComponent(LCVectorStoreComponent): BoolInput(name="search_by_text", display_name="Search By Text", advanced=True), ] - def get_valid_index_name(self, client: weaviate.Client) -> str: + def get_valid_index_name(self) -> str: capitalized_name = self.index_name.capitalize() if self.index_name != capitalized_name: raise ValueError(f"Weaviate requires the index name to be capitalized. Use: {capitalized_name}") From 311df5464de46a5a876b0f6ff600232df5f47a64 Mon Sep 17 00:00:00 2001 From: Edwin Jose Date: Fri, 27 Sep 2024 15:50:42 -0400 Subject: [PATCH 5/7] Lint error solved --- src/backend/base/langflow/components/vectorstores/Weaviate.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/backend/base/langflow/components/vectorstores/Weaviate.py b/src/backend/base/langflow/components/vectorstores/Weaviate.py index 0fc83dfc2c4..3388af52e39 100644 --- a/src/backend/base/langflow/components/vectorstores/Weaviate.py +++ b/src/backend/base/langflow/components/vectorstores/Weaviate.py @@ -41,7 +41,7 @@ class WeaviateVectorStoreComponent(LCVectorStoreComponent): BoolInput(name="search_by_text", display_name="Search By Text", advanced=True), ] - def get_valid_index_name(self) -> str: + def valid_index_name(self) -> str: capitalized_name = self.index_name.capitalize() if self.index_name != capitalized_name: raise ValueError(f"Weaviate requires the index name to be capitalized. Use: {capitalized_name}") @@ -55,7 +55,7 @@ def build_vector_store(self) -> Weaviate: else: client = weaviate.Client(url=self.url) - self.index_name = self.get_valid_index_name(client) + self.index_name = self.valid_index_name() documents = [] for _input in self.ingest_data or []: From 6699c3f552a1360363e8a686945064fa75dac014 Mon Sep 17 00:00:00 2001 From: Edwin Jose Date: Mon, 30 Sep 2024 00:56:51 -0400 Subject: [PATCH 6/7] Code corrections discarded unwanted validate functions --- src/backend/base/langflow/components/vectorstores/Weaviate.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/backend/base/langflow/components/vectorstores/Weaviate.py b/src/backend/base/langflow/components/vectorstores/Weaviate.py index 3388af52e39..5a3138bd9b0 100644 --- a/src/backend/base/langflow/components/vectorstores/Weaviate.py +++ b/src/backend/base/langflow/components/vectorstores/Weaviate.py @@ -55,7 +55,8 @@ def build_vector_store(self) -> Weaviate: else: client = weaviate.Client(url=self.url) - self.index_name = self.valid_index_name() + if self.index_name != self.index_name.capitalize(): + raise ValueError(f"Weaviate requires the index name to be capitalized. Use: {self.index_name.capitalize()}") documents = [] for _input in self.ingest_data or []: From 52f15a8b980e0742ec60bdd3dc98375b64d093b2 Mon Sep 17 00:00:00 2001 From: Edwin Jose Date: Mon, 30 Sep 2024 10:35:03 -0400 Subject: [PATCH 7/7] Update Weaviate.py --- .../base/langflow/components/vectorstores/Weaviate.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/backend/base/langflow/components/vectorstores/Weaviate.py b/src/backend/base/langflow/components/vectorstores/Weaviate.py index 5a3138bd9b0..af32cbd2f13 100644 --- a/src/backend/base/langflow/components/vectorstores/Weaviate.py +++ b/src/backend/base/langflow/components/vectorstores/Weaviate.py @@ -41,12 +41,6 @@ class WeaviateVectorStoreComponent(LCVectorStoreComponent): BoolInput(name="search_by_text", display_name="Search By Text", advanced=True), ] - def valid_index_name(self) -> str: - capitalized_name = self.index_name.capitalize() - if self.index_name != capitalized_name: - raise ValueError(f"Weaviate requires the index name to be capitalized. Use: {capitalized_name}") - return capitalized_name - @check_cached_vector_store def build_vector_store(self) -> Weaviate: if self.api_key: