Azure Document Intelligence 404 Not found

Elix Chen 5 Reputation points
2024-08-26T06:22:17.13+00:00

from langchain_community.document_loaders import AzureAIDocumentIntelligenceLoader

url_path = "https://www.posb.com.sg/Resources/posb/docs/deposit/posb_deposits_guide.pdf"
endpoint = "https://<myendpoint>.cognitiveservices.azure.com/"
key = "<mykey>"
loader = AzureAIDocumentIntelligenceLoader(
    api_endpoint=endpoint, api_key=key, url_path=url_path, api_model="prebuilt-layout"
)

documents = loader.load()

print(documents)


Hi. I'm trying to parse a document using Azure Document Intelligence using the langchain community document loader. When calling loader.load(), it's saying resource 404 not found. Do I need to configure anything extra in my azure platform?

Traceback (most recent call last):

File "/Users/elixander.tan/projects/azure/process_file_2.py", line 16, in <module>

res = obj.load()

^^^^^^^^^^

File "/opt/miniconda3/lib/python3.12/site-packages/langchain_core/document_loaders/base.py", line 30, in load

return list(self.lazy_load())

^^^^^^^^^^^^^^^^^^^^^^

File "/opt/miniconda3/lib/python3.12/site-packages/langchain_community/document_loaders/doc_intelligence.py", line 98, in lazy_load

yield from self.parser.parse_url(self.url_path) # type: ignore[arg-type]

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/opt/miniconda3/lib/python3.12/site-packages/langchain_community/document_loaders/parsers/doc_intelligence.py", line 98, in parse_url

poller = self.client.begin_analyze_document(

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/opt/miniconda3/lib/python3.12/site-packages/azure/core/tracing/decorator.py", line 94, in wrapper_use_tracer

return func(*args, **kwargs)

^^^^^^^^^^^^^^^^^^^^^

File "/opt/miniconda3/lib/python3.12/site-packages/azure/ai/documentintelligence/_operations/_operations.py", line 3627, in begin_analyze_document

raw_result = self._analyze_document_initial( # type: ignore

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/opt/miniconda3/lib/python3.12/site-packages/azure/ai/documentintelligence/_operations/_operations.py", line 516, in _analyze_document_initial

map_error(status_code=response.status_code, response=response, error_map=error_map)

File "/opt/miniconda3/lib/python3.12/site-packages/azure/core/exceptions.py", line 161, in map_error

raise error

azure.core.exceptions.ResourceNotFoundError: (404) Resource not found

Code: 404

Azure AI Document Intelligence
Azure AI Document Intelligence
An Azure service that turns documents into usable data. Previously known as Azure Form Recognizer.
2,100 questions
{count} vote

1 answer

Sort by: Most helpful
  1. santoshkc 15,325 Reputation points Microsoft External Staff Moderator
    2024-08-26T10:41:21.2533333+00:00

    Hi @Elix Chen,

    Thank you for reaching out. The 404 Not Found error you're encountering when using the AzureAIDocumentIntelligenceLoader in LangChain typically suggests that the requested resource could not be found. This could be due to an incorrect API endpoint or model name, an inaccessible document URL, or a misconfiguration in your Azure Cognitive Services account. Please double-check that your endpoint URL and API key are correct.

    I tried to reproduce the issue with the provided code and was able to successfully extract the document. To ensure proper functionality, please make sure to install the necessary packages correctly. You should first install LangChain and Azure Form Recognizer using the following commands:

    pip install langchain
    pip install langchain-community azure-ai-formrecognizer
    

    See output:
    User's image

    Also please look into the documentation:

    I hope this helps. Do let us know if you any further queries.


    If this answers your query, do click Accept Answer and Yes for was this answer helpful.

    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.