I am trying to execute a prompt flow in azure ai atudio and getting the following error:Run failed: Exception: Exception occured in search_function_construction.

Ramachandran, Sriram (Cognizant) 5 Reputation points
2024-12-24T07:13:39.2533333+00:00

raceback (most recent call last): File "/azureml-envs/prompt-flow/runtime/lib/python3.9/site-packages/pydantic/_internal/_generate_schema.py", line 864, in _resolve_forward_ref obj = _typing_extra.eval_type_backport(obj, globalns=self._types_namespace) File "/azureml-envs/prompt-flow/runtime/lib/python3.9/site-packages/pydantic/_internal/_typing_extra.py", line 279, in eval_type_backport return _eval_type_backport(value, globalns, localns, type_params) File "/azureml-envs/prompt-flow/runtime/lib/python3.9/site-packages/pydantic/_internal/_typing_extra.py", line 303, in _eval_type_backport return _eval_type(value, globalns, localns, type_params) File "/azureml-envs/prompt-flow/runtime/lib/python3.9/site-packages/pydantic/_internal/_typing_extra.py", line 332, in _eval_type return typing._eval_type( # type: ignore File "/azureml-envs/prompt-flow/runtime/lib/python3.9/typing.py", line 292, in _eval_type return t._evaluate(globalns, localns, recursive_guard) File "/azureml-envs/prompt-flow/runtime/lib/python3.9/typing.py", line 554, in _evaluate eval(self.forward_code, globalns, localns), File "<string>", line 1, in <module> NameError: name 'AzureSearch' is not defined The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/azureml-envs/prompt-flow/runtime/lib/python3.9/site-packages/promptflow_vectordb/tool/utils/profiling.py", line 18, in measure_execution_time yield File "/azureml-envs/prompt-flow/runtime/lib/python3.9/site-packages/promptflow_vectordb/tool/common_index_lookup.py", line 56, in _get_search_func search_func = build_search_func(index, top_k, query_type) File "/azureml-envs/prompt-flow/runtime/lib/python3.9/site-packages/promptflow_vectordb/tool/common_index_lookup_extensions/utils.py", line 46, in build_search_func store = index.as_langchain_vectorstore(credential=DefaultAzureCredential()) File "/azureml-envs/prompt-flow/runtime/lib/python3.9/site-packages/azureml/rag/mlindex.py", line 197, in as_langchain_vectorstore azuresearch = _get_azuresearch_module_instance(langchain_pkg_version) File "/azureml-envs/prompt-flow/runtime/lib/python3.9/site-packages/azureml/rag/utils/acs.py", line 21, in _get_azuresearch_module_instance azuresearch.AzureSearchVectorStoreRetriever.model_rebuild() File "/azureml-envs/prompt-flow/runtime/lib/python3.9/site-packages/pydantic/main.py", line 563, in model_rebuild return _model_construction.complete_model_class( File "/azureml-envs/prompt-flow/runtime/lib/python3.9/site-packages/pydantic/_internal/_model_construction.py", line 577, in complete_model_class schema = cls.get_pydantic_core_schema(cls, handler) File "/azureml-envs/prompt-flow/runtime/lib/python3.9/site-packages/pydantic/main.py", line 671, in get_pydantic_core_schema return handler(source) File "/azureml-envs/prompt-flow/runtime/lib/python3.9/site-packages/pydantic/_internal/_schema_generation_shared.py", line 83, in call schema = self._handler(source_type) File "/azureml-envs/prompt-flow/runtime/lib/python3.9/site-packages/pydantic/_internal/_generate_schema.py", line 655, in generate_schema schema = self._generate_schema_inner(obj) File "/azureml-envs/prompt-flow/runtime/lib/python3.9/site-packages/pydantic/_internal/_generate_schema.py", line 924, in _generate_schema_inner return self._model_schema(obj) File "/azureml-envs/prompt-flow/runtime/lib/python3.9/site-packages/pydantic/_internal/_generate_schema.py", line 739, in _model_schema {k: self._generate_md_field_schema(k, v, decorators) for k, v in fields.items()}, File "/azureml-envs/prompt-flow/runtime/lib/python3.9/site-packages/pydantic/_internal/_generate_schema.py", line 739, in <dictcomp> {k: self._generate_md_field_schema(k, v, decorators) for k, v in fields.items()}, File "/azureml-envs/prompt-flow/runtime/lib/python3.9/site-packages/pydantic/_internal/_generate_schema.py", line 1115, in _generate_md_field_schema common_field = self._common_field_schema(name, field_info, decorators) File "/azureml-envs/prompt-flow/runtime/lib/python3.9/site-packages/pydantic/_internal/_generate_schema.py", line 1308, in _common_field_schema schema = self._apply_annotations( File "/azureml-envs/prompt-flow/runtime/lib/python3.9/site-packages/pydantic/_internal/_generate_schema.py", line 2107, in _apply_annotations schema = get_inner_schema(source_type) File "/azureml-envs/prompt-flow/runtime/lib/python3.9/site-packages/pydantic/_internal/_schema_generation_shared.py", line 83, in call schema = self._handler(source_type) File "/azureml-envs/prompt-flow/runtime/lib/python3.9/site-packages/pydantic/_internal/_generate_schema.py", line 2088, in inner_handler schema = self._generate_schema_inner(obj) File "/azureml-envs/prompt-flow/runtime/lib/python3.9/site-packages/pydantic/_internal/_generate_schema.py", line 918, in _generate_schema_inner return self.generate_schema(self._resolve_forward_ref(obj)) File "/azureml-envs/prompt-flow/runtime/lib/python3.9/site-packages/pydantic/_internal/_generate_schema.py", line 866, in _resolve_forward_ref raise PydanticUndefinedAnnotation.from_name_error(e) from e pydantic.errors.PydanticUndefinedAnnotation: name 'AzureSearch' is not defined For further information visit https://errors.pydantic.dev/2.9/u/undefined-annotation The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/azureml-envs/prompt-flow/runtime/lib/python3.9/site-packages/promptflow/tracing/_trace.py", line 557, in wrapped output = func(*args, **kwargs) File "/azureml-envs/prompt-flow/runtime/lib/python3.9/site-packages/promptflow_vectordb/core/logging/utils.py", line 98, in wrapper res = func(*args, **kwargs) File "/azureml-envs/prompt-flow/runtime/lib/python3.9/site-packages/promptflow_vectordb/tool/common_index_lookup.py", line 170, in search search_func = _get_search_func(mlindex_content, top_k, query_type) File "/azureml-envs/prompt-flow/runtime/lib/python3.9/site-packages/promptflow_vectordb/tool/common_index_lookup.py", line 56, in _get_search_func search_func = build_search_func(index, top_k, query_type) File "/azureml-envs/prompt-flow/runtime/lib/python3.9/contextlib.py", line 137, in exit self.gen.throw(typ, value, traceback) File "/azureml-envs/prompt-flow/runtime/lib/python3.9/site-packages/promptflow_vectordb/tool/utils/profiling.py", line 21, in measure_execution_time raise Exception(error_msg) from e

Azure AI services
Azure AI services
A group of Azure services, SDKs, and APIs designed to make apps more intelligent, engaging, and discoverable.
3,003 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Sina Salam 14,551 Reputation points
    2024-12-24T16:13:24.5066667+00:00

    Hello Ramachandran, Sriram (Cognizant),

    Welcome to the Microsoft Q&A and thank you for posting your questions here.

    I understand that you are getting error:Run failed: Exception: Exception occured in search_function_construction in your prompt flow.

    The error shows that AzureSearch module is not properly defined in your Azure AI Studio prompt flow.

    1. You will need to add an import statement like: from azure.search.documents import SearchClient
    2. Install require Packages and Update them using bash:
         # To install Packages
         pip install azure-search-documents
         # Update Dependencies
         pip install --upgrade azure-search-documents pydantic
         
      
    3. Make sure your credentials are okay,
    4. If the steps above do not resolve the issue, check the links below for similar issue. https://github.com/microsoft/promptflow/issues/3696 , https://github.com/microsoft/promptflow/issues/3313 and for similar problems here - https://zcusa.951200.xyz/en-us/answers/questions/2136185/azure-ai-studio-error-in-index-lookup-step-of-prom .

    I hope this is helpful! Do not hesitate to let me know if you have any other questions.


    Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful.

    0 comments No comments

  2. romungi-MSFT 48,141 Reputation points Microsoft Employee
    2024-12-26T07:04:58.09+00:00

    @Ramachandran, Sriram (Cognizant) I think this is the same issue as this thread.

    This is a known issue and a workaround is required to downgrade the version of azureml-rag to 0.2.36

    Follow these steps and check if this works. Thanks!!

    • Open requirements.txt from expanding the files section and clicking on requirements.txt
    • User's image
    • Insert following 3 lines before promptflow-vectordb[azure]
    azureml-rag==0.2.36
    
    • Start/restart the compute session.

    If this answers your query, do click Accept Answer and Yes for was this answer helpful. And, if you have any further query do let us know.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.