{"id":31882,"date":"2024-11-13T17:48:44","date_gmt":"2024-11-13T12:18:44","guid":{"rendered":"https:\/\/mobisoftinfotech.com\/resources\/?p=31882"},"modified":"2025-10-16T13:01:23","modified_gmt":"2025-10-16T07:31:23","slug":"enhancing-rag-generative-ai-postgresql-hnsw-indexes","status":"publish","type":"post","link":"https:\/\/mobisoftinfotech.com\/resources\/blog\/enhancing-rag-generative-ai-postgresql-hnsw-indexes","title":{"rendered":"Enhancing RAG-Based Generative AI Applications with HNSW Indexes in PostgreSQL"},"content":{"rendered":"<p>In the rapidly evolving landscape of Generative AI, Retrieval-Augmented Generation (RAG) models have emerged as powerful tools, combining the strengths of large language models with external knowledge bases. However, as the size of these knowledge bases grows, ensuring efficient and rapid retrieval becomes paramount. This is where Hierarchical Navigable Small World (HNSW) indexes come into play. In this blog post, we&#8217;ll explore how HNSW indexes can significantly improve the performance of RAG-based applications using PostgreSQL and PgVector, backed by a practical experiment involving a dataset with one million rows.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Understanding RAG and Its Performance Challenges<\/strong><\/h2>\n\n\n\n<p>Retrieval-Augmented Generation applications integrate large language models with external databases or knowledge bases. Instead of relying solely on the pre-trained knowledge embedded within the model, RAG models fetch relevant information from external sources in real time, enhancing the accuracy and relevance of generated responses.<\/p>\n\n\n\n<p>However, as the size of the knowledge base grows, <strong>retrieval latency<\/strong> can become a bottleneck. Efficiently searching through millions of embeddings to find the most relevant pieces of information requires optimized indexing and search algorithms.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/mobisoftinfotech.com\/services\/artificial-intelligence?utm_source=blog&amp;utm_medium=referral&amp;utm_campaign=enhancing-rag-generative-ai-postgresql-hnsw-indexes-cta1\"><noscript><img decoding=\"async\" width=\"855\" height=\"150\" src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2024\/11\/unlock-ai-optimization.png\" alt=\"Unlock the Power of AI Optimization\" class=\"wp-image-32147\" title=\"Optimize Your AI Applications Today\"><\/noscript><img decoding=\"async\" width=\"855\" height=\"150\" src=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20855%20150%22%3E%3C%2Fsvg%3E\" alt=\"Unlock the Power of AI Optimization\" class=\"wp-image-32147 lazyload\" title=\"Optimize Your AI Applications Today\" data-src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2024\/11\/unlock-ai-optimization.png\"><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Introducing HNSW Indexes<\/strong><\/h2>\n\n\n\n<p>Hierarchical Navigable Small World (HNSW indexes) is an advanced graph-based indexing method designed for approximate nearest neighbor searches. Unlike traditional indexing methods, HNSW indexes in PostgreSQL create a multi-layered graph structure that allows for rapid traversal and efficient similarity searches, making it particularly suited for high-dimensional data like embeddings used in RAG models.<\/p>\n\n\n\n<p>By leveraging HNSW indexes, databases like PostgreSQL\u2014enhanced with extensions like PgVector\u2014can perform similarity searches much faster, drastically reducing retrieval times in RAG applications.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><noscript><img decoding=\"async\" width=\"855\" height=\"363\" src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2024\/11\/hnsw-indexing-diagram.png\" alt=\"Illustration of Hierarchical Navigable Small World (HNSW) Indexing\" class=\"wp-image-32148\" title=\"HNSW Indexing for AI Search Optimization\"><\/noscript><img decoding=\"async\" width=\"855\" height=\"363\" src=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20855%20363%22%3E%3C%2Fsvg%3E\" alt=\"Illustration of Hierarchical Navigable Small World (HNSW) Indexing\" class=\"wp-image-32148 lazyload\" title=\"HNSW Indexing for AI Search Optimization\" data-src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2024\/11\/hnsw-indexing-diagram.png\"><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Setting Up the Experiment<\/strong><\/h2>\n\n\n\n<p>To quantify the performance improvements brought by HNSW indexes, we conducted an experiment using PostgreSQL and PgVector on a substantial dataset. Here&#8217;s a detailed walkthrough of the process.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Dataset Overview<\/strong><\/h3>\n\n\n\n<p>We utilized the test.csv file from the <strong>MeDAL Dataset<\/strong>, which comprises <strong>1 million rows<\/strong>. The MeDAL (Medical Abbreviation Disambiguation) Dataset is a large-scale medical text dataset specifically curated for the task of abbreviation disambiguation in the medical domain. Each row contains textual content that we aim to embed and store in the PostgreSQL database for retrieval.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Creating the PostgreSQL Table<\/strong><\/h3>\n\n\n\n<p>First, we need to set up a PostgreSQL table optimized for storing embeddings. Using PgVector, a PostgreSQL extension for vector similarity searches in RAG Generative AI optimization, we define a table structure that accommodates our data.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">CREATE TABLE file_embeddings (\n    id SERIAL PRIMARY KEY,\n    embeddings vector(<span class=\"hljs-number\">384<\/span>),\n    content TEXT NOT <span class=\"hljs-keyword\">NULL<\/span>\n);\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><strong>Explanation:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>id<\/strong>: A unique identifier for each row, auto-incremented.<\/li>\n\n\n\n<li><strong>embeddings<\/strong>: A vector column with 384 dimensions to store the generated embeddings.<\/li>\n\n\n\n<li><strong>content<\/strong>: The textual content from which embeddings are derived.<\/li>\n<\/ul>\n\n\n\n<p>This structure ensures efficient storage and retrieval of both the textual data and their corresponding embeddings.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Generating Embeddings<\/strong><\/h2>\n\n\n\n<p>To generate embeddings for the textual content, we employed the &#8220;all-MiniLM-L12-v2&#8221; model from the <strong>SentenceTransformer<\/strong> Python package.<\/p>\n\n\n\n<p><strong>Note:<\/strong> Generating embeddings is a <strong>time-intensive<\/strong> task. On a MacBook Air M2 with 24GB RAM, it took approximately <strong>12 hours<\/strong> to insert all the rows. While a multi-threaded approach could have expedited this process, the experiment was allowed to run overnight.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Analyzing PostgreSQL Table Size<\/strong><\/h2>\n\n\n\n<p>Understanding the storage footprint of our data is crucial for performance tuning. We conducted several queries to ascertain the size of the table and its individual columns.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Total Number of Rows<\/strong><\/h3>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">SELECT COUNT(*) FROM file_embeddings;<\/code><\/span><\/pre>\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td><strong>count<\/strong><\/td><\/tr><tr><td>1000000<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Total Table Size<\/strong><\/h3>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">SELECT pg_size_pretty(pg_relation_size(<span class=\"hljs-string\">'file_embeddings'<\/span>)) <span class=\"hljs-keyword\">AS<\/span> data_size;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td><strong>data_size<\/strong><\/td><\/tr><tr><td>1064 MB<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><strong>Insight:<\/strong> The entire table occupies approximately <strong>1.064 GB<\/strong>, which is manageable but sets the stage for optimization.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Size Breakdown by Column<\/strong><\/h3>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">SELECT\n    pg_size_pretty(SUM(pg_column_size(id))) <span class=\"hljs-keyword\">AS<\/span> total_id_size,\n    pg_size_pretty(SUM(pg_column_size(embeddings))) <span class=\"hljs-keyword\">AS<\/span> total_embeddings_size,\n    pg_size_pretty(SUM(pg_column_size(content))) <span class=\"hljs-keyword\">AS<\/span> total_content_size\nFROM\n    file_embeddings;\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td><strong>total_id_size<\/strong><\/td><td><strong>total_embeddings_size<\/strong><\/td><td><strong>total_content_size<\/strong><\/td><\/tr><tr><td>3906 kB<\/td><td>1469 MB<\/td><td>811 MB<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><strong>Interpretation:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>id<\/strong>: Approximately 3.906 MB<\/li>\n\n\n\n<li><strong>embeddings<\/strong>: Approximately 1.469 GB<\/li>\n\n\n\n<li><strong>content<\/strong>: Approximately 811 MB<\/li>\n<\/ul>\n\n\n\n<p>The embeddings column is the most storage-intensive, underscoring the importance of optimizing its retrieval.<\/p>\n\n\n\n<p><strong>Note on Table Size vs. Column Sizes:<\/strong><\/p>\n\n\n\n<p>You might notice that the <strong>Total Table Size<\/strong> (pg_relation_size) reported as <strong>1.064 GB<\/strong> is <strong>less<\/strong> than the sum of the individual column sizes (<strong>~2.3 GB<\/strong>). This discrepancy is due to PostgreSQL&#8217;s <strong>TOAST (The Oversized-Attribute Storage Technique)<\/strong> mechanism.<\/p>\n\n\n\n<p><strong>What is TOAST?<\/strong><\/p>\n\n\n\n<p>TOAST is PostgreSQL&#8217;s method for handling large data fields that exceed a certain size threshold. Instead of storing all the data directly within the main table, TOAST compresses and moves large column values (like our embeddings and content columns) into a separate storage area called a TOAST table. This not only optimizes storage by compressing data but also ensures that the main table remains efficient for operations that don&#8217;t require accessing the large columns.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Performance Before Indexing<\/strong><\/h2>\n\n\n\n<p>To establish a performance baseline, we executed a set of basic similarity search queries <strong>without any indexing<\/strong>. These queries simulate the typical retrieval operations in a RAG-based application.<\/p>\n\n\n\n<p><strong>Sample Queries and Results:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><noscript><img decoding=\"async\" width=\"855\" height=\"576\" src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2024\/11\/rag-ai-query-results-before.png\" alt=\"Sample queries and results before implementing HNSW indexing\" class=\"wp-image-32149\" title=\"RAG AI Query Performance Before Optimization\"><\/noscript><img decoding=\"async\" width=\"855\" height=\"576\" src=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20855%20576%22%3E%3C%2Fsvg%3E\" alt=\"Sample queries and results before implementing HNSW indexing\" class=\"wp-image-32149 lazyload\" title=\"RAG AI Query Performance Before Optimization\" data-src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2024\/11\/rag-ai-query-results-before.png\"><\/figure>\n\n\n\n<p>Summary:<\/p>\n\n\n\n<p>Total database query time: 18.3047 seconds<\/p>\n\n\n\n<p>Average query time: 3.6609 seconds<\/p>\n\n\n\n<p><strong>Analysis:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Total Query Time:<\/strong> Approximately <strong>18.3 seconds<\/strong> for five queries.<\/li>\n\n\n\n<li><strong>Average Query Time:<\/strong> Around <strong>3.66 seconds<\/strong> per query.<\/li>\n<\/ul>\n\n\n\n<p>These results highlight the need for optimization, especially when scaling up to more extensive datasets or higher query frequencies in production environments.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Implementing HNSW Indexes<\/strong><\/h2>\n\n\n\n<p>To enhance query performance, we introduced an <strong>HNSW index<\/strong> on the embeddings column. This index facilitates rapid approximate nearest neighbor searches, significantly reducing retrieval times.<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">CREATE INDEX ON file_embeddings USING hnsw (embeddings vector_cosine_ops);<\/code><\/span><\/pre>\n\n\n<p><strong>Details:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Index Type:<\/strong> HNSW (Hierarchical Navigable Small World)<\/li>\n\n\n\n<li><strong>Operator Class:<\/strong> vector_cosine_ops specifies the use of cosine similarity for vector operations.<\/li>\n<\/ul>\n\n\n\n<p><strong>Time Taken:<\/strong> Building the HNSW index on 1 million rows took approximately <strong>33 minutes<\/strong>. While this is a considerable upfront cost, the trade-off is justified by the substantial performance gains during query operations.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Performance After Indexing<\/strong><\/h2>\n\n\n\n<p>Post-indexing, we reran the same set of similarity search queries to assess the improvements.<\/p>\n\n\n\n<p><strong>Optimized Queries and Results:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><noscript><img decoding=\"async\" width=\"855\" height=\"577\" src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2024\/11\/rag-ai-query-results-after.png\" alt=\"Optimized queries and results after HNSW indexing implementation\" class=\"wp-image-32150\" title=\"Query Performance After HNSW Indexing Optimization\"><\/noscript><img decoding=\"async\" width=\"855\" height=\"577\" src=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20855%20577%22%3E%3C%2Fsvg%3E\" alt=\"Optimized queries and results after HNSW indexing implementation\" class=\"wp-image-32150 lazyload\" title=\"Query Performance After HNSW Indexing Optimization\" data-src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2024\/11\/rag-ai-query-results-after.png\"><\/figure>\n\n\n\n<p>Summary:<\/p>\n\n\n\n<p>Total database query time: 0.6205 seconds<\/p>\n\n\n\n<p>Average query time: 0.1241 seconds<\/p>\n\n\n\n<p><strong>Comparison:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td><strong>Metric<\/strong><\/td><td><strong>Before Indexing<\/strong><\/td><td><strong>After Indexing<\/strong><\/td><\/tr><tr><td>Total Query Time<\/td><td>18.3047 seconds<\/td><td>0.6205 seconds<\/td><\/tr><tr><td>Average Query Time<\/td><td>3.6609 seconds<\/td><td>0.1241 seconds<\/td><\/tr><tr><td>Improvement Factor<\/td><td>&#8211;<\/td><td>~30x faster<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><strong>Key Observations:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Total Query Time<\/strong> decreased from <strong>18.3 seconds<\/strong> to <strong>0.62 seconds<\/strong>.<\/li>\n\n\n\n<li><strong>Average Query Time<\/strong> per query dropped from <strong>3.66 seconds<\/strong> to <strong>0.124 seconds<\/strong>.<\/li>\n\n\n\n<li>This represents an approximate <strong>30-fold improvement<\/strong> in query performance.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Conclusion<\/strong><\/h2>\n\n\n\n<p>The experiment clearly demonstrates the transformative impact of HNSW indexes on RAG-based generative AI applications. By integrating HNSW indexes within PostgreSQL using PgVector, we achieved a <strong>dramatic reduction in similarity search times<\/strong>, from several seconds per query to mere milliseconds. This enhancement not only accelerates real-time data retrieval but also scales seamlessly with growing datasets, ensuring that RAG models remain responsive and efficient even as the underlying knowledge bases expand.<\/p>\n\n\n\n<p>For developers and data scientists working with large-scale generative AI systems, implementing HNSW indexes offers a straightforward yet highly effective strategy to optimize performance. As the demand for real-time, accurate, and scalable AI-driven applications continues to surge, leveraging advanced indexing techniques like HNSW will be pivotal in meeting these challenges head-on.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/mobisoftinfotech.com\/contact-us?utm_source=blog&amp;utm_medium=referral&amp;utm_campaign=enhancing-rag-generative-ai-postgresql-hnsw-indexes-cta2\"><noscript><img decoding=\"async\" width=\"855\" height=\"150\" src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2024\/11\/scale-business-ai.png\" alt=\"Scale Your Business with Advanced AI\" class=\"wp-image-32151\" title=\"Scale Your AI Applications with HNSW\"><\/noscript><img decoding=\"async\" width=\"855\" height=\"150\" src=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20855%20150%22%3E%3C%2Fsvg%3E\" alt=\"Scale Your Business with Advanced AI\" class=\"wp-image-32151 lazyload\" title=\"Scale Your AI Applications with HNSW\" data-src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2024\/11\/scale-business-ai.png\"><\/a><\/figure>\n\n\n<div class=\"related-posts-section\"><h2>Related Posts<\/h2><ul class=\"related-posts-list\"><li><a href=\"https:\/\/mobisoftinfotech.com\/resources\/blog\/all-about-on-demand-economy-and-the-industries-being-disrupted-by-it\">All about On-demand Economy and the Industries Being Disrupted by It<\/a><\/li><li><a href=\"https:\/\/mobisoftinfotech.com\/resources\/blog\/aws-site-to-site-vpn-fortigate-firewall-setup\">AWS Site-to-Site VPN Setup with FortiGate Firewall: A Complete Guide<\/a><\/li><li><a href=\"https:\/\/mobisoftinfotech.com\/resources\/blog\/how-to-build-an-app-like-uber\">Roadmap to Build an App Like Uber &#8211; Features, Technology, Cost?<\/a><\/li><li><a href=\"https:\/\/mobisoftinfotech.com\/resources\/blog\/need-mobile-app-automation-testing\">Need of Mobile App Automation Testing<\/a><\/li><li><a href=\"https:\/\/mobisoftinfotech.com\/resources\/blog\/ai-in-healthcare\">AI in Healthcare and Its Impact in 2022<\/a><\/li><li><a href=\"https:\/\/mobisoftinfotech.com\/resources\/blog\/patient-portal-development-in-2023\">Patient Portal Development: What to Know for Your Healthcare Business in 2023?<\/a><\/li><\/ul><\/div>\n\n\n<div class=\"modern-author-card\">\n    <div class=\"author-card-content\">\n        <div class=\"author-info-section\">\n            <div class=\"author-avatar\">\n                <noscript><img decoding=\"async\" src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2022\/04\/Pritam1.jpg\" alt=\"Pritam Barhate\"><\/noscript><img decoding=\"async\" src=\"data:image\/gif;base64,R0lGODlhAQABAIAAAAAAAP\/\/\/yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\" alt=\"Pritam Barhate\" data-src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2022\/04\/Pritam1.jpg\" class=\" lazyload\">\n            <\/div>\n            <div class=\"author-details\">\n                <h3 class=\"author-name\">Pritam Barhate<\/h3>\n                <p class=\"author-title\">Head of Technology Innovation<\/p>\n                <a href=\"javascript:void(0);\" class=\"read-more-link read-more-btn\" onclick=\"toggleAuthorBio(this); return false;\">Read more <noscript><img decoding=\"async\" src=\"\/assets\/images\/blog\/Vector.png\" alt=\"expand\" class=\"read-more-arrow down-arrow\"><\/noscript><img decoding=\"async\" src=\"data:image\/gif;base64,R0lGODlhAQABAIAAAAAAAP\/\/\/yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\" alt=\"expand\" class=\"read-more-arrow down-arrow lazyload\" data-src=\"\/assets\/images\/blog\/Vector.png\"><\/a>\n                <div class=\"author-bio-expanded\">\n                    <p>Pritam Barhate, with an experience of 14+ years in technology, heads Technology Innovation at <a href=\"https:\/\/mobisoftinfotech.com\" target=\"_blank\" rel=\"noopener\">Mobisoft Infotech<\/a>. He has a rich experience in design and development. He has been a consultant for a variety of industries and startups. At Mobisoft Infotech, he primarily focuses on technology resources and develops the most advanced solutions.<\/p>\n                    <div class=\"author-social-links\">\n                        <div class=\"social-icon\">\n                            <a href=\"https:\/\/www.linkedin.com\/in\/pritam-barhate-90b93414\/\" target=\"_blank\" rel=\"nofollow noopener\"><i class=\"icon-sprite linkedin\"><\/i><\/a>\n                            <a href=\"https:\/\/twitter.com\/pritambarhate\" target=\"_blank\" rel=\"nofollow noopener\"><i class=\"icon-sprite twitter\"><\/i><\/a>\n                        <\/div>\n                    <\/div>\n                    <a href=\"javascript:void(0);\" class=\"read-more-link read-less-btn\" onclick=\"toggleAuthorBio(this); return false;\" style=\"display: none;\">Read less <noscript><img decoding=\"async\" src=\"\/assets\/images\/blog\/Vector.png\" alt=\"collapse\" class=\"read-more-arrow up-arrow\"><\/noscript><img decoding=\"async\" src=\"data:image\/gif;base64,R0lGODlhAQABAIAAAAAAAP\/\/\/yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\" alt=\"collapse\" class=\"read-more-arrow up-arrow lazyload\" data-src=\"\/assets\/images\/blog\/Vector.png\"><\/a>\n                <\/div>\n            <\/div>\n        <\/div>\n        <div class=\"share-section\">\n            <span class=\"share-label\">Share Article<\/span>\n            <div class=\"social-share-buttons\">\n                <a href=\"https:\/\/www.facebook.com\/sharer\/sharer.php?u=https%3A%2F%2Fmobisoftinfotech.com%2Fresources%2Fblog%2Fenhancing-rag-generative-ai-postgresql-hnsw-indexes\" target=\"_blank\" class=\"share-btn facebook-share\"><i class=\"fa fa-facebook-f\"><\/i><\/a>\n                <a href=\"https:\/\/www.linkedin.com\/sharing\/share-offsite\/?url=https%3A%2F%2Fmobisoftinfotech.com%2Fresources%2Fblog%2Fenhancing-rag-generative-ai-postgresql-hnsw-indexes\" target=\"_blank\" class=\"share-btn linkedin-share\"><i class=\"fa fa-linkedin\"><\/i><\/a>\n            <\/div>\n        <\/div>\n    <\/div>\n<\/div>\n\n\n\n<script type=\"application\/ld+json\">\n{\n  \"@context\": \"https:\/\/schema.org\",\n  \"@type\": \"Article\",\n  \"mainEntityOfPage\": {\n    \"@type\": \"WebPage\",\n    \"@id\": \"https:\/\/mobisoftinfotech.com\/resources\/blog\/enhancing-rag-generative-ai-postgresql-hnsw-indexes\"\n  },\n  \"headline\": \"Enhancing RAG-Based Generative AI Applications with HNSW Indexes in PostgreSQL\",\n  \"description\": \"Learn how HNSW indexes in PostgreSQL improve RAG-based generative AI performance, optimizing similarity searches and speeding up retrieval in large datasets.\",\n  \"image\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2024\/11\/rag-hnsw-indexes-postgresql.png\",\n  \"author\": {\n    \"@type\": \"Person\",\n    \"name\": \"Pritam Barhate\",\n    \"description\": \"Pritam Barhate, with an experience of 14+ years in technology, heads Technology Innovation at Mobisoft Infotech. He has a rich experience in design and development. He has been a consultant for a variety of industries and startups. At Mobisoft Infotech, he primarily focuses on technology resources and develops the most advanced solutions.\"\n  },\n  \"publisher\": {\n    \"@type\": \"Organization\",\n    \"name\": \"Mobisoft Infotech\",\n    \"logo\": {\n      \"@type\": \"ImageObject\",\n      \"url\": \"https:\/\/mobisoftinfotech.com\/assets\/images\/mshomepage\/MI_Logo-white.svg\",\n      \"width\": 600,\n      \"height\": 60\n    }\n  },\n  \"datePublished\": \"2024-11-12\",\n  \"dateModified\": \"2024-11-12\"\n}\n<\/script>\n<script type=\"application\/ld+json\">\n{\n  \"@context\": \"https:\/\/schema.org\",\n  \"@type\": \"Organization\",\n  \"name\": \"Mobisoft Infotech\",\n  \"url\": \"https:\/\/mobisoftinfotech.com\/\",\n  \"logo\": \"https:\/\/mobisoftinfotech.com\/assets\/images\/MI_Logo.svg\",\n  \"sameAs\": [\n    \"https:\/\/www.facebook.com\/pages\/Mobisoft-Infotech\/131035500270720\",\n    \"https:\/\/twitter.com\/MobisoftInfo\",\n    \"https:\/\/www.instagram.com\/mobisoftinfotech\/\",\n    \"https:\/\/www.youtube.com\/channel\/UCtwuTXKUXFX7k0NSYhsMeTg\",\n    \"https:\/\/www.linkedin.com\/company\/mobisoft-infotech\",\n    \"https:\/\/in.pinterest.com\/mobisoftinfotech\/\",\n    \"https:\/\/github.com\/MobisoftInfotech\"\n  ],\n  \"contactPoint\": [\n    {\n      \"@type\": \"ContactPoint\",\n      \"telephone\": \"+1-855-572-2777\",\n      \"contactType\": \"Customer Service\",\n      \"areaServed\": \"US\",\n      \"availableLanguage\": [\"English\"]\n    },\n    {\n      \"@type\": \"ContactPoint\",\n      \"telephone\": \"+91-858-600-8627\",\n      \"contactType\": \"Customer Service\",\n      \"areaServed\": \"IN\",\n      \"availableLanguage\": [\"English\"]\n    }\n  ]\n}\n<\/script>\n<script type=\"application\/ld+json\">\n[\n  {\n    \"@context\": \"https:\/\/schema.org\",\n    \"@type\": \"ImageObject\",\n    \"contentUrl\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2024\/11\/rag-hnsw-indexes-postgresql.png\",\n    \"url\": \"https:\/\/mobisoftinfotech.com\/resources\/blog\/enhancing-rag-generative-ai-postgresql-hnsw-indexes\",\n    \"name\": \"Enhancing RAG-Based Generative AI Applications with HNSW Indexes in PostgreSQL\",\n    \"caption\": \"Enhancing AI applications with HNSW indexing in PostgreSQL\",\n    \"description\": \"Visual representation of how HNSW indexing improves the performance of RAG-based generative AI applications in PostgreSQL databases.\",\n    \"license\": \"https:\/\/mobisoftinfotech.com\/resources\/blog\/enhancing-rag-generative-ai-postgresql-hnsw-indexes\",\n    \"acquireLicensePage\": \"https:\/\/mobisoftinfotech.com\/resources\/blog\/enhancing-rag-generative-ai-postgresql-hnsw-indexes\",\n    \"creditText\": \"Mobisoft Infotech\",\n    \"copyrightNotice\": \"Mobisoft Infotech\",\n    \"creator\": {\n      \"@type\": \"Organization\",\n      \"name\": \"Mobisoft Infotech\"\n    },\n    \"thumbnail\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2024\/11\/rag-hnsw-indexes-postgresql.png\"\n  },\n  {\n    \"@context\": \"https:\/\/schema.org\",\n    \"@type\": \"ImageObject\",\n    \"contentUrl\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2024\/11\/unlock-ai-optimization.png\",\n    \"url\": \"https:\/\/mobisoftinfotech.com\/resources\/blog\/enhancing-rag-generative-ai-postgresql-hnsw-indexes\",\n    \"name\": \"Unlock the Power of AI Optimization\",\n    \"caption\": \"Unlock advanced optimization techniques for generative AI applications.\",\n    \"description\": \"Discover how AI optimization strategies can boost your RAG-based generative AI models with advanced indexing techniques like HNSW.\",\n    \"license\": \"https:\/\/mobisoftinfotech.com\/resources\/blog\/enhancing-rag-generative-ai-postgresql-hnsw-indexes\",\n    \"acquireLicensePage\": \"https:\/\/mobisoftinfotech.com\/resources\/blog\/enhancing-rag-generative-ai-postgresql-hnsw-indexes\",\n    \"creditText\": \"Mobisoft Infotech\",\n    \"copyrightNotice\": \"Mobisoft Infotech\",\n    \"creator\": {\n      \"@type\": \"Organization\",\n      \"name\": \"Mobisoft Infotech\"\n    },\n    \"thumbnail\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2024\/11\/unlock-ai-optimization.png\"\n  },\n  {\n    \"@context\": \"https:\/\/schema.org\",\n    \"@type\": \"ImageObject\",\n    \"contentUrl\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2024\/11\/hnsw-indexing-diagram.png\",\n    \"url\": \"https:\/\/mobisoftinfotech.com\/resources\/blog\/enhancing-rag-generative-ai-postgresql-hnsw-indexes\",\n    \"name\": \"Illustration of Hierarchical Navigable Small World (HNSW) Indexing\",\n    \"caption\": \"Visual guide to HNSW indexing method in PostgreSQL\",\n    \"description\": \"A diagram showing how HNSW indexing works for fast nearest neighbor search in high-dimensional data.\",\n    \"license\": \"https:\/\/mobisoftinfotech.com\/resources\/blog\/enhancing-rag-generative-ai-postgresql-hnsw-indexes\",\n    \"acquireLicensePage\": \"https:\/\/mobisoftinfotech.com\/resources\/blog\/enhancing-rag-generative-ai-postgresql-hnsw-indexes\",\n    \"creditText\": \"Mobisoft Infotech\",\n    \"copyrightNotice\": \"Mobisoft Infotech\",\n    \"creator\": {\n      \"@type\": \"Organization\",\n      \"name\": \"Mobisoft Infotech\"\n    },\n    \"thumbnail\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2024\/11\/hnsw-indexing-diagram.png\"\n  },\n  {\n    \"@context\": \"https:\/\/schema.org\",\n    \"@type\": \"ImageObject\",\n    \"contentUrl\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2024\/11\/rag-ai-query-results-before.png\",\n    \"url\": \"https:\/\/mobisoftinfotech.com\/resources\/blog\/enhancing-rag-generative-ai-postgresql-hnsw-indexes\",\n    \"name\": \"Sample queries and results before implementing HNSW indexing\",\n    \"caption\": \"Sample queries and results before HNSW indexing optimization\",\n    \"description\": \"Performance metrics for similarity queries before implementing HNSW indexing in the PostgreSQL database.\",\n    \"license\": \"https:\/\/mobisoftinfotech.com\/resources\/blog\/enhancing-rag-generative-ai-postgresql-hnsw-indexes\",\n    \"acquireLicensePage\": \"https:\/\/mobisoftinfotech.com\/resources\/blog\/enhancing-rag-generative-ai-postgresql-hnsw-indexes\",\n    \"creditText\": \"Mobisoft Infotech\",\n    \"copyrightNotice\": \"Mobisoft Infotech\",\n    \"creator\": {\n      \"@type\": \"Organization\",\n      \"name\": \"Mobisoft Infotech\"\n    },\n    \"thumbnail\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2024\/11\/rag-ai-query-results-before.png\"\n  },\n  {\n    \"@context\": \"https:\/\/schema.org\",\n    \"@type\": \"ImageObject\",\n    \"contentUrl\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2024\/11\/rag-ai-query-results-after.png\",\n    \"url\": \"https:\/\/mobisoftinfotech.com\/resources\/blog\/enhancing-rag-generative-ai-postgresql-hnsw-indexes\",\n    \"name\": \"Optimized queries and results after HNSW indexing implementation\",\n    \"caption\": \"Improvement in query time after implementing HNSW indexing\",\n    \"description\": \"Performance improvements with HNSW indexing in PostgreSQL for RAG-based generative AI applications.\",\n    \"license\": \"https:\/\/mobisoftinfotech.com\/resources\/blog\/enhancing-rag-generative-ai-postgresql-hnsw-indexes\",\n    \"acquireLicensePage\": \"https:\/\/mobisoftinfotech.com\/resources\/blog\/enhancing-rag-generative-ai-postgresql-hnsw-indexes\",\n    \"creditText\": \"Mobisoft Infotech\",\n    \"copyrightNotice\": \"Mobisoft Infotech\",\n    \"creator\": {\n      \"@type\": \"Organization\",\n      \"name\": \"Mobisoft Infotech\"\n    },\n    \"thumbnail\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2024\/11\/rag-ai-query-results-after.png\"\n  },\n  {\n    \"@context\": \"https:\/\/schema.org\",\n    \"@type\": \"ImageObject\",\n    \"contentUrl\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2024\/11\/scale-business-ai.png\",\n    \"url\": \"https:\/\/mobisoftinfotech.com\/resources\/blog\/enhancing-rag-generative-ai-postgresql-hnsw-indexes\",\n    \"name\": \"Scale Your Business with Advanced AI\",\n    \"caption\": \"Ready to unlock advanced AI capabilities for your business?\",\n    \"description\": \"Leverage cutting-edge technologies like HNSW indexing to scale your generative AI applications and enhance performance.\",\n    \"license\": \"https:\/\/mobisoftinfotech.com\/resources\/blog\/enhancing-rag-generative-ai-postgresql-hnsw-indexes\",\n    \"acquireLicensePage\": \"https:\/\/mobisoftinfotech.com\/resources\/blog\/enhancing-rag-generative-ai-postgresql-hnsw-indexes\",\n    \"creditText\": \"Mobisoft Infotech\",\n    \"copyrightNotice\": \"Mobisoft Infotech\",\n    \"creator\": {\n      \"@type\": \"Organization\",\n      \"name\": \"Mobisoft Infotech\"\n    },\n    \"thumbnail\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2024\/11\/scale-business-ai.png\"\n  }\n]\n<\/script>\n","protected":false},"excerpt":{"rendered":"<p>In the rapidly evolving landscape of Generative AI, Retrieval-Augmented Generation (RAG) models have emerged as powerful tools, combining the strengths of large language models with external knowledge bases. However, as the size of these knowledge bases grows, ensuring efficient and rapid retrieval becomes paramount. This is where Hierarchical Navigable Small World (HNSW) indexes come into [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":32146,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_s2mail":"","footnotes":""},"categories":[286],"tags":[4312,4316,4315,4314,4313],"class_list":["post-31882","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog","tag-hnsw-indexes-in-postgresql","tag-pgvector-for-rag-models","tag-postgresql-for-ai","tag-rag-generative-ai-optimization","tag-retrieval-augmented-generation-applications"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Enhancing RAG AI with HNSW Indexes in PostgreSQL for Speed<\/title>\n<meta name=\"description\" content=\"Learn how HNSW indexes in PostgreSQL improve RAG-based generative AI performance, optimizing similarity searches and speeding up retrieval in large datasets.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/mobisoftinfotech.com\/resources\/blog\/enhancing-rag-generative-ai-postgresql-hnsw-indexes\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Enhancing RAG AI with HNSW Indexes in PostgreSQL for Speed\" \/>\n<meta property=\"og:description\" content=\"Learn how HNSW indexes in PostgreSQL improve RAG-based generative AI performance, optimizing similarity searches and speeding up retrieval in large datasets.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/mobisoftinfotech.com\/resources\/blog\/enhancing-rag-generative-ai-postgresql-hnsw-indexes\" \/>\n<meta property=\"og:site_name\" content=\"Mobisoft Infotech\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-13T12:18:44+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-10-16T07:31:23+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2024\/11\/og-Enhancing-RAG-Based-Generative-AI-Applications-with-HNSW-Indexes-in-PostgreSQL.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1000\" \/>\n\t<meta property=\"og:image:height\" content=\"525\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Pritam Barhate\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Pritam Barhate\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/blog\/enhancing-rag-generative-ai-postgresql-hnsw-indexes#article\",\"isPartOf\":{\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/blog\/enhancing-rag-generative-ai-postgresql-hnsw-indexes\"},\"author\":{\"name\":\"Pritam Barhate\",\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/#\/schema\/person\/fa762036b3364f26abeea146c01487ee\"},\"headline\":\"Enhancing RAG-Based Generative AI Applications with HNSW Indexes in PostgreSQL\",\"datePublished\":\"2024-11-13T12:18:44+00:00\",\"dateModified\":\"2025-10-16T07:31:23+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/blog\/enhancing-rag-generative-ai-postgresql-hnsw-indexes\"},\"wordCount\":1094,\"image\":{\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/blog\/enhancing-rag-generative-ai-postgresql-hnsw-indexes#primaryimage\"},\"thumbnailUrl\":\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2024\/11\/rag-hnsw-indexes-postgresql.png\",\"keywords\":[\"HNSW indexes in PostgreSQL\",\"PgVector for RAG models\",\"PostgreSQL for AI\",\"RAG Generative AI optimization\",\"Retrieval-Augmented Generation applications\"],\"articleSection\":[\"Blog\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/blog\/enhancing-rag-generative-ai-postgresql-hnsw-indexes\",\"url\":\"https:\/\/mobisoftinfotech.com\/resources\/blog\/enhancing-rag-generative-ai-postgresql-hnsw-indexes\",\"name\":\"Enhancing RAG AI with HNSW Indexes in PostgreSQL for Speed\",\"isPartOf\":{\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/blog\/enhancing-rag-generative-ai-postgresql-hnsw-indexes#primaryimage\"},\"image\":{\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/blog\/enhancing-rag-generative-ai-postgresql-hnsw-indexes#primaryimage\"},\"thumbnailUrl\":\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2024\/11\/rag-hnsw-indexes-postgresql.png\",\"datePublished\":\"2024-11-13T12:18:44+00:00\",\"dateModified\":\"2025-10-16T07:31:23+00:00\",\"author\":{\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/#\/schema\/person\/fa762036b3364f26abeea146c01487ee\"},\"description\":\"Learn how HNSW indexes in PostgreSQL improve RAG-based generative AI performance, optimizing similarity searches and speeding up retrieval in large datasets.\",\"breadcrumb\":{\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/blog\/enhancing-rag-generative-ai-postgresql-hnsw-indexes#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/mobisoftinfotech.com\/resources\/blog\/enhancing-rag-generative-ai-postgresql-hnsw-indexes\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/blog\/enhancing-rag-generative-ai-postgresql-hnsw-indexes#primaryimage\",\"url\":\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2024\/11\/rag-hnsw-indexes-postgresql.png\",\"contentUrl\":\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2024\/11\/rag-hnsw-indexes-postgresql.png\",\"width\":855,\"height\":392,\"caption\":\"Enhancing RAG-Based Generative AI Applications with HNSW Indexes in PostgreSQL\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/blog\/enhancing-rag-generative-ai-postgresql-hnsw-indexes#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/mobisoftinfotech.com\/resources\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Enhancing RAG-Based Generative AI Applications with HNSW Indexes in PostgreSQL\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/#website\",\"url\":\"https:\/\/mobisoftinfotech.com\/resources\/\",\"name\":\"Mobisoft Infotech\",\"description\":\"Discover Mobility\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/mobisoftinfotech.com\/resources\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/#\/schema\/person\/fa762036b3364f26abeea146c01487ee\",\"name\":\"Pritam Barhate\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/secure.gravatar.com\/avatar\/0e481c7ce54b3567ac70ddfc493523eefce0bdc3ee69fd2654f8f60a79e2f178?s=96&r=g\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/0e481c7ce54b3567ac70ddfc493523eefce0bdc3ee69fd2654f8f60a79e2f178?s=96&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/0e481c7ce54b3567ac70ddfc493523eefce0bdc3ee69fd2654f8f60a79e2f178?s=96&r=g\",\"caption\":\"Pritam Barhate\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Enhancing RAG AI with HNSW Indexes in PostgreSQL for Speed","description":"Learn how HNSW indexes in PostgreSQL improve RAG-based generative AI performance, optimizing similarity searches and speeding up retrieval in large datasets.","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:\/\/mobisoftinfotech.com\/resources\/blog\/enhancing-rag-generative-ai-postgresql-hnsw-indexes","og_locale":"en_US","og_type":"article","og_title":"Enhancing RAG AI with HNSW Indexes in PostgreSQL for Speed","og_description":"Learn how HNSW indexes in PostgreSQL improve RAG-based generative AI performance, optimizing similarity searches and speeding up retrieval in large datasets.","og_url":"https:\/\/mobisoftinfotech.com\/resources\/blog\/enhancing-rag-generative-ai-postgresql-hnsw-indexes","og_site_name":"Mobisoft Infotech","article_published_time":"2024-11-13T12:18:44+00:00","article_modified_time":"2025-10-16T07:31:23+00:00","og_image":[{"width":1000,"height":525,"url":"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2024\/11\/og-Enhancing-RAG-Based-Generative-AI-Applications-with-HNSW-Indexes-in-PostgreSQL.png","type":"image\/png"}],"author":"Pritam Barhate","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Pritam Barhate","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/mobisoftinfotech.com\/resources\/blog\/enhancing-rag-generative-ai-postgresql-hnsw-indexes#article","isPartOf":{"@id":"https:\/\/mobisoftinfotech.com\/resources\/blog\/enhancing-rag-generative-ai-postgresql-hnsw-indexes"},"author":{"name":"Pritam Barhate","@id":"https:\/\/mobisoftinfotech.com\/resources\/#\/schema\/person\/fa762036b3364f26abeea146c01487ee"},"headline":"Enhancing RAG-Based Generative AI Applications with HNSW Indexes in PostgreSQL","datePublished":"2024-11-13T12:18:44+00:00","dateModified":"2025-10-16T07:31:23+00:00","mainEntityOfPage":{"@id":"https:\/\/mobisoftinfotech.com\/resources\/blog\/enhancing-rag-generative-ai-postgresql-hnsw-indexes"},"wordCount":1094,"image":{"@id":"https:\/\/mobisoftinfotech.com\/resources\/blog\/enhancing-rag-generative-ai-postgresql-hnsw-indexes#primaryimage"},"thumbnailUrl":"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2024\/11\/rag-hnsw-indexes-postgresql.png","keywords":["HNSW indexes in PostgreSQL","PgVector for RAG models","PostgreSQL for AI","RAG Generative AI optimization","Retrieval-Augmented Generation applications"],"articleSection":["Blog"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/mobisoftinfotech.com\/resources\/blog\/enhancing-rag-generative-ai-postgresql-hnsw-indexes","url":"https:\/\/mobisoftinfotech.com\/resources\/blog\/enhancing-rag-generative-ai-postgresql-hnsw-indexes","name":"Enhancing RAG AI with HNSW Indexes in PostgreSQL for Speed","isPartOf":{"@id":"https:\/\/mobisoftinfotech.com\/resources\/#website"},"primaryImageOfPage":{"@id":"https:\/\/mobisoftinfotech.com\/resources\/blog\/enhancing-rag-generative-ai-postgresql-hnsw-indexes#primaryimage"},"image":{"@id":"https:\/\/mobisoftinfotech.com\/resources\/blog\/enhancing-rag-generative-ai-postgresql-hnsw-indexes#primaryimage"},"thumbnailUrl":"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2024\/11\/rag-hnsw-indexes-postgresql.png","datePublished":"2024-11-13T12:18:44+00:00","dateModified":"2025-10-16T07:31:23+00:00","author":{"@id":"https:\/\/mobisoftinfotech.com\/resources\/#\/schema\/person\/fa762036b3364f26abeea146c01487ee"},"description":"Learn how HNSW indexes in PostgreSQL improve RAG-based generative AI performance, optimizing similarity searches and speeding up retrieval in large datasets.","breadcrumb":{"@id":"https:\/\/mobisoftinfotech.com\/resources\/blog\/enhancing-rag-generative-ai-postgresql-hnsw-indexes#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/mobisoftinfotech.com\/resources\/blog\/enhancing-rag-generative-ai-postgresql-hnsw-indexes"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/mobisoftinfotech.com\/resources\/blog\/enhancing-rag-generative-ai-postgresql-hnsw-indexes#primaryimage","url":"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2024\/11\/rag-hnsw-indexes-postgresql.png","contentUrl":"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2024\/11\/rag-hnsw-indexes-postgresql.png","width":855,"height":392,"caption":"Enhancing RAG-Based Generative AI Applications with HNSW Indexes in PostgreSQL"},{"@type":"BreadcrumbList","@id":"https:\/\/mobisoftinfotech.com\/resources\/blog\/enhancing-rag-generative-ai-postgresql-hnsw-indexes#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/mobisoftinfotech.com\/resources\/"},{"@type":"ListItem","position":2,"name":"Enhancing RAG-Based Generative AI Applications with HNSW Indexes in PostgreSQL"}]},{"@type":"WebSite","@id":"https:\/\/mobisoftinfotech.com\/resources\/#website","url":"https:\/\/mobisoftinfotech.com\/resources\/","name":"Mobisoft Infotech","description":"Discover Mobility","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/mobisoftinfotech.com\/resources\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/mobisoftinfotech.com\/resources\/#\/schema\/person\/fa762036b3364f26abeea146c01487ee","name":"Pritam Barhate","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/0e481c7ce54b3567ac70ddfc493523eefce0bdc3ee69fd2654f8f60a79e2f178?s=96&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/0e481c7ce54b3567ac70ddfc493523eefce0bdc3ee69fd2654f8f60a79e2f178?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/0e481c7ce54b3567ac70ddfc493523eefce0bdc3ee69fd2654f8f60a79e2f178?s=96&r=g","caption":"Pritam Barhate"}}]}},"_links":{"self":[{"href":"https:\/\/mobisoftinfotech.com\/resources\/wp-json\/wp\/v2\/posts\/31882","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mobisoftinfotech.com\/resources\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mobisoftinfotech.com\/resources\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mobisoftinfotech.com\/resources\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mobisoftinfotech.com\/resources\/wp-json\/wp\/v2\/comments?post=31882"}],"version-history":[{"count":44,"href":"https:\/\/mobisoftinfotech.com\/resources\/wp-json\/wp\/v2\/posts\/31882\/revisions"}],"predecessor-version":[{"id":44309,"href":"https:\/\/mobisoftinfotech.com\/resources\/wp-json\/wp\/v2\/posts\/31882\/revisions\/44309"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/mobisoftinfotech.com\/resources\/wp-json\/wp\/v2\/media\/32146"}],"wp:attachment":[{"href":"https:\/\/mobisoftinfotech.com\/resources\/wp-json\/wp\/v2\/media?parent=31882"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mobisoftinfotech.com\/resources\/wp-json\/wp\/v2\/categories?post=31882"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mobisoftinfotech.com\/resources\/wp-json\/wp\/v2\/tags?post=31882"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}