Recall measures how effectively a search retrieves all relevant items for
a given query. For example, imagine you have 100 embeddings, each one
representing an entity in your database. You query your embeddings with a
target vector and limit it to 10 results. A KNN vector search finds the 10
exact closest vectors using a brute force calculation method, which
results in 100% recall. AlloyDB AI uses this method by default
if no vector search index is created or chosen.
When you create a vector index in AlloyDB for PostgreSQL, it typically uses ANN,
which might partition
vectors according to similarity to facilitate faster retrieval. As a result,
using ANN, the 10 vectors returned in the earlier example might not be exactly
the 10 vectors that are closest in
distance. If only 8 out of the 10 retrieved vectors are the closest in space
to your query vector, then your recall is 80%.
Query latency defines how fast the search results are generated. For
example, latency is calculated based on the time spent on a search to
return the vectors after you submit a query.
Choose your search strategy
When you perform vector search in AlloyDB, choose one the following
search strategies:
Search Strategy
Description
Use Cases
K-nearest neighbors (KNN)
An algorithm that finds the k-nearest neighbors data points to a given query data point.
When you perform a vector search without creating an index, a KNN search
is performed by default.
Your application is very sensitive to accuracy and you need the exact closest matches.
You have fewer than 100,000 vectors.
Approximate Nearest Neighbors (ANN)
An algorithm that finds approximately the closest data points. ANN divides existing customer data points into small groups based on similarities.
Your application requires low latency.
You have more than 100,000 vectors.
Google recommends that you create a vector index to optimize performance on your vector search queries. For more information about how the ANN index is used for
similarity searches, see Create indexes and query vectors using ScaNN.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-25 UTC."],[[["\u003cp\u003eAlloyDB AI uses k-nearest neighbors (KNN) search by default to find vectors similar to a query, but using a vector index with Approximate Nearest Neighbor (ANN) provides better performance.\u003c/p\u003e\n"],["\u003cp\u003eRecall, which measures the effectiveness of a search in retrieving all relevant items, is 100% with KNN but might be less with ANN because ANN might not return the exact closest vectors.\u003c/p\u003e\n"],["\u003cp\u003eQuery latency, which is how fast search results are generated, can be optimized by choosing the ANN strategy and creating a vector index, as recommended by Google.\u003c/p\u003e\n"],["\u003cp\u003eThe KNN search strategy is best when accuracy is critical and the number of vectors is fewer than 100,000, while ANN is better for applications with low latency and over 100,000 vectors.\u003c/p\u003e\n"],["\u003cp\u003eWhen a vector search is performed without creating a vector index, the default strategy used is KNN.\u003c/p\u003e\n"]]],[],null,["# Choose a vector index in AlloyDB AI\n\nSelect a documentation version: 15.7.0keyboard_arrow_down\n\n- [Current (16.8.0)](/alloydb/omni/current/docs/ai/choose-index-strategy)\n- [16.8.0](/alloydb/omni/16.8.0/docs/ai/choose-index-strategy)\n- [16.3.0](/alloydb/omni/16.3.0/docs/ai/choose-index-strategy)\n- [15.12.0](/alloydb/omni/15.12.0/docs/ai/choose-index-strategy)\n- [15.7.1](/alloydb/omni/15.7.1/docs/ai/choose-index-strategy)\n- [15.7.0](/alloydb/omni/15.7.0/docs/ai/choose-index-strategy)\n\n\u003cbr /\u003e\n\nThis page describes AlloyDB AI vector search strategies and explains when to use each strategy. By default, AlloyDB uses k-nearest neighbors search (KNN) to find vectors that are similar to a query. Vector indexes implement a search strategy called Approximate Nearest Neighbor (ANN). When you create a vector index, AlloyDB AI uses ANN, which provides better performance than KNN. Keep in mind that, when you select a vector index, you need to balance query latency and recall.\n\n\u003cbr /\u003e\n\n*Recall* measures how effectively a search retrieves all relevant items for\na given query. For example, imagine you have 100 embeddings, each one\nrepresenting an entity in your database. You query your embeddings with a\ntarget vector and limit it to 10 results. A KNN vector search finds the 10\nexact closest vectors using a brute force calculation method, which\nresults in 100% recall. AlloyDB AI uses this method by default\nif no vector search index is created or chosen.\nWhen you create a vector index in AlloyDB for PostgreSQL, it typically uses ANN,\nwhich might partition\nvectors according to similarity to facilitate faster retrieval. As a result,\nusing ANN, the 10 vectors returned in the earlier example might not be exactly\nthe 10 vectors that are closest in\ndistance. If only 8 out of the 10 retrieved vectors are the closest in space\nto your query vector, then your recall is 80%.\n\n*Query latency* defines how fast the search results are generated. For\nexample, latency is calculated based on the time spent on a search to\nreturn the vectors after you submit a query.\n\nChoose your search strategy\n---------------------------\n\nWhen you perform vector search in AlloyDB, choose one the following\nsearch strategies:\n\nGoogle recommends that you create a vector index to optimize performance on your vector search queries. For more information about how the ANN index is used for\nsimilarity searches, see [Create indexes and query vectors using ScaNN](/alloydb/omni/15.7.0/docs/ai/store-index-query-vectors?resource=scann).\n\nWhat's next\n-----------\n\n- [Create indexes and query vectors using ScaNN](/alloydb/omni/15.7.0/docs/ai/store-index-query-vectors?resource=scann)\n- [Tune vector query performance](/alloydb/omni/15.7.0/docs/ai/tune-indexes)"]]