<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Shreyanshpatel on Medium]]></title>
        <description><![CDATA[Stories by Shreyanshpatel on Medium]]></description>
        <link>https://medium.com/@study.shreyanshpatel?source=rss-3a215729fe1d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*c4qHvB9LRS73tWOW</url>
            <title>Stories by Shreyanshpatel on Medium</title>
            <link>https://medium.com/@study.shreyanshpatel?source=rss-3a215729fe1d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 11:59:26 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@study.shreyanshpatel/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Building Enterprise Multimodal RAG on a 15GB Colab GPU]]></title>
            <link>https://medium.com/@study.shreyanshpatel/building-enterprise-multimodal-rag-on-a-15gb-colab-gpu-19206af49584?source=rss-3a215729fe1d------2</link>
            <guid isPermaLink="false">https://medium.com/p/19206af49584</guid>
            <category><![CDATA[storage-solutions]]></category>
            <category><![CDATA[llava]]></category>
            <category><![CDATA[optimization]]></category>
            <category><![CDATA[multimodal-rag]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Shreyanshpatel]]></dc:creator>
            <pubDate>Fri, 24 Jul 2026 08:20:26 GMT</pubDate>
            <atom:updated>2026-07-24T08:20:26.802Z</atom:updated>
            <content:encoded><![CDATA[<p>Let’s be real for a second. Everyone in the developer community is talking about Multimodal RAG right now. The idea of being able to “chat” with complex documents — not just the plain text, but the messy financial tables, charts, and architecture diagrams — sounds like pure magic.</p><p>But if you have ever actually tried to build this yourself, you know exactly what happens next.</p><p>You boot up a free Google Colab notebook, load up a vision model like LLaVA to read a heavy PDF, and hit run. <em>Crash.</em> Your session dies instantly. Why? Because processing images and massive document contexts with a local LLM will absolutely nuke the 15GB VRAM limit on Colab’s standard T4 GPU.</p><p>It feels like the industry is telling us that unless we have deep pockets to rent expensive cloud clusters or buy massive local rigs, building advanced AI systems just isn’t meant for us.</p><p>As AI researcher Yann LeCun frequently points out regarding the democratization of AI,</p><blockquote><em>“The future of AI is open source… people will not want a single corporate entity to control their AI.”</em></blockquote><p>So, I refused to accept the hardware bottleneck.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/631/1*9Sv4bQULv0EigNc1pzJZcg.png" /><figcaption>Figure 1.1 Complex financial table</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T4tV5XAVuhLpEotlftX9eg.png" /><figcaption>Figure 1.2 Colab output perfectly extracting the exact budgeted amount</figcaption></figure><p>I set out to build a highly reliable, production-ready AI pipeline capable of parsing complex technical reports and financial estimates. It needed to understand structural tables flawlessly, and most importantly, it had to run entirely on open-source tools — without paying a single rupee for cloud compute.</p><p><em>Spoiler alert:</em> It is 100% possible. But to fit a massive enterprise-grade architecture into a tiny free-tier GPU, we had to rely on some serious engineering <em>jugaads</em>. You can’t just throw raw compute power at the problem; you have to outsmart the hardware.</p><p>In this article, I am going to walk you through exactly how I bypassed these heavy limitations. We will cover:</p><ol><li><strong>Strict VRAM Multiplexing:</strong> How to forcefully flush and swap models in and out of the GPU memory without breaking the pipeline.</li><li><strong>A Custom Markdown Chunker:</strong> How to slice up documents so that data tables never lose their headers.</li><li><strong>Zero-Cost Prompt Engineering:</strong> How to hack the LLM’s own attention mechanism by exploiting “positional bias” to stop table hallucinations completely.</li></ol><p>If you are tired of OOM errors and want to see how to push a free Colab instance to its absolute limits, let’s dive in.</p><h3>The Architecture: Building a Heavyweight Stack on a Lightweight Budget</h3><p>Look, when you are building an AI pipeline for an enterprise — but you are doing it on a strict zero-rupee cloud budget — you can’t just throw premium API keys at the problem. You need to carefully handpick open-source tools that punch way above their weight class.</p><p>Here is the exact tech stack I used to bridge the gap between messy PDF data and the LLM, keeping everything running strictly local on the Colab instance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7FIM2mwNr5OVhWik_TA4Ow.png" /></figure><ol><li><strong>The Ingestion Layer: Marker v1.x</strong> <br>If you have ever used standard libraries like PyPDF2 to read a financial document, you would be well aware that they completely destroy the table formatting. The columns merge into an unreadable mess of text. Instead, I used <strong>Marker</strong>. It is a heavy-duty layout parser that renders the PDF into clean Markdown (preserving those precious table structures) and neatly extracts all the visual diagrams into a folder.</li></ol><p><strong>2. The Dual-Embedding Brain: Nomic &amp; SigLIP</strong> <br>Because this is a <em>multimodal</em> system, we can’t just search for text; we need to search for images too.</p><ul><li>For the text and tables, I used <strong>Nomic’s text embedding model</strong>. It is incredibly efficient and mathematically brilliant at understanding dense data.</li><li>For the visual diagrams, I used <strong>Google’s SigLIP</strong>. When a user asks a question, SigLIP acts like a radar, matching the words in the query directly to the pixel patterns in the extracted images.</li></ul><p><strong>3. The Local Memory: ChromaDB</strong> <br>I needed a vector database that doesn’t require setting up a massive external cloud cluster. <strong>ChromaDB</strong> is the perfect fit. It runs locally inside the Colab notebook and uses Cosine Similarity to pull the most relevant text chunks, data tables, and diagrams in milliseconds.</p><p><strong>4. The Execution Engine: LLaVA + Ollama + LangChain</strong> <br>This is the star of the show. I used <strong>Ollama</strong> to host a local server daemon right inside the Colab container. This lets us run <strong>LLaVA</strong> (Large Language-and-Vision Assistant). Finally, I used <strong>LangChain</strong> as the bridge. LangChain takes the text context and the base64-encoded image bytes from ChromaDB and packages them perfectly so LLaVA can “read” and “see” at the same time.</p><p>It sounds like a dream team of open-source tech, right?</p><p>Well, there is a massive catch. If you try to load Marker, Nomic, SigLIP, and LLaVA into a 15GB GPU at the same time, the math simply does not work. The system will crash before you even ask your first question.</p><p>Here is exactly how I engineered my way out of that hardware trap.</p><h3>The VRAM Bridge: Surviving the 15GB GPU Limit</h3><p>Let’s talk about the elephant in the room: memory.</p><p>When I first wired all these amazing open-source tools together and hit “Run,” the notebook crashed immediately. Why? Because an 8B vision model like LLaVA needs about 5GB of VRAM just to wake up. When you add the heavy Marker layout model, the embedding models, and the massive text context from the PDFs, you hit what I call the “Fatal Spill.”</p><p>The GPU runs out of VRAM, tries to spill the overflow into the system RAM, and Colab instantly kills the session with an Out-Of-Memory (OOM) error.</p><p>To survive on a free T4 GPU, I had to be absolutely ruthless with memory management. Then I realized that the ingestion phase (reading the PDF) and the generation phase (talking to the LLM) do not actually need to happen at the same time.</p><p>So, I built a strict “one-in, one-out” system. I call it the <strong>VRAM Bridge</strong>.</p><p>Once Marker and the embedding models finish converting the PDF and saving everything safely into ChromaDB, I explicitly hunt down those massive models and destroy them to clear the room.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/322/1*Zg1YyO5tdm8cwUEUQziWDA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/902/1*4L_ig-n9azOxPPBEARECIQ.png" /><figcaption>Figure 2 Graphical plot showing drop in VRAM after applying VRAM Bridge</figcaption></figure><p>Here is the exact Python snippet I used to flush the pipeline:</p><pre>import gc<br>import torch<br><br>print(&quot;Phase 1 Complete: Offline Ingestion Finished.&quot;)<br><br># This explicitly hunt down and destroy the massive Marker layout model<br>if hasattr(ingestor, &#39;marker_converter&#39;):<br>    del ingestor.marker_converter<br>del ingestor<br><br># Force Python garbage collection and empty the PyTorch CUDA cache<br>gc.collect()<br>torch.cuda.empty_cache()<br><br>print(&quot;VRAM flushed successfully. The GPU is now ready for LLaVA.&quot;)</pre><p>It is a simple <em>jugaad</em>, but it is the only way to make this architecture work on a zero-rupee budget. By forcing PyTorch to empty its cache, I drop the VRAM usage back down to zero.</p><p>Only <em>after</em> this bridge is crossed do I boot up the Ollama server and load LLaVA. The vision model now has the entire 15GB playground to itself, completely eliminating the crash risk.</p><h3>The Table Hallucination Matrix: Zero-Cost Prompt Engineering</h3><p>So, the VRAM was managed, the pipeline was flowing, and LLaVA was successfully reading my PDFs. It was time for the ultimate test.</p><p>I asked the system a highly specific question: <em>“What is the exact budgeted amount for Civil Engineering works?”</em></p><p>The retrieval system worked flawlessly. ChromaDB pulled the exact Markdown table containing the correct numbers. But when LLaVA generated the answer… it was completely wrong. Instead of reading the table, the model hallucinated a random number from a plain-text paragraph a few pages away.</p><p>Why did this happen? Because parsing a complex Markdown grid requires spatial reasoning. Now that is “hard work” for the model and LLMs are inherently lazy; they take the path of least resistance. If there is an easier, plain-text paragraph lying around in the prompt, the model will grab that instead of doing the math.</p><p>Normally, in an enterprise setup, you would fix this by routing the text to a second, highly optimized reasoning model. But remember my golden rule: <strong>I only have 15GB of VRAM.</strong> I could not load another model without crashing the system. I had to fix this using pure prompt engineering.</p><p>Here are the two zero-cost hacks I used to force LLaVA to read the tables perfectly.</p><p><strong>1. Hacking Positional Bias</strong> <br>In 2023, researchers at Stanford University published a landmark paper titled <a href="https://arxiv.org/pdf/2307.03172"><em>Lost in the Middle: How Language Models Use Long Contexts</em></a>. Their research proved a glaring flaw in LLMs:</p><blockquote>“We observe that performance degrades significantly when relevant information is placed in the middle of the input context… models are much better at using information at the very beginning or the very end of a prompt.”</blockquote><p>My ChromaDB was sorting chunks purely by cosine distance, meaning text and tables were getting mixed together. So, when the query asked for a table, I added just these few lines of Python to physically split the list and forced all the data tables to the absolute bottom of the prompt — right next to the user’s question.</p><pre># Separate chunks by type<br>text_contexts = [chunk for chunk in chunks if &quot;Type: Text&quot; in chunk]<br>table_contexts = [chunk for chunk in chunks if &quot;Type: Data Table&quot; in chunk]<br><br># Force tables to the bottom so it&#39;s the last thing the LLM reads<br>ordered_context = text_contexts + table_contexts<br>context = &quot;\n&quot;.join(ordered_context)</pre><p><strong>2. Chain-of-Thought (CoT) Bounding</strong> <br>The second mistake I made was demanding a direct answer. If you force an LLM to instantly spit out a number, it panics and grabs the easiest text it can find. You have to give it a “scratchpad” to do its thinking.</p><p>I rewrote my prompt to strictly enforce a two-step reasoning format:</p><pre>STRICT RESPONSE FORMAT:<br>You must structure your response exactly like this:<br><br>ANALYSIS: (Briefly explain which chunk you are looking at and verify the column headers).<br>EXTRACTION: (State the exact numbers or facts found and stop).</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T4tV5XAVuhLpEotlftX9eg.png" /><figcaption>Figure 3 Final Output</figcaption></figure><p>The result? The hallucinations stopped completely.</p><p>By pushing the tables to the bottom of the prompt and forcing the model to write out the column headers in the ANALYSIS phase, its own attention mechanism locked onto the table. It became mathematically impossible for the model to get distracted.</p><p>It cost exactly 0 bytes of VRAM, required zero extra cloud compute, and fixed the biggest flaw in the pipeline.</p><h3>The Lexical Trap: When Your AI Outsmarts Your Evaluator</h3><p>At this point, the pipeline was generating perfect answers. But in enterprise development, “eyeballing” the results isn’t enough. You need automated evaluation metrics.</p><p>I wrote a strict Python grading script to calculate metrics like <em>Factual Consistency</em> and <em>Hallucination Rate</em> by comparing the model’s output to the original PDF text.</p><p>But when I ran the grader, it gave my perfect model a failing grade. Why?</p><p><strong>The Lexical Trap.</strong> <br>Because I forced the LLM to use a Chain-of-Thought scratchpad, it was outputting reasoning words like ANALYSIS: and EXTRACTION:. My grading script was doing a strict, mathematical word-for-word check. Because the original PDF document obviously didn&#39;t contain the words &quot;Analysis&quot; or &quot;User Request&quot;, the blind script penalized the model, flagging those reasoning words as &quot;hallucinations.&quot;</p><p>My AI had literally outsmarted my grader.</p><p>To fix this, I had to rewrite my evaluation script to act like a human teacher grading a math test. I added a simple parsing step so the grader completely ignores the “rough work” and only evaluates the final answer:</p><pre># Strip away the ANALYSIS block, only evaluate the final factual claim<br>if &quot;EXTRACTION:&quot; in response:<br>    clean_response = response.split(&quot;EXTRACTION:&quot;)[-1].strip()<br>else:<br>    clean_response = response</pre><p>Once I applied this fix, the metrics correctly reflected reality: perfect retrieval scores and massive improvements in Factual Consistency. To make sure I never lost this data, I wired the final metrics directly to a Google Sheet using the gspread library, creating a permanent, automated log of every test.</p><h3>Conclusion: Engineering Over Compute</h3><p>We are constantly told that the future of AI belongs only to the tech giants with infinite cloud budgets and thousands of GPUs. But as Twitter co-founder Biz Stone famously said,</p><blockquote><em>“Constraint inspires creativity.”</em></blockquote><p>Building this Multimodal RAG pipeline taught me something important: you don’t always need to throw more money or hardware at a problem. Sometimes, all you need is a deep understanding of data flow, a willingness to manage your VRAM ruthlessly, and a little bit of engineering <em>jugaad</em>.</p><p>By combining Marker’s flawless layout parsing, the Nomic/SigLIP dual-brain, and some clever positional prompt hacks, I built a highly capable, enterprise-grade AI system that runs perfectly within the constraints of a free 15GB Colab instance.</p><p>While I cannot share the proprietary codebase we use internally at my company, the architectural blueprint I have laid out above is everything you need to recreate this system yourself. The logic is hardware-agnostic; whether you are on a Colab T4 or a local workstation, these memory management and prompt techniques apply everywhere.</p><p>If you try building this architecture for your own enterprise use cases, or if you find another way to squeeze even more performance out of a constrained GPU, drop a comment below. I’d love to hear how you tackle these VRAM challenges!</p><p>Srinivas Padmanabhuni — Medium <a href="https://share.google/vAnZDkV5MbPF0SOmP">https://share.google/vAnZDkV5MbPF0SOmP</a></p><p>Testaing — Enterprise AI Product Engineering &amp; Testing Services <a href="https://share.google/gMe6X7mFv0pub3uEE">https://share.google/gMe6X7mFv0pub3uEE</a></p><p><a href="https://www.linkedin.com/company/testaing/">https://www.linkedin.com/company/testaing/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=19206af49584" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>