Why Indexing Matters
Consider searching through 1 million 768-dimensional vectors:- Without index (brute-force): ~1-5 seconds per query
- With HNSW index: ~1-10 milliseconds per query
Index Types Overview
Zvec supports four index types:| Index Type | Best For | Search Speed | Memory Usage | Accuracy |
|---|---|---|---|---|
| HNSW | Most use cases | Very fast | High | Excellent |
| IVF | Large datasets, lower memory | Fast | Medium | Good |
| Flat | Small datasets, exact search | Medium | Low | Perfect (100%) |
| Inverted | Scalar field filtering | Very fast | Low | Perfect (100%) |
Vector Indexes
Vector indexes are used for similarity search on vector fields.HNSW (Hierarchical Navigable Small World)
HNSW is the recommended index for most applications. It provides excellent recall with very fast query performance.How HNSW Works
HNSW builds a multi-layer graph where:- Each vector is a node
- Edges connect similar vectors
- Upper layers enable long-range navigation
- Bottom layer contains all vectors
Creating an HNSW Index
HNSW Parameters
m (default: 16)
- Number of connections per node in the graph
- Higher → better recall, more memory, slower build time
- Typical range: 8-64
- Recommended: 16 for most cases, 32 for high-dimensional vectors
ef_construction (default: 200)
- Size of candidate list during index construction
- Higher → better index quality, slower build time
- Typical range: 100-500
- Recommended: 200 for balanced quality/speed
ef (query time, default: 100)
- Size of candidate list during search
- Higher → better recall, slower search
- Can be adjusted per query using
HnswQueryParam - Typical range: 50-500
Query-Time Configuration
HNSW Best Practices
Choosing m
Choosing m
Choosing ef_construction
Choosing ef_construction
Tuning query-time ef
Tuning query-time ef
ef should be ≥ topk and typically 2-10x larger.IVF (Inverted File Index)
IVF partitions vectors into clusters, then searches only the nearest clusters. This reduces memory usage compared to HNSW.How IVF Works
- Training: Use k-means to partition vectors into
nlistclusters - Indexing: Assign each vector to its nearest cluster
- Searching: Search only
nprobenearest clusters to the query
Creating an IVF Index
IVF Parameters
nlist (default: 100)
- Number of clusters (Voronoi cells)
- Higher → better recall, more memory, slower search
- Typical range: sqrt(N) to 4*sqrt(N), where N = number of vectors
- Example: For 1M vectors, use nlist ≈ 1000-4000
nprobe (default: 10)
- Number of clusters to search
- Higher → better recall, slower search
- Typical range: 1-100
- Recommended: 10-20 for balanced recall/speed
Query-Time Configuration
IVF Best Practices
Flat (Brute-Force Index)
Flat index performs exact brute-force search. Use for small datasets or when you need perfect recall.Creating a Flat Index
When to Use Flat
Use Flat index when:
- Dataset is small (< 10,000 vectors)
- You need 100% recall (exact search)
- Query latency < 100ms is acceptable
- Memory is limited (Flat uses least memory)
Don’t use Flat when:
- Dataset is large (> 100,000 vectors)
- You need sub-10ms query latency
- You can tolerate 95-99% recall
Inverted Index (Scalar Fields)
Inverted indexes accelerate filtering on scalar fields. They’re essential for queries with filter expressions.Creating an Inverted Index
At Schema Creation
After Collection Creation
Inverted Index Use Cases
When to Add Inverted Indexes
Add inverted indexes to fields used in filter expressions:Index Management
Building Indexes
Indexes can be created at schema definition or after collection creation:Dropping Indexes
Rebuilding Indexes
Rebuild indexes after bulk insertions or to apply new parameters:Index Build Time
Index construction time depends on dataset size and parameters:- 100K vectors: ~10-60 seconds (HNSW m=16)
- 1M vectors: ~2-10 minutes (HNSW m=16)
- 10M vectors: ~30-90 minutes (HNSW m=16)
Index Selection Guide
Performance Tuning
HNSW Recall vs Speed Tradeoff
IVF Recall vs Speed Tradeoff
Best Practices
Index after bulk insertions
Index after bulk insertions
Create indexes after inserting your data, not before:
Monitor index quality
Monitor index quality
Test recall on a validation set:
Optimize after index creation
Optimize after index creation
Run optimize to improve index quality:
Next Steps
Querying
Learn how to execute vector similarity searches
Vectors
Understand vector types and dimensions
Collections
Manage collections and data operations
Schemas
Define collection schemas