RCRAG Converter

Local PDF Ingest for RAG: What a Rust Parser and Inflate Change

A squared block of white paper on a dark surface, with a few blank sheets fanning up and apart from its top under a cool key light and a faint red rim light

Local PDF ingest for RAG does two jobs before a single chunk exists: it walks the file's structure and it inflates the compressed streams that hold the text. rusty_pdf_core is a pure-Rust reader that opened 986 of 989 files in the pdf.js test corpus without a single panic, and rusty_zlib is a zlib-rs fork whose output matches upstream byte for byte. FFAI is adopting the reader now.

What changes for local PDF ingest for RAG when the parser and the inflate step are written in Rust?

The two steps that run before chunking get a sturdier floor. The new reader opened 986 of 989 files in the pdf.js corpus, zero panics and zero timeouts, and its own code forbids unsafe. rusty_zlib writes the same bytes as upstream zlib-rs at every level. FFAI is adopting the reader now, so it isn't a RAG Converter release yet.

Before the chunker, there's a parser and an inflate

People talk about RAG quality as if it starts at chunking. For a PDF it starts earlier. A PDF is a pile of numbered objects plus a cross-reference table that says where each one lives. The words on a page sit in content streams, and those streams are nearly always compressed with Flate, which is the same deflate format zlib reads and writes. So before any chunk exists, something has to find the objects, follow the table, and inflate the streams. That's the real first step of local PDF ingest for RAG, and it's easy to forget it's there.

That layer is boring right up until it breaks. A broken cross-reference table, a stream that claims to be longer than it is, or a password on a file nobody mentioned can stop a whole batch. If you convert locally, the parser runs on your laptop or in your browser tab. When it falls over, that's your afternoon, not a vendor's.

It's also the layer that touches hostile input first. A customer folder can hold anything. In a C parser, a malformed file can be memory corruption, and that runs with whatever access the converting process has. Our PDF guide covers what a PDF yields once it's parsed. This piece is about the step underneath, and two new Rust crates that sit there.

What rusty_pdf_core does at the parsing step

rusty_pdf is the house workspace for PDF. The one crate published so far is the reader. Install it as rusty_pdf_core. A crate called rusty_pdf already exists on crates.io and it belongs to a different project, so cargo add rusty_pdf_core is the line you want.

The repo tests the reader on the pdf.js corpus, pinned to a commit with a checksummed manifest, 989 files in all. It opened 986 of them with zero panics and zero timeouts at 20 seconds per file. Two of the three it couldn't open need passwords the corpus doesn't ship. The third has no document catalog at all, and lopdf rejects it too.

For ingest, the useful parts are plain ones. It reads encrypted files when you have the password, with RC4 keys from 40 to 128 bit, AES-128 and AES-256. It repairs a broken cross-reference table instead of giving up. It gives you pages, the text layer and the images inside them. Its own code forbids unsafe outright, though some of its dependencies do use unsafe, and it builds for wasm32, which is the target a browser converter runs on.

What it doesn't do yet matters as much. Rendering and writing aren't published. A scanned page is still a picture of text, so you still need OCR for it. There's a short summary on the rusty_pdf page on MATA, and the engineering detail is on the Remade site.

Where zlib comes in, and what 1.19x actually measures

rusty_zlib is a fork of zlib-rs, the pure-Rust zlib from the Trifecta Tech Foundation. The promise is narrow on purpose: at every compression level it writes exactly the bytes upstream writes. If your pipeline hashes compressed blobs to spot duplicates, or caches by checksum, swapping it in changes nothing you can see in the output.

The headline number is 1.19x faster level 1 compression, and it's against the fork's own 0.1.0 release. It isn't a race with C zlib or zlib-ng. Levels 6 and 9 came out flat. For ingest that's worth reading twice, because pulling text out of a PDF is mostly inflate, not deflate, and the repo's decompression gain is much smaller than 1.19x. The fork builds for wasm32 and for no_std targets. Like upstream, it still has unsafe blocks inside, so treat it as a Rust zlib and not as a crate free of unsafe.

One honest wrinkle. Right now rusty_pdf_core inflates through flate2, and flate2 pulls upstream zlib-rs, not this fork. So the two crates are siblings in the same family, not one stack wired end to end. The rusty_zlib page on MATA has the install line and the current version.

How this reaches RAG Converter through FFAI

FFAI is the Rust toolkit for OCR, speech and vision. RAG Converter's server tier already uses it to read scans. Right now FFAI is moving its media crate off lopdf and onto the new reader. The move is happening as we write, so nothing here says the converter runs it today.

If it lands the way it's going, the change for you is quiet. A text-layer PDF gets parsed in Rust from the first byte. A scan still goes to OCR, which is where accuracy is won or lost. A password-protected file or a damaged one should come back as an error you can read, not a stalled job. None of it changes the JSONL you download or how you chunk it.

The reason to care is the same reason people convert locally at all. If the file shouldn't leave your machine, the code that opens it should be the sturdiest part of the pipeline, not the oldest. Images and scans remain their own job, and sending the PDF straight to a model remains the expensive way round. MATA is the house stack for keeping all of it on hardware you hold.

FAQ

Q: Which crate do I install to read PDFs?

A: The reader crate, rusty_pdf_core. The repo is named rusty_pdf, but the crate with that short name on crates.io is someone else's, so use the longer name with cargo add. Only the reader is published so far, so don't expect rendering or writing from it.

Q: Did the reader open every file in its test corpus?

A: It opened 986 of the 989 files in the pinned pdf.js corpus, and none of the 989 caused a panic or hit the 20 second limit. Two of the misses need passwords the corpus lacks. The third has no catalog, and lopdf refuses it as well.

Q: Is the 1.19x zlib speedup measured against C zlib?

A: No. It's level 1 compression measured against rusty_zlib's own 0.1.0 release. Levels 6 and 9 were flat, and decompression moved far less. The output stays byte-identical to upstream zlib-rs at every level.

Q: Does RAG Converter use these crates today?

A: Not yet. FFAI, which already handles OCR for the server tier, is adopting the PDF reader as we speak. The swap is in progress. Until it ships, treat this as a look at where PDF parsing is heading, not a release note.

Q: Do these crates help with scanned PDFs?

A: Only partly. The reader can pull the scan images out of a PDF, but turning a picture of text into words is OCR's job. That's still a separate step, and it's the one that sets how much a scanned page contributes to retrieval.

More on converting for RAG