IBM AI →
The Community for AI architects and builders to learn, share ideas and connect with others
Join/Log In
Learn more about TechXchange Dev Days virtual and in-person events here
Share on LinkedIn
This document is designed to guide developers in selecting similarity metrics and In-Memory indexes when using the Milvus vector database. It provides a concise overview of key concepts and parameters, encourages iterative testing with your dataset, and invites users to explore the resource links for an in-depth understanding of the topics discussed.
For floating-point embeddings, Milvus provides three metric types:
Euclidean Distance (L2):
Inner Product (IP):
Cosine Similarity (COSINE):
Pro Tip: Use COSINE for normalized vectors unless your use case benefits specifically from another metric.
COSINE
Milvus supports several index types, each optimized for specific scenarios:
Overview: Graph-based index offering high recall and speed. Faster than any of the suggested indexes.
Scenario: Preferred for datasets >2GB where accuracy and speed are critical.
Trade-offs: High memory usage and slower index building times.
Key Parameters:
Index Parameters
M
efConstruction
Search Parameters
efSearch
NB: efSearch should always be greater than the number of nearest neighbors you want to retrieve.
Overview: Speeds up queries by organizing vectors into clusters and calculating the distance between the target input vector and the cluster centers. Based on the configured number of clusters to search, the system performs similarity comparisons only within the most relevant cluster(s), returning results more efficiently.
Scenario: Preferred for scenarios where a mid accuracy and speed are needed.
nlist
nprobe
float32
int64
Divide the segment size by the average entity size (in MB):
n = 512 / (average entity size in MB)
Use the following rule of thumb:
nlist = 4 × √n
Where n is the total number of entities in a segment.
Calculate using:
nprobe = nlist / 16
NB: nprobe should either be less than or equal to nlist
IVF_FLAT
Index Parameter Calculation Guide
IVF_PQ
SCANN
Iterative Optimization:
Benchmark indexes systematically using representative datasets.
Compare performance trade-offs between different strategies.
Performance Tracking:
Log key metrics: query latency, vector collection size, search scope, and index parameters.
Use data to drive indexing decisions.
Methodical Approach:
Start with FLAT index as a baseline.
Progressively explore more complex indexing techniques.
Continuous Profiling:
Regularly benchmark and adapt index strategies.
Create repeatable optimization processes.
Note: This guide is a starting point for selecting similarity metrics and indexes in Milvus. For optimal results, always test with your dataset and refine parameters iteratively.