<?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 Archana Gupta on Medium]]></title>
        <description><![CDATA[Stories by Archana Gupta on Medium]]></description>
        <link>https://medium.com/@arcgupta?source=rss-55d3ad2d2021------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*lKbakoo3Zq9gF5EV</url>
            <title>Stories by Archana Gupta on Medium</title>
            <link>https://medium.com/@arcgupta?source=rss-55d3ad2d2021------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 23:51:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@arcgupta/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[Agentspace & AlloyDB : Search on Cloud to be enterprise ready for production]]></title>
            <link>https://medium.com/google-cloud/agentspace-alloydb-search-on-cloud-to-be-enterprise-ready-for-production-de39ac04816c?source=rss-55d3ad2d2021------2</link>
            <guid isPermaLink="false">https://medium.com/p/de39ac04816c</guid>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[vector-database]]></category>
            <category><![CDATA[alloydb]]></category>
            <category><![CDATA[data]]></category>
            <category><![CDATA[agents]]></category>
            <dc:creator><![CDATA[Archana Gupta]]></dc:creator>
            <pubDate>Fri, 15 Aug 2025 15:14:07 GMT</pubDate>
            <atom:updated>2025-08-16T02:53:41.888Z</atom:updated>
            <content:encoded><![CDATA[<h3>Agentspace &amp; AlloyDB : Search on Cloud to be enterprise ready for production</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aSGk0gBrxffIjUfidp-v1A.png" /></figure><p>Have you ever considered the power of integrating a built-in search platform directly within your AlloyDB PostgreSQL database? Imagine the ease and efficiency of searching your critical data using enterprise-ready tooling.</p><p><strong>Agentspace Assistant and Agent Development Kit</strong> from Vertex AI is now integrated with AlloyDB — Now you can both use the Agentspace Assistant to securely search AlloyDB as well as build custom Agents with AlloyDB for your agentic workflows.</p><p>This article introduces the revolutionary capabilities of the newly launched Agentspace with AlloyDB, empowering you to query and search your AlloyDB data with the unparalleled advanced reasoning of Gemini and Google-quality search. This direct integration is crucial, providing Agentspace users with the ability to obtain answers based on real-time enterprise knowledge, pulled directly from your live AlloyDB data. This ensures that the natural language answers provided are not only intuitive but also accurate and up-to-date, truly reflecting the current state of your business operations. We will also talk about how we can easily set this up, working instantaneously on enterprise operational data on AlloyDB.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*b31hiO4ynbDLRrXWEFF4aQ.png" /></figure><p>Let’s start off with introducing our flagship Google Agentspace — There is a long-standing problem of fragmented technology systems within businesses. Years ago, you had a lot of technology that didn’t work that well. Today, you have a lot of technology that works amazing, but very little of it works together.</p><p>An extraordinary proliferation of cutting-edge technologies — such as Large Language Models (LLMs), intelligent Agents, Generative AI, alongside tools enabling automated workflows and enterprise-wide search — is currently underway, each holding immense promise. Yet, this rapid innovation, while stimulating, also introduces a fresh wave of complexity. Businesses frequently pose the following inquiries:</p><ul><li>How can we comprehend the vast array of these novel tools?</li><li>What is their interrelationship?</li><li>Crucially, how can they be effectively utilized to resolve genuine business challenges?</li></ul><p>The fundamental obstacle lies not merely in understanding these technologies in isolation, but in leveraging them to attain tangible outcomes. It is imperative to be able to:</p><ul><li><strong>Access information swiftly:</strong> Whether for employees or customers, timely access to pertinent information is paramount. How can these new AI-driven tools facilitate the immediate sifting through extensive data to reveal what is relevant?</li><li><strong>Connect data sources:</strong> The majority of businesses contend with data dispersed across disparate systems, silos, and formats. The true potency emerges when these divergent sources can be linked. How can LLMs and agents aid in bridging these voids and forging a more cohesive perspective of your data?</li><li><strong>Take action:</strong> Ultimately, insights are only valuable when they culminate in action. How can these technologies be integrated into workflows to not only analyze or predict, but to actively support decision-making and automate tasks?</li></ul><p><strong>This is precisely where Google Cloud intervenes.</strong> We acknowledge the daunting nature of navigating this intricate new technological landscape. Our objective is to abstract away a significant portion of this underlying complexity. We aim to be your steadfast partner in streamlining this journey, ensuring you can capitalize on these advancements without becoming entangled in their intricacies.</p><p><strong>What if you could pull together search, AI and agents across your enterprise into a single platform?</strong> You could fundamentally change the way your workforce interacts with information, and in turn, drive positive business outcomes. <strong>This is where Google Agentspace comes in</strong> — By providing a <strong>single, secure platform to build, manage, and adopt AI agents at scale</strong> and <strong>unlock the true potential of individuals, organizations, and even entire enterprises</strong>, it can deliver business value immediately using your existing data, so you don’t have to wait for long data and AI integration projects just to get started. <strong>Powering this search capability with your enterprise data in AlloyDB and leveraging its Natural Language features helps enterprises search structured and unstructured operational data.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*b31hiO4ynbDLRrXWEFF4aQ.png" /></figure><p>Let’s jump to the fun part now — how can we set this up from our Google Cloud consoles. Consider the below data, already available in my AlloyDB database with an “employee” table, consisting of employee details in an organisation. <strong><em>(Fun tip: Generated the schema and the ingested data from Agentspace itself 😏)</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*b31hiO4ynbDLRrXWEFF4aQ.png" /></figure><p>The data here comprises employee level information, starting from the CEO, all the way down to vendors, with data about their personal level information, organisational level, and business entities that they are a part of.</p><p>Start off with opting into Agentspace connectivity with AlloyDB and AlloyDB AI on the forms <a href="https://docs.google.com/forms/d/e/1FAIpQLSdV_GGjyAa_RpmO2ZyB-5iUQvVIkYcp8WUwmDCFnEq8KaMO2A/viewform">here</a> and <a href="https://docs.google.com/forms/d/16wliam2vok6sdBjYwJIgWV4hw7MW9x5iQ29UwPAKqB0/viewform?edit_requested=true">here</a> respectively. Once access has been granted, you would need to install the AlloyDB AI Natural Language extension (don’t worry, no downtime on your cluster!) using the below command:</p><pre>CREATE EXTENSION alloydb_ai_nl cascade;</pre><p>AlloyDB AI Natural Language uses <strong>nl_config</strong> to associate applications to certain schemas, query templates and model endpoints — a large application could essentially use different configurations, for different parts of an application, as long as you specify the right configuration when a question or prompt is sent across.</p><p>For this specific example, to create a natural language configuration, follow the below steps (a brief description of what that command does is mentioned right below the SQL command for clarity)</p><pre> - Creating a natural language configuraton<br><br>SELECT<br>alloydb_ai_nl.g_create_configuration(<br>&#39;my_app_config&#39; - configuration_id<br>);<br><br> - Register a schema for a specified configuration<br><br>SELECT<br>alloydb_ai_nl.g_manage_configuration(<br>operation =&gt; &#39;register_schema&#39;,<br>configuration_id_in =&gt; &#39;my_app_config&#39;,<br>schema_names_in =&gt; &#39;{my_schema}&#39;<br>);<br><br> - Add contect for the configuration rules<br><br>SELECT<br>alloydb_ai_nl.g_manage_configuration(<br>&#39;add_general_context&#39;,<br>&#39;my_app_config&#39;,<br>general_context_in =&gt; &#39;{&quot;If the user asks for a certain name and multiple entries exist for the same name, return all the results rather than the most suitable one&quot;}&#39;<br>);<br><br> - To generate contexts for schema objects, call the following APIs. For best results, make sure that the database tables contain representative data. For all schema objects (tables, views, materialized views and columns) within the scope of a provided nl_config.<br><br>SELECT<br>alloydb_ai_nl.generate_schema_context(<br>&#39;my_app_config&#39; - nl_config<br>);<br><br> - Review the generated schema contexts by running the following statements [Sanity checks]<br><br>SELECT schema_object, object_context<br>FROM alloydb_ai_nl.generated_schema_context_view;<br><br> - For all schema objects (tables, views, materialized views and columns)<br> - within the scope of nl_config.<br><br>SELECT<br>alloydb_ai_nl.apply_generated_schema_context(<br>&#39;my_app_config&#39; - nl_config<br>);<br><br> - For table, view or materialized view.<br><br>SELECT<br>alloydb_ai_nl.get_relation_context(<br>&#39;my_schema.my_table&#39;<br>);<br><br> - For column<br><br>SELECT<br>alloydb_ai_nl.get_column_context(<br>&#39;my_schema.my_table.column1&#39;<br>);</pre><p>Once set up, you would need to set up authentication between AlloyDB and Agentspace, by running the below commands:</p><pre>CREATE ROLE agentspace WITH LOGIN PASSWORD &#39;&lt;Password for Agentspace&gt;&#39;;<br>GRANT SELECT ON TABLE &quot;public&quot;.&quot;employee&quot; TO agentspace;<br>--Replace &#39;public&#39; and &#39;employee&#39; with the database and table name respectively</pre><p>Additionally, make sure that you Grant the <strong>Cloud AlloyDB for PostgreSQL Database User</strong> role to the following principal: service-PROJECT_NUMBER@<a href="http://gcp-sa-discoveryengine.iam.gserviceaccount.com/">gcp-sa-discoveryengine.iam.gserviceaccount.com</a> This would be followed by the final step of linking Agentspace with AlloyDB.</p><p>Next, create a datastore in Agentspace with your AlloyDB for PostgreSQL connection details using the API.</p><pre>curl -X POST \<br>  -H &quot;Authorization: Bearer $(gcloud auth print-access-token)&quot; \<br>  -H &quot;Content-Type: application/json&quot; \<br>  -H &quot;X-Goog-User-Project: archana-primary&quot; \<br>  &quot;https://discoveryengine.googleapis.com/v1alpha/projects/archana-primary/locations/global/collections/default_collection/dataStores?dataStoreId=alloydb&quot; -d &#39;{<br>  &quot;displayName&quot;: &quot;DATA_STORE_NAME&quot;,<br>  &quot;federatedSearchConfig&quot;: {<br>    &quot;alloyDbConfig&quot;: {<br>      &quot;alloydbConnectionConfig&quot;: {<br>        &quot;instance&quot;: &quot;alloy-data&quot;,<br>        &quot;database&quot;: &quot;postgres&quot;,<br>        &quot;user&quot;: &quot;postgres&quot;,<br>        &quot;password&quot;: &quot;Password&quot;,<br>        &quot;authMode&quot;: &quot;AUTH_MODE_SERVICE_ACCOUNT&quot;<br>      },<br>      &quot;alloydb_ai_nl_config&quot;: { &quot;nlConfigId&quot;: &quot;my_app_config&quot; }<br>    }<br>  },<br>  &quot;industryVertical&quot;: &quot;GENERIC&quot;,<br>  &quot;solutionTypes&quot;: [&quot;SOLUTION_TYPE_SEARCH&quot;]<br>}&#39;</pre><p>Upload the schema information of your AlloyDB for PostgreSQL database, which would be the schema of my employee table data.</p><pre>curl -X PATCH \<br>-H &quot;Authorization: Bearer $(gcloud auth print-access-token)&quot; \<br>-H &quot;Content-Type: application/json&quot; \<br>&quot;https://discoveryengine.googleapis.com/v1beta/projects/archana-primary/locations/global/collections/default_collection/dataStores/alloydb/schemas/default_schema&quot; \<br>-d &#39;{<br>  &quot;structSchema&quot;: {<br>    &quot;$schema&quot;: &quot;https://json-schema.org/draft/2020-12/schema&quot;,<br>    &quot;type&quot;: &quot;object&quot;,<br>    &quot;properties&quot;: {<br>      &quot;employee&quot;: {<br>        &quot;type&quot;: &quot;object&quot;,<br>        &quot;properties&quot;: {<br>          &quot;rownumber&quot;: { &quot;type&quot;: &quot;integer&quot; },<br>          &quot;businessentityid&quot;: { &quot;type&quot;: &quot;integer&quot;},<br>          &quot;nationalidnumber&quot;: { &quot;type&quot;: &quot;character&quot;, &quot;keyPropertyMapping&quot;: &quot;national ID&quot; },<br>          &quot;loginid&quot;: { &quot;type&quot;: &quot;character&quot; },<br>          &quot;organizationlevel&quot;: { &quot;type&quot;: &quot;integer&quot;},<br>          &quot;jobtitle&quot;: { &quot;type&quot;: &quot;character&quot;, &quot;keyPropertyMapping&quot;: &quot;job title&quot; },<br>          &quot;birthdate&quot;: { &quot;type&quot;: &quot;date&quot;, &quot;keyPropertyMapping&quot;: &quot;birth date&quot; },<br>          &quot;maritalstatus&quot;: { &quot;type&quot;: &quot;character&quot;, &quot;keyPropertyMapping&quot;: &quot;marital status&quot; },<br>          &quot;gender&quot;: { &quot;type&quot;: &quot;character&quot;, &quot;keyPropertyMapping&quot;: &quot;Gender&quot; },<br>          &quot;hiredate&quot;: { &quot;type&quot;: &quot;date&quot;, &quot;keyPropertyMapping&quot;: &quot;Hire date&quot; },<br>          &quot;salariedflag&quot;: { &quot;type&quot;: &quot;character&quot;, &quot;keyPropertyMapping&quot;: &quot;salaried flag&quot; },<br>          &quot;vacationhours&quot;: { &quot;type&quot;: &quot;smallint&quot;, &quot;keyPropertyMapping&quot;: &quot;vacation hours&quot; },<br>          &quot;sickleavehours&quot;: { &quot;type&quot;: &quot;smallint&quot;, &quot;keyPropertyMapping&quot;: &quot;sick leave hours&quot; },<br>          &quot;currentflag&quot;: { &quot;type&quot;: &quot;character&quot;},<br>          &quot;rowguid&quot;: { &quot;type&quot;: &quot;character&quot;},<br>          &quot;modifieddate&quot;: { &quot;type&quot;: &quot;date&quot;, &quot;keyPropertyMapping&quot;: &quot;modified date&quot; }<br>        }<br>      }<br>    }<br>  }<br>}&#39;</pre><p>Finally, update the UI configuration so that search results from AlloyDB for PostgreSQL are displayed correctly in Agentspace. This is an optional step, usually needed if you need to add some context to your data and make it more human readable <strong><em>(no need if the column namings are self explanatory and 90% of the time not needed AT ALL!)</em></strong></p><pre>curl -X PATCH \<br>-H &quot;X-Goog-User-Project: archana-primary&quot; \<br>-H &quot;Authorization: Bearer $(gcloud auth print-access-token)&quot; \<br>-H &quot;Content-Type: application/json&quot; \<br>https://discoveryengine.googleapis.com/v1alpha/projects/archana-primary/locations/global/collections/default_collection/engines/enterprise-search-alloydb-_1747151802542 /widgetConfigs/default_search_widget_config?updateMask=uiSettings -d &#39;{<br>  &quot;uiSettings&quot;: {<br>    &quot;dataStoreUiConfigs&quot;: [<br>      {<br>        &quot;name&quot;: &quot;projects/archana-primary/locations/global/collections/default_collection/dataStores/alloydb&quot;,<br>        &quot;id&quot;: &quot;alloydb&quot;,<br>        &quot;fieldsUiComponentsMap&quot;: {<br>          &quot;title&quot;: {<br>            &quot;field&quot;: &quot;title&quot;,<br>            &quot;displayTemplate&quot;: &quot;{value}&quot;<br>          },<br>          &quot;text1&quot;: {<br>            &quot;field&quot;: &quot;description&quot;,<br>            &quot;displayTemplate&quot;: &quot;{value}&quot;<br>          },<br>          &quot;url&quot;: {<br>            &quot;field&quot;: &quot;url&quot;,<br>            &quot;displayTemplate&quot;: &quot;{value}&quot;<br>          }<br>        }<br>      }<br>    ],<br>    &quot;interactionType&quot;: &quot;SEARCH_ONLY&quot;<br>  }<br>}&#39;</pre><p>And with that, your enterprise data on AlloyDB is connected to Agentspace — go and query it from Agentspace, live, with no further modifications needed!</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/0*UARWxb_6qlkjhORQ" /></figure><p>The obvious question that comes up — what if I want to make this whole process simpler? Well good news, the latter part of having to define a datastore and having to define the schema will be completely eliminated down the line, to make this more scalable and efficient for organisations. Furthermore, the other question that comes up, where you would like to join data from multiple sources, this would mean updating your config file (as of today) with multiple tables as shown <a href="https://cloud.google.com/agentspace/docs/connect-alloydb-data#:~:text=%22table_xyz%22%3A%20%7B%20//%20another%20table">here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=de39ac04816c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-cloud/agentspace-alloydb-search-on-cloud-to-be-enterprise-ready-for-production-de39ac04816c">Agentspace &amp; AlloyDB : Search on Cloud to be enterprise ready for production</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[A glimpse into indexing in PostgreSQL and AlloyDB on Google Cloud]]></title>
            <link>https://medium.com/google-cloud/a-glimpse-into-indexing-in-postgresql-and-alloydb-on-google-cloud-0e1c2fddd649?source=rss-55d3ad2d2021------2</link>
            <guid isPermaLink="false">https://medium.com/p/0e1c2fddd649</guid>
            <category><![CDATA[data]]></category>
            <category><![CDATA[index]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[postgresql]]></category>
            <category><![CDATA[alloydb]]></category>
            <dc:creator><![CDATA[Archana Gupta]]></dc:creator>
            <pubDate>Tue, 25 Feb 2025 14:54:53 GMT</pubDate>
            <atom:updated>2025-08-16T02:53:25.639Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/826/1*F2CbXw9AbVKbl7-UKn2nWw.png" /></figure><p>There has been a large surge in the usage and adoption of vector embeddings and vector search today which is being used to represent any kind of data, such as numbers, images, or text as a vector. Artificial intelligence helps build an embedding space as a map of the content’s meanings and plots these vectors as data points, which helps cluster similar vector points together, aiding in similarity search. Today, relational databases are being used to store these vectors and its embeddings, and then finding data that is semantically related to the user request, represented as vectors, by using algorithms to aid in the same.</p><p>PostgreSQL has become one of the most popular relational and transactional databases, added with rich capabilities towards vector search. This document discusses some of the indexing mechanisms in PostgreSQL, which one to make use of in the use cases trying to be achieved and an introduction into ScaNN index, which brings 12 years of <a href="https://research.google/blog/announcing-scann-efficient-vector-similarity-search/">Google research and innovation in ANN algorithms</a> to AlloyDB, our fully managed PostgreSQL compatible database service for more demanding enterprise workloads.</p><h3>Indexing Technologies — KNN and ANN Search</h3><p>Vector similarity search is an information retrieval system that finds the most similar data in a dataset to the input data represented as a vector, by measuring the similarity among data in the dataset and the input data in an embedding space. Data is represented as a vector in an embedding space and the similarity between data points in the embedding space can be measured by a distance measure or other similarity measure. Because of this, the embedding space should be an abstract multidimensional vector space with a proper distance metric, so called metric space.</p><p>One of the most common search methodologies in vector similarity search is <strong>K Nearest Neighbour Vector Search (KNN) </strong>— this is more of a brute force mechanism where it computes the distance between each database embedding and query embedding, and returns the top K database embeddings that had shortest distances, hence most similar. The distance measurement algorithms are very customer based — they include:</p><ul><li>euclidean distance: √(∑(xi — yi)²) ,</li><li>cosine distance: 1 — cos(θ) and</li><li>Dot product distance: ∑(xi * yi)</li></ul><p>The problem with this approach is that brute force mechanisms are known for their issues on scalability — not being able to scale this over millions of vectors in an embedding space, adds to latency, costs and implementation concerns.</p><p>This is why <strong>Approximate Nearest Neighbour (ANN) search</strong> came. This enables approximate nearest neighbor search using vector indexes allowing precision and recall for lower latencies and cost and hence, enabling a larger dataset to be searched.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*uKjYEch9pF14FAfO" /><figcaption>How ANN algorithm works on PostgreSQL databases</figcaption></figure><p>As the example shows above, in our database embedding space, we are trying to query for a “blue sandal”. The ANN search divides the dataset into subsets using vector quantization, to group similar items together and while trying to search for the item in this embedding space, this limits the search to a subset of items, making the search much faster and more efficient.</p><h3>Types of ANN Indexing — IVF Flat and HNSWs</h3><p><strong>In ANN, there are two popular types of indices: graph based and tree quantization based.</strong></p><ul><li><strong>Tree-quantization-based vector indexes</strong>, at a high level, structure the data such that clusters of nearby vectors are grouped together and are properly compressed (quantized). Tree-quantization indices have smaller memory footprints and faster index build times than graph-based ANN indices.</li><li>ScaNN indexes belong to the family of tree quantization based ANN indices. Tree quantizations typically learn a search tree together with a quantization or hashing function and the following <a href="https://ieeexplore.ieee.org/document/7915742">journal paper</a> is an interesting and detailed study on this topic.</li><li><strong>Graph-based algorithms</strong> construct a network of nodes, which are connected by edges based on similarity.</li><li>One of the best examples of this is <strong>Inverted File with Flat Compression (IVF Flat)</strong> where vectors are divided into lists, and then searches a subset of those lists that are closest to the query vector. The algorithm calculates a number of centroids and finds the clusters around those centroids.</li><li>While IVF Flat allows simple implementations and faster build times, while limiting its use of memory compared to HNSW, the lower speed/recall performance and repetitive indexing due to data changes can be deal breakers for users. Additionally, IVF Flat requires a k- means training phase before the indexing is applied, so you must create the index after the data is loaded, which is not needed in HNSW.</li><li>pgvector’s <strong>HNSW index</strong> implements <strong>Hierarchical Navigable Small Worlds (HNSW) graph algorithm</strong> used in many popular vector databases. This uses a hierarchical graph to very efficiently traverse the graph to find nearest neighbors.</li></ul><p><strong>HNSW combines Navigable Small World graphs with Skip Lists to produce a very high-performance vector index in terms of speed-recall tradeoff.</strong> Unlike IVF Flat, no k means training is needed hence, you can create the index before data is inserted into the table, and reindexing is typically not needed. The HNSW (Hierarchical Navigable Small Worlds) index takes a different approach by creating a multi-layered graph structure for the vectors, allowing for a more nuanced search mechanism that navigates the layers (or ‘zoom levels’) to find the nearest neighbors.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*3fux2562REkd8Qt_" /><figcaption>Navigable Small Worlds are regular graphs that are probabilistically rewired to include long-range neighbors</figcaption></figure><p>To explain what a small world graph, one of the components of an HNSW looks like, let’s look at an example above to set the context. A regular graph is a graph where each vertex has the same number of neighbors/vertices (i.e. nodes of the same degree). In the regular graph shown here, each vertex has exactly 2 neighbors.</p><p>On the other hand, a random graph is a graph whose connections (vertices) are generated by some random process with a random number of neighbors.</p><p>However, what’s the problem between these 2 graph techniques? Given a random entry point to the graph, regular graphs will eventually get you to the target node by traversing the neighbors of each vertex, but it will be slow due to the short-range nature of the connections. Random graphs give unpredictable performance and output.</p><p><strong>Navigable Small Worlds</strong> are regular graphs (with short-range neighbors) that are probabilistically rewired to include connections to long-range neighbors. This effectively reduces the diameter of the graph (i.e. the longest path across the graph from any one vertex to another), and it has a high clustering coefficient, enabling more efficient search along the graph using “greedy search”.</p><p>This algorithm works well for small NSWs in the hundreds or thousands of nodes, but it tends to break down for much larger NSWs. We can fix this by increasing the average number of short-, medium-, and long-range connections for each node, but this increases the overall complexity of the network and results in longer search times. In the absolute “worst” case, where each node is connected to every other node in our dataset, NSW is no better than naïve (linear) search.</p><p>This is where skip lists come into play, which is the second component integrated with NSW to create HNSWs. A skip list is a <strong>multi-level linked list where the upper levels maintain long connections.</strong> <strong>As we move down the layers, the connections become shorter and shorter, with the bottommost layer being the “original” linked list containing all of the elements. Notice that this results in duplication of elements that are included in more than one layer.</strong></p><p>We start at the highest layer to reach element i in a skip list. Once we find a node corresponding to an element in the list greater than i, we backtrack to the previous node and move to the layer below. This continues until we’ve found the element we’re looking for.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*PwsfaM9Jm9LgWPP1" /><figcaption>Skips lists are one the key components used with NSWs to implement HNSW algorithm</figcaption></figure><p>Combining these two concepts together, HNSW maintains multiple layers of NSWs in hierarchical format.</p><p>HNSW maintains multiple layers of NSWs. The uppermost layer of an HNSW graph has few nodes and the longest links, while the bottommost layer has all nodes and the shortest links.</p><p>During the search, we enter the top layer and traverse edges in each layer just like NSW, using greedy search to move to the next nearest vertex until we find a local minimum. Unlike NSW, we then shift to the current vertex in a lower layer and begin searching again. We repeat this process until we find the local minimum of our bottom layer — layer 0. We can then return the <em>n </em>nearest neighbors of that terminal node as the result of our ANN query.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*yJ5jwPxSniJIqere" /></figure><p><strong>IVF Flat and HNSW indexes are both available in pg vector extension to use to implement vector search on PostgreSQL databases including CloudSQL and AlloyDB on Google Cloud.</strong></p><h3>Which indexing is recommended for which use case?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5GPXmSRyUWUb9pcQmCXjUA.png" /></figure><h3>ScaNN Indexing in AlloyDB</h3><p>AlloyDB for PostgreSQL on Google Cloud enables faster vector indexing and a much more improved performance known as ScaNN (Scalable Nearest Neighbour), specifically created for AlloyDB as part of Google research technology. The release allows faster vector index creations, improves performance of vector search while having a low memory footprint.</p><p>ScaNN indexing makes use of a tree quantization based technique which creates a search tree consisting of root and lead nodes that branch from the root. Each leaf node includes a set of vectors that are close to one another and the leaf node will be associated to a centroid vector — the root node will be storing the list of all these centroids and pointers to navigate to these centroids and its leaf nodes.</p><p>In the initial phases when the index is created, the centroids are created and trained — the datapoints or vectors are placed and grouped based on how close it is to the centroids. This would look something like below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/726/0*ribhOmxw7dBm8wWP" /><figcaption>Each index is divided into leaf nodes and their centroids are calculated — these vectors are placed close to one another based on their similarities in an n dimensional space</figcaption></figure><p>When you run a query to find a certain datapoint in this example, under the hood, AlloyDB ScaNN tries to compute the distance between each centroid and query vector and using the variable <em>scann.num_leaves_to_search</em>, it determines how many leaf nodes need to be searched. As you can see below, the query vector is highlighted and the three leaves closest to it are narrowed down (considering <em>scann.num_leaves_to_search </em>is set to 3).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4mtglvXDRy6tKuLt" /><figcaption>The red point above indicates the query vector initiated on your database, whose proximity to other centroids in this space are calculated and found</figcaption></figure><p>Next, AlloyDB will compute the distance between each vector in the leaf nodes and the query vector and obtain the list of 10 vectors which are closest and returns those results to the end user. A more detailed analysis of how this is implemented under the hood has been discussed in our <a href="https://services.google.com/fh/files/misc/scann_for_alloydb_whitepaper.pdf">whitepaper</a>.</p><p>The new ScaNN indexing for AlloyDB has significant benefits over HNSW.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PjDIvSZWtERWe2X66s4QYg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0e1c2fddd649" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-cloud/a-glimpse-into-indexing-in-postgresql-and-alloydb-on-google-cloud-0e1c2fddd649">A glimpse into indexing in PostgreSQL and AlloyDB on Google Cloud</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>