Spaces:
Runtime error
Runtime error
File size: 739 Bytes
d5c018a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | from langchain_community.document_loaders import PyPDFLoader
from langchain_core.documents import Document
from script.errors import IngestionError
MIN_TEXT_LENGTH = 500 # heuristic, tune later
def extract_text_native(pdf_path: str) -> list[Document]:
loader = PyPDFLoader(pdf_path)
documents = loader.load()
if not documents:
raise IngestionError(
code="PDF_PARSE_FAILED",
message="No pages extracted from PDF"
)
full_text = "\n".join(d.page_content for d in documents).strip()
if len(full_text) < MIN_TEXT_LENGTH:
raise IngestionError(
code="INSUFFICIENT_TEXT",
message="PDF likely scanned or image-based"
)
return documents
|