
This blog post explores the concept of Vector Search, detailing the challenges of indexing vector spaces, measuring distances between vectors, and the algorithms used for efficient searching, including ScaNN and its application in Google services.
Vector Search is a core technology that enables efficient searching within multi-dimensional vector spaces. This blog post delves into the intricacies of creating Vector Search, focusing on the challenges of indexing, measuring distances between vectors, and the algorithms that facilitate fast and scalable searches.
Creating a Vector Search system involves several challenges, primarily how to index the vector space for quick and efficient searches. Two major issues arise:
In a multi-dimensional vector space, determining the proximity of vectors is crucial. For instance, how do we ascertain that Paris and Tokyo are closer to each other than to Apple? When building Vector Search on platforms like Google Cloud, there are four widely used metrics to measure vector distances:
Manhattan Distance: Also known as L1 distance, it calculates the distance between two points in a grid-like pattern. It is defined as the sum of the absolute differences between the corresponding coordinates of the two points.
Euclidean Distance: Known as L2 or square distance, it measures the shortest distance between two points in a straight line. It is calculated as the square root of the sum of the squared differences between the coordinates.
Cosine Distance: This metric assesses the similarity of two vectors based on the angle between them. Cosine similarity is determined by the cosine of the angle, where zero indicates complete alignment and one indicates orthogonality.
Dot Product Distance: Also referred to as inner product distance, it evaluates the similarity between two vectors in terms of both direction and magnitude.
Once the distance measurement is established, the next challenge is to efficiently locate similar vectors within a vast vector space. Two primary search algorithms are commonly employed:
Brute-force Search: This method involves an exhaustive search approach, consisting of three steps:
TreeAh Algorithm: This algorithm utilizes an approximate tree search method known as Approximate Nearest Neighbor (ANN). TreeAh, which stands for shallow tree and Asymmetric Hashing, is widely used in production environments. It enhances search speed by dividing the search space into multiple areas and indexing them using a tree structure, trading some accuracy for significant speed improvements.
In 2020, Google Research introduced ScaNN (Scalable Approximate Nearest Neighbor), a new ANN algorithm that serves as the backbone for various Google services, including Google Search and YouTube. ScaNN is recognized for its balance of accuracy and speed, making it one of the leading ANN algorithms in the industry.
ScaNN enhances Vector Search performance by applying several critical techniques:
Space Pruning: This technique reduces the search space by constructing a multi-level tree search. The vector space is divided into hierarchical partitions, and a search tree is created to represent this structure. Only the closest partitions to the query are selected, while irrelevant spaces are pruned.
Data Quantization: This process compresses data points to save space and reduce indexing time. For example, a nine-dimensional vector can be compressed from nine floats to 12 bits.
Incorporating Business Logic: This involves filtering the search to retrieve only relevant data. For instance, one might filter results to find resorts in the United States or dresses in a specific color.
Building on the principles of ScaNN, Vertex AI Vector Search offers a fully managed similarity Vector Search service. Launched in 2021 under the name Matching Engine, it is powered by ScaNN and Vertex AI, providing a unified AI development platform. Vertex AI Vector Search is noted for being 30 to 50% less expensive than comparable services while maintaining fast search capabilities, lower latencies, and scalability to billions of vectors.
Vector Search is a powerful technology that addresses the complexities of searching within multi-dimensional spaces. By understanding the distance metrics, search algorithms, and innovations like ScaNN, developers can create efficient and scalable search solutions. As the demand for fast and accurate search capabilities continues to grow, mastering these techniques will be essential for leveraging the full potential of Vector Search in various applications.
Paste a YouTube link and let Magica create the key takeaways.
Summarize another video