Changes to accomodate new vector stores (#366)

This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-05-27 14:10:54 -03:00 • committed by GitHub
commit 09aa796af0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 571 additions and 247 deletions

View file

@ -108,6 +108,8 @@ utilities:
- SQLDatabase
vectorstores:
- Chroma
- Qdrant
- Weaviate
wrappers:
- RequestsWrapper # Wait more tests
# - ChatPromptTemplate

View file

@ -1,4 +1,3 @@
from copy import deepcopy
from typing import Any, Dict, List, Optional, Union
from langflow.graph.base import Node

View file

@ -10,7 +10,6 @@ from langchain import (
requests,
text_splitter,
utilities,
vectorstores,
)
from langchain.agents import agent_toolkits
from langchain.chat_models import ChatOpenAI

View file

@ -634,6 +634,26 @@ class VectorStoreFrontendNode(FrontendNode):
@staticmethod
def format_field(field: TemplateField, name: Optional[str] = None) -> None:
FrontendNode.format_field(field, name)
# Define common field attributes
basic_fields = ["work_dir", "collection_name", "api_key", "location"]
advanced_fields = [
"n_dim",
"key",
"prefix",
"distance_func",
"content_payload_key",
"metadata_payload_key",
"timeout",
"host",
"path",
"url",
"port",
"https",
"prefer_grpc",
"grpc_port",
]
# Check and set field attributes
if field.name == "texts":
field.name = "documents"
field.field_type = "TextSplitter"
@ -642,7 +662,7 @@ class VectorStoreFrontendNode(FrontendNode):
field.show = True
field.advanced = False
if "embedding" in field.name:
elif "embedding" in field.name:
# for backwards compatibility
field.name = "embedding"
field.required = True
@ -651,9 +671,21 @@ class VectorStoreFrontendNode(FrontendNode):
field.display_name = "Embedding"
field.field_type = "Embeddings"
elif field.name == "n_dim":
field.show = True
field.advanced = True
elif field.name == "work_dir":
elif field.name in basic_fields:
field.show = True
field.advanced = False
if field.name == "api_key":
field.display_name = "API Key"
field.password = True
elif field.name == "location":
field.value = ":memory:"
field.placeholder = ":memory:"
elif field.name in advanced_fields:
field.show = True
field.advanced = True
if "key" in field.name:
field.password = False
# TODO: Weaviate requires weaviate_url to be passed as it is not part of
# the class or from_texts method. We need the add_extra_fields to fix this