<?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: Kode</title>
    <description>The latest articles on DEV Community by Kode (@kendricktech).</description>
    <link>https://dev.to/kendricktech</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.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1397597%2F61051278-f511-43b0-ba97-fa85193701f2.png</url>
      <title>DEV Community: Kode</title>
      <link>https://dev.to/kendricktech</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kendricktech"/>
    <language>en</language>
    <item>
      <title>Introducing Vectors And Vector Search</title>
      <dc:creator>Kode</dc:creator>
      <pubDate>Sat, 18 Apr 2026 23:25:42 +0000</pubDate>
      <link>https://dev.to/kendricktech/introducing-vectors-and-vector-search-2388</link>
      <guid>https://dev.to/kendricktech/introducing-vectors-and-vector-search-2388</guid>
      <description>&lt;h2&gt;
  
  
  Where Traditional Queries Fail
&lt;/h2&gt;

&lt;p&gt;Picture this: your dog just birthed a cute litter of say 5 puppies.&lt;/p&gt;

&lt;p&gt;Now let's assume you have no other pets.&lt;/p&gt;

&lt;p&gt;If I asked you: "how many pets do you have?", you would naturally say 6.&lt;br&gt;
If I asked you: "how many dogs do you have?", you would of course still say 6.&lt;/p&gt;

&lt;p&gt;Now I asked slightly similar questions, but you were able to parse the question and answer it correctly.&lt;/p&gt;

&lt;p&gt;If you were querying a database for the same answer you would write something to this effect:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;animals&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'pet'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;pets&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'dog'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Depending on how you designed your database, your query might yield your desired result.&lt;/p&gt;

&lt;p&gt;But we're already running into some common problems. Chief of them is that we need to design our tables and queries to accurately represent relationships between data — not a small feat in itself. For that we need structured data.&lt;/p&gt;

&lt;p&gt;Bear in mind that most everyday data is unstructured:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;"I have 2 Rottweilers"&lt;/li&gt;
&lt;li&gt;"I have 3 Cats"&lt;/li&gt;
&lt;li&gt;"I have 3 Tom cats"&lt;/li&gt;
&lt;li&gt;"I have a pet parrot"&lt;/li&gt;
&lt;li&gt;"I have a pet bird"&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To us humans, all the above questions obviously have high "similarity".&lt;/p&gt;

&lt;p&gt;But in a database there's no implicit similarity between them — it treats each piece of data as an isolated point — unless we make any such relationship explicit somehow. That leads us to the most important issue: encoding such "similarities" to enable computers to process them.&lt;/p&gt;

&lt;h2&gt;
  
  
  Vector Search
&lt;/h2&gt;

&lt;p&gt;Vectors provide a comprehensive mathematical encoding of the similarities between such unstructured data.&lt;/p&gt;

&lt;p&gt;In its simplest form, a vector is any quantity that has both magnitude and direction.&lt;/p&gt;

&lt;p&gt;Visualize the diagram in the image below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fexz8a8nnywelj7krybyl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fexz8a8nnywelj7krybyl.png" alt="Alt text" width="800" height="817"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Imagine you're standing at the origin (the center point marked "0").&lt;/p&gt;

&lt;p&gt;I could tell you to move &lt;strong&gt;60 km&lt;/strong&gt;, but that is incomplete — 60km &lt;em&gt;where&lt;/em&gt;? you ask.&lt;/p&gt;

&lt;p&gt;You need both pieces of information:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Magnitude:&lt;/strong&gt; 60 km (how far)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Direction:&lt;/strong&gt; Northwest (which way)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So the complete instruction is: "Move 60km Northwest" or "Move 40km Southeast" or "Move 40km North."&lt;/p&gt;

&lt;h3&gt;
  
  
  Why Direction Matters
&lt;/h3&gt;

&lt;p&gt;Disclaimer: I personally suck at compass navigation.&lt;br&gt;
Now imagine three people starting at the origin:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Person A:&lt;/strong&gt; Moves 90km Northwest&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Person B:&lt;/strong&gt; Moves 60km Northwest&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Person C:&lt;/strong&gt; Moves 10km Southeast&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Even though Person C traveled the least (10km), they're actually the &lt;strong&gt;farthest&lt;/strong&gt; from Person A.&lt;/p&gt;

&lt;p&gt;Person B, who only went 60km, is &lt;strong&gt;closer&lt;/strong&gt; to Person A than Person C is.&lt;/p&gt;

&lt;p&gt;Why? Person B's direction (Northwest) is more similar to Person A's direction (Northwest) than Person C's direction (Southeast). Hence both their travel destinations did not diverge as far as Person B and Person C's.&lt;/p&gt;

&lt;h3&gt;
  
  
  Measuring Similarity with Angles
&lt;/h3&gt;

&lt;p&gt;But the previous instruction is itself still not complete.&lt;/p&gt;

&lt;p&gt;Northwest could be any direction between North and West; to be more precise we could add angles:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;move 90km 85° Northwest&lt;/li&gt;
&lt;li&gt;move 60km 60° Northwest&lt;/li&gt;
&lt;li&gt;move 10km 230° Southeast&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy6ikiuaqdjktuj14rdhr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy6ikiuaqdjktuj14rdhr.png" alt="Alt text" width="800" height="937"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;How do we measure how "similar" any two directions are?&lt;br&gt;
We measure the &lt;strong&gt;angle&lt;/strong&gt; between them.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc7wcvsza76cq2uiuvwng.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc7wcvsza76cq2uiuvwng.png" alt="Alt text" width="800" height="1199"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The smaller the angle, the more similar the two directions are and the lesser the divergence as we travel outwards from the origin.&lt;br&gt;
If we represent "I have a dog" as a vector at 40°, "My dog gave birth to a litter of five puppies" as 60°, and "Car" as 230°, we develop a system for ranking similarity. Crucially, this is magnitude-invariant. Just because "A" is a whole book about dogs doesn't change its similarity to the sentence "I have a dog," because they both point in the same "thematic" direction.&lt;/p&gt;

&lt;h2&gt;
  
  
  Back to Queries
&lt;/h2&gt;

&lt;p&gt;Back to our cute puppy litters.&lt;/p&gt;

&lt;p&gt;If we could represent each sentence as a vector:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;"How many pets do you have?" → Vector A (pointing in some direction)&lt;/li&gt;
&lt;li&gt;"How many dogs do you have?" → Vector B (pointing in a similar direction)&lt;/li&gt;
&lt;li&gt;"What's the weather today?" → Vector C (pointing in a completely different direction)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Then finding similar questions becomes a simple matter of:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Converting and labeling our data as vectors&lt;/li&gt;
&lt;li&gt;Converting the query into a vector&lt;/li&gt;
&lt;li&gt;Measuring the angle between the query and all stored vectors&lt;/li&gt;
&lt;li&gt;Returning the ones with the smallest angles (and consequently higher similarity)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By encoding data into a mathematical representation on a vector plane, &lt;br&gt;
we have achieved a means of comparing data points to one another &lt;br&gt;
across various dimensions.&lt;br&gt;
But the most important measure we want here is cosine similarity.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Thanks for reading this far — this is part of an ongoing series where I build a working vector search engine from scratch in Rust, covering embeddings, SQLite storage, cosine similarity, and more. The complete guide with working code examples lives here: &lt;a href="https://olorikendrick.github.io/vector-search-with-rust-and-sqlite/" rel="noopener noreferrer"&gt;Vector Search with Rust and Sqlite&lt;/a&gt;&lt;br&gt;
I'm always open to collaborations and questions — feel free to reach out to me!&lt;/em&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>rust</category>
      <category>vectordatabase</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
