Inferensys

Glossary

Bi-Encoder

A neural architecture that independently encodes a query and a candidate passage or entity into dense vectors, enabling fast, scalable candidate retrieval via dot product scoring.
Developer working on RAG retrieval system, document chunks visible on screen, technical workspace with code editor.
NEURAL RETRIEVAL ARCHITECTURE

What is a Bi-Encoder?

A Bi-Encoder is a dual-tower neural architecture that independently encodes a query and a candidate document into separate dense vector representations, enabling efficient similarity computation via dot product for large-scale retrieval tasks.

A Bi-Encoder is a neural retrieval architecture consisting of two independent transformer encoders that map a query and a candidate passage into separate, fixed-size dense vector embeddings. Unlike a Cross-Encoder, which processes the concatenated query-document pair through full cross-attention, the Bi-Encoder encodes each input in isolation. This separation allows candidate document embeddings to be pre-computed and indexed offline in a vector database using FAISS or similar approximate nearest neighbor libraries. At inference time, only the query must be encoded, and retrieval reduces to a fast maximum inner product search between the query vector and the pre-indexed candidate vectors, making the architecture highly scalable to billions of documents.

Bi-Encoders are typically trained using contrastive representation learning with in-batch negatives, where a Siamese network structure shares weights between the two encoder towers. The training objective maximizes the similarity between a query and its relevant positive passage while minimizing similarity with irrelevant negatives within the same mini-batch. This architecture is foundational to modern Dense Passage Retrieval systems and serves as the efficient first-stage retriever in entity linking pipelines like BLINK, where it rapidly narrows a large knowledge base of millions of entities down to a manageable candidate set before a precise Cross-Encoder reranker performs final disambiguation.

Bi-Encoder Architecture

Key Architectural Features

The Bi-Encoder is a dual-tower neural architecture that independently encodes a text mention and a candidate entity into dense vector representations, enabling fast, scalable candidate retrieval via dot product scoring.

01

Dual-Tower Independence

The defining characteristic of a Bi-Encoder is its two separate encoders that process the mention and the entity independently. Unlike a Cross-Encoder, there is no cross-attention between the two inputs. The mention encoder (often a BERT-based model) maps the textual context to a dense vector, while the entity encoder maps the entity's title and description to a vector in the same shared embedding space. This independence is what enables pre-computation of all entity embeddings.

02

Pre-Computed Entity Index

Because the entity encoder operates independently, all candidate entity embeddings can be computed offline and indexed once. At inference time, only the mention needs to be encoded. This is the key to Bi-Encoder scalability:

  • Entity embeddings are stored in a vector index like FAISS
  • Indexes can hold millions or billions of entities
  • Retrieval is reduced to a fast approximate nearest neighbor (ANN) search
  • Index updates require only re-encoding new or changed entities
Millions
Entities Indexed
< 10ms
Retrieval Latency
03

Dot Product Scoring

Relevance between a mention and a candidate entity is computed as the dot product (or cosine similarity) between their respective embeddings. This is a lightweight, linear operation that scales efficiently:

  • score(m, e) = embedding(m) · embedding(e)
  • Enables fast top-k retrieval from massive indexes
  • Supports batching for processing multiple mentions simultaneously
  • The score represents semantic similarity in the shared latent space
04

Contrastive Training Objective

Bi-Encoders are trained using contrastive learning, typically with an in-batch negatives strategy. The model learns to pull the embedding of a mention close to its correct entity while pushing it away from all other entities in the batch:

  • Positive pairs: (mention, correct entity)
  • Negative pairs: (mention, all other entities in the batch)
  • Loss function: usually cross-entropy over the dot product scores
  • Hard negative mining improves discrimination of similar entities
05

Two-Stage Retrieval Pipeline

In production entity linking systems like BLINK, the Bi-Encoder serves as the first-stage retriever in a two-stage pipeline:

  • Stage 1 (Bi-Encoder): Fast recall — retrieves top-k candidates (e.g., k=100) from millions
  • Stage 2 (Cross-Encoder): Precision re-ranking — scores each candidate with full cross-attention
  • This architecture balances the speed of Bi-Encoders with the accuracy of Cross-Encoders
  • The Bi-Encoder's recall quality is critical; missed candidates cannot be recovered
06

Shared Embedding Space

Both the mention encoder and entity encoder must map their inputs into a common vector space where geometric proximity corresponds to semantic relatedness. Key design considerations:

  • Both encoders typically share the same base architecture (e.g., BERT-base)
  • The final representation is usually the [CLS] token embedding or mean pooling of all tokens
  • Dimensionality is fixed (commonly 768 or 1024)
  • The space is normalized so cosine similarity is meaningful
ARCHITECTURAL COMPARISON

Bi-Encoder vs. Cross-Encoder

A technical comparison of the two dominant neural architectures used in modern entity linking pipelines for candidate retrieval and final disambiguation.

FeatureBi-EncoderCross-Encoder

Encoding Mechanism

Encodes mention and candidate entity independently into separate dense vectors

Encodes the concatenated mention-candidate pair jointly through full cross-attention

Scoring Method

Dot product or cosine similarity between pre-computed vectors

Feed-forward classifier on top of the joint [CLS] representation

Inference Speed

< 1 ms per candidate

10-50 ms per candidate

Candidate Throughput

Millions of candidates per second (via FAISS/ANN)

Hundreds of candidates per second

Contextual Interaction

Pre-computable Entity Embeddings

Primary Pipeline Role

Fast first-stage candidate retrieval

Precise second-stage re-ranking

Typical Recall@100

95%

N/A (used for re-ranking top-k)

Precision@1

Moderate (70-85%)

High (85-95%)

BI-ENCODER ARCHITECTURE

Frequently Asked Questions

Explore the core mechanics, training methodologies, and production deployment strategies for Bi-Encoder models in entity linking and dense retrieval systems.

A Bi-Encoder is a neural network architecture that independently encodes two separate inputs—such as a textual mention and a candidate entity—into dense, fixed-dimensional vector representations using two distinct (or shared-weight) transformer models. The core mechanism involves passing the mention context through one encoder and the entity's title and description through another, producing mention embeddings and entity embeddings that are mapped into the same latent semantic space. A similarity metric, typically a dot product or cosine similarity, is then computed between these vectors to produce a relevance score. This dual-encoder design is fundamentally different from Cross-Encoders because it allows all entity embeddings to be pre-computed and indexed offline. At inference time, only the mention needs to be encoded, and the top-k candidates are retrieved via fast Approximate Nearest Neighbor (ANN) search using libraries like FAISS. This decoupling makes Bi-Encoders exceptionally scalable for tasks like entity linking over knowledge bases containing millions of entities, where real-time performance is critical.

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.