Inferensys

Glossary

Bi-Encoder

A dual-encoder architecture that independently encodes queries and documents into dense vectors, enabling fast maximum inner product search for retrieval.
Stylish WeWork-like workspace with hot desks and document wall, professional searching through enterprise knowledge base on a mounted ultrawide display, warm industrial pendants overhead.
DUAL-ENCODER ARCHITECTURE

What is Bi-Encoder?

A bi-encoder is a neural retrieval architecture that independently encodes queries and documents into dense vectors, enabling fast maximum inner product search for semantic matching.

A bi-encoder is a dual-encoder architecture that independently maps queries and documents into a shared embedding space using two separate transformer models. Unlike a cross-encoder, which processes the query-document pair jointly through full self-attention, the bi-encoder computes representations in isolation. This decoupling allows document embeddings to be pre-computed and indexed offline, while only the query must be encoded at runtime, enabling sub-linear retrieval over millions of passages via Maximum Inner Product Search (MIPS).

Training relies on contrastive loss functions that pull relevant query-document pairs together while pushing in-batch negatives and hard negatives apart. The architecture is foundational to Dense Passage Retrieval (DPR) and is often improved through cross-encoder distillation, where a slower but more accurate teacher model transfers its relevance scoring knowledge to the fast bi-encoder student. The resulting query embedding and passage embedding vectors are compared using cosine similarity or dot product, making bi-encoders the standard for scalable, first-stage semantic retrieval pipelines.

ARCHITECTURAL PRINCIPLES

Key Characteristics of Bi-Encoders

Bi-encoders are defined by a specific set of architectural and operational characteristics that distinguish them from other neural retrieval models. These principles enable their signature speed and scalability.

01

Dual-Tower Independence

The defining feature: a bi-encoder uses two separate, independently parameterized encoders—one for the query and one for the document. This allows documents to be encoded offline and stored in a vector index. At query time, only the query needs to be encoded, enabling sub-linear search times.

  • Query Encoder: Processes the user's search query.
  • Document Encoder: Processes all passages in the corpus, typically as a batch preprocessing step.
02

Late Semantic Binding

Unlike a cross-encoder, a bi-encoder defers all interaction between the query and the document until the final scoring step. The two texts are encoded into dense vectors completely independently. Their semantic relationship is then computed as a single, fast mathematical operation—typically cosine similarity or a dot product—on the resulting fixed-size embeddings.

03

Pooling Strategy

A transformer model outputs a vector for every input token. To create a single, fixed-size passage embedding, a pooling strategy must be applied. The choice of strategy significantly impacts retrieval quality.

  • Mean Pooling: Averages all token vectors; provides a stable, general-purpose representation.
  • [CLS] Token: Uses the output vector of the special classification token; its effectiveness depends on how the model was pre-trained.
  • Max Pooling: Takes the maximum value over time for each dimension.
04

Maximum Inner Product Search (MIPS)

Bi-encoders are architected specifically for MIPS. Because the query and document are independent vectors, the retrieval task is reduced to finding the document vectors that maximize the dot product with the query vector. This mathematical equivalence allows the use of highly optimized Approximate Nearest Neighbor (ANN) libraries like FAISS, which can search billion-scale vector indexes in milliseconds.

05

Asymmetric Model Architecture

The query and document encoders do not need to share weights. This asymmetric design allows for optimization. A common pattern is to use a deeper, more powerful model for the shorter query and a slightly shallower, faster model for encoding the massive document corpus. This balances the need for a nuanced query understanding with the computational cost of indexing millions of passages.

06

Contrastive Training Paradigm

Bi-encoders are trained using contrastive loss functions. The model learns by pulling the embeddings of a query and its relevant document closer together in the vector space while simultaneously pushing irrelevant documents apart. Key training techniques include:

  • In-Batch Negatives: Reusing other positive documents in the mini-batch as negative examples for free.
  • Hard Negatives: Using passages that are top-ranked by a sparse retriever (like BM25) but are not relevant, forcing the model to learn fine-grained distinctions.
ARCHITECTURAL COMPARISON

Bi-Encoder vs. Cross-Encoder

A technical comparison of the dual-tower Bi-Encoder and the joint-attention Cross-Encoder architectures for semantic retrieval and scoring.

FeatureBi-EncoderCross-EncoderLate Interaction

Encoding Strategy

Queries and documents encoded independently

Query-document pair processed jointly through full self-attention

Token-level embeddings stored; partial computation at query time

Inference Speed

< 10 ms per query

1000 ms per query

~50-200 ms per query

Indexability

Pre-computed Document Embeddings

Suitable for Retrieval (Recall)

Suitable for Re-ranking (Precision)

Attention Mechanism

Self-attention within query and document separately

Full cross-attention between all query and document tokens

MaxSim operation over token-level embeddings

Memory Footprint

Low: single vector per document

High: requires full model inference per pair

Medium: multiple vectors per document

PRODUCTION ARCHITECTURES

Real-World Bi-Encoder Implementations

Bi-encoders power the first stage of modern retrieval pipelines. These implementations demonstrate how independent query and document encoding enables sub-100ms search across billion-scale corpora.

01

Facebook AI's Dense Passage Retrieval (DPR)

The canonical bi-encoder implementation that demonstrated dense retrieval outperforming BM25 for open-domain QA. DPR uses two independent BERT encoders—one for queries, one for passages—trained with in-batch negatives and a contrastive loss function. The system encodes all Wikipedia passages offline into a FAISS index, then performs Maximum Inner Product Search (MIPS) at query time.

  • Query encoder and passage encoder share no parameters
  • Trained on question-passage pairs with hard negatives mined via BM25
  • Achieves 79.4% top-20 accuracy on Natural Questions
  • Indexes 21 million passages for sub-second retrieval
21M+
Passages Indexed
79.4%
Top-20 Accuracy
02

Sentence-BERT (SBERT)

A practical bi-encoder adaptation that makes BERT viable for semantic similarity search by adding a mean pooling layer on top of token embeddings. Unlike vanilla BERT—which requires both sentences fed together and is too slow for retrieval—SBERT encodes sentences independently into fixed-size vectors. These vectors can be compared using cosine similarity and indexed in vector databases.

  • Siamese network structure with tied weights for symmetric tasks
  • Supports classification, regression, and triplet objective functions
  • Reduces finding the most similar sentence pair from 65 hours to ~5 seconds
  • Pre-trained models available via the sentence-transformers library
~5 sec
10K Pair Comparison
65 hrs
Vanilla BERT Time
03

ColBERT's Late Interaction

A bi-encoder variant that stores token-level embeddings rather than a single pooled vector. ColBERT encodes queries and documents into sets of vectors, then computes relevance via a MaxSim operation—summing the maximum cosine similarity for each query token against all document tokens. This preserves fine-grained lexical matching while retaining the indexing speed of a bi-encoder.

  • Multi-vector encoding: each token gets its own embedding
  • Late interaction defers cross-attention to a lightweight scoring step
  • Achieves strong zero-shot retrieval without task-specific fine-tuning
  • Used in production by companies requiring high-recall semantic search
Token-Level
Encoding Granularity
04

OpenAI's Embeddings API

A hosted bi-encoder service where the text-embedding-3-large model encodes text into vectors of up to 3,072 dimensions. The encoder processes input independently, allowing users to pre-compute document embeddings and store them in vector databases like Pinecone or Weaviate. Query embeddings are generated on-the-fly and compared via cosine similarity.

  • Supports truncation to smaller dimensions (256, 512, 1024) with minimal accuracy loss
  • Matryoshka representation learning enables flexible dimensionality
  • Powers retrieval-augmented generation (RAG) across thousands of applications
  • Stateless encoder design: no shared parameters between query and document passes
3,072
Max Dimensions
< 100ms
Encoding Latency
05

Jina AI's Jina Embeddings v2

A multilingual bi-encoder supporting 8K token context windows—far exceeding the typical 512-token limit. Jina Embeddings v2 encodes documents up to ~8,000 tokens into a single dense vector using mean pooling with position-aware attention. This eliminates the need for aggressive chunking and enables long-document semantic search.

  • Supports English, Chinese, German, and Spanish in a single model
  • 8,192 token context window for encoding full articles or legal documents
  • Outputs 768-dimensional embeddings compatible with any vector database
  • Open-source under Apache 2.0 license
8,192
Token Context Window
4
Languages Supported
06

Cohere's Embed v3

A bi-encoder designed for enterprise retrieval with native support for semantic chunking and input type specification. Embed v3 accepts a input_type parameter (search_document, search_query, classification, clustering) that adjusts encoding behavior. For search, the query and document encoders operate asymmetrically, optimizing the embedding space for retrieval rather than symmetric similarity.

  • Asymmetric encoding tuned specifically for query-document relevance
  • Compression-aware training maintains accuracy even with binary quantization
  • Supports 100+ languages with strong cross-lingual retrieval
  • Integrates with major vector databases via standardized API
100+
Languages
Asymmetric
Encoding Mode
BI-ENCODER ARCHITECTURE

Frequently Asked Questions

Clear, technical answers to the most common questions about dual-encoder architectures, their training dynamics, and their role in modern semantic search pipelines.

A bi-encoder is a neural retrieval architecture that independently encodes queries and documents into dense vector representations using two separate transformer models, enabling fast semantic similarity search via Maximum Inner Product Search (MIPS). The architecture maps semantically related text to proximate points in a shared embedding space, where relevance is computed as the cosine similarity or dot product between the query vector and document vectors. Unlike cross-encoders that process query-document pairs jointly with full attention, bi-encoders pre-compute document embeddings offline, making them ideal for large-scale retrieval where latency is critical. The query encoder and document encoder can share weights or be independently parameterized, with the latter being standard in Dense Passage Retrieval (DPR) setups to allow domain-specific optimization of each tower.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.