<?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 Shu Zhou on Medium]]></title>
        <description><![CDATA[Stories by Shu Zhou on Medium]]></description>
        <link>https://medium.com/@francxz?source=rss-3a566a35087d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*cTafQ2JeL8oS0m-QEO8ZAA.jpeg</url>
            <title>Stories by Shu Zhou on Medium</title>
            <link>https://medium.com/@francxz?source=rss-3a566a35087d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 16:34:42 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@francxz/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[Optimizing MySQL Vector Indexes for Efficient Similarity Search]]></title>
            <link>https://medium.com/google-cloud/optimizing-mysql-vector-indexes-for-efficient-similarity-search-d150d4a6c84d?source=rss-3a566a35087d------2</link>
            <guid isPermaLink="false">https://medium.com/p/d150d4a6c84d</guid>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[google-cloud-sql]]></category>
            <category><![CDATA[generative-ai]]></category>
            <category><![CDATA[data]]></category>
            <category><![CDATA[vector-database]]></category>
            <dc:creator><![CDATA[Shu Zhou]]></dc:creator>
            <pubDate>Fri, 05 Dec 2025 09:18:29 GMT</pubDate>
            <atom:updated>2025-12-05T09:18:29.325Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qIzptxiFpZ3A_9iFT34H7w.png" /></figure><p>Vector indexes are a powerful tool for fast similarity searches on large datasets of vector embeddings. To get the best performance, it’s crucial to optimize your vector indexes. This blog post will guide you through the key aspects of optimizing Cloud SQL for MySQL vector indexes. We’ll cover:</p><ol><li>The minimal (and meaningful) data size for using a vector index</li><li>Number of leaves</li><li>Identifying the right max memory setting for your index</li><li>Choosing a distance measure</li></ol><h3>Minimal and Meaningful Data Size</h3><p><a href="https://docs.cloud.google.com/sql/docs/mysql/vector-search">Vector search in Cloud SQL for MySQL</a> is powered by the <a href="https://github.com/google-research/google-research/tree/master/scann">ScaNN</a> engine, which uses <a href="https://en.wikipedia.org/wiki/K-means_clustering">K-Means clustering</a> based indexes. The index is structured in a tree, where the bottom level of the nodes is called <em>leaves</em>. Leaf nodes are containers of embeddings, and non-leaf nodes are used for fast searching.</p><p>When creating a vector index, the database first scans the table with vector embeddings (base table) to collect training data that are later used to predict the tree structure. In Cloud SQL, index creation will fail if you have fewer than 1,000 embeddings in your base table simply because they are not enough to make any predictions. While the technical minimum is 1,000, a <em>meaningful</em> size for good performance is generally larger. KNN is recommended over ANN for datasets with fewer than 100,000 embeddings (check our <a href="https://goo.gle/4oPxMXK">KNN vs ANN blog</a>). While creating a vector index, it’s recommended to have at least 100 data points per leaf node to ensure stable partitioning, i.e., the centroids of leaves are meaningful representations of their member vectors.</p><h3>Number of Leaves</h3><p>The number of leaves, often denoted as <strong><em>K</em></strong> in the context of K-Means clustering, is a critical parameter for vector index performance. Choosing a good <strong><em>K</em></strong> is a trade-off between query speed and index build time. In general, one should follow a few basic guidelines:</p><ol><li>The larger the <em>K</em> is, the longer it takes to build a vector index; but in return you can achieve a faster query speed.</li><li><em>K</em> should not be too large to keep a meaningful leaf size as explained earlier, which is about at least 100 embeddings per leaf.</li><li>The smaller the <em>K</em> is, the slower vector searches perform; but the index build time will be shorter.</li></ol><p>Cloud SQL for MySQL provides balanced partition tuning out-of-the-box. It is a good starting point for testing and trying out your embeddings and queries. You can further fine tune the number of partitions manually, by specifying the num_leavesargument in the create vector index statement. If you want to prioritize query speed, increase num_leaves; if you want to prioritize index build time, decrease num_leaves.</p><pre>create vector index v_idx on tbl(embeddings) distance_measure=cosine num_leaves=&lt;number&gt;</pre><p>To check the num_leaves configuration of an existing vector index, you can query information_schema.innodb_vector_indexes, as shown in the example below:</p><pre>mysql&gt; create vector index v_idx on tbl(embeddings) distance_measure=l2_squared;<br>Query OK, 0 rows affected (3.23 sec)<br>Records: 0  Duplicates: 0  Warnings: 0<br><br>mysql&gt; select * from information_schema.innodb_vector_indexes where index_name like &#39;%v_idx%&#39;\G<br>*************************** 1. row ***************************<br>          INDEX_NAME: v_idx<br>          TABLE_NAME: test.tbl<br>          INDEX_TYPE: TREE_SQ<br>           DIMENSION: 50<br>        DIST_MEASURE: L2_SQUARED<br>              STATUS: Ready<br>               STATE: INDEX_READY_TO_USE<br>          NUM_LEAVES: 2000<br>NUM_LEAVES_TO_SEARCH: 100<br>             QUERIES: 0<br>           MUTATIONS: 0<br>         TREE_MEMORY: 839909<br>1 row in set (0.00 sec)</pre><p>The result includes a few key metadata/metrics related to this blog:</p><ul><li>num_leaves : total number of leaves created in this vector index. In this example the value is automatically computed.</li><li>tree_memory : the size of the vector index. This is the footprint of this vector index if it is loaded into the memory.</li></ul><h3>Memory Configuration</h3><p>Memory management is another key factor for the stability and performance of your vector indexes. Cloud SQL for MySQL dedicates a specific portion of memory for vector indexes, which can be specified by flag cloudsql_vector_max_mem_size. This flag comes with a <a href="https://docs.cloud.google.com/sql/docs/mysql/create-manage-vector-indexes#configure_memory_allocation_for_vector_indexes">default value tailored to the machine tier</a> on every instance that has the vector search feature turned on (cloudsql_vector=on). You can always check the value through</p><pre>select @@global.cloudsql_vector_max_mem_size;</pre><p>This vector memory region is a pool of memory for vector related queries and computations. Training can consume up to 80% of this memory, so it is the primary factor to consider when allocating max vector memory size. A formula to estimate the memory requirement is:</p><pre>memory required = dataset_size (rows) * dimensions * 4 * 10% * 1.25</pre><p>This formula is based on the fact that each dimension of a vector is stored as a float (4 byte) number, and by default 10% of the overall dataset is used for training purposes.</p><p>After the indexes are built, the vector memory is used to host those indexes (each has a footprint of its tree_size). If a new query requires a new vector index to be loaded into the system but there is not enough space, Cloud SQL for MySQL will evict inactive ones to make space. This runtime eviction ensures that unlimited vector indexes can all work at the same time, but might hurt the query throughput.</p><p>It is recommended to set the max vector memory size ( cloudsql_vector_max_mem_size ) to a value big enough, so that</p><ul><li>it satisfies the training requirements of your datasets, and</li><li>it is big enough to hold all built indexes so there are no evictions during the query time</li></ul><p>cloudsql_vector_max_mem_size is a dynamic flag, no restart needed. Note, if you increase it, you must correspondingly decrease innodb_buffer_pool_size to avoid potential memory issues.</p><p>To get an overview of how the vector memory is used at runtime, you can query information_schema.innodb_vector_indexes_memory .</p><pre>select * from information_schema.innodb_vector_indexes_memory;</pre><h3>Choice of Distance Measure</h3><p>The selection of the appropriate distance measure is a mandatory step in nearest neighbor searches, including vector index creation. My previous blog <a href="https://goo.gle/3Lz5SRk">Understanding Vector Distance Measures</a> has a detailed discussion on this topic. Readers are encouraged to check it out if not already. In short,</p><ul><li>Use the distance measure that suits the model used in generating the embeddings.</li><li>Consider the nature of data and use cases. Cosine is usually good for text embeddings and other high-dimensional data, while Euclidean distance can be a good choice for image analysis use cases.</li><li>If you don’t know what to do, start with cosine distance.</li></ul><h3>Try it Now</h3><p>Are you ready to try it out yourself? You can transform your existing dataset to include vector embeddings using Cloud SQL for MySQL’s Vertex AI integration. Follow <a href="https://docs.cloud.google.com/sql/docs/mysql/vector-search">this guide</a> and experience the magic of generative AI!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d150d4a6c84d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-cloud/optimizing-mysql-vector-indexes-for-efficient-similarity-search-d150d4a6c84d">Optimizing MySQL Vector Indexes for Efficient Similarity Search</a> was originally published in <a href="https://medium.com/google-cloud">Google Cloud - Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Vector Distance Measures]]></title>
            <link>https://medium.com/google-cloud/understanding-vector-distance-measures-1e02af6a7f81?source=rss-3a566a35087d------2</link>
            <guid isPermaLink="false">https://medium.com/p/1e02af6a7f81</guid>
            <category><![CDATA[mysql]]></category>
            <category><![CDATA[vector-database]]></category>
            <category><![CDATA[google-cloud-sql]]></category>
            <category><![CDATA[rags]]></category>
            <category><![CDATA[genai]]></category>
            <dc:creator><![CDATA[Shu Zhou]]></dc:creator>
            <pubDate>Wed, 12 Nov 2025 06:04:03 GMT</pubDate>
            <atom:updated>2025-11-12T06:04:03.639Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gAHmUU9IWCjCK0CeGBHbgQ.png" /></figure><p>In the realm of vector search and machine learning, defining “<em>similarity</em>” between data points is achieved through various vector distance measures, mathematical formulas that quantify how far apart two vectors are in a given space. The choice of distance measure might significantly impact the performance and accuracy of algorithms, as it directly influences how relationships between data points are calculated. This document explores some of the most common vector distance measures, highlighting their characteristics, formulas, and typical use cases.</p><h3>Understanding Vector Magnitude and Direction</h3><p>In the context of vector search, a vector is a mathematical entity that possesses both <a href="https://study.com/skill/learn/calculating-a-vectors-magnitude-direction-from-its-components-explanation.html">magnitude and direction</a>. These two properties are fundamental to understanding how vector similarity is calculated.</p><ul><li><strong>Magnitude</strong> refers to the length or size of the vector. It is a scalar value that represents the “how much” aspect of the vector. In many vector search applications, especially those involving text, the magnitude of the vector might be less important than its direction.</li><li><strong>Direction</strong> refers to the orientation of the vector in the multi-dimensional space. It indicates “which way” the vector is pointing. The direction is often the more critical component in determining semantic similarity. For example, in natural language processing, vectors representing similar concepts will point in similar directions, even if their magnitudes differ.</li></ul><p>Different distance measures prioritize these properties differently. For instance, <strong>Cosine Distance</strong> focuses solely on the angle (direction) between vectors, ignoring their magnitudes, which is why it’s a popular choice for text-based similarity tasks. On the other hand, <strong>L2 (Euclidean) Distance</strong> considers both magnitude and direction, making it a common choice for image processing.</p><h3>Common Vector Distance Measures</h3><p>Cloud SQL for MySQL supports 3 most commonly used distance measure functions, l2_squared_distance, cosine_distance, and doc_product, each suitable for unique use cases of how magnitude or direction are weighed.</p><h4>L2 (Euclidean) Distance</h4><p>Euclidean distance is arguably one of the most intuitive distance measures. It represents the straight-line distance between two points in Euclidean space. It is particularly effective when the magnitude of the difference between vector components is important.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*_FAZqeT8MqQsr7NUiKFlkA.png" /></figure><ul><li>Measures the shortest distance between two points.</li><li>Can be affected by outliers.</li><li><strong>Use Cases:</strong> Image similarity, general-purpose similarity tasks where the absolute difference in features matters.</li></ul><h4>Cosine Distance</h4><p>Unlike Euclidean distance, cosine similarity measures the cosine of the angle between two vectors. It focuses on the orientation of the vectors rather than their magnitude. A cosine value of 1 indicates identical orientation (perfect similarity), 0 indicates orthogonality (no similarity), and -1 indicates exactly opposite orientation. Cosine distance is typically calculated as 1-cosine(angle_between_2_vectors).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/631/1*o-mh99xCSRYJAxutmq0KKw.png" /></figure><ul><li>Measures the angular difference, ignoring vector magnitude.</li><li>Effective when the direction of vectors is more important than their absolute values.</li><li><strong>Use Cases:</strong> Text analysis (e.g., document similarity based on word embedding), recommendation systems, sentiment analysis.</li></ul><h4>Dot Product Distance</h4><p>Dot Product Distance is derived from the dot product operation between two vectors. While it is not a formal distance metric, it is frequently used in vector search to find similar items.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/631/1*ASCyHYvav0zMG4G_E2CFfA.png" /></figure><ul><li>This is not a true distance measure as it does not satisfy the <a href="https://en.wikipedia.org/wiki/Triangle_inequality">triangle inequality</a>, finding the minimum dot product distance is the same as finding the maximum inner product between vectors.</li><li>For unit normalized vectors, the ordering of distances is equivalent to that of cosine distance.</li><li><strong>Use Cases:</strong> Even though it is possible, dot-product is not often used directly as a distance measure function. It is the base of how other 2 types of distances are calculated.</li></ul><p>In Cloud SQL for MySQL, the dot product result is returned as a negative value, -1*d(a,b), to maintain the semantic unification where smaller values represent closer distances.</p><h3>Choosing the Right Distance Measure</h3><p>The selection of the appropriate distance measure is a critical step in any data analysis or machine learning task. The best choice depends heavily on:</p><p><strong>Embedding Model:</strong> The most important factor. Embedding models are designed to arrange vectors in a high-dimensional space where the distance between them reflects the semantic similarity of the original data (e.g., text, images). The model’s training process is often optimized for a particular distance metric. Always check the documentation of the embedding model to see which distance metric it was trained on. A mismatch can lead to significantly poorer search results. For example,</p><ul><li><a href="https://cloud.google.com/vertex-ai/generative-ai/docs/embeddings/get-text-embeddings">VertexAI text embeddings</a> are normalized, can be used with all three distance measures and yield the same similarity rankings.</li><li>OpenAI <a href="https://platform.openai.com/docs/guides/embeddings/what-are-embeddings#:~:text=should%20I%20use%3F-,We%20recommend,cosine%20similarity,-.%20The%20choice%20of">text-embedding-3-small</a> recommends cosine similarity.</li><li>FaceNet’s <a href="https://arxiv.org/abs/1503.03832#:~:text=a%20mapping%20from%20face%20images%20to%20a%20compact%20Euclidean%20space">face recognition and clustering model</a> uses Euclidean similarity.</li></ul><p>If not already, you can check out the previous blog in this series, <a href="https://goo.gle/4ol0f7M">Choosing the Right Vector Embedding Model</a>, for more information about the model selection.</p><p><strong>Nature of the Data and Use Case:</strong> What does “similarity” truly mean in the context of your application? Cosine similarity is often preferred for text embedding and other high-dimensional data. This is because in high-dimensional spaces, the concept of distance can become less intuitive (an issue known as the “curse of dimensionality”), and the angle between vectors is often a more reliable measure of similarity. On the other hand, Euclidean distance is a good choice when the magnitude of the vector components is meaningful, such as in image analysis where pixel intensities matter or in recommendation systems where counts are important.</p><p><strong>What if You Don’t Know the Training Metric</strong>: The best practice is to assume <strong>cosine distance</strong> for most modern, high-dimensional text and multi-modal embedding models. It’s the most common metric used in their training. If performance is critical, it’s always a good idea to run your own evaluation to compare it against other metrics.</p><h3>Distance Measure In Cloud SQL for MySQL</h3><p>In Cloud SQL for MySQL, distance measure is a key characteristic of vector indexes, involving both index creation and nearest neighbor queries.</p><p>While creating a vector index, the distance measure is a mandatory argument. It specifies the algorithm used in distance computation, not only when creating the index, but also future DMLs.</p><pre>create vector index idx on tbl(embeddings) distance_measure=cosine;</pre><p>When performing a nearest neighbor search, the query syntax requires the distance_measure argument so that the database can perform necessary optimization when possible (check out our <a href="https://goo.gle/4oPxMXK">ANN vs KNN</a> post for details).</p><pre>select id from tbl order by approx_distance(embeddings, string_to_vector(&#39;[...]&#39;), &#39;distance_measure=cosine`) limit 10;</pre><p>It is also possible to explicitly request a specific distance computation algorithm in a KNN query, such as</p><pre>select id from tbl order by cosine_distance(embedding, string_to_vector(&#39;[...]&#39;)) limit 10;</pre><p>Want to find the best distance measure of your own dataset? Follow this <a href="https://codelabs.developers.google.com/csql-mysql-ai-embedding#0">codelab</a> and try it out on a Cloud SQL for MySQL instance.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1e02af6a7f81" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-cloud/understanding-vector-distance-measures-1e02af6a7f81">Understanding Vector Distance Measures</a> was originally published in <a href="https://medium.com/google-cloud">Google Cloud - Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Vector Search: Demystifying ANN and KNN]]></title>
            <link>https://medium.com/google-cloud/vector-search-demystifying-ann-and-knn-64bc2b24cca8?source=rss-3a566a35087d------2</link>
            <guid isPermaLink="false">https://medium.com/p/64bc2b24cca8</guid>
            <category><![CDATA[google-cloud-sql]]></category>
            <category><![CDATA[genai]]></category>
            <category><![CDATA[rags]]></category>
            <category><![CDATA[mysql]]></category>
            <category><![CDATA[vector-database]]></category>
            <dc:creator><![CDATA[Shu Zhou]]></dc:creator>
            <pubDate>Fri, 31 Oct 2025 03:26:12 GMT</pubDate>
            <atom:updated>2025-10-31T03:26:12.753Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Iag4KRLj0jAVk3xLDjxcVg.png" /></figure><p>In the rapidly evolving landscape of data, the ability to efficiently search and retrieve relevant information — even as your data set explodes — is critical. This is where vector search shines, transforming how we interact with large datasets by representing data as numerical vectors that capture semantic meaning in a high-dimensional space. This transforms the sophisticated semantic similarity problem into a mathematical vector distance problem. Vector search uses algorithms designed to find similar vectors, with K-Nearest Neighbors (KNN) and Approximate Nearest Neighbors (ANN) being two of the most prominent.</p><p>Similar to the previous blog in this series, <a href="https://goo.gle/3X7tNcV">Choosing Your Vector Search Solution</a>, I’ll continue using Cloud SQL for MySQL as the example.</p><h3><strong>What Is KNN (K-Nearest Neighbors)</strong></h3><p>KNN is a direct approach to finding similar data points in vector search. Given a query vector, KNN exhaustively calculates the distance (or similarity) between the query and every single vector in the database. It then returns the K vectors that are closest to the query.</p><p><strong>Key Characteristics of KNN:</strong></p><ul><li><strong>Accuracy:</strong> KNN is known for its accuracy because it performs an exhaustive search. It guarantees finding the true K-nearest neighbors.</li><li><strong>High Computational Cost:</strong> As the dataset size grows, the computational cost (and thus time) for each query increases linearly. It would become prohibitively slow when the number of vectors grows to millions.</li></ul><p>In Cloud SQL for MySQL, one can perform KNN queries using explicit distance measure functions such as:</p><pre>select id from tbl order by cosine_distance(emb, string_to_vector(‘[...]’) limit 10;</pre><h3><strong>What is ANN (Approximate Nearest Neighbors)</strong></h3><p>ANN algorithms are designed to overcome the scalability limitations of KNN. Instead of guaranteeing the absolute K-nearest neighbors, ANN aims to find a <em>good approximation</em> of the nearest neighbors, sacrificing some accuracy for significantly improved speed and scalability. This “approximation” is often more than sufficient for most real-world applications where near real-time performance is crucial.</p><p><strong>Key Characteristics of ANN:</strong></p><ul><li><strong>Speed:</strong> ANN algorithms are orders of magnitude faster than KNN for large datasets.</li><li><strong>Scalability:</strong> ANN can handle datasets with billions of vectors, making it suitable for modern large-scale applications like recommendation systems, image search, and natural language processing.</li><li><strong>Index:</strong> ANN queries are done through the help of vector indexes.</li><li><strong>Tunable Accuracy vs. Speed Trade-off:</strong> There’s an inherent trade-off. Users can often tune the vector index to prioritize higher accuracy at the cost of some speed or higher speed at the cost of some accuracy.</li><li><strong>Complexity:</strong> ANN algorithms are more complex to implement and understand than basic KNN, involving techniques like tree-based methods (e.g., ScaNN, Annoy), hashing-based methods (e.g., Locality Sensitive Hashing — LSH), and graph-based methods (e.g., HNSW).</li></ul><p>In Cloud SQL for MySQL, ANN is signified by the <strong><em>approx_distance</em></strong> function, see below example.</p><pre>select id from tbl order by approx_distance(emb, string_to_vector(‘[...]’), ‘distance_measure=cosine’) limit 10;</pre><h3>KNN vs. ANN: A Comparison</h3><p>Let’s summarize the key differences between KNN and ANN:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2daa7173341cb57a4fc90f536337bf42/href">https://medium.com/media/2daa7173341cb57a4fc90f536337bf42/href</a></iframe><ul><li>Your dataset is relatively small (low hundreds of thousands of vectors).</li><li>You require 100% precision in finding the absolute nearest neighbors.</li><li>Computational time is not a critical constraint.</li></ul><p><strong>Choose ANN when:</strong></p><ul><li>Your dataset is large (millions to billions of vectors).</li><li>Speed and scalability are paramount for your application (e.g., real-time search).</li><li>A slight trade-off in accuracy for significantly improved performance is acceptable.</li></ul><h3>Auto Switch in Cloud SQL for MySQL</h3><p>Cloud SQL for MySQL includes a resilient feature where a query requesting an ANN search can automatically revert to performing an exact KNN search. This fallback is triggered when KNN is deemed more suitable for the query. The optimizer in Cloud SQL MySQL is aware of the vector index, which allows it to recognize when the conditions for an accelerated ANN search are not met. Common reasons include:</p><ul><li>Missing Vector Index: The query is against a vector column that does not have a corresponding index. In this case, the database has no choice but to perform an exhaustive, “exact” search.</li><li>Unsupported Query arguments: ANN queries often have specific requirements for how they are used in a query. For instance, they might explicitly require a specific distance measure algorithm, that is not the same as what the index uses.</li><li>Optimizer determines KNN search is lower cost: Certain queries (i.e. high selectivity filters) make KNN search a more efficient choice than ANN. The optimizer may intelligently use KNN in this scenario.</li></ul><p>This smart feature provides a few benefits:</p><ol><li>This automatic fallback makes the application more resilient to potential errors. Instead of failing, the query still executes and returns correct results. The application gets a valid response, although the performance will be that of a slower KNN search rather than the faster ANN search. This ensures that your application continues to function, while also implicitly signaling that the query or underlying table structure may need optimization (e.g., by creating a missing vector index).</li><li>It is also a handy tool for app development and debugging. The developers can use the ANN queries as in real production when working in their dev environments. The test datasets are usually small, sometimes too small to create a vector index, but the developers can still use the prod syntax all the way through the whole application development cycle.</li></ol><p>You can always <a href="https://cloud.google.com/sql/docs/mysql/search-filter-vector-embeddings#check_the_fallback_status_on_ann_searches">monitor the KNN/ANN switch status</a> by consulting the dedicated status.</p><pre>show global status like &#39;%cloudsql_vector_knn_fallback%&#39;;</pre><h3>Get Started</h3><p>Both KNN and ANN are vital for vector search, but they serve different needs. While KNN offers unparalleled precision for smaller scales, ANN is the clear winner for handling the massive datasets prevalent in today’s data-driven world. Understanding their differences is crucial for anyone building efficient and scalable vector search systems.</p><p>If you’re interested in learning more about the broader landscape of vector search solutions and whether a specialized database is right for you, I recommend reading our previous post: <a href="https://goo.gle/3X7tNcV">Cloud SQL vs. Specialized Databases: Choosing Your Vector Search Solution</a>.</p><p>Ready to try it out and test it yourself? Follow this <a href="https://codelabs.developers.google.com/csql-mysql-ai-embedding#0">codelab</a> and start building your first vector search powered app!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=64bc2b24cca8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-cloud/vector-search-demystifying-ann-and-knn-64bc2b24cca8">Vector Search: Demystifying ANN and KNN</a> was originally published in <a href="https://medium.com/google-cloud">Google Cloud - Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>