r/Rag • u/hyeonsang010716 • 22d ago
Showcase I built an open-source document-to-Markdown converter for RAG that keeps table structure (and reads Korean HWP files)
When I built RAG over real company documents, retrieval and the model were not what broke first. Conversion was. Tables in PDFs came out as running text, merged cells in spreadsheets became blanks, and HWP files (the Korean word processor format, which is everywhere in Korean offices) did not open at all.
So I wrote a library that only does that step: document in, Markdown out.
Repo: https://github.com/hyeonsang010716/OpenDocKit (MIT, pip install opendockit)
from opendockit import convert_file
result = convert_file("quarterly-report.docx")
result.text # Markdown: headings, tables, lists, footnotes, LaTeX equations
result.sections # per page / slide / sheet, for chunking and citations
result.warnings # what was skipped or approximatedWhat it does that mattered for my retrieval quality:
Merged cells are repeated in every row they cover, so a row still makes sense after chunking splits the table.
Spreadsheets use the displayed value (
46.4%), not the stored one (0.464459), and several tables on one sheet are split apart.Multi-column PDFs are read in order, borderless tables are detected, repeated headers and footers are dropped.
Sections are pages, slides or sheets, so a chunk can cite "page 3" without guessing.
No GPU and no ML models. Conversion is offline and deterministic.
Formats: PDF, DOCX, PPTX, XLSX/XLS/CSV, HWP/HWPX, ODT/ODS/ODP, RTF, EPUB, HTML, email, plus images through a vision model if you plug one in. There are LangChain and LlamaIndex loaders and an MCP server (uvx opendockit-mcp).
I compared it with MarkItDown, Kreuzberg, Unstructured and Docling on the same files. It passed 49 of 49 structure checks (yes/no questions like "is the merged cell still attached to its row"); the next tool passed 36. I wrote those checks myself and developed against them, so read that as "no gaps on these checks", not "best on your documents". The method and raw outputs are in the repo under benchmarks/ if you want to rerun it.
What it does not do:
No built-in OCR. Scanned PDFs need a vision model API. If you need offline OCR, Docling or Unstructured are the right tools.
It is not the fastest. Kreuzberg is roughly 30x faster.
On Windows, HTML, email and EPUB are not supported yet.
If it breaks on one of your documents I would like to hear about it. A file that reproduces the problem is the most useful thing you can send.
1
u/Tania_Lawson01 21d ago
Keeping PDF footnotes in place rather than guessing their references seems like the safer tradeoff. A wrong footnote attached to a chunk could be more misleading than leaving the link unresolved.
1
u/hyeonsang010716 20d ago
That tradeoff ended up shaping the whole feature, so thank you.
Before building anything I checked how other converters handle this. marker, Docling, MinerU and pymupdf4llm all leave the link unresolved. markitdown goes further and merges the mark into the number, so 135¹% comes out as 1351%. Nobody guesses, and I think you're right that this is the honest default.
So 0.3.6 links a footnote only when the page proves it. That means a short rule with smaller text under it, note numbers that run on, and exactly one raised mark in the body for each note, in the same order. If anything allows a second reading, like m^2 on a page that also has note 2, the whole page stays exactly as before: 135^1%, with the note in place at the bottom.
Most of the rules came from reviews that built pages to fool the previous version. Examples: a wrapped note line starting with "2 percent", a mark inside a table cell, and a figure caption that LaTeX floated above mark 1. On 120 test documents with real footnotes (1,580 marks), it links 864 and none to the wrong note. I'd rather leave the other 45% unlinked than get one wrong.
1
u/hamza-shkk 13d ago
Preserving table structure before chunking is such an underrated part of RAG. I like that you've focused on extraction instead of building another entire pipeline around it. Have you tested multi-page tables where rows continue across page boundaries?
1
u/DJ_Beardsquirt 22d ago
How does it handle footnotes?