RAG & search
Multimodal document RAG
Answer questions over documents whose real content lives in images, tables, and charts by having a vision model describe every visual and indexing those descriptions alongside the text.
Copy or download the full plan and paste it into your AI coding agent to build it.
Why build it
Most real documents are not plain prose: financial reports hide the answer in a chart, manuals put it in a diagram, and slide decks are almost entirely images and tables. A text-only RAG pipeline silently drops all of that and then answers wrong or says it does not know. Multimodal RAG solves this by using a vision-language model to turn each figure, table, and chart into a rich text description at ingest time, so the visual becomes searchable like any passage. This is where retrieval meets real enterprise documents, and it teaches you to route content by type, describe visuals faithfully, and stitch mixed evidence into one grounded answer.
Who it's for: You are comfortable with basic RAG and want to handle the documents that break it: PDFs full of charts, tables, and scanned figures.
What you'll build
Core (MVP)
- Parse PDFs into a stream of text blocks, tables, and images with their page numbers
- Send each image and chart to a vision model for a factual description
- Convert tables into clean markdown so numbers stay aligned
- Embed and index text, image descriptions, and tables in one vector store with a type tag
- Retrieve across all modalities for a query and mark which type each hit is
- Answer with citations that point to the exact page and the source type
Stretch
- Show the actual cropped figure next to its cited answer
- Ask the vision model targeted questions about a chart at query time, not just at ingest
- Detect and specially handle multi-page tables
- Add a confidence note when the answer rests only on a described image
Step-by-step build
- 1
Split the document by content type
Use PyMuPDF or unstructured to walk each PDF page and emit typed blocks: text runs, table regions, and image regions with their bounding boxes and page numbers. Save cropped images to disk keyed by page. You now have a stream you can route by type instead of a flat wall of text.
- 2
Describe the visuals
For each image and chart, prompt the vision-language model to describe exactly what it shows, including axis labels, trends, and any numbers it can read, and to avoid guessing. Store that description as the searchable text for that figure, keeping a link back to the crop and page.
- 3
Linearize the tables
Convert each detected table into markdown with headers preserved so rows and columns stay aligned. A well-formatted markdown table is something the LLM reads reliably, unlike a jumble of stray cell text. Keep the page number with it.
- 4
Embed everything into one space
Embed the text passages, the image descriptions, and the markdown tables with the same model and store each as { text, embedding, page, modality, cropPath }. Tagging modality lets you later see whether an answer came from prose, a table, or a figure.
- 5
Retrieve across modalities
On a query, embed it and vector-search the whole collection so a chart description can outrank a paragraph when it is more relevant. Return the top chunks with their modality and page so the next step and the UI both know what kind of evidence each is.
- 6
Compose the grounded answer
Send the retrieved mixed-modality chunks to Groq with a prompt that says to answer only from the provided evidence, cite the page, and note when the answer comes from a described figure. This keeps you honest about evidence that was itself model-generated at ingest.
- 7
Surface the evidence
In the UI, render the answer and beneath it the cited chunks, showing the actual cropped image for figure citations and the markdown for table citations. Seeing the source visual next to the claim is what makes multimodal RAG trustworthy.
- 8
Test on a chart-heavy document
Pick a report where key answers live only in charts and tables and verify the system gets them, then confirm a text-only baseline fails the same questions. That contrast is the whole point of the project and your best demo.
Done when
- ✓A question whose answer exists only in a chart is answered correctly and cites that figure's page.
- ✓A text-only RAG baseline fails several questions that your multimodal pipeline gets right.
- ✓Table-based numeric questions return the right value from the linearized table, not a hallucination.
- ✓Every answer names the page and the modality of its evidence, and figure citations show the real crop.
- ✓A brand-new chart-heavy PDF works end to end with no code changes.
Ship it
Dockerize the FastAPI service with the parser and vision model, and deploy to Hugging Face Spaces or AWS free tier with an Atlas M0 store. Ship a live URL and a README that shows one question answered from a chart with the cropped figure beside it, next to a text-only baseline getting it wrong. That single before-and-after sells the whole project.
What it proves: You can build RAG over the messy, visual documents that real companies actually have, routing content by type, using a vision model to make figures and tables searchable, and grounding answers in mixed-modality evidence with honest citations.
Hand it to your AI agent
Paste this into Cursor, Claude, or ChatGPT and build it step by step.
You are my senior AI engineer pair. Help me build "Multimodal document RAG" step by step. RAG means retrieval-augmented generation: fetch relevant evidence and make the LLM answer only from it. Multimodal here means the evidence includes images, charts, and tables, not just text; a vision-language model (VLM) reads each visual and writes a text description we can index. Stack: FastAPI, PyMuPDF or unstructured for PDF layout parsing, a free vision-language model (Llama 3.2 Vision) for figure descriptions, all-MiniLM-L6-v2 embeddings, MongoDB Atlas Vector Search (free M0) with a modality tag, Groq (Llama 3.3 70B) for the grounded answer.
Requirements:
1. Parse each PDF into typed blocks: text, tables, images, each with a page number.
2. Describe every image/chart with the VLM and linearize tables to markdown.
3. Embed text, descriptions, and tables into one store as { text, embedding, page, modality, cropPath }.
4. Retrieve across all modalities and answer only from the evidence with page + modality citations.
5. UI that shows the cited crop for figure answers and the markdown for table answers.
Work in this order: PDF splitting by type, then visual description, then table linearization, then unified embedding, then cross-modal retrieval, then the grounded answer, then the evidence UI. Give me the commands and code for each step and STOP after each so I can test. Do not write the whole app at once.More in RAG & search
Chat with your PDF
Upload documents, ask questions in plain English, and get answers that cite the exact source page.
Semantic search over your notes
Search your own notes and markdown by meaning instead of exact keywords, and get back the passages that actually answer you.
Hybrid-search RAG + reranking
Combine keyword search and vector search, then rerank the merged hits with a cross-encoder so the passage the model reads is actually the best one.
Building this? I post a new AI project plan on LinkedIn most weeks. Follow along and share what you ship.