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-08 UTC."],[[["\u003cp\u003eAlloyDB AI uses k-nearest neighbors (KNN) search by default to find similar vectors, offering 100% recall by employing a brute force calculation method, but it may be slower.\u003c/p\u003e\n"],["\u003cp\u003eCreating a vector index in AlloyDB AI utilizes Approximate Nearest Neighbor (ANN), which provides faster performance than KNN by partitioning vectors, but with potentially lower recall.\u003c/p\u003e\n"],["\u003cp\u003eRecall measures how effectively a search retrieves all relevant items, with KNN guaranteeing 100% recall, while ANN may result in a lower percentage.\u003c/p\u003e\n"],["\u003cp\u003eQuery latency defines the speed at which search results are generated, and ANN is preferred for low latency, while KNN is preferred for exact accuracy.\u003c/p\u003e\n"],["\u003cp\u003eThe choice between KNN and ANN depends on application needs: KNN is ideal for accuracy and fewer than 100,000 vectors, while ANN is better for low latency and more than 100,000 vectors, with Google recommending vector indexes for performance optimization.\u003c/p\u003e\n"]]],[],null,[]]