<?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"><channel><title><![CDATA[CogniVerse: A Multimodal AI Study Buddy]]></title><description><![CDATA[CogniVerse: A Multimodal AI Study Buddy]]></description><link>https://cogniverse.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Fri, 11 Sep 2026 01:27:10 GMT</lastBuildDate><atom:link href="https://cogniverse.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[The CogniVerse Chronicles: Building a Multimodal AI Study Buddy from Scratch]]></title><description><![CDATA[The Universal Frustration That Sparked an Idea
We’ve all been there. You're deep into a study session for a tough university course, poring over a dense textbook. You turn to a generic AI chatbot for a quick explanation, and it gives you a beautifull...]]></description><link>https://cogniverse.hashnode.dev/the-cogniverse-chronicles-building-a-multimodal-ai-study-buddy-from-scratch</link><guid isPermaLink="true">https://cogniverse.hashnode.dev/the-cogniverse-chronicles-building-a-multimodal-ai-study-buddy-from-scratch</guid><category><![CDATA[RAG ]]></category><category><![CDATA[langchain]]></category><category><![CDATA[generative ai]]></category><category><![CDATA[Multimodal AI]]></category><category><![CDATA[AI Engineering]]></category><dc:creator><![CDATA[Karthik]]></dc:creator><pubDate>Sat, 13 Sep 2025 09:04:39 GMT</pubDate><content:encoded><![CDATA[<h3 id="heading-the-universal-frustration-that-sparked-an-idea">The Universal Frustration That Sparked an Idea</h3>
<p>We’ve all been there. You're deep into a study session for a tough university course, poring over a dense textbook. You turn to a generic AI chatbot for a quick explanation, and it gives you a beautifully written, confident-sounding, and... completely wrong answer. It's not based on <em>your</em> textbook, and therefore, it's useless for your exam.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1757750596784/54b9122c-caf3-4922-8b75-a198d09b0bc6.png" alt class="image--center mx-auto" /></p>
<p>This fundamental disconnect was the spark for my project: a quest to build a truly useful AI study buddy. I decided to call it <strong>CogniVerse</strong>—a private universe of knowledge built from a single source of truth: the textbook itself.</p>
<p>This blog post is the detailed, unfiltered story of that journey. It’s a chronicle of building a Retrieval-Augmented Generation (RAG) system, from a naive script to a sophisticated application that can understand not just text, but the crucial diagrams within. This is a story of bugs, breakthroughs, and the often-painful realities of AI engineering. If you're on a similar journey, I hope my struggles and solutions can serve as your guide.</p>
<h3 id="heading-chapter-1-the-naive-beginning-amp-the-hallucination-leak">Chapter 1: The Naive Beginning &amp; The Hallucination Leak</h3>
<p>Every project starts with a simple first step. The goal was a Question-Answering bot that was physically incapable of "hallucinating." It would run locally using open-source models.</p>
<p><strong>Initial Tech Stack:</strong></p>
<ul>
<li><p><strong>LLM:</strong> <code>phi3:mini</code> running via Ollama server.</p>
</li>
<li><p><strong>PDF Parsing:</strong> <code>PyMuPDFLoader</code> from LangChain.</p>
</li>
<li><p><strong>Chunking:</strong> <code>RecursiveCharacterTextSplitter</code>.</p>
</li>
<li><p><strong>Vector Store:</strong> FAISS, a fast, local vector database.</p>
</li>
<li><p><strong>Orchestration:</strong> LangChain to tie it all together.</p>
</li>
</ul>
<p>The plan was a textbook implementation of RAG: load the PDF, chop it into 1000-character chunks, embed them, and store them. Simple, right?</p>
<p><strong>Hurdle #1: The Hallucination Leak</strong> The very first test immediately exposed a flaw. I asked a question I knew wasn't in my "Computer Networks" textbook: <strong>"What are living cells?"</strong></p>
<p>The bot's response was a beautifully detailed, accurate biological explanation. <strong>This was a total failure.</strong> The LLM, trained to be helpful, recognized my intent, ignored the useless context it was given, and fell back on its internal knowledge.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1757750975295/65dacc8e-a26d-4d7c-be50-67951d40451e.png" alt="Describes the hurdle #1: The hallucination leak" class="image--center mx-auto" /></p>
<p><strong>Resolution: Fortifying the Prompt with Unbreakable Rules</strong> The first tool in any RAG developer's arsenal is the prompt. I engineered a much stricter prompt with:</p>
<ul>
<li><p><strong>Forceful Language:</strong> Using capitalized, commanding words like <code>ONLY</code>, <code>MUST</code>, and <code>FORBIDDEN</code>.</p>
</li>
<li><p><strong>An Explicit "Escape Hatch":</strong> Giving the model a precise phrase to use when the context was insufficient: "Based on the provided textbook, I cannot answer this question." This gives the LLM a safe and correct way to fail.</p>
</li>
</ul>
<p>This worked perfectly. The first guardrail was in place.</p>
<h3 id="heading-chapter-2-the-retrieval-crisis-when-good-prompts-get-bad-data">Chapter 2: The Retrieval Crisis - When Good Prompts Get Bad Data</h3>
<p>With hallucination solved, I asked a relevant question: <strong>"what are the components of a communication system?"</strong> The answer was right there in the book.</p>
<p>The bot's response? "Based on the provided textbook, I cannot answer this question."</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1757751651627/d333addf-8c2e-4049-95ea-93223b28b5fe.png" alt="The retrieval crisis " class="image--center mx-auto" /></p>
<p>This was the project's most critical moment. The problem was a fundamental failure in the <strong>Retrieval (R)</strong> step. A debug script revealed the problem: the naive text splitter had sliced the textbook's headings right off from their content. The context was a fragmented, confusing mess.</p>
<p><strong>Resolution: From Naive Chunking to Structure-Aware Parsing</strong> The solution was to stop treating the PDF like a text file and start treating it like a structured document.</p>
<ol>
<li><p><strong>Semantic Analysis with</strong> <code>unstructured</code>: I switched to a library that uses Document Layout Analysis (DLA) to identify the semantic role of each piece of content (Title, ListItem, NarrativeText).</p>
</li>
<li><p><strong>Intelligent Chunking with</strong> <code>MarkdownHeaderTextSplitter</code>: I converted the structured elements into a clean Markdown document, then used LangChain's Markdown splitter to create perfect, semantically complete chunks based on the <code>#</code> headers.</p>
</li>
</ol>
<p>The quality of the text chunks improved dramatically.</p>
<h3 id="heading-chapter-3-the-multimodal-dream-amp-the-reality-of-broken-data">Chapter 3: The Multimodal Dream &amp; The Reality of Broken Data</h3>
<p>The final frontier was multimodality. The system was still blind to diagrams. The state-of-the-art architecture was the <strong>Multi-Vector Retriever</strong>, where you create a summary for every element (text, table, image) and store those in the vector database.</p>
<p><strong>Hurdle #2: The Automated Tools Kept Failing</strong> This is where the project met the brutal reality of real-world data. No matter which tool I used, the automated image extraction failed on my complex textbooks. A single diagram was consistently fragmented into 5-10 smaller, meaningless image components. This was the most important lesson of the entire project: <strong>"Garbage In, Garbage Out" is the First Law of AI.</strong></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1757752253442/89ddd4b3-96d9-4fa3-a10d-703a27695874.png" alt="Fragmented image pieces making it messed" class="image--center mx-auto" /></p>
<p><strong>Resolution: The "Guaranteed Quality" Manual Workflow</strong> When automated tools consistently fail, the only robust engineering solution is to bypass them. I switched to a two-part manual process:</p>
<ol>
<li><p><strong>For Text:</strong> I manually copy-pasted the text from the PDF into a <a target="_blank" href="http://textbook.md"><code>textbook.md</code></a> file.</p>
</li>
<li><p><strong>For Images:</strong> I used a screenshot tool to capture the complete, correct diagrams.</p>
</li>
</ol>
<p>This one-time effort created a perfect, clean dataset.</p>
<h3 id="heading-chapter-4-the-final-boss-solving-the-weak-signal">Chapter 4: The Final Boss - Solving the 'Weak Signal'</h3>
<p>With a perfect dataset, I asked: <strong>"what are the components of data communication?"</strong> The response: "Based on the provided textbook, I cannot answer this question."</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1757751651627/d333addf-8c2e-4049-95ea-93223b28b5fe.png" alt class="image--center mx-auto" /></p>
<p>This was the most baffling failure yet. A diagnostic script revealed the vector search was working, but it was returning the correct summary with a very low confidence score—a "weak signal." The Cohere Re-ranker, acting as a quality filter, correctly discarded it. The problem was the semantic difference between the structure of a <em>question</em> and the structure of a <em>statement</em>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1757752556731/99cb5084-693c-4ef5-9fda-b3c0ec0ce0d8.png" alt="Successful summaries retrieved for a given question" class="image--center mx-auto" /></p>
<p><strong>Resolution: Query Transformation with Hypothetical Document Embeddings (HyDE)</strong> The solution was to change our question. I implemented HyDE. The chain now sends the user's question to a local model (<code>phi3:mini</code>) and instructs it to generate a hypothetical, textbook-style answer. The system then uses this new hypothetical answer (a statement) for the vector search. The result was magic. Comparing a statement to another statement created a very strong signal, and the system finally delivered the perfect answer.</p>
<h3 id="heading-chapter-5-the-grand-finale-cogniverse-today">Chapter 5: The Grand Finale - CogniVerse Today</h3>
<p>The system as it stands now is a complete, conversational, multimodal RAG application. A query triggers a sophisticated chain:</p>
<ol>
<li><p><strong>HyDE Generation:</strong> The user's question is transformed into a hypothetical answer using a small, local model.</p>
</li>
<li><p><strong>AI-Powered Indexing &amp; Retrieval:</strong> The system searches over high-quality Gemini-generated summaries of the perfect text, tables, and manually-curated images.</p>
</li>
<li><p><strong>Intelligent Re-ranking:</strong> A Cohere Re-ranker filters and prioritizes the top 3 most relevant documents.</p>
</li>
<li><p><strong>Obedient, Synthesized Answer:</strong> The final, rich context is sent to the <strong>Gemini 1.5 Flash API</strong> to generate the answer. An early challenge was that local models like <code>moondream</code> or <code>llava</code>, while powerful, would sometimes fail to strictly adhere to the provided context. Switching to a highly-aligned API model like Gemini for the final step proved to be the ultimate solution for guaranteeing obedient, tutor-like explanations that never use outside knowledge.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1757753334488/e5a3c70d-06c9-4fca-8e15-82c3befa2c64.png" alt="Working prototype examples" class="image--center mx-auto" /></p>
</li>
</ol>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1757753491880/83b4fbaf-f03b-415f-ab67-ad3eb809598d.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1757753822298/a16e9a47-6aa0-4d8d-8bae-5138b412302e.png" alt class="image--center mx-auto" /></p>
<p>My biggest lessons are:</p>
<ul>
<li><p><strong>Data Quality is Everything:</strong> Your AI is only as good as the data you give it. Spend 80% of your time on the data pipeline.</p>
</li>
<li><p><strong>Trust but Verify:</strong> Automated tools can fail silently, and LLMs will disobey instructions. The final choice of model is a critical guardrail.</p>
</li>
<li><p><strong>Know Your Constraints:</strong> Local models are great but may have obedience limitations. API models offer higher compliance but have usage limits. Design your architecture for the right tool for each job.</p>
</li>
<li><p><strong>The Struggle is the Lesson:</strong> Pushing through moments of failure—from hallucinations to retrieval errors to model disobedience—is where the most valuable learning happens.</p>
</li>
</ul>
<p>You can find the complete code for Project CogniVerse on my GitHub here: <a target="_blank" href="https://github.com/K-A-R-T-H-I-K-V/CogniVerse/tree/main">https://github.com/K-A-R-T-H-I-K-V/CogniVerse/tree/main</a></p>
]]></content:encoded></item></channel></rss>