Ultralytics YOLO27: Join the waitlist.
License YOLO
Back to Ultralytics Glossary

Vector Search

Vector search finds the stored embeddings closest to a query vector, using exact k-NN or approximate indexes such as HNSW and IVF to search millions fast.

Vector search retrieves the items whose embeddings lie closest to a query embedding under a similarity measure such as cosine similarity, dot product, or Euclidean distance. An embedding model places items with similar meaning or appearance near each other, so the nearest vectors are the most similar documents, images, or products, even when they share no keywords with the query. Exact vector search is a k-nearest neighbors (k-NN) lookup over every stored vector. At scale, systems use approximate nearest neighbor (ANN) indexes that compare the query with a small fraction of the vectors and still return nearly all of the true neighbors.

How Vector Search Works#

The query and the stored items are embedded by the same model or by a pair trained together: a sentence encoder for text, CLIP for matching text to images, or a vision backbone for matching images to images. The metric should match how the model was trained. For unit-length vectors, cosine similarity equals the dot product, and ranking by Euclidean distance gives the same order. Exact search costs one comparison per stored vector for every query, which is fast for tens of thousands of vectors and too slow for hundreds of millions, so large systems use one of four families of ANN index:

  • Graph indexes such as HNSW: Link each vector to its near neighbors in a layered graph and answer a query by walking greedily toward it.
  • Clustering indexes (IVF): Group the vectors with k-means and scan only the clusters whose centroids are closest to the query.
  • Vector quantization: Compresses each vector to a few bytes, as in product quantization, so distances are approximated from compact codes held in memory.
  • Disk-based graphs: Keep a graph index on SSD, as DiskANN does, to search billions of vectors on a single machine.

The core idea of an IVF index fits in a short NumPy and scikit-learn example that compares it with exact search:

import numpy as np
from sklearn.cluster import KMeans

# 20,000 embeddings grouped by topic, normalized so a dot product is cosine similarity
rng = np.random.default_rng(0)
topics = rng.normal(size=(200, 64))
vectors = topics[rng.integers(200, size=20000)] + 0.5 * rng.normal(size=(20000, 64))
vectors /= np.linalg.norm(vectors, axis=1, keepdims=True)
query = vectors[0] + 0.1 * rng.normal(size=64)

# Exact search: score every stored vector
exact = np.argsort(-(vectors @ query))[:10]

# IVF index: cluster the vectors, then scan only the lists of the 5 closest centroids
kmeans = KMeans(n_clusters=100, n_init=1, random_state=0).fit(vectors)
probed = np.argsort(-(kmeans.cluster_centers_ @ query))[:5]
candidates = np.flatnonzero(np.isin(kmeans.labels_, probed))
approx = candidates[np.argsort(-(vectors[candidates] @ query))[:10]]

print(f"scanned {len(candidates) / len(vectors):.1%} of vectors")
print(f"recall@10: {len(set(exact) & set(approx)) / 10:.0%}")

Probing 5 of the 100 clusters scans 5.1% of the vectors and still finds all 10 true nearest neighbors, a recall@10 of 100%. Probing more clusters raises recall and cost together, which makes the number of probes the main setting to tune in an IVF index.

  • Keyword search: Looks up exact terms in an inverted index and ranks them with formulas such as BM25. It excels at names, codes, and rare words and misses synonyms.
  • Semantic search: Search by meaning, the goal that vector search most often serves. Semantic search systems often add query rewriting or a reranker on top.
  • Hybrid search: Runs keyword and vector search together and merges the two ranked lists.
  • Vector database: The system that stores vectors with metadata and serves vector search with filtering, updates, and persistence.

Real-World Applications#

Ultralytics Platform uses vector search to grow training datasets. Its Find Similar Images action takes a selected image, searches public datasets and the user's own and team datasets for the nearest images by embedding, and shows up to 24 matches with their similarity scores, which can be added to the dataset as unlabeled training images.

Explore solutions

Computer vision in sports

Computer vision in sports

Discover how Ultralytics YOLO powers sports vision with player and ball tracking, performance analytics, coaching insights, and athlete rehabilitation.
Learn more
Computer vision for aerial imagery

Computer vision for aerial imagery

Turn drone and aerial imagery into real-time insights for agriculture, aquaculture, conservation, and geospatial analysis with Ultralytics YOLO.
Learn more
Computer vision in aerospace

Computer vision in aerospace

Apply computer vision in aerospace with Ultralytics YOLO for aircraft inspection, runway FOD detection, airport ground operations, and composite defect detection.
Learn more
Computer vision in security

Computer vision in security

Protect every site with Ultralytics YOLO models. Vision AI powers perimeter monitoring, threat detection, license-plate recognition, and workplace safety.
Learn more
Computer vision in robotics

Computer vision in robotics

Power smarter machines with Ultralytics YOLO models. Vision AI in robotics drives autonomous navigation, perception, object tracking, and real-time control.
Learn more
Computer vision in logistics

Computer vision in logistics

Streamline logistics with Ultralytics YOLO models. Vision AI enables package inspection, sorting, vehicle tracking, and real-time warehouse safety monitoring.
Learn more
Computer vision in retail

Computer vision in retail

Reimagine retail with Ultralytics YOLO models. Vision AI powers inventory tracking, shelf monitoring, queue management, and smarter customer insights.
Learn more
Computer vision in healthcare

Computer vision in healthcare

Build healthcare solutions with Ultralytics YOLO models. Vision AI in healthcare powers faster medical imaging, smarter diagnostics, and patient monitoring.
Learn more
Computer vision in manufacturing

Computer vision in manufacturing

Optimize manufacturing with Ultralytics YOLO models. Vision AI drives quality control, defect detection, PPE compliance, and assembly line automation.
Learn more
Computer vision in automotive

Computer vision in automotive

Apply computer vision in automotive with Ultralytics YOLO models. Vision AI elevates road safety, driver assistance, and vehicle automation for smarter roads.
Learn more
Computer vision in agriculture

Computer vision in agriculture

Bring vision AI to smart agriculture with Ultralytics YOLO models. Power crop monitoring, livestock tracking, and precision farming for higher, smarter yields.
Learn more

Let's build the future of AI together!

Begin your journey with the future of machine learning