Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

while two "NestedDict" data set advance False in a custom component, error happen #1777

Open
liaochf opened this issue Apr 26, 2024 · 2 comments
Assignees

Comments

@liaochf
Copy link

liaochf commented Apr 26, 2024

from typing import Optional, Union

from langchain.schema import BaseRetriever, Document
from langflow import CustomComponent
from langchain_community.vectorstores import VectorStore, Milvus
from langchain.embeddings.base import Embeddings
from langflow.field_typing import NestedDict,Embeddings,Document

class MilvusVectorStore(CustomComponent):
    display_name: str = "Milvus"
    description: str = "Implementation of Vector Store using Milvus"
    documentation = "https://python.langchain.com/docs/integrations/vectorstores/milvus"
    beta = True
    field_config = {
        "connection_args": {
            "display_name": "Connection Args", 
            "field_type": "NestedDict",
            "required": True,
            "value": {
                "host": "localhost",
                "port": "19530",
                "user": "",
                "password": ""
            }
        },
        "collection_name": {
            "display_name": "Collection Name",
            "field_type": "str",
            "required": False,
        },
        "documents": {
            "display_name": "Documents", 
            "field_type": "Document",
            "is_list": True
        },
        "embedding_function": {
            "display_name": "Embedding",
            "required": True,
            "field_type": "Embeddings"
        },
        "index_params": {
            "display_name": "Index Parameters",
            "required": False,
            "field_type": "NestedDict",
            "advanced": F,
        },
        "search_params": {
            "display_name": "Search Parameters", 
            "field_type": "NestedDict",
            "advanced": True,
        },
        "text_field":{
            "display_name": "Text Field",
            "field_type": "str",
        },
        "vector_field":{
            "display_name": "Vector Field",
            "field_type": "str",
        },
        "code": {"show": False},
    }

    def build(
        self,
        connection_args: NestedDict,
        collection_name: Optional[str] = None,
        index_params: Optional[NestedDict] = None,
        search_params: Optional[NestedDict] = None,
        embedding_function: Optional[Embeddings] = None,
        documents: Optional[Document] = None
    ) -> Union[VectorStore, BaseRetriever]:
        
        if documents is not None and embedding_function is not None:
            try:
                vector_db = Milvus.from_documents(
                    documents=documents,
                    embedding=embedding_function,
                    connection_args=connection_args,
                    collection_name=collection_name,
                    index_params=index_params,
                    search_params=search_params
                )
            except Exception as e:
                raise ValueError(str(e)) from e
        try:
            vector_db = Milvus(
                connection_args=connection_args,
                collection_name=collection_name,
                embedding_function=embedding_function,
                search_params=search_params,
                index_params=index_params
            )
        except Exception as e:
            raise ValueError(str(e)) from e
        
        return vector_db
@liaochf
Copy link
Author

liaochf commented Apr 26, 2024

image

@liaochf liaochf changed the title while two "NestedDict" data set advance True , flow while two "NestedDict" data set advance False in a custom component, error happen Apr 26, 2024
@ogabrielluiz
Copy link
Contributor

Hey @liaochf

Thank you for reporting this.

Hey @Cristhianzl could you take a look at this, please? This is a problem in the stable version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants