The Scalable Nearest Neighbors (ScaNN) index in AlloyDB for PostgreSQL accelerates vector similarity queries while reducing memory usage through tree-quantization indexing. In tree-quantization techniques, indexes learn a search tree together with a quantization (or hashing) function. When you run a query, the search tree prunes the search space while quantization compresses the index size, speeding up similarity scoring between the query vector and your database vectors.
To achieve both a high query-per-second rate (QPS)
and a high recall with your nearest-neighbor queries, you must partition
the tree of your ScaNN index in a way that is most appropriate to your data
and your queries.
A common characteristic of the current generation of high-dimensional embedding models is that they can still retain much of the information at much lower dimensionality; for example, 90% of the information can be retained with only 20% of the embedding's dimensions. To help speed up such datasets, AlloyDB AI ScaNN automatically performs dimension reduction using Principal Component Analysis (scann.enable_pca in the ScaNN index reference) on the indexed vectors, which further reduces CPU and memory usage for the vector search. Because dimension reduction still causes minor recall loss in the index, AlloyDB AI ScaNN compensates through an initial ranking step with a larger number of PCA-reduced vector candidates from the index and then re-ranking them by the original vectors (scann.pre_reordering_num_neighbors in the ScaNN index reference).