Skip to main content

llama-index-readers-pdfluent

A LlamaIndex reader for PDFluent. It reads a PDF with PDFluent's structured extraction and hands LlamaIndex Documents in reading order, with the page and box each came from in its metadata so an answer can cite its source. Everything runs locally. Your documents stay on your machine.

Install

pip install llama-index-readers-pdfluent

It needs Python 3.9 or later and pdfluent 1.2.0 or later, which pip pulls in automatically. It also depends on llama-index-core (MIT).

Quick start

from llama_index.readers.pdfluent import PDFluentReader

docs = PDFluentReader().load_data("report.pdf")
print(docs[0].text, docs[0].metadata["page"])

A runnable notebook, PDF to VectorStoreIndex in about ten lines with a local embedding and no API key, is in examples/pdf_to_index.ipynb.

Modes

mode decides what one Document is.

Blocks mode

One document per paragraph, heading, list item or table (a table is one document), in reading order. This is the default.

from llama_index.readers.pdfluent import PDFluentReader

reader = PDFluentReader()
for doc in reader.lazy_load_data("report.pdf"):
    print(doc.metadata["kind"], doc.metadata["page"], doc.metadata["bbox"])

Markdown mode

One document per page, as markdown. Pass quality="balanced" for the layout-model tier (see below).

from llama_index.readers.pdfluent import PDFluentReader

pages = PDFluentReader(mode="markdown").load_data("report.pdf")
print(len(pages), "pages")
print(pages[0].text[:200])

Document mode

One document for the whole selection: the markdown of every selected page, joined by a blank line. metadata["pages"] lists the pages it covers.

from llama_index.readers.pdfluent import PDFluentReader

whole = PDFluentReader(mode="document", pages=[0, 2]).load_data("report.pdf")
print(whole[0].metadata["pages"])

Quality and pages

quality is "fast" (default) or "balanced", the layout-model tier of pdfluent 1.2. The balanced tier assembles markdown, so it goes with mode="markdown" or mode="document"; with mode="blocks" the engine refuses it and says so. It needs the model weights, installed once with the pdfluent command-line tool:

pdfluent models install layout tables
from llama_index.readers.pdfluent import PDFluentReader

PDFluentReader(mode="markdown", quality="balanced").load_data("report.pdf")

pages=[0, 3] loads exactly those pages (0-based); first_page and page_count load a window.

Every PDF in a directory

from llama_index.core import SimpleDirectoryReader
from llama_index.readers.pdfluent import PDFluentReader

documents = SimpleDirectoryReader(
    "pdfs/", file_extractor={".pdf": PDFluentReader()}
).load_data()

Options

Argument Default What it does
mode "blocks" "blocks", "markdown" (one document per page) or "document" (one document).
quality "fast" "fast" or "balanced" (markdown and document modes).
model_dir None Where the balanced tier finds its weights; None uses PDFLUENT_MODEL_DIR or the per-user model directory.
table_model_dir None Directory of the table-structure model; opts the balanced tier's tables into it.
include_furniture False Keep the running heads and page numbers a document repeats on every page.
first_page, page_count 0, None Load a window of pages.
pages None Load exactly these 0-based pages instead of the window.
hierarchical, max_chars False, 2000 Add section_path and split long tables by rows.

Metadata

Key Value
source the path the PDF was loaded from
page 0-based page index (blocks and markdown modes)
pages the 0-based pages a document covers (document mode)
kind paragraph, heading, list_item, table, header, footer; page in markdown mode; document in document mode
bbox [x0, y0, x1, y1] in points, origin at the bottom left of the page, y up (blocks mode)
confidence the learned model's probability for kind, only where a model decided it
section the last heading above the chunk
section_path the enclosing headings (hierarchical=True)
level a heading's level, 1 to 3
continues_previous True on the second half of a paragraph a page break cut in two
toc_items the outline entries pointing at the page, as [level, title, page] triples (markdown and document modes)
tables one {"bbox", "rows", "columns"} per table on the page (markdown mode)

bbox, toc_items and tables are lists. The geometry and the confidence are for citing and highlighting, so they are excluded from what the embedding model and the LLM see; source, page, kind and section stay in.

Benchmarks

Extraction quality is measured in the public pdfluent-bench repository (link follows when it is public).

Licence

AGPL-3.0 or a commercial licence, at your option; see LICENSE and LICENSE-COMMERCIAL. The commercial licence is sold yearly and self-service at https://pdfluent.com/sdk/pricing.

Metadata

Release files for llama-index-readers-pdfluent 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for llama-index-readers-pdfluent 0.2.0
File Size Uploaded Provenance
llama_index_readers_pdfluent-0.2.0.tar.gz 26.6 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for llama-index-readers-pdfluent 0.2.0
File Interpreter ABI Platform
llama_index_readers_pdfluent-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 49.2 kB

Release files / llama_index_readers_pdfluent-0.2.0.tar.gz

Download URL llama_index_readers_pdfluent-0.2.0.tar.gz
Size 26.6 kB
Tags Source
SHA-256 checksum
How to use checksums
ac442da601ca5e930e33438512f24e89beceade471e4189bc042ddf8a7195d32
BLAKE2b-256 checksum
How to use checksums
15b6155780dc6558db664db8f897db0b2a9407fe1425940bb5e3412d3f336ffd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Release files / llama_index_readers_pdfluent-0.2.0-py3-none-any.whl

Download URL llama_index_readers_pdfluent-0.2.0-py3-none-any.whl
Size 22.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
07b9372e9a3e9b7050115bfa6ce1cd2af6568456945de97733967736c9b75ba8
BLAKE2b-256 checksum
How to use checksums
3acf253e0146d5f6c95b8ece7842b1cc3b6edba2649a58b219e7272d90fb9bfb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Security for llama-index-readers-pdfluent 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page