Spanner vector search overview

This page describes vector search and how it works in Spanner.

Vector search is a high-performance, built-in capability that enables semanticsearch and similarity matching on high-dimensional vector data. By storing andindexing vector embeddings directly within your transactional database,Spanner eliminates the need for separate vector databases andcomplex ETL pipelines.

Key concepts

This section introduces the following key concepts of vector search:

  • Vector embeddings
  • Search methods (KNN and ANN)
  • Distance functions

Vector embeddings

Vector embeddings are high-dimensional, numerical representations ofunstructured data. They are generated from the unstructured data usingmachine learning models. For example, you can use the Vertex AItext embedding API togenerate, store, and update text embeddingsfor data stored in Spanner.

Search methods

Spanner supports two methods for finding similar vectors:

  • K-nearest neighbors (KNN):Performs an exact search by calculating the distance between the query andevery vector in the dataset. It provides more accurate recall, but iscomputationally expensive for massive datasets.

  • Approximate nearest neighbor (ANN):Uses avector index (based on Google's ScaNNalgorithm) to find matches quickly across a large number of vectors. It tradesa small amount of accuracy (recall) for gains in speed and scalability.

Key capabilities

  • Scalability: Supports billions of vectors for unpartitioned ANN search,or trillions of vectors for partitioned KNN workloads.

  • Unified AI database and engine: Use theGoogleSQLML.PREDICTorPostgreSQLspanner.ML_PREDICT_ROWfunction to generate embeddings from Vertex AI models directlywithin your query flow.

  • Inline filtering: Efficiently combine vector search with structuredmetadata filters (for example, "Find similar images where category = 'shoes'and price < 100") without losing performance.

  • LangChain integration: Built-in support forLangChainlets you buildretrieval-augmented generation (RAG)applications using Spanner as the vector store.

Hybrid search capabilities

Vector search is most powerful when combined with Spanner's otherdata features:

CombinationBenefit
Vector search with SQL filteringEfficiently combine vector search with filters (for example, "Find similar images where category = 'shoes' and price < 100").
Vector search + full-text searchCombine semantic similarity with keyword precision using reciprocal rank fusion (RRF) for superior search relevance.
Vector + graphUse vector search to find relevant entry points (nodes) in a property graph and then traverse complex relationships.

What's next

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026-02-19 UTC.