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

Semantic Search

Semantic search ranks documents and images by the meaning of a query instead of its exact words, using embeddings, nearest-neighbor search, and rerankers.

Semantic search ranks documents, images, or other items by how closely their meaning matches the meaning of a query, instead of by the words they share with it. A search for "my cat is hungry" can return a page titled "Feeding schedule for a new kitten" although the two share no words. Modern systems do this with embeddings: a neural encoder maps queries and items to vectors that sit close together when their meanings are similar, and vector search finds the nearest items. Web search moved in this direction in 2019, when Google began applying BERT to understand search queries, a change it said affected one in ten English-language searches in the US.

How Semantic Search Works#

Most semantic search systems retrieve with a bi-encoder and refine with a reranker. The bi-encoder embeds every document once, ahead of time, and the vectors go into a vector database. At query time only the query is embedded, and an approximate nearest-neighbor index returns the top candidates by cosine similarity. Sentence-BERT (2019) made this practical for sentences: finding the most similar pair among 10,000 sentences took about 65 hours with a BERT cross-encoder and about 5 seconds with its sentence embeddings. Dense Passage Retrieval (2020) then showed that learned embeddings beat BM25 keyword ranking by 9 to 19 points of top-20 passage retrieval accuracy on open-domain question answering. A cross-encoder reranker finally reads the query and each candidate together to reorder the short list more precisely.

This example compares word overlap with embedding similarity using the Sentence Transformers library:

from sentence_transformers import SentenceTransformer

model = SentenceTransformer("sentence-transformers/all-MiniLM-L6-v2")

documents = [
    "How to reset a forgotten account password",
    "Feeding schedule for a new kitten",
    "Quarterly sales report for the retail division",
    "Best hiking trails near Denver",
]
query = "my cat is hungry"

# Keyword search: documents sharing at least one word with the query
query_words = set(query.lower().split())
print("Keyword matches:", [d for d in documents if query_words & set(d.lower().split())])

# Semantic search: rank documents by cosine similarity of their embeddings
doc_embeddings = model.encode(documents)
query_embedding = model.encode(query)
scores = model.similarity(query_embedding, doc_embeddings)[0]
best = int(scores.argmax())
print(f"Semantic match: {documents[best]!r} (cosine {scores[best]:.2f})")

Keyword matching returns an empty list, because no document contains "my," "cat," "is," or "hungry." Semantic search returns the kitten feeding schedule with a cosine similarity of 0.56, the closest document in meaning.

  • Keyword search: Ranks documents by exact term matches with formulas such as BM25. It handles names, part numbers, and rare words that embeddings can blur, and misses synonyms and paraphrases.
  • Hybrid search: Runs keyword and semantic retrieval together and merges the results, a common setup in production search and RAG systems.
  • Semantic segmentation: An unrelated computer vision task that labels every pixel of an image with a class and shares only the word "semantic."
  • Semantic caching: Applies the same meaning-based matching to LLM requests, reusing a stored answer when a new prompt means the same as an earlier one.

Real-World Applications#

  • Retrieval-augmented generation (RAG): Finds the passages a language model needs, even when the user's wording differs from the documentation's.
  • Patent search: Surfaces prior art that describes the same invention in different terminology.
  • Retail product search: Matches a query such as "shoes for a rainy commute" with waterproof sneakers whose listings never use those words.
  • Recommendation systems: Suggest articles or products whose embeddings sit near those a user has already chosen.

Searching Images by Meaning#

Models trained with contrastive learning on image-caption pairs, such as CLIP, embed text and images into one space, so a text query can rank photos that carry no tags or captions. The Ultralytics semantic image search solution is built this way: its VisualAISearch class embeds every image in a folder with CLIP once, embeds each text query into the same space, and returns up to 30 images whose cosine similarity to the query passes a threshold, ranked from most to least similar. A query such as "a dog sitting on a bench" then finds matching photos in an unlabeled collection.

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