In applications such as personalized recommendations and scientific research, accurately identifying the closest data points to a given query is crucial. Traditional methods like Approximate Nearest Neighbor (ANN) search offer faster retrieval times by approximating results but may sacrifice accuracy, leading to potential errors in scenarios where precision is essential. This trade-off between speed and accuracy poses a significant challenge when exact results are necessary.
Exact Vector Search (ENN) is a search method that compares your input vector to every single vector in the dataset to find the closest matches. It’s the most accurate way to find nearest neighbors because it doesn’t skip any candidates. In vCore-based Azure Cosmos DB for MongoDB, ENN is supported as part of the vector search capabilities for no additional cost. It allows you to run high-precision searches across your vector-indexed collections without needing to rebuild existing indexes.
ANN vs ENN: What’s the Difference?
Feature | ANN (Approximate) | ENN (Exact) |
---|---|---|
Speed (on large dataset) | Fast | Slower |
Accuracy | Close (not always 100%) | Always correct |
Scales well? | Yes (great for millions of vectors) | Only if data is small or filtered |
When to Use ENN
You should use Exact Vector Search when:
- You need perfect accuracy — e.g., in recommendations, scientific work, legal/financial scenarios.
- You have a small dataset — or performance isn’t a concern.
- You’re using filters that return a small subset of data — even in big datasets!
Practical Example: Why ENN Can Be the Better Choice?
A customer was working with ~300K documents across thousands of tenants (using tenant_id
). They originally used ANN vector search with a tenant_id
filter but ran into slow query performance and inconsistent accuracy.
After switching to Exact Nearest Neighbor (ENN) search with the same filter, they saw:
-
50× faster query performance
-
100% accuracy in nearest neighbor results
The reason? Each tenant only had a few thousand documents, and ANN indexing isn’t as efficient on small-filtered subsets. ENN, by scanning all candidates in the filtered set, delivered better results without any index changes—just by setting "exact": true
in the query.
How to Use It
​Before using ENN vector search in vCore-based Azure Cosmos DB for MongoDB, ensure that a vector index is created for the target field, similar to the setup for ANN searches. If you already have an existing vector index, you don’t need to rebuild your vector index — just flip a switch in your query:
{
"$search": {
"cosmosSearch": {
"path": "myVectorField",
"exact": true, // Enables ENN
"query": [0.2, 0.4, 0.9], // Query vector
"k": 10, // Number of results to return
"filter": {
"tenant_id": { "$eq": "tenant123" }
}
}
}
}
Conclusion
- Use ENNÂ when you need perfect accuracy, or when you’re searching in a small or filtered set of vectors.
- Use ANNÂ for large-scale, fast searches where approximate matches are good enough.
- You enable ENN by setting
"exact": true
in your query. No index rebuild needed.
Leave a review
Tell us about your Azure Cosmos DB experience! Leave a review on PeerSpot and we’ll gift you $50. Get started here.
About Azure Cosmos DB
Azure Cosmos DB is a fully managed and serverless NoSQL and vector database for modern app development, including AI applications. With its SLA-backed speed and availability as well as instant dynamic scalability, it is ideal for real-time NoSQL and MongoDB applications that require high performance and distributed computing over massive volumes of NoSQL and vector data.
Try Azure Cosmos DB for free here. To stay in the loop on Azure Cosmos DB updates, follow us on X, YouTube, and LinkedIn.
0 comments
Be the first to start the discussion.