PyPDFToDocument
PyPDFToDocument
PDF 파일을 문서로 변환하는 컴포넌트예요.
출처: 문서
본문
| 항목 | 내용 |
|---|---|
| 파이프라인에서 가장 흔한 위치 | PreProcessors 앞, 또는 인덱싱 파이프라인의 맨 처음 |
| 필수 run 변수 | sources: PDF 파일 경로 또는 ByteStream 객체 |
| 출력 변수 | documents: 문서 목록 |
| API reference | Converters |
| GitHub 링크 | pypdf.py |
| 패키지 이름 | haystack-ai |
개요
PyPDFToDocument 컴포넌트는 PDF 파일을 문서로 변환해요. 인덱싱 파이프라인에서 PDF 파일의 내용을 Document Store에 인덱싱할 때 사용할 수 있죠. 파일 경로나 ByteStream 객체 목록을 입력으로 받아 변환 결과를 문서 목록으로 출력해요. 선택적으로 meta 입력 파라미터로 문서에 메타데이터를 붙일 수 있어요.
사용법
PyPDFToDocument 컨버터를 사용하려면 pypdf 패키지를 설치해야 해요:
pip install pypdf
단독으로 사용하기
from pathlib import Path
from haystack.components.converters import PyPDFToDocument
converter = PyPDFToDocument()
docs = converter.run(sources=[Path("my_file.pdf")])
파이프라인에서 사용하기
from haystack import Pipeline
from haystack.document_stores.in_memory import InMemoryDocumentStore
from haystack.components.converters import PyPDFToDocument
from haystack.components.preprocessors import DocumentCleaner
from haystack.components.preprocessors import DocumentSplitter
from haystack.components.writers import DocumentWriter
document_store = InMemoryDocumentStore()
pipeline = Pipeline()
pipeline.add_component("converter", PyPDFToDocument())
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": file_names}})
추가 참고 자료
- 🧑🍳 Cookbook: PDF-Based Question Answering with Amazon Bedrock and Haystack
- 📓 Tutorial: Preprocessing Different File Types