# Nearest Neighbor Search

> Finding the stored vectors closest to the one you ask with.

**Field:** Artificial Intelligence  
**Category:** Retrieval & Search  
**Also known as:** k-Nearest Neighbor Search, k-NN Search, Vector Search

## Think of it like

Think of it like you look on a map for the three homes near yours.

## Definition

Nearest neighbor search finds the stored vectors that are closest to a query vector. You ask for the top k, such as the 5 or 10 closest. Closeness is measured with a score like cosine similarity. The exact way checks every stored vector, which is fine for thousands but slow for millions. That is why large systems use approximate methods instead.

## Example

Jack's app turns a question into a vector and asks for the 5 nearest neighbors among 20,000 product pages. Those 5 pages are the results.

## Why it matters

It is the core step of every vector search. Everything else is about doing it faster or better.

## Common mistake

Asking for too few results. If the right page is 6th and you take 5, the model never sees it.

## Three principles

- **Closest to the query.** By a score.
- **Top k.** Like the best 5.
- **Exact is slow at scale.** Checks every vector.

## Related terms

- [Approximate Nearest Neighbor (ANN)](https://learn.benibix.com/term/ai/approximate-nearest-neighbor)
- [Cosine Similarity](https://learn.benibix.com/term/ai/cosine-similarity)
- [Vector Database](https://learn.benibix.com/term/ai/vector-database)
- [Embedding (AI)](https://learn.benibix.com/term/ai/embedding)

![A cloud of points with a star for the question. A circle around the star takes in the three closest points, which are the results.](https://learn.benibix.com/diagrams/rt-nearest-neighbors.svg)

---

Source: https://learn.benibix.com/term/ai/nearest-neighbor-search
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-18
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
