# Semantic search

> Search that finds results by meaning, not by matching the exact words you typed.

- Level: Intermediate
- Topics: AI, Data
- URL: https://tidbit.legios.com.ar/semantic-search/
- In Spanish: [Búsqueda semántica](https://tidbit.legios.com.ar/es/semantic-search/)

Classic **keyword search** looks for the words you typed. Search a help center for "can't log in" and it may miss the article called "Reset your password". **Semantic search** looks for meaning instead: it recognizes that both are about the same problem and returns the article even though they share no words.

It works with embeddings. Every document, usually split into chunks of a few paragraphs, is turned by a model into a long list of numbers that captures what it is about, and stored, often in a vector database. When a query arrives it is turned into numbers the same way, and the search returns the chunks whose numbers are closest, typically measured with **cosine similarity**. Similar meaning, nearby numbers.

It is the retrieval step behind most RAG systems: before an LLM answers a question about a company's documents, semantic search finds the few passages worth reading. It also powers "similar products", search across languages and finding photos by description. Its weak spot is exact detail: product codes, rare names, error numbers. That is why many systems run **hybrid search**, mixing keyword and semantic results, and then reorder the top hits with a second model called a **reranker**.

## An analogy

A good librarian. You ask for "a book about someone stranded alone on an island" and she hands you Robinson Crusoe, even though you never said the title or the author.

## Keep in mind

- It matches meaning, so synonyms and paraphrases still find each other.
- Documents and queries become embeddings; the nearest ones win.
- It is the usual retrieval step inside RAG.
- It struggles with exact codes and names, hence hybrid search with keywords.

## Go deeper

- [Semantic search on Wikipedia](https://en.wikipedia.org/wiki/Semantic_search)
- [What is semantic search, and how does it work? (Google Cloud)](https://cloud.google.com/discover/what-is-semantic-search)
- [Semantic search (Sentence Transformers docs)](https://www.sbert.net/examples/sentence_transformer/applications/semantic-search/README.html)

## Related terms

- [Embeddings](https://tidbit.legios.com.ar/embeddings/): Turning words, images or documents into lists of numbers that capture meaning.
- [Vector database](https://tidbit.legios.com.ar/vector-database/): A database that finds things by similar meaning instead of exact matching words.
- [RAG](https://tidbit.legios.com.ar/rag/): Let the model look things up in your documents before it answers.
- [LLM](https://tidbit.legios.com.ar/llm/): A neural network trained on huge amounts of text to predict the next word.
