Cosmos DB for NoSQL top-five vector similarity query
Short answer
D Limit the query to five results with TOP 5 while ordering by VectorDistance on the embedding property to return the nearest documents.
Question
Key Takeaways
Azure Cosmos DB for NoSQL vector search ranks documents with VectorDistance and returns the nearest matches by bounding the result set. The correct choice, option D, is to limit the number of results, typically with TOP 5 after ordering by vector distance; offset pagination, strong consistency, and grouping do not produce the five closest documents.
Expert Analysis
To retrieve the five most similar documents from Azure Cosmos DB for NoSQL using vector search, you must limit the number of results. When performing vector similarity searches with the VectorDistance function, you restrict the output size directly in the query. Offset pagination, strong consistency, and grouping by embedding value do not control the top-N result count.
The retrieval requirement is to rank documents by closeness between the stored embedding property and an input vector, then keep only the closest five. In Cosmos DB for NoSQL that is expressed as a scoring expression plus a row bound. VectorDistance(c.embedding, @inputEmbedding) computes the distance for each candidate document, while the number five must become a result-count restriction. Option D is the only choice that names that restriction; without it, the query can return every document that has an embedding, even if each row carries a distance score.
The mechanism that makes the row bound meaningful is the vector ordering. For the five returned rows to be the five most similar documents, the query must sort by the same distance expression, as in SELECT TOP 5 c.id FROM c ORDER BY VectorDistance(c.embedding, @inputEmbedding). VectorDistance supplies the score, ORDER BY determines which rows are nearest, and TOP 5 truncates the ordered result to five. If TOP 5 were applied without the vector ordering, it would return five arbitrary documents; if the distance were projected without ordering and truncation, it would return scores for a larger set. The top-N semantics come from combining the ranking and the cutoff, and Option D supplies the cutoff.
Option A — offset pagination. Offset pagination is a way to skip rows and take a later slice of an ordered result. OFFSET 0 LIMIT 5 may look superficially similar to a top-five request, but the option describes a paging technique, not the ranking-and-cutoff operation that defines nearest neighbours. Pagination is useful for continuing through results; it does not by itself establish which documents are closest to the input embedding. The five most similar documents are obtained by ordering on VectorDistance and bounding the output, so the pagination option misses the decisive operation.
Option B — strong consistency. Strong consistency changes the read guarantee for replicated data: it ensures a read sees the latest committed write. It does not compute the distance between embedding values, order documents by similarity, or stop after five matches. A strongly consistent query can still return every document in the container, so consistency cannot satisfy the top-five requirement.
Option C — group by embedding value. Grouping by embedding is an aggregation over identical vectors. Similarity search needs a per-document distance from the input embedding; grouping would collapse documents that share a vector and would not rank groups by closeness to the supplied vector. It answers a different question—how documents cluster by exact embedding value—rather than which five individual documents are nearest.
Option D — limit the number of results. Limiting the result count directly enforces the five-document cap. In Cosmos DB for NoSQL, the concrete form is TOP 5 placed on the vector query that is ordered by VectorDistance. That combination returns the requested nearest-neighbour set with a bounded response, which is exactly what the retrieval step requires. The quantity "five" in the requirement maps to the option that truncates rows, while the phrase "most similar" maps to the required vector-distance ordering.
Official Reference
- https://learn.microsoft.com/en-us/azure/cosmos-db/nosql/vector-search
- https://learn.microsoft.com/en-us/azure/cosmos-db/nosql/query/vectordistance
These links open the official vendor documentation in a new tab.
Exam Strategy
With Cosmos DB vector search, separate the ranking from the row count: the nearest documents come from ORDER BY VectorDistance(...), and the requested number comes from TOP. When an option names consistency, grouping, or paging instead of a result-count bound, eliminate it because those settings cannot express “five closest”. Map the quantity in the stem to the only option that truncates rows.
Related Analysis
Practice All AI-200 Questions
Access 69 questions with complete answers and detailed explanations.
View Full AI-200 Practice Test →