liveBook · Manning

Similarity search

As explained in Build an Advanced RAG Application (From Scratch)

Information retrieval is the process of finding relevant information from a collection of documents or other stored data in response to a query.

Conceptual search retrieves relevant information by matching a query against a stored collection of documents, pages, articles, or other data. A retrieval system indexes content, stores documents and indexes for fast lookup, accepts queries, and returns matches ranked by relevance. It underpins web search, enterprise search, legal e-discovery, and library catalogs. section 3.0

Semantic search is a conceptual-search approach that aims to match intent and contextual meaning rather than only exact query terms. A query for “dog” can retrieve material about puppies, canines, and pets because text is represented as vectors and compared by similarity. This can surface relevant content when the query and document do not share the same words. section 3.3 section 3.5

A practical semantic-search pipeline works as follows:

  • Choose and prepare the searchable documents; hotel reviews can be treated as individual documents. section 4.1
  • Encode documents into dense embeddings that represent semantic meaning, then retain them for later comparison. section 4.2.1
  • Encode the user query and rank document vectors with a similarity or distance metric such as cosine similarity or Euclidean distance. section 4.6
  • Use a vector index such as FAISS to search embeddings efficiently, especially as the collection grows. section 4.6

Hotel preference search

For “Hotel with a view of the Eiffel Tower,” encode the query, search a FAISS index of Paris hotel-review embeddings, and return the top-ranked reviews with hotel names and similarity scores. Retrieving more reviews can provide a broader, less outlier-driven basis for grouping and ranking hotels. section 6.1 section 4.5

Conceptual similarity alone does not establish that a result is appropriate. In multi-domain collections, semantically related text may still come from the wrong domain, lack authority, or be stale. Route queries to suitable retrieval backends when domain boundaries and source suitability matter. section 7.2

In retrieval-augmented generation, retrieval supplies external context before response generation. The retrieved candidates are integrated with the original input so an LLM can produce a more informed, contextually relevant answer; retrieval itself does not guarantee that the information is reliable. section 1.2

How Build an Advanced RAG Application (From Scratch) covers it

How deep it goes
Builds a semantic search pipeline from document loading through embeddings, similarity ranking, FAISS search, and result aggregation.
Examples
Uses Paris hotel reviews to answer free-form requests such as hotels with Eiffel Tower views.
What it assumes
Introduces vectors as numeric representations before using Sentence Transformers, similarity metrics, and FAISS.
What you can do after
Build it from scratch with document embeddings, similarity metrics, and a FAISS index that returns ranked results.
How it connects
Connects information retrieval with keyword search, embeddings, cosine similarity, FAISS, retrieval-augmented generation, and agentic routing.

Also explained in

Compare how 37 books explain similarity search →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build an Advanced RAG Application (From Scratch). The section links point to the parts of the book it draws on.