<?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 Neil Kanungo on Medium]]></title>
        <description><![CDATA[Stories by Neil Kanungo on Medium]]></description>
        <link>https://medium.com/@neil.kanungo?source=rss-c8bc7cf1d844------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*lXmJmaCzRiQmWnReFHYuFg.png</url>
            <title>Stories by Neil Kanungo on Medium</title>
            <link>https://medium.com/@neil.kanungo?source=rss-c8bc7cf1d844------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 22:53:09 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@neil.kanungo/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[Why DevRel is the Best Job for Aspiring Data Scientists and AI Engineers]]></title>
            <link>https://medium.com/@neil.kanungo/why-devrel-is-the-best-job-for-aspiring-data-scientists-and-ai-engineers-ebb8d962f1bd?source=rss-c8bc7cf1d844------2</link>
            <guid isPermaLink="false">https://medium.com/p/ebb8d962f1bd</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[careers]]></category>
            <category><![CDATA[developer-relations]]></category>
            <category><![CDATA[devrel]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Neil Kanungo]]></dc:creator>
            <pubDate>Tue, 05 Aug 2025 05:58:31 GMT</pubDate>
            <atom:updated>2025-08-05T05:58:31.363Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vxi8UgD0ANcO_lSUv-H1Pw.png" /><figcaption>Image created by Midjourney</figcaption></figure><p>DevRel (short for “Developer Relations”) is like strapping a jetpack to your career. It launches you into the orbit of builders, thinkers, and tech leaders. You get paid to learn, build, and connect. And let’s be real: you get paid pretty well.</p><h3>Sounds great! So what is DevRel?</h3><p>Developer Relations started out pretty informally: mostly engineers writing docs and a few early evangelists spreading the word about new tools pre-2000s. In the early 2000s, as APIs and open-source projects took off, companies like Google, Twitter, and AWS realized they needed dedicated people to help developers get started and stay engaged. By the 2010s, DevRel had become a real strategy, with teams running events, creating content, and building communities for developer-first companies like Twilio and Stripe. Fast forward to today, and DevRel has grown into a mix of education, community, content, and product experience, all focused on helping developers succeed and driving adoption. It’s now a key part of how modern tech companies grow, especially in AI, open source, and API-driven products.</p><p>While DevRel has evolved, every phase still exists in some form. And each one has something to offer.</p><h3>A Quick Flashback</h3><p>When I started teaching others how to code over a decade ago, many companies still offered <strong>paid enterprise training</strong> as the <em>only</em> way to learn their tools. But <strong>YouTube</strong> and <strong>social media</strong> were exploding. Smart companies and developers realized they could drive bottom-up growth by giving that knowledge away for free.</p><p>Passionate developers learned they could share their <a href="https://youtu.be/e3BmOGkqoNM?feature=shared">videos</a> online and double down on social platforms to build a following that users could tune into and genuinely learn from. These individuals, sometimes referred to as “influencers,” became instrumental in disseminating information about product releases, new use cases, educational content, and overall demand generation in the software industry.</p><p>In today’s world, while enterprise training, documentation, and social engagement are still important parts of DevRel, it’s evolving yet again with new developer portals, personalized digital nurturing, community advocacy, developer experience, and more. A lot of this ties to the <a href="https://www.productled.org/foundations/what-is-product-led-growth">Product-Led Growth</a> and <a href="https://www.communityledgrowth.com/community-led-growth-framework/">Community-Led Growth</a> strategies and creates partnerships with Product, Sales, and Marketing teams.</p><h3>Okay, so how does this help you?</h3><p>Do you find yourself struggling to keep up with all the new developments in tech? Are you unsure what to specialize in and often feel overwhelmed? Are you a fresh grad with a limited network, finding your resume lost in the stacks of others? Do you like to make money?</p><p>If you answered “yes” to any of these questions, then I have a role for you!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/406/1*kqnJGXtGOmZOt8ytAKSDQw.gif" /></figure><p>Developer Relations teams employ “Developer Advocates” who are literally <em>paid </em>to learn technology and share it with their networks, and paid pretty well. In major US cities, a starting Developer Advocate can earn as much as $ 150,000–$200,000 per year. Some companies, like <a href="https://www.linkedin.com/jobs/view/4275252594">Anthropic</a>, are even offering up to $405k/year:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/856/0*DaIBz3bRzmpiuia4" /><figcaption>Anthropic DevRel job listing in August 2025</figcaption></figure><p>It’s more than the money though. It’s the networking, presentation/communication skills, personal brand-building, and genuinely helping a community.</p><h3>How DevRel Supports Career Growth</h3><p>There are several ways being a <em>genuine</em> Developer Advocate can support your career, in ways other than just money. To name a few:</p><p><strong>🧑‍💼 Networking</strong></p><p>Meet developers, founders, and tech leaders through events, open source, and online communities.</p><p><strong>🗣️ Communication Skills</strong></p><p>Improve writing, speaking, and demoing by regularly explaining technical topics to varied audiences.</p><p><strong>🌐 Personal Brand-Building</strong></p><p>Build visibility by creating content, speaking at events, and contributing to projects under your own name.</p><p><strong>🧠 Technical Depth</strong></p><p>Gain broad and deep experience by using and teaching your company’s tech in real-world scenarios.</p><p><strong>🤝 Cross-Functional Experience</strong></p><p>Work closely with product, marketing, sales, and engineering, boosting your strategic and collaborative skills.</p><p><strong>🛣️ Career Flexibility</strong></p><p>Open paths into product management, leadership, consulting, or launching your own company.</p><h3>Why am I sharing this?</h3><p>Well for one, because I’m the Head of DevRel at <a href="https://qdrant.tech/">Qdrant</a> and I genuinely love helping people when there’s an opportunity. But also because <strong>the industry needs you!</strong></p><p>DevRel is growing faster than ever, and I’m seeing tons of super-smart, individuals get over-fixated on becoming a “Data Scientist” or “[insert next hot role here]” in back-of-office scenarios.</p><p><strong>Screw that!</strong></p><p>Become a <em>front-facing</em> technical expert in your field while actually acquiring REAL business experience!</p><p>Don’t cut yourself short battling for the same roles everyone else is. You can get those roles… but with so much more. It just has a different name 😉</p><h3>Take action today</h3><p>Want to break into tech the smart way?</p><p>👉 Read the <a href="https://www.stateofdeveloperrelations.com/2024devrelreport">State of DevRel Report</a> to get the lay of the land</p><p>💬 DM me on <a href="https://www.linkedin.com/in/neilkanungo/">LinkedIn</a> if you’re curious. Seriously, I’m happy to help</p><p>Stop battling for the same roles as everyone else. Do more, get noticed, and actually enjoy the ride 🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ebb8d962f1bd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Vector Indexing: A Roadmap for Vector Databases]]></title>
            <link>https://medium.com/kx-systems/vector-indexing-a-roadmap-for-vector-databases-65866f07daf5?source=rss-c8bc7cf1d844------2</link>
            <guid isPermaLink="false">https://medium.com/p/65866f07daf5</guid>
            <category><![CDATA[generative-ai]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[vector-database]]></category>
            <category><![CDATA[index-vector]]></category>
            <dc:creator><![CDATA[Neil Kanungo]]></dc:creator>
            <pubDate>Fri, 08 Sep 2023 05:45:00 GMT</pubDate>
            <atom:updated>2024-12-12T20:51:12.082Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k4JtMNuqcHi2Y0lnmJGi0g.png" /></figure><p>Road maps are useful when traveling because they take dense geographical information from the real world and condense it into an easily navigable sheet of paper (or smartphone display). In the same way travelers benefit from maps, vector databases benefit from the vector index. A vector index is a condensed form of raw vectors that allow efficient, rapid searches. The compactness of the index reduces memory requirements and enhances accessibility when contrasted with processing searches via raw embeddings.</p><p>Indices come in many forms and are created by different algorithmic approaches. You don’t need to know the details of creating indices themselves with most vector databases; they are easily created through simple commands that you choose. However, grasping the fundamental workings of vector indices and their various forms can help know which one to choose and when. This article discusses three primary categories of vector indices:</p><ul><li>Flat (e.g. Brute Force)</li><li>Graph (e.g. HNSW)</li><li>Inverted (e.g. IVF, IVF-PQ)</li></ul><h3>Flat Index</h3><p>Flat indices (otherwise known as “Brute Force”) deliver the best accuracy of all indexing methods, however, they are notoriously slow. This is because flat indices are a direct representation of the vector embedding. Unlike other indexing methods, generating flat indices does not use pre-trained clusters or any other modification of the vector embeddings. With flat indices, search is <em>exhaustive:</em> it’s performed from the query vector across <em>every single vector embedding</em> and distances are calculated for each pair. Then, k number of embeddings are returned using k-nearest neighbors (kNN) search:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/825/1*Po5wt0bU4V2KycKL0xA0nA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*4-vyY60jeP2A8JoKtkH8dQ.png" /></figure><p>This type of pairwise distance calculation doesn’t seem very efficient (hint: it’s not), however, the high accuracy of search results is sometimes required depending on your application. Specifically, here are some scenarios in which flat indexing is beneficial:</p><ul><li><strong>Low-Dimensional Data:</strong> With low-dimensional vectors, typically up to a few dozen dimensions, flat indices can be sufficiently fast while maintaining high accuracy.</li><li><strong>Small-Scale Databases: </strong>When the database contains a relatively small number of vectors, a flat index can be sufficient to provide quick retrieval times.</li><li><strong>Simple Querying: </strong>If the primary use case involves simple queries, a flat index can offer competitive performance compared to other indices without the complexity</li><li><strong>Real-time Data Ingestion:</strong> When vectors are continuously added to the database, they must be indexed quickly. Due to the simplicity of flat indexing, minimal computation is needed to generate the new indices.</li><li><strong>Low Query Volume: </strong>If the rate of queries being performed on the database is low, a flat index can handle these queries effectively</li><li><strong>Benchmarking Comparisons: </strong>In situations where you want to evaluate the accuracy of other index methods, using the perfectly accurate flat index can be used as a benchmark for comparison purposes.</li></ul><h3>Graph Index</h3><p>Graph indices use nodes and edges to construct a network-like structure. The nodes (or “vertices”) represent the vector embeddings while the edges represent the relationships between embeddings. The most common type of graph index is Hierarchical Navigable Small Words (HNSW).</p><p>HNSW is a “proximity graph” where two embedding vertices are linked based on their proximity — often defined by Euclidean Distance. Each vertex in the graph connects to other vertices called “friends” and each vertex keeps a “friends list.” Starting at a predefined “entry point”, the algorithm traverses connected friend vertices until it finds the nearest neighbor to the query vector:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m8B1Q3M7p6hTu81l-I84UA.png" /></figure><p>Each traversal is continued on via Nearest Neighboring vertices in the “friends list” until no nearer vertex is found — a local minimum is reached for distance.</p><p>The entry point is typically on high-degree vertices (vertices with many connections) to reduce the chance of stopping early by starting on low-degree vertices:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Rg5Br7FOWPsArQaSQdojTQ.png" /></figure><p>The number of degrees on the entry vertex can be specified and is typically balanced between recall and search speed.</p><p>Rather than doing this across one layer (which would take considerable time and memory), the index space is split into hierarchical layers, thus the “H” in HNSW:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4l7XPLWhrZ2dnQ_4I9IwOw.png" /></figure><p>The top layer has the longest distances but includes the highest degree vertices. The algorithm starts by traversing the longer distances until it finds a local minimum with the high degree vertices, then it drops down a layer where more “friend” vertices are available to the previous layer’s high degree vertex. This traversal continues until the nearest neighbor’s distance to the query vector reaches a local minimum.</p><p>Specifically, here are the scenarios where HNSW indexing makes the most sense:</p><ul><li><strong>High-Dimensional Data: </strong>HNSW is specifically designed for high-dimensional data, typically hundreds or thousands of dimensions.</li><li><strong>Efficient Nearest Neighbor Search: </strong>HNSW is well-suited for applications where quickly finding the most similar data points to a given query is critical, such as recommendation systems, content-based image retrieval, and natural language processing tasks.</li><li><strong>Approximate Nearest Neighbor Search</strong>: While HNSW is primarily designed for accurate nearest neighbor search, it can also be used for approximate nearest neighbor search tasks where the user seeks to minimize search computation cost.</li><li><strong>Large-Scale Databases: </strong>HNSW is designed to scale well with large datasets.</li><li><strong>Real-time and Dynamic Data: </strong>HNSW is capable of accommodating dynamically changing data, such as real-time updates</li><li><strong>Highly-Resourced Environments:</strong> HNSW’s performance is not solely reliant on the memory of a single machine, making it well-suited to distributed and parallel computing environments.</li></ul><h3>Inverted Index (and Product Quantization)</h3><p>Inverted indices are widely used in search engines because they provide an efficient way to find document contents. Imagine you have a collection of documents, like web pages in a search engine database. Each document contains words, and you want to be able to quickly find all the documents that contain a particular word. For each unique word in the entire collection of documents, the inverted index creates a list of document references or identifiers (such as document IDs) where that word appears:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uLVZQx_ML5x_FMx2X2TPLg.png" /></figure><p>This is an initial broad stroke of the indexing. We can further optimize the index with “Product Quantization”.</p><p>Product Quantization works in 4 steps:</p><ol><li>Take a high dimensional vector</li><li>Split into equally sized sub-vectors</li><li>Assign each subvector to its nearest centroid (defined by k-means clustering)</li><li>Replace each centroid value with Unique IDs</li></ol><p>Once the quantized subvectors are available, they can be arranged in <a href="https://en.wikipedia.org/wiki/Voronoi_diagram">Voronoi cells</a>. This is shown below with subvectors in yellow, Voronoi cells bounded by white lines, and their centroids in white circles. The query vector is the green star:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/908/1*essc9f_xLokoPoxCaMNIrw.png" /></figure><p>The Voronoi cells chosen are defined by the query vector and probe parameter. Search is restricted to the cell the query vector lies in, and nearest centroids of surrounding cells. Below, a probe parameter of 3 grabs the 3 nearest cells to the query vector:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/908/1*yYUw-JkU_LRRD8czs7TLxA.png" /></figure><p>This yields a huge reduction in memory usage and search time, with great recall. Like HNSW, it’s well-suited to high dimensional vectors and when you need fast nearest neighbor search. In fact, IVFPQ shares a lot of similar benefits as HNSW ranging from Highly-Resourced Environments, to High-Dimensionality Vectors, to Large-Scale Databases. It would be more useful to highlight the nuanced differences in the two index types:</p><p><strong>IVFPQ Index is better for:</strong></p><ul><li><strong>Accuracy</strong>: Excels when high precision of nearest neighbors is important</li><li><strong>Approximate Search</strong>: Both exact and approximate nearest neighbor search are used, however, it’s particularly strong in scenarios where exact results are desired.</li><li><strong>Memory Efficiency</strong>: Due to the use of product quantization, IVFPQ is very memory efficient.</li></ul><p><strong>HNSW Index is better for:</strong></p><ul><li><strong>Approximate Search</strong>: HNSW is designed for efficient approximate nearest neighbor calculations. If your goal is to find a relatively good solution quickly, even if it’s not the exact nearest neighbor, choose HNSW.</li><li><strong>Simplicity</strong>: HNSW is relatively simpler to implement and configure compared to IVFPQ. There are fewer steps in constructing the index since PQ is not involved.</li><li><strong>Scalability</strong>: Handles large datasets with ease and is adaptive to real-time and dynamic data.</li><li><strong>Storage</strong>: HNSW does not require PQ, and therefore needs less storage space.</li><li><strong>Speed (over accuracy):</strong> If you can accept approximate results, the speed benefits of HNSW may be worth it.</li></ul><h3>Final Considerations</h3><p>The benefits of each of the three index types described here can be summarized in the following table:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/654/1*V8OOYnFmXvVi39npQqt2sQ.png" /></figure><p>It’s important to remember that <a href="https://kdb.ai/">KDB.AI</a> does vector indexing for you through simple commands, however, this article covered some important considerations and inner workings of how those indices are created as well as the specific tradeoffs to help you better decide how to use them.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=65866f07daf5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/kx-systems/vector-indexing-a-roadmap-for-vector-databases-65866f07daf5">Vector Indexing: A Roadmap for Vector Databases</a> was originally published in <a href="https://medium.com/kx-systems">KX Systems</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How Vector Databases Search by Similarity: A Comprehensive Primer]]></title>
            <link>https://medium.com/kx-systems/how-vector-databases-search-by-similarity-a-comprehensive-primer-c4b80d13ce63?source=rss-c8bc7cf1d844------2</link>
            <guid isPermaLink="false">https://medium.com/p/c4b80d13ce63</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[similarity-search]]></category>
            <category><![CDATA[vector-database]]></category>
            <category><![CDATA[vector]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Neil Kanungo]]></dc:creator>
            <pubDate>Thu, 24 Aug 2023 22:47:19 GMT</pubDate>
            <atom:updated>2024-12-12T20:54:11.638Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ypMZ7of81wgzw4kzu5t77g.png" /></figure><p>Similarity search allows for exploration of complex, unstructured data sets, but how is this done exactly? At their core, similarity methods quantify how closely two vectors resemble one another, where vectors are numerical representations of data objects such as documents, images, words, audio files, or temporal data known as <a href="https://medium.com/kx-systems/vector-embedding-101-the-new-building-blocks-for-generative-ai-a5f598a806ba">vector embeddings</a>. By understanding the similarity between vectors, we can understand similarity between the data objects themselves. In this way, similarity measures help to understand relationships, identify patterns, and make informed decisions in surprisingly diverse and powerful applications such as:</p><ul><li><strong>Anomaly Detection:</strong> Identifying deviations from normal patterns by measuring the similarity of data points and detecting anomalies</li><li><strong>Clustering and Classification:</strong> Clustering similar data points or classifying objects into distinct categories as these tasks require similar points to be grouped together</li><li><strong>Information Retrieval:</strong> Using search engines for measuring the similarity between user queries and indexed documents to retrieve the most relevant results</li><li><strong>Recommendation Systems:</strong> Finding similar items or products and enabling recommendation systems to suggest items based on user preferences</li></ul><h3>Commonly Used Similarity Measures Explained</h3><p>The similarity measure you choose will depend on the nature of the data and the specific application at hand. There are three commonly used similarity measures, all with their various strengths and weaknesses. Let’s look at each in turn, then we’ll talk about when to use them.</p><p><strong>Euclidean Distance<br></strong>Euclidean distance assesses the similarity of two vectors by measuring the straight-line distance between the two vector points. Vectors that are more similar will have a shorter absolute distance between them, while more dissimilar vectors will have a larger distance between one another.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NA476QCoWGa5DzDYR1c2GQ.png" /><figcaption>Euclidean distance measures the direct distance between two points</figcaption></figure><p>The mathematical formula for calculating the Euclidean Distance between vectors <strong><em>a</em></strong> and <strong><em>b</em></strong> with ’n’ dimensions is given by:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/696/1*q-pXGisYShrd86jolLm1xQ.png" /></figure><p>To the mathematicians among you, you will understand that this takes the difference between the corresponding elements in the two vectors, squares the resulting values, sums these squares together, and then provides the square root of this value.</p><p>Let’s walk through an example where we’ll define two three-dimensional vectors, A = (4, 5, 6) and B = (1, 2, 3), and run through the calculation steps.</p><p><strong>Step 1: </strong>Find the difference between the corresponding elements in the two vectors</p><p><em>x-coordinate:</em> 4–1 = 3<br><em>y-coordinate:</em> 5–2 = 3<br><em>z-coordinate:</em> 6–3 = 3</p><p><strong>Step 2: </strong>Square the obtained differences</p><p><em>x-coordinate:</em> 32 = 9<br><em>y-coordinate:</em> 32 = 9<br><em>z-coordinate:</em> 32 = 9</p><p><strong>Step 3: </strong>Add these squared differences together</p><p>9 + 9 + 9 = 27</p><p><strong>Step 4: </strong>Get the square root of this summed value</p><p>√27 ≈ 5.196</p><p>When calculating Euclidean Distance in spaces higher than 2- or 3- dimensions, it i’s often referred to as the “L2-norm.” This is why when specifying Euclidean Distance as your similarity measure in <a href="https://kx.com/products/kdb-ai/">KDB.AI</a>, you will use “L2” as the metric parameter. L2-norm is just a generalization of Euclidean Distance in higher dimensional space.</p><p>One key feature about the way Euclidean Distance is calculated is that it takes the magnitude of the vectors and the relative direction of the vectors into account. This gives a comprehensive measure of the separation and alignment of the two points in space. However, as magnitude is important, this may yield surprising results in cases where the magnitude of the vectors varies across a dataset:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*x1qLT4cFeZRKHyinXhEqeg.png" /><figcaption>Comparison of distances and angles</figcaption></figure><p>As you can see from the above image, vectors C and D point in the same direction, which may initially lead you to believe they are more similar than vectors A and B. However, as Euclidean distance is calculated through the straight-line distance between the vectors, the fact A and B are smaller vectors means they are deemed more similar when using this measure.</p><p><strong>Dot Product</strong><br>The dot product is a simple measure used to see how <em>aligned </em>two vectors are with one another. It tells us if the vectors point in the same direction, opposite directions, or are perpendicular to each other. It is calculated by multiplying the corresponding elements of the vectors and adding up the results to get a single scalar number.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1003/1*ixhl6ATGqUxXYTBD3cTPAA.png" /><figcaption>Dot Product measures how perpendicularly relative vectors are</figcaption></figure><p>For vectors <strong><em>a</em></strong> and <strong><em>b</em></strong> with n-dimensions, the dot product is defined mathematically as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/549/1*bdZxWFfRDbs50i3pb4XQeg.png" /></figure><p>This simple equation multiplies the corresponding elements of the vectors and sums these resulting products together. To give an example of this, if we had two vectors: A = (1, 2, 3) and B = (4, 5, 6), the dot product would be calculated as follows:</p><p><strong>Step 1: </strong>Multiply the corresponding elements in the two vectors</p><p><em>x-coordinate:</em> 1 * 4 = 4<br><em>y-coordinate:</em> 2 * 5 = 10<br><em>z-coordinate:</em> 3 * 6 = 18</p><p><strong>Step 2: </strong>Add these results together</p><p>4 + 10 + 18 = 32</p><p>If the result is large and positive, it means the vectors have similar directions, while if the result is large and negative, it means the vectors have opposite directions. When the dot product is zero, it means the vectors are perpendicular, forming a 90-degree angle.</p><p>It is common in similarity calculations for vector search to not use exactly 0°, 90°, or 180° to determine similar, unrelated, or opposite vectors respectively. This is because it can exhaust computing resources looking for exact matches between vectors, rather than approximate ones:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KVTymWwtmhfEhBeZpMBfcg.png" /></figure><p><strong>Cosine Similarity</strong><br>Cosine similarity measures the similarity of two vectors by using the angle between these two vectors. The magnitude of the vectors themselves does not matter and only the angle is considered in this calculation, so if one vector contains small values and the other contains large values, this will not affect the resulting similarity value.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1006/1*26EChffPQm65BCyK5uQHaw.png" /><figcaption>Cosine Similarity measures the alignment of vectors by angle</figcaption></figure><p>Think of it this way. Euclidean distance is the “as-the-crow-flies” measure between two points while cosine similarity is the idea that similar vectors will likely point in the same direction so the angle between them will be reduced.</p><p>For vectors <strong><em>a</em></strong> and <strong><em>b</em></strong> with ’n’ dimensions, cosine similarity is defined mathematically as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/1*iXAXuy7oGunfRpApFaKq3A.png" /></figure><p>You may notice that the formula for the “dot product” similarity measure is the top part of this equation. This is because the dot product measures the alignment of the vectors’ directions and then the bottom part of the equation normalizes this value by accounting for the magnitude differences in the vectors. This gives us a similarity value between –1 and 1. We can walk through exactly what is going on here using the same two three-dimensional vectors, A = (1, 2, 3) and B = (4, 5, 6), as we used in the dot product example:</p><p><strong><em>Top of Equation:</em><br>Step 1: </strong>Multiply the corresponding elements in the two vectors</p><p><em>x-coordinate:</em> 4 * 1 = 4<br><em>y-coordinate:</em> 5 * 2 = 10<br><em>z-coordinate:</em> 6 * 3 = 18</p><p><strong>Step 2: </strong>Add these results together</p><p>4 + 10 + 18 = 32</p><p><strong><em>Bottom of Equation:</em></strong><br><strong>Step 3: </strong>Square each element in each vector</p><p><em>Vector 1: </em>(1², 2², 3²) = (1, 4, 9)<br><em>Vector 2: </em>(4², 5², 6²) = (16, 25, 36)</p><p><strong>Step 4: </strong>Add the resulting squared values together</p><p><em>Vector 1: </em>1 + 4 + 9 = 14<br><em>Vector 2: </em>16 + 25 + 36 = 77</p><p><strong>Step 5: </strong>Multiply these results together</p><p>sqrt(14 * 77) = sqrt(1,078) = 32.83</p><p><strong><em>Full Equation:</em><br>Step 6: </strong>Divide the top value by the bottom value</p><p>32/32.83 = 0.9747</p><p>As mentioned, cosine similarity only focuses on the direction of the vectors and not on their magnitude, so only the angle between the vectors is considered. This means that vectors will be deemed <em>least </em>similar if they point directly in the opposite direction (180°) and vectors will be deemed <em>most </em>similar if they point in the exact same direction (0°). The cosine of these angles always gives a resulting value ranging between -1 to 1, with a higher value meaning the vectors are more similar.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/783/1*BUi57azLRrpb4wEzO20ylA.png" /></figure><p>As you can see from the picture above, vectors A and B are deemed more similar when using cosine similarity than vectors C and D as the angle between them is smaller despite the magnitude of these vectors being very different.</p><h3><strong>When to Use Each Measure</strong></h3><p>It’s a general best practice to use the same similarity measure for search that the embeddings were trained on; however, the choice of similarity measure also depends on the specific characteristics of the data and the context of the problem you are trying to solve. Here are some top applications for each of the discussed similarity measures:</p><p><strong>Euclidean Distance:</strong></p><ul><li><strong>Clustering Analysis: </strong>Clustering, like k-means, groups data points based on their proximity in vector space.</li><li><strong>Anomaly and Fraud Detection:</strong> In these use cases, unusual data points can be detected through unusually large distances from the centroid of normal transactions.</li></ul><p><strong>Dot Product:</strong></p><ul><li><strong>Image Retrieval and Matching:</strong> Images with similar visual content will have closely aligned vectors, resulting in higher dot product values. This makes dot product a good choice when you want to find images similar to a given query image.</li><li><strong>Neural Networks and Deep Learning: </strong>In neural networks, fully connected layers use the dot product to combine input features with learnable weights. This captures relationships between features and is helpful for tasks like classification and regression.</li><li><strong>Music Recommendation: </strong>Dot product similarity helps identify tracks with similar audio characteristics, making it valuable for music recommendation systems.</li></ul><p><strong>Cosine Similarity:</strong></p><ul><li><strong>Topic Modeling:</strong> In document embeddings, each dimension can represent a word’s frequency or TF-IDF weight. However, two documents of different lengths can have drastically different word frequencies yet the same word distribution. Since this places them in similar directions in vector space but not similar distances, cosine similarity is a great choice.</li><li><strong>Document Similarity: </strong>Another application of Topic Modeling. Similar document embeddings have similar direction but can have different distances.</li><li><strong>Collaborative Filtering:</strong> This approach in recommendation systems uses the collective preferences and behaviors of users (or items) to make personalized recommendations. Users (or items) are represented as vectors based on their interactions. Since overall ratings and popularity can create different distances, but the direction of similar vectors remains close, cosine similarity is often used.</li></ul><h3>The Brains of Vector Databases</h3><p>Vector similarity is the fundamental reason vector databases work so well. By understanding the different similarity measures and their appropriate use cases, we can make informed decisions and extract valuable insights from complex datasets. Whether it’s for information retrieval, recommendation systems, or clustering, these measures form the foundation of unstructured data search.</p><p>See how you can use different similarity methods in <a href="https://kx.com/products/kdb-ai/">KDB.AI</a> and apply them to your own vector search.</p><p><em>This article was co-authored by </em><a href="https://medium.com/u/c8bc7cf1d844"><em>Neil Kanungo</em></a><em> and </em><a href="https://medium.com/u/3424a8e837b0"><em>Nathan Crone</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c4b80d13ce63" width="1" height="1" alt=""><hr><p><a href="https://medium.com/kx-systems/how-vector-databases-search-by-similarity-a-comprehensive-primer-c4b80d13ce63">How Vector Databases Search by Similarity: A Comprehensive Primer</a> was originally published in <a href="https://medium.com/kx-systems">KX Systems</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>