<?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 Anirudh Sharma on Medium]]></title>
        <description><![CDATA[Stories by Anirudh Sharma on Medium]]></description>
        <link>https://medium.com/@sanirudh0095?source=rss-113cb936fe37------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*F8GDqIBnHONt71p-</url>
            <title>Stories by Anirudh Sharma on Medium</title>
            <link>https://medium.com/@sanirudh0095?source=rss-113cb936fe37------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 14:52:12 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sanirudh0095/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[I Built a Local RAG Chatbot That Kinda Sucks (But Hey, It’s Mine)]]></title>
            <link>https://medium.com/@sanirudh0095/i-built-a-local-rag-chatbot-that-kinda-sucks-but-hey-its-mine-66cea236b3ee?source=rss-113cb936fe37------2</link>
            <guid isPermaLink="false">https://medium.com/p/66cea236b3ee</guid>
            <category><![CDATA[retrieval-augmented-gen]]></category>
            <category><![CDATA[local-llm]]></category>
            <category><![CDATA[gradio]]></category>
            <category><![CDATA[chatbots]]></category>
            <category><![CDATA[llm]]></category>
            <dc:creator><![CDATA[Anirudh Sharma]]></dc:creator>
            <pubDate>Thu, 28 Aug 2025 16:28:50 GMT</pubDate>
            <atom:updated>2025-08-28T16:28:50.050Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*cuZsALdz2d7RDu4a3HLUGg.jpeg" /></figure><p>Alright, confession time.<br>I don’t even have a GPU. That’s right — no shiny RTX card, no CUDA magic. Just my sad little CPU grinding away like it’s on a hamster wheel.</p><p>And yet… I made a <strong>local RAG chatbot</strong>.</p><p>Does it suck? Absolutely.<br>Is it slow? Like molasses in January.<br>Are the answers sometimes nonsense? You bet.</p><p>But it’s mine. It runs locally, costs $0, and doesn’t send my PDFs off to Silicon Valley. And honestly, that’s kind of a win.</p><p>In this tutorial, we’ll build a <strong>customer support chatbot</strong> powered by a <strong>local LLM</strong> (no API costs or privacy concerns) and expose it through a <strong>Gradio interface</strong>.</p><h3>The Tech Grocery List</h3><p>Here’s what we’re cooking with:</p><ul><li><strong>CTransformers</strong> → lets us run local models like LLaMA or Mistral.</li><li><strong>HuggingFace BGE-small</strong> → makes embeddings so at least retrieval is smarter than the model.</li><li><strong>ChromaDB</strong> → keeps track of your PDF chunks like a librarian with sticky notes.</li><li><strong>LangChain</strong> → ties the whole RAG thing together.</li><li><strong>Gradio</strong> → gives us a web app instead of ugly print statements.</li></ul><p>Install everything with:</p><pre>pip install -r requirements.txt</pre><h3>Step 1. The Local LLM (aka The Dumb Genius)</h3><p>We point config.yaml to a local GGUF/GGML model:</p><pre>llm:<br>  provider: &quot;ctransformers&quot;<br>  ctransformers:<br>    model_file: &quot;models/llama-2-7b-chat.ggmlv3.q4_0.bin&quot;<br>    model_type: &quot;llama&quot;<br>    config:<br>      max_new_tokens: 512<br>      temperature: 0.7</pre><p>Then load it with a wrapper class (configure_llm.py):</p><pre>import yaml<br><br>class LLMWrapper:<br>    def __init__(self, llm_config: dict):<br>        self.config = llm_config<br>        provider = llm_config.get(&quot;provider&quot;, &quot;ctransformers&quot;)<br>        <br>        if provider == &quot;ctransformers&quot;:<br>            self._init_ctransformers()<br>        else:<br>            raise ValueError(f&quot;Unsupported provider: {provider}&quot;)<br>        <br>    def _init_ctransformers(self):<br>        from langchain_community.llms import CTransformers<br>        cfg = self.config.get(&quot;ctransformers&quot;, {})<br>        gen_cfg = cfg.get(&quot;config&quot;, {})<br>        <br>        self.llm = CTransformers(<br>            model=cfg.get(&quot;model_file&quot;),<br>            model_type=cfg.get(&quot;model_type&quot;),<br>            **gen_cfg<br>        )<br>    <br>    def invoke(self, prompt: str) -&gt; str:<br>        return self.llm(prompt)<br><br>with open(&quot;config.yaml&quot;, &quot;r&quot;) as f:<br>    cfg = yaml.safe_load(f)<br><br>configured_llm = LLMWrapper(cfg.get(&quot;llm&quot;))</pre><p>The LLM isn’t fast. It isn’t particularly smart. But hey, it runs on your laptop without calling daddy OpenAI.</p><h3>Step 2. Making the Bot Read (Embeddings)</h3><p>The LLM itself has the memory of a goldfish. That’s why we need embeddings.<br>We take your PDF, smash it into vectors, and save them. Now when you ask, <em>“What’s the refund policy?”</em>, the bot doesn’t just hallucinate a refund in Bitcoin — it actually finds the relevant page.</p><p>We use <strong>BGE-small</strong> because it’s efficient and, frankly, it works better than the LLM it’s paired with.</p><pre>from transformers import AutoTokenizer, AutoModel<br>import torch<br>from langchain_core.embeddings import Embeddings<br><br>tokenizer = AutoTokenizer.from_pretrained(&quot;BAAI/bge-small-en-v1.5&quot;)<br>model = AutoModel.from_pretrained(&quot;BAAI/bge-small-en-v1.5&quot;)<br><br>class HFEmbeddings(Embeddings):<br>    def embed_documents(self, texts):<br>        return [self._embed(t) for t in texts]<br><br>    def embed_query(self, text):<br>        return self._embed(text)<br><br>    def _embed(self, text):<br>        inputs = tokenizer(text, return_tensors=&quot;pt&quot;, truncation=True, padding=True)<br>        with torch.no_grad():<br>            outputs = model(**inputs)<br>            embeddings = outputs.last_hidden_state.mean(dim=1)  # Mean pooling<br>        return embeddings[0].numpy().tolist()</pre><h3>Step 3. Document Loading and Splitting</h3><p>We chop PDFs into 1,000-character chunks with some overlap.<br>Because feeding the whole file at once is like asking someone to recite the entire Harry Potter series from memory. Good luck.</p><pre>from langchain_community.document_loaders import PyPDFLoader<br>from langchain.text_splitter import RecursiveCharacterTextSplitter<br><br>def document_loader(file):<br>    loader = PyPDFLoader(file.name)<br>    return loader.load()<br><br>def text_splitter(data):<br>    splitter = RecursiveCharacterTextSplitter(<br>        chunk_size=1000,<br>        chunk_overlap=50,<br>        length_function=len,<br>    )<br>    return splitter.split_documents(data)</pre><h3>Step 4. Create a Vector Database</h3><p>Chunks go into ChromaDB. Now we can say:<br>“Hey bot, grab me the three most relevant chunks about shipping.”<br>And it’ll dig them out like a caffeinated librarian.</p><pre>from langchain_community.vectorstores import Chroma<br><br>def vector_database(chunks):<br>    embedding_model = HFEmbeddings()<br>    return Chroma.from_documents(chunks, embedding_model)<br><br>def retriever(file):<br>    splits = document_loader(file)<br>    chunks = text_splitter(splits)<br>    vectordb = vector_database(chunks)<br>    return vectordb.as_retriever()</pre><h3>Step 5. Build the RAG Chain</h3><p>Now the magic-ish part:</p><ol><li>User asks a question.</li><li>Retriever grabs chunks.</li><li>We wrap them into a prompt.</li><li>Local LLM gives its best shot.</li></ol><p>Does it nail it every time? No. Sometimes it gives you a motivational speech about pineapples. But when it works… it works.</p><pre>from langchain.prompts import ChatPromptTemplate<br>from langchain.schema import StrOutputParser<br>from langchain_core.runnables import RunnableLambda<br>import re<br><br>from configure_llm import configured_llm<br>llm = RunnableLambda(lambda x: configured_llm.invoke(x))<br><br>def retriever_qa(file, query):<br>    retriever_obj = retriever(file)<br>    <br>    docs = retriever_obj.get_relevant_documents(query)<br>    context = &quot;\n\n&quot;.join([d.page_content for d in docs])<br>    <br>    prompt = ChatPromptTemplate.from_template(<br>        &quot;Answer the question using the context below:\n\n{context}\n\nQuestion: {question}&quot;<br>    )<br>    <br>    chain = prompt | llm | StrOutputParser()<br>    response = chain.invoke({&quot;context&quot;: context, &quot;question&quot;: query})<br>    <br>    return re.sub(r&quot;\s+&quot;, &quot; &quot;, response).strip()</pre><h3>Step 6. Gradio — Because UI Matters</h3><p>Let’s be honest, nobody wants to print() chatbot outputs in 2025.<br>So we use Gradio for a slick little web UI where you can upload PDFs, type questions, and watch your bot sweat to answer.</p><pre>import gradio as gr<br><br>rag_application = gr.Interface(<br>    fn=retriever_qa,<br>    allow_flagging=&quot;never&quot;,<br>    inputs=[<br>        gr.File(label=&quot;Upload PDF&quot;, file_count=&quot;single&quot;, file_types=[&#39;.pdf&#39;], type=&quot;filepath&quot;),<br>        gr.Textbox(label=&quot;Ask a Question&quot;, lines=2, placeholder=&quot;Type your question here...&quot;)<br>    ],<br>    outputs=gr.Textbox(label=&quot;Answer&quot;),<br>    title=&quot;RAG Application with Local LLM&quot;,<br>    description=&quot;Upload a PDF and ask any question. The chatbot will retrieve information and respond using a local LLM.&quot;<br>)<br><br>rag_application.launch(server_name=&quot;127.0.0.1&quot;, server_port=7860)</pre><p>Run it and open http://127.0.0.1:7860.<br>Upload a file, ask a question, and hope for the best.</p><h3>Final Thoughts</h3><p>So yeah — my local RAG chatbot kinda sucks.<br> It’s slow. It’s forgetful. Sometimes its answers feel like it pre-gamed before work.</p><p>But here’s the thing:</p><ul><li>It’s free.</li><li>It’s private.</li><li>And it’s mine.</li></ul><p>And honestly? That’s good enough for me.</p><p>If you want perfect answers, go pay for GPT-4.<br> If you want a scrappy underdog that stumbles but never sends your data to the cloud… this is it.</p><h3>Try It Yourself</h3><p>I’ve open-sourced the code on GitHub so you can try it out (and maybe laugh at how slow it is on CPU 😅):</p><p><a href="https://github.com/WalkofLife/slowrag-local-rag-chatbot-gradio">slowrag-local-rag-chatbot-gradio</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=66cea236b3ee" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hierarchical Review Classification Using Local LLMs with LangGraph]]></title>
            <link>https://medium.com/@sanirudh0095/hierarchical-review-classification-using-local-llms-with-langgraph-f65daf9eb248?source=rss-113cb936fe37------2</link>
            <guid isPermaLink="false">https://medium.com/p/f65daf9eb248</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[review-classification]]></category>
            <category><![CDATA[text-classification]]></category>
            <dc:creator><![CDATA[Anirudh Sharma]]></dc:creator>
            <pubDate>Wed, 06 Aug 2025 13:26:32 GMT</pubDate>
            <atom:updated>2025-08-07T13:35:36.318Z</atom:updated>
            <content:encoded><![CDATA[<p>Every business collects customer reviews — but without structure, they’re just a wall of text.<br> The real value lies in <strong>categorizing</strong> them so teams can see exactly <strong>which areas customers are happy or unhappy with</strong>.</p><p>In this project, I built a <strong>two-level review classification system</strong> using a <strong>local Large Language Model (LLM)</strong> and <strong>LangGraph</strong>.</p><p>The goal: Automatically tag each review with both a broad <strong>parent category</strong> and a more detailed <strong>subcategory</strong> — without sending any data to external servers.</p><h3>Why Hierarchical Classification?</h3><p>Traditional sentiment or category classification gives you just <strong>one label</strong>.<br> For example:</p><blockquote><em>“The delivery was delayed by 2 hours.”<br> → </em>Service</blockquote><p>But in reality, businesses need <strong>granular insights</strong>:</p><blockquote><em>“The delivery was delayed by 2 hours.”<br> → </em>Service<em> → </em>Delivery Time</blockquote><p>With a hierarchy:</p><ul><li><strong>Level 1</strong>: The main area (e.g., <em>Food</em>, <em>Service</em>, <em>Staff</em>, <em>Price</em>).</li><li><strong>Level 2</strong>: Specific issue (e.g., <em>Taste</em>, <em>Delivery Time</em>, <em>Politeness</em>, <em>Value for Money</em>).</li></ul><p>This structure makes reports <strong>more actionable</strong> and enables <strong>better trend analysis</strong>.</p><h3>How It Works — Without the Jargon</h3><p>The system works like a decision flow:</p><ol><li><strong>Read the review text</strong> (e.g., “The food was too spicy and made me uncomfortable.”)</li><li><strong>Classify into Level 1</strong> using the LLM — in this case: <em>Food</em></li><li><strong>Look up possible Level 2 options</strong> for that Level 1 category</li><li><strong>Classify into Level 2</strong> — here: <em>Taste</em></li><li><strong>Output the hierarchy</strong>: <em>Food &gt; Taste</em></li></ol><p>The category hierarchy itself is stored in a simple table, so it can be updated without changing any logic.</p><h3>Tech Stack (Fully Offline)</h3><p>To ensure privacy and portability, I chose a <strong>local-first tech stack</strong>:</p><ul><li>🧠 <strong>LLM:</strong> Mistral-7B-Instruct (GGUF format) running locally</li><li>🔗 <strong>LangGraph:</strong> To orchestrate multi-step classification flows</li><li>🧱 <strong>LangChain:</strong> Prompting + LLM wrappers</li><li>⚡ <strong>CTransformers:</strong> For fast inference on local hardware (no GPU required)</li><li>📄 <strong>CSV-based Hierarchy:</strong> Editable hierarchy table — no code changes needed for new categories</li></ul><h3>Example Results</h3><p>Here’s what the system produced for a few sample reviews:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/893/1*cvk8dfX0LZANz1WPqFtZpA.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f65daf9eb248" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>