Live data from Hacker News

Ask HN: What are you using to parse PDFs for RAG?

news.ycombinator.com

41–50 of 102 posts

Re: Ask HN: What are you using to parse PDFs for RAG?

#42

In my experience Azure’s Form Recognizer (now called “Document Intelligence”) is the best (cheapest/most accurate) PDF parser for tabular data. If I were working on this problem in 2024, I’d use Azure to pre-process all docs into something machine parsable, and then use an LLM to transform/structure the processed content into my specific use-case. For RAG, I’d treat the problem like traditional search (multiple indic…

Did you encounter hidden costs when using Azure Document Intelligence? I processed some PDFs using the paid tier, but the resulting costs were way higher than expected, despite using a prebuilt layout model for only structured extraction. Have no clue what could cause it, no extra details on the billing page. Not sure if the price is misleading, or if it's a skill issue on my part :)

Re: Ask HN: What are you using to parse PDFs for RAG?

#48
I need to get some data out of a table in a regularly published PDF file.

The thing is the table looks like a table when the PDF is rendered, but there's nothing within the PDF itself to semantically mark it out as a table: it's just a bunch of text and graphical elements placed on the page in an arrangement that makes them look like a table to a human being reading the document.

What I've ended up doing, after much experimentation[0], is use poppler to convert the PDF to HTML, then find the start and end of the table by matching on text that always appears at header and footer. Fortunately the row values appear in order in the markup so I can then look at the x coordinates of the elements to figure out which column they belong to or, rather, when a new row starts.

What I actually do due to #reasons is spit out the rows into a text file and then use Lark to parse each row.

Bottom line: it works well for my use case but I'd obviously recommend you avoid any situation where your API is a PDF document if at all possible.

EDIT: A little bit more detail might be helpful.

You could use poppler to convert to HTML, then from there implement a pipeline to convert the HTML to markdown. Just bear in mind that the HTML you get out of poppler is far removed from anything semantic, or at least it has been with the PDFs I'm working with: e.g., lots of elements with position information and containing text, but not much to indicate the meaning. Still, you may find that if you implement a pipeline, where each stage solves one part of the problem of transforming to markdown, you can get something usable.

Poppler will spit out the images for you but, for reasons I've already outlined, tables are likely to be painful to deal with.

I notice some commenters suggesting LLM based solutions or services. I'd be hesitant about that. You might find an LLM helpful if there is a high degree of variability within the structural elements of the documents you're working with, or for performing specific tasks (like recognising and extracting markup for a table containing particular information of interest), but I've enough practical experience with LLMs not to be a maximalist, so I don't think a solely LLM-based approach or service will provide a total solution.

[0] Python is well served with libraries that either emit or parse PDFs but working with PDF object streams is no joke, and it turned out to be more complex and messier - for my use case - than simply converting the PDF to an easier to work with format and extracting the data that way.

Re: Ask HN: What are you using to parse PDFs for RAG?

#49
My apps are native Mac apps [0] [1] so naturally I use the native SDK for that.

Apple provides PDFKit framework to work with PDFs and it works really well.

For scanned documents, I use the Vision framework to OCR the content.

Some additional content cleaning is still required but overall I don’t need any other third-party libraries.

[0]: https://boltai.com

[1]: https://pdfpals.com

Post reply on HN