In this blog, we will focus on performance tuning and optimizations for running vector similarity searches at scale.
We will continue working on the Wikipedia scenario where we generate the embeddings of wiki pages using OpenAI and store them in kusto. We then use series_cosine_similarity_fl kusto function to perform similarity searches.
.alter-merge table WikipediaEmbeddingsTitleD policy partitioning
"MaxPartitionCount": 2048, // set it to max value create smaller partitions thus more balanced spread among all cluster nodes
"EffectiveDateTime": "2000-01-01" // set it to old date in order to apply partitioning on existing data
In the example above we modified the partitioning policy for WikipediaEmbeddingsTitleD. This table was created from WikipediaEmbeddings by projecting the documents’ title and embeddings.
The partitioning process requires a string key with high cardinality, so we also projected the unique vector_id and converted it to string.
The best practice is to create an empty table, modify its partition policy then ingest the data. In that case there is no need to define the old EffectiveDateTime as above.
It takes some time after data ingestion until the policy is applied.
To test the effect of partitioning we created in a similar manner multiple tables containing up to 1M embedding vectors and tested the cosine similarity performance on clusters with 1, 2, 4, 8 & 20 nodes (SKU Standard_E4d_v5).
The following table and chart compare search performance (in seconds) before and after partitioning:
Number of Nodes
# of vectors
1* (no partitioning)
* Note that the cluster has 2 nodes, but the tables are stored on a single node (this is our baseline before applying the partitioning policy)
You can see that even on the smallest 2 nodes cluster the search speed is improved by more than x4 factor, and in general the speed is inversely proportional to the number of nodes.The number of embedding vectors that are needed for common LLM scenarios (e.g.Retrieval Augmented Generation)rarely exceeds 100K, thus by having 8 nodes searching can be done in 1 sec.
How can you get started?
If you would like to try this demo, head to the azure_kusto_vector GitHub repository and follow the instructions.
The Notebook in the repo will allow you to -
Download precomputed embeddings created by OpenAI API.
Store the embeddings in ADX.
Convert raw text query to an embedding with OpenAI API.
Use ADX to perform cosine similarity search in the stored embeddings