liveBook · Manning

Embedding-based retrieval

As explained in AI-Powered Search

A bi-encoder is a model that independently encodes two inputs, such as a query and a document, into separate embeddings for comparison.

Embedding-based retrieval represents a query and each document as separate embeddings, then compares those vectors—often with cosine similarity—to produce a relevance score. This architecture is called a bi-encoder because it encodes the two inputs independently. section 13.8

A typical dense-retrieval pipeline separates matching into these stages:

  • Encode queries and documents independently into vectors. section 13.8
  • Compare the query vector with document vectors using a similarity function such as cosine similarity. section 13.8
  • Use approximate nearest-neighbor search to filter toward similar vectors before expensive similarity calculations. section 13.9
  • Combine retrieval optimizations such as ANN search, quantization, Matryoshka Representation Learning embeddings, over-requesting, and reranking. section 13.9

Why independent encoding can miss nuance

For the query “mountain hike,” a bi-encoder may retrieve “first time snow hiking” because both concern hiking. A cross-encoder reads the query and document together, allowing attention to distinguish beginner snow hiking from the more specific mountain-hike intent. In practice, bi-encoders support high-volume retrieval, while cross-encoders can rerank a smaller result set with more computation. section 13.8 section 13.9

Figure 13.14 Bi-encoders vs. cross-encoders. Bi-encoders process query and document inputs separately, whereas cross-encoders process them together into a similarity score.
figure

Compare the two architectures visually: bi-encoders process query and document inputs separately, while cross-encoders process them together. section 13.8

How AI-Powered Search covers it

How deep it goes
Explains independent encoding, cosine scoring, ANN acceleration, and cross-encoder trade-offs without detailing encoder internals.
Examples
Uses “mountain hike” retrieval and “first time snow hiking” as a concrete relevance comparison.
What it assumes
Assumes familiarity with queries, documents, embeddings, vectors, and similarity scores.
What you can do after
Apply bi-encoder retrieval to support high-volume matching and combine it with reranking for more nuanced results.
How it connects
Connects embeddings, semantic search, cosine similarity, approximate nearest-neighbor search, and cross-encoders.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of AI-Powered Search. The section links point to the parts of the book it draws on.