Context is key in building effective AI enabled solutions. The most popular way to extend the pretrained knowledge set of a Large Language Model is through RAG, or Retrieval-Augmented Generation. By augmenting LLMs with external data we ensure that outputs are not only coherent but also factually grounded and up-to-date. This makes it invaluable for applications like chatbots, personalized recommendations, content creation, and decision support systems.
What is MarkItDown?
For any RAG solution to function effectively, the quality and format of the input data are critical. This is where MarkItDown, a lightweight Python utility created by Microsoft, stands out. It specializes in converting various files into Markdown format, a token-efficient and LLM-friendly structure.
From the documentation:
MarkItDown is a lightweight Python utility for converting various files to Markdown for use with LLMs and related text analysis pipelines. To this end, it is most comparable to textract, but with a focus on preserving important document structure and content as Markdown (including: headings, lists, tables, links, etc.) While the output is often reasonably presentable and human-friendly, it is meant to be consumed by text analysis tools -- and may not be the best option for high-fidelity document conversions for human consumption.
At present, MarkItDown supports:
- PowerPoint
- Word
- Excel
- Images (EXIF metadata and OCR)
- Audio (EXIF metadata and speech transcription)
- HTML
- Text-based formats (CSV, JSON, XML)
- ZIP files (iterates over contents)
- Youtube URLs
- EPubs
- ... and more!
Running MarkItDown
You can install it directly using pip:
pip install 'markitdown[all]~=0.1.0a1'
But as I like to keep my system clean, I’ll use docker instead:
- First clone the repository:
git clone https://github.com/microsoft/markitdown.git
- Now we can build the docker image using:
docker build -t markitdown:latest .
- Once we have build our docker image, we can convert a file using the following command:
docker run --rm -i -v .:/docs markitdown:latest /docs/input.pdf > output.md
As you can see whe share our current folder with Docker; using this flag: -v .:/docs
. This makes our current folder accessible as the /docs
folder in the container.
Let’s give it a try with an example PDF of a CV
docker run --rm -i -v .:/docs markitdown:latest /docs/cvexample.pdf > cvoutput.md
This was the example PDF (found somewhere online) I used:
And here is the output I got back:
That’s a good starter…
In a next post I’ll look how we can also process images in our source documents. See you again tomorrow!
More information
microsoft/markitdown: Python tool for converting files and office documents to Markdown.