๐Ÿ†• Haystack 2.31 is here! Slimming down Haystack core ahead of 3.0
Maintained by deepset

Integration: Azure Form Recognizer

Convert files to Documents using Azure's Document Intelligence service (Form Recognizer SDK)

Authors
deepset

Table of Contents

Overview

AzureOCRDocumentConverter converts files to Haystack Documents using Azure’s Document Intelligence service through the azure-ai-formrecognizer SDK.

Supported file formats: PDF, JPEG, PNG, BMP, TIFF, DOCX, XLSX, PPTX, HTML.

Unlike the AzureDocumentIntelligenceConverter (which produces Markdown), this component extracts tables as separate Document objects that preserve their two-dimensional (CSV) structure, and returns the remaining text with page breaks (\f) so it can be split per page by downstream preprocessors.

You need an active Azure account and a Document Intelligence or Cognitive Services resource. Follow the Azure setup guide to create your resource.

Installation

pip install azure-form-recognizer-haystack

Usage

Provide your service endpoint and an API key. By default the component reads the key from the AZURE_AI_API_KEY environment variable.

import os
from haystack_integrations.components.converters.azure_form_recognizer import AzureOCRDocumentConverter
from haystack.utils import Secret

converter = AzureOCRDocumentConverter(
    endpoint=os.environ["AZURE_AI_ENDPOINT"],
    api_key=Secret.from_env_var("AZURE_AI_API_KEY"),
)

results = converter.run(sources=["document.pdf"])
documents = results["documents"]
print(documents[0].content)

In a pipeline

from haystack import Pipeline
from haystack.document_stores.in_memory import InMemoryDocumentStore
from haystack.components.preprocessors import DocumentCleaner, DocumentSplitter
from haystack.components.writers import DocumentWriter
from haystack.utils import Secret
from haystack_integrations.components.converters.azure_form_recognizer import AzureOCRDocumentConverter

document_store = InMemoryDocumentStore()

pipeline = Pipeline()
pipeline.add_component("converter", AzureOCRDocumentConverter(endpoint="azure_resource_url", api_key=Secret.from_env_var("AZURE_AI_API_KEY")))
pipeline.add_component("cleaner", DocumentCleaner())
pipeline.add_component("splitter", DocumentSplitter(split_by="sentence", split_length=5))
pipeline.add_component("writer", DocumentWriter(document_store=document_store))
pipeline.connect("converter", "cleaner")
pipeline.connect("cleaner", "splitter")
pipeline.connect("splitter", "writer")

pipeline.run({"converter": {"sources": ["my_file.pdf"]}})