Repository navigation
Read the PDFs with PyMuPDF and PyPDF directly, and pin every package - #11
Merged
Merged
Conversation
langchain-community, which provided the two PDF loaders, was retired in May 2026, and every make embed printed a warning saying so. src/ingest_pdfs.py now calls PyMuPDF and PyPDF itself and puts each page's tables where the old loader did, so the pages, the passages and the embedding estimate stay the same. Four packages leave the install. requirements.txt pinned only the 25 packages the project uses directly, so pip took the newest version of everything they need. requirements.in now lists the direct packages, and make lock uses uv to pin all 139 packages, for Python 3.11 to 3.14, into requirements.txt, which make install and the checks still install with pip. Checked: all 1,556 pages of the 34 PDFs I have come out the same with the old loaders and the new code, with both readers; the table placement matches the old loader's own code for 186,873 short texts; the embedding dry run on the 25 reports PR #10 selects gives 5,499 passages and 1,980,104 tokens with both; the tests pass on new installs of the lock on Python 3.11, 3.13 and 3.14; and the tests catch 7 of 7 planted bugs.
The pinned onnxruntime has no ready-made package for Intel Macs or macOS 13, so the README now names the systems the lock installs on, and the decisions entry gives the fallback for an Apple silicon Mac on macOS 13. A test now checks that a page with a footer and two tables comes out exactly as each old langchain-community loader made it, and another that requirements.txt pins each package in requirements.in at the same version. The comment on where tables go now gives the old loader's rule. The evidence counts the random pages checked, 938,288, and the tokens embedded, 1,980,104.
# Conflicts: # docs/future_work.md
Owner
Author
|
Evidence for
The table placement check and its output"""Check insert_tables against langchain-community's _merge_text_and_extras, exhaustively and at random.
Run from a checkout of this branch, with a Python that still has langchain-community 0.4.2:
python -W ignore placement_check.py
"""
import itertools
import random
import sys
import warnings
from pathlib import Path
sys.path.insert(0, str(Path.cwd()))
warnings.filterwarnings("ignore")
from langchain_community.document_loaders.parsers.pdf import _merge_text_and_extras # noqa: E402
from src.ingest_pdfs import insert_tables # noqa: E402
def old(text: str, tables: str) -> str:
# PyMuPDFParser._get_page_content appends the tables only when the joined string is non-empty
return _merge_text_and_extras([tables] if tables else [], text).strip()
def new(text: str, tables: str) -> str:
return insert_tables(text, tables).strip()
TABLES = ["", "|A|1|\n|---|---|\n", "|B|2|\n|---|---|\n\n|C|3|\n|---|---|\n", "\n"]
def texts(alphabet: str, longest: int):
for length in range(longest + 1):
for letters in itertools.product(alphabet, repeat=length):
yield "".join(letters)
def main() -> None:
cases = set()
for alphabet, longest in (("a\n", 14), ("a \n", 9)):
cases.update(texts(alphabet, longest))
print(f"author's grid: {(2**15 - 1) + (3**10 - 1) // 2} texts counted with overlap, "
f"{len(cases)} distinct; x3 table choices = {3 * ((2**15 - 1) + (3**10 - 1) // 2)} vs {3 * len(cases)}")
cases.update(texts("a\n", 16))
checked = mismatches = 0
for text in cases:
for tables in TABLES:
checked += 1
if old(text, tables) != new(text, tables):
mismatches += 1
if mismatches <= 5:
print("MISMATCH", repr(text), repr(tables))
rng = random.Random(20261201)
pieces = ["a", "b", " ", "\n", "\n\n", "\n\n\n", "\r", "\x0c", "\t", "Page 4"]
for _ in range(300_000):
text = "".join(rng.choice(pieces) for _ in range(rng.randint(0, 40)))
tables = rng.choice(TABLES)
checked += 1
if old(text, tables) != new(text, tables):
mismatches += 1
if mismatches <= 10:
print("MISMATCH", repr(text), repr(tables))
print(f"checked {checked} cases, {mismatches} mismatches")
if __name__ == "__main__":
main()The first line is from the review, which found that the count first given here, 186,873, counted 1,023 texts twice. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
langchain-community, which LangChain retired in May 2026 and no longer actively maintains. Everymake embedprinted a warning saying so.requirements.txtpinned only the 25 packages the project uses directly. pip chose the newest release of the more than 100 others they need on the day of each install, so an install could change or break with no change here.What changes
src/ingest_pdfs.pycalls PyMuPDF, or PyPDF with--loader pypdf, itself.insert_tablesputs each page's Markdown tables where the old loader put them, so the pages, the passages and the embedding estimate stay the same. Passages now record only their page, project and file name; nothing read the other details the old loaders stored.requirements.inlists the 24 packages the project uses directly, now withoutlangchain-community.make lockruns uv to pin them, and everything they need, inrequirements.txt: 139 packages for Python 3.11 to 3.14.make installand the checks still installrequirements.txtwith pip. Four packages leave the install:langchain-community,langchain-classic, SQLAlchemy andhttpx-sse.make installfails there. The README's Quickstart now names the systems it supports, and the decisions entry gives a fallback for Apple silicon Macs on macOS 13.requirements.txtpins every package inrequirements.inat the same version.docs/decisions.mdgive the alternatives, evidence and trade-offs. The README's "Built with" section mentions the lock, and the two future-work items this completes are gone.Verification
insert_tablesgives exactly whatlangchain-community's own_merge_text_and_extrasgives: 938,288 cases, with no difference.make fetchselects gives 5,499 passages, 1,980,104 tokens and $0.0396, with the old code and with the new. Only the old one prints the retirement warning.make installdoes), 222 tests pass in each, withmainmerged in, andlangchain_communityisn't installed. The warnings are PyMuPDF's, as onmain, and on Python 3.14 a deprecation warning from Chroma, whichmainshows too.requirements.inalone resolves, with an older onnxruntime.make lockis stable. Running it twice gives the same file, with the same pins as the first resolution.requirements.inwithoutmake lock.Not checked against OpenAI's live API
Nothing here calls OpenAI: the embedding dry run counts tokens offline. The passages are the same as with the old loaders, so the paid steps should behave the same, but none of them, embedding, extraction or the evaluation, has run with either, because the account has no credits yet.
Review
An independent review of
be6b425found no blockers and four things to fix before merging: say where the lock installs, test that the pages stay exactly the same, describe the table rule correctly, and take #10'smain. It also made seven minor points.7266f38and the commits after it fix all of them but one: I haven't addedrequirements.txt.tmpto.gitignore, so amake lockthat fails halfway leaves a file that shows. These fixes had my review only.