<?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: Sunny Dagar</title>
    <description>The latest articles on DEV Community by Sunny Dagar (@sunny_dagar_9dc293f7ebf1d).</description>
    <link>https://dev.to/sunny_dagar_9dc293f7ebf1d</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%2F4087119%2Ff952f0db-f65a-4bcf-b420-b02a57b5300e.png</url>
      <title>DEV Community: Sunny Dagar</title>
      <link>https://dev.to/sunny_dagar_9dc293f7ebf1d</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sunny_dagar_9dc293f7ebf1d"/>
    <language>en</language>
    <item>
      <title>RAG Without a Vector Database: My Production Assistant Runs on MariaDB and 10 Lines of Cosine Similarity</title>
      <dc:creator>Sunny Dagar</dc:creator>
      <pubDate>Thu, 20 Aug 2026 19:11:52 +0000</pubDate>
      <link>https://dev.to/sunny_dagar_9dc293f7ebf1d/rag-without-a-vector-database-my-production-assistant-runs-on-mariadb-and-10-lines-of-cosine-3c8o</link>
      <guid>https://dev.to/sunny_dagar_9dc293f7ebf1d/rag-without-a-vector-database-my-production-assistant-runs-on-mariadb-and-10-lines-of-cosine-3c8o</guid>
      <description>&lt;p&gt;Everyone will tell you that building a RAG (Retrieval-Augmented Generation) assistant means signing up for Pinecone, Weaviate, or spinning up pgvector. I want to show you the counter-example I run in production: the AI assistant on my robotics platform, &lt;a href="https://roboturfs.ca" rel="noopener noreferrer"&gt;roboturfs.ca&lt;/a&gt;, answers customer questions every day with &lt;strong&gt;no vector database at all&lt;/strong&gt;—just MariaDB, Gemini embeddings, and a cosine-similarity function that fits in ten lines of PHP.&lt;/p&gt;

&lt;p&gt;This isn't a toy. It retrieves knowledge, quotes live inventory and prices, captures leads, and books appointments. Here's how it works, why I built it this way, and honestly when you should not copy me.&lt;/p&gt;

&lt;h2&gt;
  
  
  What RAG actually requires (less than you think)
&lt;/h2&gt;

&lt;p&gt;Strip away the hype and RAG needs exactly four things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Chunks&lt;/strong&gt; of your content (knowledge-base entries, docs, FAQs)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;An embedding per chunk&lt;/strong&gt;—a list of numbers that captures its &lt;em&gt;meaning&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A way to find the nearest chunks by meaning&lt;/strong&gt; when a question arrives&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A prompt&lt;/strong&gt; that pastes those chunks in and tells the model to answer &lt;em&gt;only from them&lt;/em&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Notice what's missing: nothing in that list says "dedicated vector database." A vector DB is a scaling optimization, not a requirement of the pattern.&lt;/p&gt;

&lt;h2&gt;
  
  
  My setup
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Embeddings:&lt;/strong&gt; Google's &lt;code&gt;gemini-embedding&lt;/code&gt; at &lt;strong&gt;256 dimensions&lt;/strong&gt;. One API call per chunk.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Storage:&lt;/strong&gt; each chunk lives in a plain MariaDB table (&lt;code&gt;kb_chunks (id, title, content, embedding)&lt;/code&gt;) with the embedding cached as JSON in a column.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lazy embedding:&lt;/strong&gt; chunks are embedded on first use, then cached forever. Add a new knowledge chunk to the table today, the assistant knows it today—no reindexing pipeline, no deploy.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Retrieval:&lt;/strong&gt; brute-force cosine similarity over every chunk, in PHP, at request time. Top 4 chunks win.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Corpus size:&lt;/strong&gt; a few hundred chunks.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The entire "vector search engine"
&lt;/h2&gt;

&lt;p&gt;This is the actual production code:&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
php
function cosine(array $a, array $b): float {$dot = $na =$nb = 0.0;
    $n = min(count($a), count($b));
    for ($i = 0; $i &amp;lt;$n; $i++) {$dot += $a[$i] * $b[$i];
        $na +=$a[$i] *$a[$i];$nb += $b[$i] * $b[$i];
    }
    return ($na &amp;amp;&amp;amp; $nb) ?$dot / (sqrt($na) * sqrt($nb)) : 0.0;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>ai</category>
      <category>rag</category>
      <category>php</category>
    </item>
  </channel>
</rss>
