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