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

OpenSearch Custom Component Failed to build #2243

Closed
weily2 opened this issue Jun 21, 2024 · 1 comment
Closed

OpenSearch Custom Component Failed to build #2243

weily2 opened this issue Jun 21, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@weily2
Copy link

weily2 commented Jun 21, 2024

I had created a OpenSerach custom component with the follow python script:

from typing import List, Union,Optional

from langchain.embeddings.base import Embeddings
from langchain_community.vectorstores import VectorStore
from langchain_community.vectorstores import OpenSearchVectorSearch
from langchain_core.documents import Document
from langchain_core.retrievers import BaseRetriever
from langflow import CustomComponent

class OpenSearchComponent(CustomComponent):
    """
    A custom component for implementing a Vector Store using OpenSearch.
    """
    display_name: str = "OpenSearchVector"
    description: str = "Implementation of Vector Store using OpenSearch"
    documentation = "https://python.langchain.com/v0.2/docs/integrations/vectorstores/opensearch/"

    def build_config(self):
        """
        Builds the configuration for the component.

        Returns:
        - dict: A dictionary containing the configuration options for the component.
        """
        return {
            "index_name": {"display_name": "Index Name", "value": "your_index"},
            "code": {"show": False, "display_name": "Code"},
            "documents": {"display_name": "Documents", "is_list": True},
            "embedding": {"display_name": "Embedding"},
            "opensearch_url": {
                "display_name": "OpenSearch Connection Url",
                "advanced": False,
            },
            "opensearch_user":{ "display_name": "OpenSearch Username","advanced": True },
            "opensearch_pass":{ "display_name": "OpenSearch Password","advanced": True },
        }

    def build(
        self,
        embedding: Embeddings,
        opensearch_url: str,
        index_name: str,
        documents: List[Document],
        opensearch_user: Optional[str] = None,
        opensearch_pass: Optional[str] = None
    ) -> Union[VectorStore, BaseRetriever]:
        """
        Builds the Vector Store or BaseRetriever object.

        Args:
        - embedding (Embeddings): The embeddings to use for the Vector Store.
        - documents (Optional[Document]): The documents to use for the Vector Store.
        - index_name (str): The name of the OpenSearch Index.
        - opensearch_url (str): The URL for the OpenSearch.

        Returns:
        - VectorStore: The Vector Store object.
        """
        try:
            vector_store = OpenSearchVectorSearch.from_documents(
                embedding=embedding,
                documents=documents,
                index_name=index_name,
                opensearch_url=opensearch_url,
                http_auth=(opensearch_user,opensearch_pass)
            )
        except Exception as e:
            raise RuntimeError(f"Failed to build OpenSearchVector: {e}")
        return vector_store

but after build in canvas, i got the following error:

                             RuntimeError: Failed to build OpenSearchVector: ('1 document(s) failed to
                             index.', [{'index': {'_index': 'test-knn', '_id':
                             '12d6c176-9a77-4f7c-abb5-20fd61c9dcd2', 'status': 400, 'error': {'type':
                             'mapper_parsing_exception', 'reason': 'failed to parse', 'caused_by': {'type':
                             'illegal_argument_exception', 'reason': 'field name cannot be an empty
                             string'}}, 'data': {'vector_field': [0.029189004564168446,
                             -0.009481273894479912, 0.02987076996347487, 0.023576344185419578,
                             0.029839058428795914, -0.03849587339981753, -0.02979149392074529,
                             6.583529676665422e-05, -0.029189004564168446, -0.04601113272704339,
                             0.02987076996347487, 0.0010414735048384863, -0.026208271178608397,
                             0.02593873524103112, 0.047025849682704166, 0.03332715215483156,
                             0.005612660378748868, 0.00041569756158867907, 0.011130190810073886,
                             0.03843245405575004, 0.027175423626218553, 0.00849033826152184,
                             -0.0035416047289152023, -0.030568388336152958, 0.023956863975114977,
                             -0.0001445527642123442, -0.013603566649126151, -0.038527583071851286,
                             0.002683454278921055, -0.04277671637727772, 0.012113199025023523,
                             -0.03732260808398802, 0.03465896955612024, 0.015339686094135538,
                             0.01385724681936395, -0.031725802541256024, -0.028158432772490794,
                             0.04147660864802279, -0.031725802541256024, -0.009489201312488349,
                             .
                             .
                             .
                             .
                             .
                             .
                             0.006623415022389335, -0.000402567688200711, -0.0034563840540018996,
                             0.00171233707456875, -0.004471102406646585, 0.005168721244985975,
                             -0.025241116868353033, -0.00615172945993561, 0.0049507153871087475,
                             0.029252425770881153, -0.02885605114516888, -0.016164145017593827,
                             -0.0057117540351769355, -0.027222988134269176, 0.000639649070283729,
                             0.0049705339321298395, -0.0013764098260780908, -0.00403310883639002,
                             -0.0063182066350966955, 0.02968051006862717, -0.0017876482441408555,
                             -0.003343417416059067, 0.012588848762142769, 0.015284194168076479,
                             -0.037956805249953394, -0.007657951920055113, -0.021673748962233015,
                             0.004122293220307541, 0.04978461722667318], 'text': '123', 'metadata':
                             {'source':
                             'C:\\Users\\admin\\AppData\\Local\\langflow\\langflow\\Cache\\640436d1-33c0-4354-
                             9520-1bebeaaa63e8\\a665a45920422f9d417e4867efdc4fb8a04a1f3fff1fa07e998e86f7f7a2
                             7ae3.txt', '': ''}}}}])

                             The above exception was the direct cause of the following exception:

                             ╭───────────────────── Traceback (most recent call last) ─────────────────────╮
                             │ C:\Users\admin\langflow\lib\site-packages\langflow\api\v1\chat.py:201 in      │
                             │ event_stream                                                                │
                             │                                                                             │
                             │   198 │   │   │   │   │                                                     │
                             │   199 │   │   │   │   │   yield str(StreamData(event="message", data=respon │
                             │   200 │   │   │                                                             │
                             │ ❱ 201 │   │   │   langchain_object = await graph.build()                    │
                             │   202 │   │   │   # Now we  need to check the input_keys to send them to th │
                             │   203 │   │   │   if hasattr(langchain_object, "input_keys"):               │
                             │   204 │   │   │   │   input_keys_response = build_input_keys_response(langc │
                             │       artifacts)                                                            │
                             │                                                                             │
                             │ C:\Users\admin\langflow\lib\site-packages\langflow\graph\graph\base.py:134 in │
                             │ build                                                                       │
                             │                                                                             │
                             │   131 │   │   root_vertex = payload.get_root_vertex(self)                   │
                             │   132 │   │   if root_vertex is None:                                       │
                             │   133 │   │   │   raise ValueError("No root vertex found")                  │
                             │ ❱ 134 │   │   return await root_vertex.build()                              │
                             │   135 │                                                                     │
                             │   136 │   def topological_sort(self) -> List[Vertex]:                       │
                             │   137 │   │   """                                                           │
                             │                                                                             │
                             │ C:\Users\admin\langflow\lib\site-packages\langflow\graph\vertex\base.py:356   │
                             │ in build                                                                    │
                             │                                                                             │
                             │   353 │                                                                     │
                             │   354 │   async def build(self, force: bool = False, user_id=None, *args, * │
                             │   355 │   │   if not self._built or force:                                  │
                             │ ❱ 356 │   │   │   await self._build(user_id, *args, **kwargs)               │
                             │   357 │   │                                                                 │
                             │   358 │   │   return self._built_object                                     │
                             │   359                                                                       │
                             │                                                                             │
                             │ C:\Users\admin\langflow\lib\site-packages\langflow\graph\vertex\base.py:214   │
                             │ in _build                                                                   │
                             │                                                                             │
                             │   211 │   │   Initiate the build process.                                   │
                             │   212 │   │   """                                                           │
                             │   213 │   │   logger.debug(f"Building {self.vertex_type}")                  │
                             │ ❱ 214 │   │   await self._build_each_node_in_params_dict(user_id)           │
                             │   215 │   │   await self._get_and_instantiate_class(user_id)                │
                             │   216 │   │   self._validate_built_object()                                 │
                             │   217                                                                       │
                             │                                                                             │
                             │ C:\Users\admin\langflow\lib\site-packages\langflow\graph\vertex\base.py:229   │
                             │ in _build_each_node_in_params_dict                                          │
                             │                                                                             │
                             │   226 │   │   │   │   if value == self:                                     │
                             │   227 │   │   │   │   │   del self.params[key]                              │
                             │   228 │   │   │   │   │   continue                                          │
                             │ ❱ 229 │   │   │   │   await self._build_node_and_update_params(key, value,  │
                             │   230 │   │   │   elif isinstance(value, list) and self._is_list_of_nodes(v │
                             │   231 │   │   │   │   await self._build_list_of_nodes_and_update_params(key │
                             │   232                                                                       │
                             │                                                                             │
                             │ C:\Users\admin\langflow\lib\site-packages\langflow\graph\vertex\base.py:272   │
                             │ in _build_node_and_update_params                                            │
                             │                                                                             │
                             │   269 │   │   Builds a given node and updates the params dictionary accordi │
                             │   270 │   │   """                                                           │
                             │   271 │   │                                                                 │
                             │ ❱ 272 │   │   result = await node.get_result(user_id)                       │
                             │   273 │   │   self._handle_func(key, result)                                │
                             │   274 │   │   if isinstance(result, list):                                  │
                             │   275 │   │   │   self._extend_params_list_with_result(key, result)         │
                             │                                                                             │
                             │ C:\Users\admin\langflow\lib\site-packages\langflow\graph\vertex\base.py:264   │
                             │ in get_result                                                               │
                             │                                                                             │
                             │   261 │   │   │   │   pass                                                  │
                             │   262 │   │                                                                 │
                             │   263 │   │   # If there's no task_id, build the vertex locally             │
                             │ ❱ 264 │   │   await self.build(user_id=user_id)                             │
                             │   265 │   │   return self._built_object                                     │
                             │   266 │                                                                     │
                             │   267 │   async def _build_node_and_update_params(self, key, node, user_id= │
                             │                                                                             │
                             │ C:\Users\admin\langflow\lib\site-packages\langflow\graph\vertex\base.py:356   │
                             │ in build                                                                    │
                             │                                                                             │
                             │   353 │                                                                     │
                             │   354 │   async def build(self, force: bool = False, user_id=None, *args, * │
                             │   355 │   │   if not self._built or force:                                  │
                             │ ❱ 356 │   │   │   await self._build(user_id, *args, **kwargs)               │
                             │   357 │   │                                                                 │
                             │   358 │   │   return self._built_object                                     │
                             │   359                                                                       │
                             │                                                                             │
                             │ C:\Users\admin\langflow\lib\site-packages\langflow\graph\vertex\base.py:215   │
                             │ in _build                                                                   │
                             │                                                                             │
                             │   212 │   │   """                                                           │
                             │   213 │   │   logger.debug(f"Building {self.vertex_type}")                  │
                             │   214 │   │   await self._build_each_node_in_params_dict(user_id)           │
                             │ ❱ 215 │   │   await self._get_and_instantiate_class(user_id)                │
                             │   216 │   │   self._validate_built_object()                                 │
                             │   217 │   │                                                                 │
                             │   218 │   │   self._built = True                                            │
                             │                                                                             │
                             │ C:\Users\admin\langflow\lib\site-packages\langflow\graph\vertex\base.py:330   │
                             │ in _get_and_instantiate_class                                               │
                             │                                                                             │
                             │   327 │   │   │   self._update_built_object_and_artifacts(result)           │
                             │   328 │   │   except Exception as exc:                                      │
                             │   329 │   │   │   logger.exception(exc)                                     │
                             │ ❱ 330 │   │   │   raise ValueError(f"Error building node {self.vertex_type} │
                             │       {str(exc)}") from exc                                                 │
                             │   331 │                                                                     │
                             │   332 │   def _update_built_object_and_artifacts(self, result):             │
                             │   333 │   │   """                                                           │
                             ╰─────────────────────────────────────────────────────────────────────────────╯
                             ValueError: Error building node CustomComponent(ID:CustomComponent-qj887):
                             Failed to build OpenSearchVector: ('1 document(s) failed to index.', [{'index':
                             {'_index': 'test-knn', '_id': '12d6c176-9a77-4f7c-abb5-20fd61c9dcd2', 'status':
                             400, 'error': {'type': 'mapper_parsing_exception', 'reason': 'failed to parse',
                             'caused_by': {'type': 'illegal_argument_exception', 'reason': 'field name
                             cannot be an empty string'}}, 'data': {'vector_field': [0.029189004564168446,
                             -0.009481273894479912, 0.02987076996347487, 0.023576344185419578,
                             0.029839058428795914, -0.03849587339981753, -0.02979149392074529,
                             6.583529676665422e-05, -0.029189004564168446, -0.04601113272704339,
                             0.02987076996347487, 0.0010414735048384863, -0.026208271178608397,
                             0.02593873524103112, 0.047025849682704166, 0.03332715215483156,
                             0.005612660378748868, 0.00041569756158867907, 0.011130190810073886,
                             0.03843245405575004, 0.027175423626218553, 0.00849033826152184,
                             -0.0035416047289152023, -0.030568388336152958, 0.023956863975114977,
                             -0.0001445527642123442, -0.013603566649126151, -0.038527583071851286,
                             0.002683454278921055, -0.04277671637727772, 0.012113199025023523,
                             -0.03732260808398802, 0.03465896955612024, 0.015339686094135538,
                             .
                             .
                             .
                             .
                             .
                             .
                             -0.013445017357634806, 0.021039549933622424, 0.0016945002676344411,
                             -0.0010999387947273373, 0.002885605067950758, 0.033549123584358215,
                             0.028998746531965956, 0.020532189593146826, 0.03500777967378189,
                             -0.009631895767962822, 0.030806212739051278, 0.01100335119061629,
                             -0.027016873403404605, -0.026113140299861944, -0.03288321302106867,
                             0.011375943562303249, 0.017852699954552593, -0.019945556935232065,
                             0.00806621767278004, -0.009013552506691709, -0.018296639088315487,
                             -0.06792270609217473, 0.029617088861914467, -0.038527583071851286,
                             0.004752528074252612, 0.007281396305025238, -0.013571856977092404,
                             -0.013595639231117715, 0.001551805462913993, -0.04287184539337897,
                             -0.01562507686772969, 0.0020452915413062453, -0.022720175589927543,
                             0.010186820616489041, 0.04712097869880541, 0.027999882549676842,
                             0.009877648520192184, 0.006449010429219813, 0.025336247747099486,
                             0.017979538642687583, -0.010067907483717277, -0.021277374336520744,
                             0.0034425110724871344, -0.011296668450896274, 0.02814257793647392,
                             0.013706624014558438, -0.029506105009796346, 0.005081518715570563,
                             0.006623415022389335, -0.000402567688200711, -0.0034563840540018996,
                             0.00171233707456875, -0.004471102406646585, 0.005168721244985975,
                             -0.025241116868353033, -0.00615172945993561, 0.0049507153871087475,
                             0.029252425770881153, -0.02885605114516888, -0.016164145017593827,
                             -0.0057117540351769355, -0.027222988134269176, 0.000639649070283729,
                             0.0049705339321298395, -0.0013764098260780908, -0.00403310883639002,
                             -0.0063182066350966955, 0.02968051006862717, -0.0017876482441408555,
                             -0.003343417416059067, 0.012588848762142769, 0.015284194168076479,
                             -0.037956805249953394, -0.007657951920055113, -0.021673748962233015,
                             0.004122293220307541, 0.04978461722667318], 'text': '123', 'metadata':
                             {'source':
                             'C:\\Users\\admin\\AppData\\Local\\langflow\\langflow\\Cache\\640436d1-33c0-4354-
                             9520-1bebeaaa63e8\\a665a45920422f9d417e4867efdc4fb8a04a1f3fff1fa07e998e86f7f7a2
                             7ae3.txt', '': ''}}}}])
[06/21/24 10:07:40] ERROR    2024-06-21 10:07:40 - ERROR    - chat - Error while building the flow: %s       chat.py:218

Can someone help with this? Thank you very much.

@dosubot dosubot bot added the bug Something isn't working label Jun 21, 2024
Copy link

dosubot bot commented Jun 21, 2024

Hello, @weily2! I'm here to help you with any issues you're facing. If you need assistance with bugs, questions, or becoming a contributor, feel free to ask.

The error you're encountering, mapper_parsing_exception caused by an illegal_argument_exception with the reason "field name cannot be an empty string," indicates that one of the field names in your JSON configuration is an empty string. This typically happens in the metadata section of your documents.

To resolve this issue, ensure that none of the field names in your JSON configuration are empty strings. Specifically, check the metadata dictionary in your documents for any keys that are empty strings and replace them with valid names.

Here's an example of how to correct the metadata field:

{
  "vector_field": [0.029189004564168446, -0.009481273894479912, ...],
  "text": "123",
  "metadata": {
    "source": "C:\\Users\\admin\\AppData\\Local\\langflow\\langflow\\Cache\\640436d1-33c0-4354-9520-1bebeaaa63e8\\a665a45920422f9d417e4867efdc4fb8a04a1f3fff1fa07e998e86f7f7a27ae3.txt",
    "": ""  # This is the problematic field
  }
}

Replace the empty string key in the metadata dictionary with a valid key:

{
  "vector_field": [0.029189004564168446, -0.009481273894479912, ...],
  "text": "123",
  "metadata": {
    "source": "C:\\Users\\admin\\AppData\\Local\\langflow\\langflow\\Cache\\640436d1-33c0-4354-9520-1bebeaaa63e8\\a665a45920422f9d417e4867efdc4fb8a04a1f3fff1fa07e998e86f7f7a27ae3.txt",
    "valid_key": "valid_value"  # Replace with a valid key-value pair
  }
}

Ensure that all field names in your documents are properly named and not empty strings. This should resolve the mapper_parsing_exception error [1].

To continue talking to Dosu, mention @dosu.

@weily2 weily2 closed this as completed Jun 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant