This post is a part of the DP-800: Developing AI-Enabled Database Solutions Exam Prep Hub.
This topic falls under these sections:
Implement AI capabilities in database solutions (25–30%)
--> Design and implement intelligent search
--> Choose between using ANN and ENN for vector search
Note that there are 10 practice questions (with answers) at the end of each section to help you solidify your knowledge of the material. Also, there are 4 practice tests with 30 questions each available from the hub's main page below the exam topics section.
Introduction
Vector search is the foundation of modern AI-powered applications such as Retrieval-Augmented Generation (RAG), semantic search, recommendation engines, document similarity, and intelligent assistants. As vector databases grow from thousands to millions of embeddings, selecting the appropriate search algorithm becomes increasingly important.
One of the most important architectural decisions is choosing between:
- Approximate Nearest Neighbor (ANN) search
- Exact Nearest Neighbor (ENN) search
Although both methods retrieve vectors that are similar to a query vector, they differ significantly in performance, scalability, accuracy, resource usage, and appropriate use cases.
For the DP-800 exam, candidates should understand when to use ANN versus ENN, how vector indexes influence each approach, and the trade-offs involved in balancing search speed with search accuracy.
Understanding Nearest Neighbor Search
Once embeddings have been generated for documents, products, images, or other data, a user query is also converted into an embedding.
The search engine must identify the vectors that are “closest” to the query vector.
Closeness is typically measured using:
- Cosine similarity
- Euclidean distance (L2)
- Dot product
The challenge becomes finding the nearest vectors efficiently.
If a database contains:
- 5,000 vectors
- 500,000 vectors
- 50 million vectors
the search strategy dramatically affects response time.
Exact Nearest Neighbor (ENN)
Exact Nearest Neighbor performs an exhaustive comparison.
Every stored vector is compared against the query vector.
The system computes the distance to every record before returning the closest matches.
Characteristics
- Searches every vector
- Produces mathematically exact results
- No approximation
- Highest accuracy
- Computationally expensive
- Slower as data grows
ENN Workflow
Query Vector↓Compare against Vector 1↓Compare against Vector 2↓Compare against Vector 3↓...↓Compare against Vector N↓Sort by similarity↓Return Top K
Advantages of ENN
Maximum Accuracy
Every possible vector is evaluated.
No relevant documents are skipped.
Deterministic Results
The same query always produces the same ranking.
No Index Approximation
Results represent the actual nearest neighbors.
Simpler Conceptually
The algorithm is straightforward.
No graph traversal or approximation heuristics are involved.
Disadvantages of ENN
Poor Scalability
Performance decreases linearly with dataset size.
Examples:
- 1,000 vectors → very fast
- 100,000 vectors → acceptable
- 10 million vectors → slow
- 100 million vectors → often impractical
High CPU Usage
Every query compares against every stored embedding.
Higher Latency
Search time increases as the vector collection grows.
Common ENN Use Cases
ENN is appropriate when:
- Maximum precision is required
- Dataset is relatively small
- Scientific applications require exact matches
- Benchmarking ANN algorithms
- Testing search quality
- Evaluation environments
Examples include:
- Medical research
- Financial analytics
- Legal document comparison
- Academic datasets
- Quality assurance testing
Approximate Nearest Neighbor (ANN)
Approximate Nearest Neighbor avoids comparing every vector.
Instead, it uses specialized vector indexes that intelligently narrow the search space.
The goal is to find vectors that are almost certainly among the nearest neighbors while dramatically improving search speed.
ANN typically achieves:
- 95–99.9% recall
- Much lower latency
- Massive scalability
ANN Workflow
Query Vector↓Search Vector Index↓Explore Nearby Candidates↓Evaluate Candidate Vectors↓Return Top K
Instead of examining millions of vectors, ANN may evaluate only a few hundred or a few thousand candidate vectors.
Advantages of ANN
Extremely Fast
ANN dramatically reduces search time.
Milliseconds instead of seconds.
Highly Scalable
Suitable for:
- Millions of vectors
- Tens of millions
- Hundreds of millions
- Billions of vectors
Lower Compute Costs
Fewer distance calculations are required.
Excellent User Experience
Ideal for interactive AI applications requiring real-time responses.
Production Ready
Nearly every modern AI search engine uses ANN.
Examples include:
- Azure AI Search
- Azure SQL vector indexes
- Azure Cosmos DB vector search
- Pinecone
- Milvus
- Weaviate
- Qdrant
- FAISS
- pgvector with ANN indexes
Disadvantages of ANN
Results Are Approximate
Occasionally, the true nearest neighbor may not be returned.
Instead, the algorithm returns vectors that are extremely close.
Slight Reduction in Recall
Typical recall values:
- 95%
- 98%
- 99%
depending on index configuration.
Index Maintenance
ANN requires building and maintaining vector indexes.
Additional Memory Usage
Indexes consume additional storage.
ANN vs ENN Comparison
| Feature | ENN | ANN |
|---|---|---|
| Accuracy | 100% | Nearly 100% |
| Speed | Slower | Much faster |
| Scalability | Poor | Excellent |
| Uses Vector Index | No | Yes |
| CPU Usage | High | Lower |
| Memory Usage | Lower | Higher |
| Best for Small Data | Yes | Sometimes |
| Best for Large Data | No | Yes |
| Typical Production Choice | Rare | Very Common |
Why ANN Is Usually Preferred
Most enterprise AI applications prioritize:
- Fast responses
- Interactive user experiences
- Large knowledge bases
- Millions of documents
Waiting several seconds for every search is unacceptable.
Therefore, ANN has become the industry standard for production semantic search.
For example:
A chatbot searching:
- 8 million support articles
cannot realistically compare every embedding.
Instead, ANN rapidly narrows the candidate set before computing exact similarity among only the most promising vectors.
Recall vs Accuracy
One of the most important concepts is recall.
Recall measures how many of the true nearest neighbors are successfully returned.
Example:
Suppose the true Top 10 neighbors are:
ABCDEFGHIJ
An ANN search returns:
ABCDEFGHIK
Recall is:
9 / 10 = 90%
Although one neighbor is missing, the results are still highly useful for most AI applications.
Many ANN algorithms achieve recall rates above 99%.
Popular ANN Algorithms
Several indexing algorithms support ANN search.
Common examples include:
HNSW (Hierarchical Navigable Small World)
Most common modern ANN algorithm.
Advantages:
- Very fast
- Excellent recall
- High-quality results
- Widely used
IVF (Inverted File Index)
Partitions vectors into clusters.
Search examines only relevant clusters.
Good for extremely large datasets.
DiskANN
Optimized for very large vector collections stored partly on disk.
Designed for cloud-scale systems.
Product Quantization (PQ)
Compresses vectors to reduce memory usage.
Often combined with IVF.
Choosing Between ANN and ENN
Choose ENN When
- Dataset is small
- Exact results are mandatory
- Benchmarking search quality
- Scientific analysis
- Compliance requires deterministic behavior
- Testing vector models
Choose ANN When
- Dataset contains millions of vectors
- Response time matters
- Building chatbots
- Implementing RAG
- Semantic document search
- Recommendation systems
- AI copilots
- Enterprise knowledge bases
ANN in Azure SQL
Azure SQL’s vector search capabilities are designed to support scalable semantic search workloads.
When vector indexes are implemented, Azure SQL can perform ANN searches efficiently, making it practical to query very large embedding collections while maintaining excellent recall.
This enables AI-powered applications to combine:
- Relational filtering
- Vector similarity
- SQL queries
- AI inference
within a single database platform.
ANN and Hybrid Search
Many production applications combine ANN with traditional filtering.
Example:
A company stores:
- 20 million product embeddings
A customer searches:
“Wireless ergonomic keyboard”
The query first filters:
Category = ElectronicsBrand = MicrosoftPrice < $150
Then ANN searches only the filtered candidate vectors.
This combination improves:
- Speed
- Relevance
- Scalability
DP-800 Exam Tips
- Understand that ENN performs exhaustive comparisons, while ANN uses vector indexes to accelerate nearest-neighbor retrieval.
- Remember that ANN trades a small amount of accuracy for significant gains in performance and scalability, making it the preferred option for production AI systems.
- Be familiar with HNSW, IVF, and other ANN indexing techniques at a conceptual level.
- Know that ENN is appropriate for small datasets, benchmarking, and scenarios requiring mathematically exact results.
- Expect scenario-based questions asking which approach is best based on dataset size, latency requirements, scalability, and accuracy expectations.
- Recognize that ANN is the default choice for RAG systems, semantic search, recommendation engines, AI assistants, and enterprise knowledge bases containing millions of embeddings.
Practice Exam Questions
Question 1
A company has built a Retrieval-Augmented Generation (RAG) solution that searches through 50 million document embeddings. Users expect responses within two seconds. Which vector search approach is the most appropriate?
A. Exact Nearest Neighbor (ENN) because it guarantees mathematically exact results for every query
B. Approximate Nearest Neighbor (ANN) because it provides low-latency searches while maintaining high recall
C. Sequential table scans because they avoid maintaining vector indexes
D. Full-text search because embeddings are not required for semantic search
Correct Answer: B
Explanation: ANN is specifically designed for large-scale vector datasets where fast response times are essential. It dramatically reduces search latency while maintaining very high recall, making it ideal for production RAG systems.
Question 2
A research laboratory is validating a new embedding model and requires every query to return the mathematically closest vectors with no approximation. Which search method should be used?
A. Hybrid search
B. Hierarchical Navigable Small World (HNSW)
C. Exact Nearest Neighbor (ENN)
D. Approximate Nearest Neighbor (ANN)
Correct Answer: C
Explanation: ENN compares the query vector against every stored vector, guaranteeing exact nearest-neighbor results. This makes it appropriate for benchmarking, scientific validation, and testing.
Question 3
What is the primary advantage of Approximate Nearest Neighbor (ANN) search over Exact Nearest Neighbor (ENN) search?
A. ANN always returns more accurate results.
B. ANN eliminates the need for vector embeddings.
C. ANN significantly improves search performance and scalability by reducing the number of vectors evaluated.
D. ANN only works with relational databases.
Correct Answer: C
Explanation: ANN achieves much faster searches by using specialized vector indexes to evaluate only the most promising candidate vectors instead of comparing every vector.
Question 4
A database contains approximately 2,500 embeddings used by a legal review application where accuracy is more important than response time. Which search strategy is most appropriate?
A. Approximate Nearest Neighbor (ANN)
B. Hybrid search
C. Semantic ranking
D. Exact Nearest Neighbor (ENN)
Correct Answer: D
Explanation: With a relatively small dataset and strict accuracy requirements, ENN is preferred because it guarantees exact nearest-neighbor results.
Question 5
Which statement best describes the concept of recall in Approximate Nearest Neighbor search?
A. It measures how quickly a query completes.
B. It measures the percentage of true nearest neighbors successfully returned.
C. It measures the amount of memory consumed by the vector index.
D. It measures the total number of vectors stored.
Correct Answer: B
Explanation: Recall measures how many of the actual nearest neighbors are retrieved by the ANN algorithm. Higher recall indicates results that more closely match those of an exact search.
Question 6
Which indexing algorithm is most commonly associated with modern ANN implementations due to its excellent balance of speed and recall?
A. HNSW (Hierarchical Navigable Small World)
B. B-tree
C. Hash index
D. Clustered columnstore index
Correct Answer: A
Explanation: HNSW is one of the most widely used ANN algorithms because it provides fast searches with excellent recall for large vector datasets.
Question 7
A development team notices that vector search performance decreases as the database grows from thousands to tens of millions of embeddings. Which architectural change is most likely to improve scalability?
A. Replace vector embeddings with keyword indexes.
B. Use ENN for every query.
C. Disable vector indexes.
D. Implement ANN with an appropriate vector index.
Correct Answer: D
Explanation: ANN combined with vector indexes is specifically designed to scale efficiently to millions or even billions of embeddings while maintaining acceptable accuracy.
Question 8
Which characteristic is typically associated with Exact Nearest Neighbor (ENN) search?
A. Uses approximation techniques to improve performance.
B. Compares only a subset of candidate vectors.
C. Performs exhaustive comparisons against every stored vector.
D. Requires HNSW indexing.
Correct Answer: C
Explanation: ENN performs a complete comparison against all stored vectors, ensuring mathematically exact results but requiring significantly more computation.
Question 9
An AI-powered product recommendation system serves millions of users each day. The recommendation engine must respond in milliseconds while maintaining highly relevant results. Which approach best meets these requirements?
A. Exact Nearest Neighbor (ENN)
B. Sequential vector scans
C. ANN using vector indexes
D. Full-table scans followed by sorting
Correct Answer: C
Explanation: ANN is optimized for production AI workloads that require low latency and high scalability while maintaining high-quality semantic search results.
Question 10
Which statement best summarizes the trade-off between ANN and ENN?
A. ENN sacrifices accuracy for better scalability.
B. ANN always returns identical results to ENN.
C. ENN requires vector indexes while ANN does not.
D. ANN slightly reduces accuracy in exchange for dramatically improved search performance and scalability.
Correct Answer: D
Explanation: The primary trade-off is that ANN accepts a small reduction in accuracy (typically maintaining 95–99%+ recall) to achieve significantly faster query performance and support very large datasets.
Go to the DP-800 Exam Prep Hub main page
