AzureDocumentIntelligenceConverter
AzureDocumentIntelligenceConverter
AzureDocumentIntelligenceConverter는 Azure의 Document Intelligence 서비스를 사용해 파일을 Documents로 변환해요. 더 나은 LLM/RAG 통합을 위해 GitHub Flavored Markdown 출력을 제공하죠. 지원 파일 형식: PDF(검색 가능 및 이미지 전용), JPEG, PNG, BMP, TIFF, DOCX, XLSX, PPTX, HTML.
파이프라인에서 가장 흔한 위치: PreProcessors 앞, 또는 인덱싱 파이프라인의 맨 앞
필수 init 변수: endpoint(Azure Document Intelligence 리소스의 엔드포인트 URL), api_key(Azure 인증용 API 키. AZURE_DI_API_KEY 환경 변수로 설정 가능)
필수 run 변수: sources — 파일 경로 또는 ByteStream 객체 목록
출력 변수: documents(문서 목록), raw_azure_response(Azure의 원시 응답 목록)
API reference: Azure Document Intelligence
GitHub link: https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/azure_doc_intelligence
Package name: azure-doc-intelligence-haystack
출처: 문서
본문
Overview
AzureDocumentIntelligenceConverter는 파일 경로 또는 ByteStream 객체 목록을 입력으로 받아 Azure의 Document Intelligence 서비스로 파일을 문서 목록으로 변환해요. 선택적으로 meta 입력 파라미터로 문서에 메타데이터를 붙일 수 있어요. 이 통합을 쓰려면 활성 Azure 계정과 Document Intelligence 또는 Cognitive Services 리소스가 필요합니다. 리소스 설정은 Azure 문서의 단계를 따르세요.
컴포넌트는 기본적으로 AZURE_DI_API_KEY 환경 변수를 사용해요. 또는 초기화 때 api_key를 전달할 수 있습니다 — 아래 코드 예시를 참고하세요.
이 컴포넌트는 azure-ai-documentintelligence 패키지(v1.0.0+)를 사용하며 GitHub Flavored Markdown을 출력해요. 제목, 표, 목록 같은 문서 구조를 보존하죠. 표는 별도 문서로 추출되는 대신 인라인 마크다운 표로 렌더링됩니다.
컴포넌트를 초기화할 때 사용할 모델을 가리키는 model_id를 선택적으로 설정할 수 있어요. 사용 가능한 옵션:
"prebuilt-document": 일반 문서 분석(기본값)"prebuilt-read": 텍스트 추출용 빠른 OCR"prebuilt-layout": 더 나은 표·구조 탐지가 있는 향상된 레이아웃 분석- Azure 리소스의 사용자 정의 모델 ID
사용 가능한 모델 전체 목록은 Azure 문서를 참고하세요.
info 이 컴포넌트는 이전
azure-ai-formrecognizer패키지를 쓰는 레거시 AzureOCRDocumentConverter를 대체해요.AzureDocumentIntelligenceConverter는 더 새로운azure-ai-documentintelligenceSDK를 사용하고 평문 텍스트 대신 Markdown 출력을 만들어, LLM과 RAG 애플리케이션에 더 적합합니다.
note 이 컴포넌트는 Markdown 콘텐츠를 반환해요. 기본 설정의
DocumentCleaner()로 파이프하지 마세요.remove_extra_whitespaces=True와remove_empty_lines=True가 줄바꿈을 접고 제목·표·목록을 평평하게 만들 수 있기 때문이죠. 컨버터를 다음 컴포넌트에 직접 연결하거나, 사용자 정의 정리가 필요하면 그 옵션들을 끄세요.
Usage
AzureDocumentIntelligenceConverter를 쓰려면 azure-doc-intelligence-haystack 통합을 설치해야 해요:
pip install azure-doc-intelligence-haystack
On its own
from pathlib import Path
from haystack_integrations.components.converters.azure_doc_intelligence import (
AzureDocumentIntelligenceConverter,
)
from haystack.utils import Secret
converter = AzureDocumentIntelligenceConverter(
endpoint="https://YOUR_RESOURCE.cognitiveservices.azure.com/",
api_key=Secret.from_env_var("AZURE_DI_API_KEY"),
)
result = converter.run(sources=[Path("my_file.pdf")])
documents = result["documents"]
In a pipeline
from haystack import Pipeline
from haystack.document_stores.in_memory import InMemoryDocumentStore
from haystack.components.preprocessors import DocumentSplitter
from haystack.components.writers import DocumentWriter
from haystack.utils import Secret
from haystack_integrations.components.converters.azure_doc_intelligence import (
AzureDocumentIntelligenceConverter,
)
document_store = InMemoryDocumentStore()
pipeline = Pipeline()
pipeline.add_component(
"converter",
AzureDocumentIntelligenceConverter(
endpoint="https://YOUR_RESOURCE.cognitiveservices.azure.com/",
api_key=Secret.from_env_var("AZURE_DI_API_KEY"),
),
)
pipeline.add_component(
"splitter",
DocumentSplitter(split_by="sentence", split_length=5),
)
pipeline.add_component("writer", DocumentWriter(document_store=document_store))
pipeline.connect("converter", "splitter")
pipeline.connect("splitter", "writer")
file_names = ["my_file.pdf"]
pipeline.run({"converter": {"sources": file_names}})
더 알아보기 (Learn more)
- AzureOCRDocumentConverter — 레거시 컨버터
- Converters — 컨버터 개요