<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: deaw.ai</title>
    <description>The latest articles on DEV Community by deaw.ai (@deaw_ai).</description>
    <link>https://dev.to/deaw_ai</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4043954%2F715fc185-c131-4b2c-b896-fc59a086cb78.jpg</url>
      <title>DEV Community: deaw.ai</title>
      <link>https://dev.to/deaw_ai</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/deaw_ai"/>
    <language>en</language>
    <item>
      <title>Building a RAG Chatbot with FastAPI and ChromaDB (that runs locally, no API key)</title>
      <dc:creator>deaw.ai</dc:creator>
      <pubDate>Thu, 23 Jul 2026 13:57:14 +0000</pubDate>
      <link>https://dev.to/deaw_ai/building-a-rag-chatbot-with-fastapi-and-chromadb-that-runs-locally-no-api-key-36aj</link>
      <guid>https://dev.to/deaw_ai/building-a-rag-chatbot-with-fastapi-and-chromadb-that-runs-locally-no-api-key-36aj</guid>
      <description>&lt;p&gt;Everyone wants a chatbot that can answer questions from &lt;em&gt;their own&lt;/em&gt; documents — a company handbook, a contract, a research paper. The technique behind this is called &lt;strong&gt;RAG (Retrieval-Augmented Generation)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;I build production RAG and LLM systems for a living, and I kept re-wiring the same foundation on every project. So I cleaned it up into a small, open-source starter. This post walks through how RAG actually works, the design decisions that matter, and how you can run the whole thing for free — no API key required.&lt;/p&gt;

&lt;p&gt;At the end there's a link to the full open-source repo you can clone and run in minutes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why RAG?
&lt;/h2&gt;

&lt;p&gt;An LLM like GPT or Claude only knows what it was trained on. Ask it about a document sitting on your laptop and it will guess — or hallucinate.&lt;/p&gt;

&lt;p&gt;RAG fixes this with a simple idea: &lt;strong&gt;retrieve the relevant information first, then let the LLM answer using only that.&lt;/strong&gt; The result is answers grounded in your actual documents, with citations you can trace back to a specific page.&lt;/p&gt;

&lt;h2&gt;
  
  
  The pipeline, in two paths
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Path 1 — Indexing (when a document comes in):&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Extract text from the PDF&lt;/li&gt;
&lt;li&gt;Split it into overlapping chunks&lt;/li&gt;
&lt;li&gt;Convert each chunk into a vector (an embedding) that captures its meaning&lt;/li&gt;
&lt;li&gt;Store those vectors in a vector database&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Path 2 — Querying (when a user asks something):&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Embed the question with the same model&lt;/li&gt;
&lt;li&gt;Search the vector database for the most similar chunks&lt;/li&gt;
&lt;li&gt;Send those chunks + the question to the LLM&lt;/li&gt;
&lt;li&gt;The LLM answers using that context, and we return the source pages&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Picking the stack
&lt;/h2&gt;

&lt;p&gt;After building a few of these, here's a stack that's easy to start with and holds up in production:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;FastAPI&lt;/strong&gt; — fast to write, clean async APIs&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;ChromaDB&lt;/strong&gt; — a lightweight vector database that runs embedded, no separate server to manage&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;SentenceTransformers&lt;/strong&gt; — free embeddings, with multilingual models available&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Any LLM&lt;/strong&gt; — OpenAI, Claude, Gemini, or local Ollama&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;One detail people miss: you can test the whole pipeline &lt;strong&gt;without any API key&lt;/strong&gt;, either in a retrieval-only mode that returns the matched chunks, or fully local with Ollama so nothing leaves your machine.&lt;/p&gt;

&lt;h2&gt;
  
  
  The core of the retrieval step
&lt;/h2&gt;

&lt;p&gt;Here's roughly what the query side looks like — embed the question, search, hand the chunks to the LLM:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;answer_question&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;question&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;top_k&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="c1"&gt;# 1. Embed the question with the same model used at indexing time
&lt;/span&gt;    &lt;span class="n"&gt;query_embedding&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;embed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;question&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# 2. Retrieve the most similar chunks from the vector store
&lt;/span&gt;    &lt;span class="n"&gt;chunks&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;vector_store&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;search&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;query_embedding&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;top_k&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;top_k&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# 3. Build a prompt grounded in those chunks, then ask the LLM
&lt;/span&gt;    &lt;span class="n"&gt;context&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n\n&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;text&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;chunks&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;answer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;llm&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;generate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;question&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;question&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;answer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;chunks&lt;/span&gt;  &lt;span class="c1"&gt;# chunks double as citations
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The key constraint: &lt;strong&gt;use the same embedding model for the question and the documents.&lt;/strong&gt; Vectors from different models aren't comparable, and this is a surprisingly common bug.&lt;/p&gt;

&lt;h2&gt;
  
  
  Details that make or break quality
&lt;/h2&gt;

&lt;p&gt;From experience, whether a RAG system answers well comes down to a few things people underestimate:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Chunk size.&lt;/strong&gt; Too big and unrelated content bleeds together; too small and each chunk loses context. Overlap between chunks helps avoid cutting sentences mid-thought.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scanned PDFs.&lt;/strong&gt; If the file is an image, normal text extraction returns nothing. You need an OCR fallback, or those pages silently index as empty.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Re-ranking.&lt;/strong&gt; Pure vector search is fast but coarse. Adding a cross-encoder re-ranker that reads the question and each chunk together noticeably improves which chunks you actually feed the model.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Try it (free, open source)
&lt;/h2&gt;

&lt;p&gt;I packaged all of this into a starter template, open-sourced under MIT. Clone it, run one Docker command, and you have a working document Q&amp;amp;A chatbot with source citations. It's multilingual, and runs free with no API key.&lt;/p&gt;

&lt;p&gt;👉 &lt;strong&gt;GitHub:&lt;/strong&gt; &lt;a href="https://github.com/panutpl/rag-chatbot-template-starter" rel="noopener noreferrer"&gt;https://github.com/panutpl/rag-chatbot-template-starter&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/panutpl/rag-chatbot-template-starter
&lt;span class="nb"&gt;cd &lt;/span&gt;rag-chatbot-template-starter
&lt;span class="nb"&gt;cp&lt;/span&gt; .env.example .env
docker compose up &lt;span class="nt"&gt;--build&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then open &lt;code&gt;http://localhost:8000/docs&lt;/code&gt;, upload a PDF, and start asking questions.&lt;/p&gt;




&lt;p&gt;If you're building RAG or just getting started, I'd love feedback — especially on chunking and retrieval strategies, which I'm still tuning myself. Drop a comment about what's working for you.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>python</category>
      <category>tutorial</category>
      <category>opensource</category>
    </item>
  </channel>
</rss>
