{"id":27944,"date":"2025-06-20T12:22:56","date_gmt":"2025-06-20T19:22:56","guid":{"rendered":"https:\/\/www.pingcap.com\/?post_type=article&#038;p=27944"},"modified":"2025-08-18T23:26:15","modified_gmt":"2025-08-19T06:26:15","slug":"approximate-nearest-neighbor-ann-search-explained-ivf-vs-hnsw-vs-pq","status":"publish","type":"article","link":"https:\/\/www.pingcap.com\/ko\/article\/approximate-nearest-neighbor-ann-search-explained-ivf-vs-hnsw-vs-pq\/","title":{"rendered":"Approximate Nearest Neighbor (ANN) Search Explained: IVF vs HNSW vs PQ"},"content":{"rendered":"<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_Is_Approximate_Nearest_Neighbor_ANN_Search\"><\/span>What Is Approximate Nearest Neighbor (ANN) Search?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Approximate Nearest Neighbor (ANN) search has become essential for applications dealing with high-dimensional data\u2014think natural language processing, image recognition, and recommendation engines. For a deeper understanding of TiDB&#8217;s approach, visit our <a href=\"https:\/\/www.pingcap.com\/ko\/ai\/\">Vector Search Overview<\/a>. Unlike exact methods, ANN strikes a practical balance between speed and accuracy, making it ideal for large-scale, real-time AI systems.<\/p>\n\n\n\n<p>At its core, ANN algorithms aim to identify data points that are closest to a given query point. They do so approximately, dramatically reducing computational load while maintaining acceptable accuracy levels. This efficiency is especially important when working with massive datasets.<\/p>\n\n\n\n<p>Applications of ANN span various industries. E-commerce platforms use it for personalized product recommendations. Social media and streaming services deploy ANN to surface relevant content. Healthcare leverages it for predictive analytics, diagnostics, and genome sequencing, enabling faster and more reliable results.<\/p>\n\n\n\n<p>To meet these diverse needs, several indexing techniques have been developed. For a detailed guide, check out <a href=\"https:\/\/www.pingcap.com\/ko\/article\/mastering-faiss-vector-database-a-beginners-handbook\/\" target=\"_blank\" rel=\"noreferrer noopener\">Mastering Faiss Vector Database: A Beginner\u2019s Handbook<\/a>. Among the most popular are Inverted File (IVF), Hierarchical Navigable Small World (HNSW), and Product Quantization (PQ). These methods each take a different approach to indexing, offering trade-offs in speed, scalability, and accuracy.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Vector_Indexing_Techniques_IVF_HNSW_and_PQ\"><\/span>Vector Indexing Techniques: IVF, HNSW, and PQ<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Inverted File (IVF)<\/h3>\n\n\n\n<p>IVF divides the data space into clusters using algorithms like k-means. During a query, only the relevant clusters are searched, significantly speeding up the process. IVF is ideal for datasets that naturally segment into distinct clusters. However, its accuracy depends on how well the clusters (centroids) represent the overall data.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Hierarchical Navigable Small World (HNSW)<\/h3>\n\n\n\n<p>HNSW builds a multi-layer graph where data points are connected across layers based on proximity. This graph structure enables fast navigation and high recall, making HNSW suitable for precision-focused applications like search engines. The downside? It requires more memory and longer build times.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Product Quantization (PQ)<\/h3>\n\n\n\n<p>PQ compresses vectors by splitting them into subvectors and encoding each with a separate codebook. This reduces both memory usage and search time, which is especially useful for edge devices or environments with limited resources. While fast, PQ can suffer from reduced precision if not tuned properly.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"IVF_vs_HNSW_vs_PQ_How_to_Choose_the_Right_ANN_Index\"><\/span>IVF vs HNSW vs PQ: How to Choose the Right ANN Index<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Choosing the right index type depends on your priorities:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>IVF<\/strong> is best for speed and clustered data but may lack precision.<\/li>\n\n\n\n<li><strong>HNSW<\/strong> provides high accuracy and recall but consumes more memory and compute.<\/li>\n\n\n\n<li><strong>PQ<\/strong> is optimal for memory efficiency and fast responses but requires preprocessing and may reduce accuracy.<\/li>\n<\/ul>\n\n\n\n<p>Understanding these trade-offs allows teams to align their choice of indexing strategy with both technical constraints and business needs. For a competitive breakdown, read <a href=\"https:\/\/www.pingcap.com\/ko\/article\/open-source-vector-databases-transforming-data-management\/\" target=\"_blank\" rel=\"noreferrer noopener\">Open Source Vector Databases: Transforming Data Management.<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_TiDB_Integrates_Faiss_for_High-Performance_ANN_Search\"><\/span>How TiDB Integrates Faiss for High-Performance ANN Search<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>TiDB integrates with Faiss, Facebook AI\u2019s similarity search library, to offer powerful ANN capabilities. Faiss supports IVF, HNSW, and PQ\u2014allowing TiDB users to choose the indexing structure that best fits their data and workload.<\/p>\n\n\n\n<p>This integration brings ANN search into TiDB\u2019s SQL-centric environment, making it accessible to teams already familiar with relational databases. Developers can run hybrid queries that combine traditional SQL filters with semantic similarity powered by Faiss.<\/p>\n\n\n\n<p>What\u2019s more, TiDB supports GPU acceleration via Faiss, significantly improving performance on large-scale vector workloads. See our benchmarking in <a href=\"https:\/\/www.pingcap.com\/ko\/article\/analyzing-performance-gains-in-openais-text-embedding-3-small\/\" target=\"_blank\" rel=\"noreferrer noopener\">Analyzing Performance Gains in OpenAI\u2019s Text\u2011Embedding\u20113\u2011Small<\/a>. This is especially valuable for real-time analytics, customer personalization, and AI inference applications.<\/p>\n\n\n\n<p>The combination of TiDB\u2019s hybrid transactional and analytical processing (HTAP) model with Faiss\u2019s indexing power enables:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Real-time product recommendations<\/li>\n\n\n\n<li>Fast, semantic enterprise search<\/li>\n\n\n\n<li>Scalable RAG (retrieval-augmented generation) use cases<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Final_Thoughts_Call_to_Action\"><\/span>Final Thoughts &amp; Call to Action<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>By understanding the strengths and trade-offs of IVF, HNSW, and PQ\u2014and how TiDB integrates these via Faiss\u2014you\u2019re better equipped to implement scalable, intelligent search in your AI applications. For implementation strategies, explore <a href=\"https:\/\/www.pingcap.com\/ko\/article\/cost-effective-semantic-search-llms\/\" target=\"_blank\" rel=\"noreferrer noopener\">How to Build Cost-Effective Semantic Search with LLMs<\/a> \uadf8\ub9ac\uace0 <a href=\"https:\/\/www.pingcap.com\/ko\/article\/how-to-optimize-rag-pipelines-for-maximum-efficiency\/\" target=\"_blank\" rel=\"noreferrer noopener\">How to Optimize RAG Pipelines for Maximum Efficiency<\/a>.<\/p>\n\n\n\n<p><strong>Ready to build faster, smarter AI applications?<\/strong> TiDB integrates powerful vector indexing methods through Faiss, making it easy to scale personalized search, semantic matching, and real-time recommendations.<\/p>\n\n\n\n<p><a href=\"https:\/\/tidbcloud.com\/free-trial\" target=\"_blank\" rel=\"noreferrer noopener\">Explore TiDB Cloud Starter<\/a> today\u2014for free.<\/p>\n\n\n\n<p><\/p>","protected":false},"excerpt":{"rendered":"<p>What Is Approximate Nearest Neighbor (ANN) Search? Approximate Nearest Neighbor (ANN) search has become essential for applications dealing with high-dimensional data\u2014think natural language processing, image recognition, and recommendation engines. For a deeper understanding of TiDB&#8217;s approach, visit our Vector Search Overview. Unlike exact methods, ANN strikes a practical balance between speed and accuracy, making it [&hellip;]<\/p>\n","protected":false},"author":305,"featured_media":0,"template":"","class_list":["post-27944","article","type-article","status-publish","hentry"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Approximate Nearest Neighbor (ANN) Search Explained: IVF vs HNSW vs PQ | TiDB<\/title>\n<meta name=\"description\" content=\"What Is Approximate Nearest Neighbor (ANN) Search? Approximate Nearest Neighbor (ANN) search has become essential for applications dealing with Discover how Approximate Nearest Neighbor (ANN) search enables fast, scalable AI applications. Learn the differences between IVF, HNSW, and PQ indexing\u2014and how TiDB integrates Faiss for high-performance vector search.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.pingcap.com\/ko\/article\/approximate-nearest-neighbor-ann-search-explained-ivf-vs-hnsw-vs-pq\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Approximate Nearest Neighbor (ANN) Search Explained: IVF vs HNSW vs PQ | TiDB\" \/>\n<meta property=\"og:description\" content=\"What Is Approximate Nearest Neighbor (ANN) Search? Approximate Nearest Neighbor (ANN) search has become essential for applications dealing with Discover how Approximate Nearest Neighbor (ANN) search enables fast, scalable AI applications. Learn the differences between IVF, HNSW, and PQ indexing\u2014and how TiDB integrates Faiss for high-performance vector search.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pingcap.com\/ko\/article\/approximate-nearest-neighbor-ann-search-explained-ivf-vs-hnsw-vs-pq\/\" \/>\n<meta property=\"og:site_name\" content=\"TiDB\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/facebook.com\/pingcap2015\" \/>\n<meta property=\"article:modified_time\" content=\"2025-08-19T06:26:15+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/static.pingcap.com\/files\/2024\/09\/11005522\/Homepage-Ad.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1440\" \/>\n\t<meta property=\"og:image:height\" content=\"714\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:site\" content=\"@PingCAP\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"3\ubd84\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.pingcap.com\/article\/approximate-nearest-neighbor-ann-search-explained-ivf-vs-hnsw-vs-pq\/\",\"url\":\"https:\/\/www.pingcap.com\/article\/approximate-nearest-neighbor-ann-search-explained-ivf-vs-hnsw-vs-pq\/\",\"name\":\"Approximate Nearest Neighbor (ANN) Search Explained: IVF vs HNSW vs PQ | TiDB\",\"isPartOf\":{\"@id\":\"https:\/\/www.pingcap.com\/#website\"},\"datePublished\":\"2025-06-20T19:22:56+00:00\",\"dateModified\":\"2025-08-19T06:26:15+00:00\",\"description\":\"What Is Approximate Nearest Neighbor (ANN) Search? Approximate Nearest Neighbor (ANN) search has become essential for applications dealing with Discover how Approximate Nearest Neighbor (ANN) search enables fast, scalable AI applications. Learn the differences between IVF, HNSW, and PQ indexing\u2014and how TiDB integrates Faiss for high-performance vector search.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.pingcap.com\/article\/approximate-nearest-neighbor-ann-search-explained-ivf-vs-hnsw-vs-pq\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.pingcap.com\/article\/approximate-nearest-neighbor-ann-search-explained-ivf-vs-hnsw-vs-pq\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.pingcap.com\/article\/approximate-nearest-neighbor-ann-search-explained-ivf-vs-hnsw-vs-pq\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.pingcap.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Articles\",\"item\":\"https:\/\/www.pingcap.com\/article\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Approximate Nearest Neighbor (ANN) Search Explained: IVF vs HNSW vs PQ\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.pingcap.com\/#website\",\"url\":\"https:\/\/www.pingcap.com\/\",\"name\":\"TiDB\",\"description\":\"TiDB | SQL at Scale\",\"publisher\":{\"@id\":\"https:\/\/www.pingcap.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.pingcap.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"ko-KR\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.pingcap.com\/#organization\",\"name\":\"PingCAP\",\"url\":\"https:\/\/www.pingcap.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/www.pingcap.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/static.pingcap.com\/files\/2021\/11\/pingcap-logo.png\",\"contentUrl\":\"https:\/\/static.pingcap.com\/files\/2021\/11\/pingcap-logo.png\",\"width\":811,\"height\":232,\"caption\":\"PingCAP\"},\"image\":{\"@id\":\"https:\/\/www.pingcap.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/facebook.com\/pingcap2015\",\"https:\/\/x.com\/PingCAP\",\"https:\/\/linkedin.com\/company\/pingcap\",\"https:\/\/youtube.com\/channel\/UCuq4puT32DzHKT5rU1IZpIA\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Approximate Nearest Neighbor (ANN) Search Explained: IVF vs HNSW vs PQ | TiDB","description":"What Is Approximate Nearest Neighbor (ANN) Search? Approximate Nearest Neighbor (ANN) search has become essential for applications dealing with Discover how Approximate Nearest Neighbor (ANN) search enables fast, scalable AI applications. Learn the differences between IVF, HNSW, and PQ indexing\u2014and how TiDB integrates Faiss for high-performance vector search.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.pingcap.com\/ko\/article\/approximate-nearest-neighbor-ann-search-explained-ivf-vs-hnsw-vs-pq\/","og_locale":"ko_KR","og_type":"article","og_title":"Approximate Nearest Neighbor (ANN) Search Explained: IVF vs HNSW vs PQ | TiDB","og_description":"What Is Approximate Nearest Neighbor (ANN) Search? Approximate Nearest Neighbor (ANN) search has become essential for applications dealing with Discover how Approximate Nearest Neighbor (ANN) search enables fast, scalable AI applications. Learn the differences between IVF, HNSW, and PQ indexing\u2014and how TiDB integrates Faiss for high-performance vector search.","og_url":"https:\/\/www.pingcap.com\/ko\/article\/approximate-nearest-neighbor-ann-search-explained-ivf-vs-hnsw-vs-pq\/","og_site_name":"TiDB","article_publisher":"https:\/\/facebook.com\/pingcap2015","article_modified_time":"2025-08-19T06:26:15+00:00","og_image":[{"width":1440,"height":714,"url":"https:\/\/static.pingcap.com\/files\/2024\/09\/11005522\/Homepage-Ad.png","type":"image\/png"}],"twitter_card":"summary_large_image","twitter_site":"@PingCAP","twitter_misc":{"Est. reading time":"3\ubd84"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.pingcap.com\/article\/approximate-nearest-neighbor-ann-search-explained-ivf-vs-hnsw-vs-pq\/","url":"https:\/\/www.pingcap.com\/article\/approximate-nearest-neighbor-ann-search-explained-ivf-vs-hnsw-vs-pq\/","name":"Approximate Nearest Neighbor (ANN) Search Explained: IVF vs HNSW vs PQ | TiDB","isPartOf":{"@id":"https:\/\/www.pingcap.com\/#website"},"datePublished":"2025-06-20T19:22:56+00:00","dateModified":"2025-08-19T06:26:15+00:00","description":"What Is Approximate Nearest Neighbor (ANN) Search? Approximate Nearest Neighbor (ANN) search has become essential for applications dealing with Discover how Approximate Nearest Neighbor (ANN) search enables fast, scalable AI applications. Learn the differences between IVF, HNSW, and PQ indexing\u2014and how TiDB integrates Faiss for high-performance vector search.","breadcrumb":{"@id":"https:\/\/www.pingcap.com\/article\/approximate-nearest-neighbor-ann-search-explained-ivf-vs-hnsw-vs-pq\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pingcap.com\/article\/approximate-nearest-neighbor-ann-search-explained-ivf-vs-hnsw-vs-pq\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.pingcap.com\/article\/approximate-nearest-neighbor-ann-search-explained-ivf-vs-hnsw-vs-pq\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pingcap.com\/"},{"@type":"ListItem","position":2,"name":"Articles","item":"https:\/\/www.pingcap.com\/article\/"},{"@type":"ListItem","position":3,"name":"Approximate Nearest Neighbor (ANN) Search Explained: IVF vs HNSW vs PQ"}]},{"@type":"WebSite","@id":"https:\/\/www.pingcap.com\/#website","url":"https:\/\/www.pingcap.com\/","name":"\ud2f0DB","description":"TiDB | SQL at Scale","publisher":{"@id":"https:\/\/www.pingcap.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.pingcap.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"ko-KR"},{"@type":"Organization","@id":"https:\/\/www.pingcap.com\/#organization","name":"PingCAP","url":"https:\/\/www.pingcap.com\/","logo":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/www.pingcap.com\/#\/schema\/logo\/image\/","url":"https:\/\/static.pingcap.com\/files\/2021\/11\/pingcap-logo.png","contentUrl":"https:\/\/static.pingcap.com\/files\/2021\/11\/pingcap-logo.png","width":811,"height":232,"caption":"PingCAP"},"image":{"@id":"https:\/\/www.pingcap.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/facebook.com\/pingcap2015","https:\/\/x.com\/PingCAP","https:\/\/linkedin.com\/company\/pingcap","https:\/\/youtube.com\/channel\/UCuq4puT32DzHKT5rU1IZpIA"]}]}},"card_markup":"        <a class=\"card-article\" href=\"https:\/\/www.pingcap.com\/ko\/article\/approximate-nearest-neighbor-ann-search-explained-ivf-vs-hnsw-vs-pq\/\">            <h3>Approximate Nearest Neighbor (ANN) Search Explained: IVF vs HNSW vs PQ<\/h3>            <p>What Is Approximate Nearest Neighbor (ANN) Search? Approximate Nearest Neighbor (ANN) search has become essential for applications dealing with high-dimensional data\u2014think natural language processing, image recognition, and recommendation engines. For a deeper understanding of TiDB&#8217;s approach, visit our Vector Search Overview. Unlike exact methods, ANN strikes a practical balance between speed and accuracy, making it [&hellip;]<\/p>        <\/a>","_links":{"self":[{"href":"https:\/\/www.pingcap.com\/ko\/wp-json\/wp\/v2\/article\/27944","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pingcap.com\/ko\/wp-json\/wp\/v2\/article"}],"about":[{"href":"https:\/\/www.pingcap.com\/ko\/wp-json\/wp\/v2\/types\/article"}],"author":[{"embeddable":true,"href":"https:\/\/www.pingcap.com\/ko\/wp-json\/wp\/v2\/users\/305"}],"wp:attachment":[{"href":"https:\/\/www.pingcap.com\/ko\/wp-json\/wp\/v2\/media?parent=27944"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}