Vector Queries in Azure AI Search
Vector queries find semantically similar content using numeric embeddings and nearest neighbor algorithms.Prerequisites
- Vector index with vector fields
- Embedding model (Azure OpenAI, etc.)
- Optional: Vectorizer for query-time conversion
Basic Vector Query
kind: “vector” for embedding arraysvector: Query embedding (same dimensions as field)fields: Vector field(s) to searchk: Number of nearest neighbors to return
Generate Query Embeddings
Azure OpenAI
Use Same Model
Integrated Vectorization
Let Azure AI Search handle vectorization:Configure Vectorizer
Query with Text
- No manual embedding generation
- Consistent model usage
- Simplified queries
Multiple Vector Fields
Search across multiple vector fields:All fields must use embeddings from the same model and have the same dimensions.
Multiple Vector Queries
Execute multiple vector queries in parallel:Vector Weighting
Adjust relative importance:Filtering Vector Results
Apply filters to vector queries:Filter Modes
- preFilter: Apply before vector search (faster, fewer candidates)
- postFilter: Apply after vector search (more candidates, better recall)
Exhaustive KNN
Force exact search instead of approximate:- Maximum accuracy required
- Small dataset
- Willing to accept slower queries
Threshold Filtering (Preview)
Exclude low-similarity results:Query Response
- Higher score = more similar
- Range depends on similarity metric
- Cosine: -1 to 1 (1 = identical)
Oversampling
Request more candidates for reranking:Hybrid Vector + Text
Combine for best results:- Keyword precision + semantic recall
- RRF fusion
- Better than either alone
Performance Optimization
Right-Size k
Right-Size k
- Request only needed results
- Typical: k=10-50
- Larger k = slower queries
Use Compression
Use Compression
- Enable scalar/binary quantization
- 75-96% size reduction
- Minimal accuracy loss with rescoring
Tune HNSW
Tune HNSW
- Adjust efSearch for accuracy vs speed
- Higher efSearch = more accurate, slower
- Default 500 works for most cases
Pre-filter When Possible
Pre-filter When Possible
- Reduces search space
- Faster than post-filtering
- Better for selective filters
Common Patterns
Semantic Product Search
Multimodal Image Search
Document Similarity
Troubleshooting
Low Quality Results
- Verify same embedding model for index and query
- Check vector dimensions match
- Ensure sufficient k value
- Consider hybrid search instead
Slow Queries
- Reduce k value
- Enable compression
- Use preFilter instead of postFilter
- Tune HNSW efSearch parameter
No Results
- Check filter conditions
- Verify vector field name
- Ensure index has vector data
- Remove threshold if set too high
Next Steps
Create Vector Index
Build a vector-enabled index
Hybrid Search
Combine with keyword search
Generate Embeddings
Create embeddings from content