Course contentsShow
← Machine Learning and Deep Learning
Lesson 1951 of 3,53842. Retrieval-Augmented Generation: FoundationsFree lesson

Embedding Models: Bi-Encoders for Retrieval

Understanding how bi-encoder models separately encode queries and documents for efficient similarity search.

Embedding Models: Bi-Encoders for Retrieval

What you'll learn: How bi-encoder models separately encode queries and documents to enable fast, scalable similarity search in RAG systems.

The Core Idea

A bi-encoder is an embedding model architecture that uses two independent neural networks (or the same network twice) to convert text into dense vector representations. One encoder processes your query, another processes documents in your knowledge base. The magic: once documents are encoded offline, you only need to encode new queries at runtime, making retrieval lightning-fast.

Think of it like a library cataloging system. Instead of reading every book when a patron asks a question, librarians pre-assign category codes to books (document encoding). When someone asks a question, they translate it into the same coding system (query encoding), then quickly find matching books by comparing codes—no re-reading required.

How It Works

In the indexing phase, the document encoder transforms each text chunk into a fixed-size vector (e.g., 768 or 1024 dimensions). These embeddings are stored in a vector database.

During the retrieval phase, the query encoder transforms your search query into the same vector space. You then compute similarity (typically cosine similarity or dot product) between the query vector and all document vectors to find the most relevant matches.

The key advantage: pre-computed document embeddings. You encode millions of documents once, then answer thousands of queries with just one encoding operation per query plus fast vector math.

Key Takeaway: Bi-encoders enable efficient RAG retrieval by separately encoding queries and documents into a shared vector space, allowing pre-computation of document embeddings and fast similarity search at query time.