Inferensys

Glossary

Bi-Encoder Architecture

A dual-tower neural network that independently encodes a text mention and a knowledge base entity into dense vectors for efficient, scalable semantic similarity search.
Knowledge engineer constructing knowledge base on laptop, document hierarchy visible, casual office setup.
DUAL-TOWER NEURAL RETRIEVAL

What is Bi-Encoder Architecture?

A foundational neural design for efficient, large-scale semantic search that independently encodes queries and documents into a shared dense vector space.

A Bi-Encoder Architecture is a neural network design featuring two independent encoder towers that map a text mention and a knowledge base entity into separate dense vector representations for efficient semantic similarity search. Unlike cross-encoders, the two inputs are processed in isolation, allowing the computationally expensive entity encoding to be performed offline and indexed for rapid retrieval at inference time.

During training, the architecture uses a contrastive learning objective to pull the vector representations of correct mention-entity pairs together while pushing incorrect pairs apart in the shared embedding space. At inference, the mention is encoded in real-time, and the most similar pre-computed entity vectors are retrieved using Approximate Nearest Neighbor (ANN) search, enabling sub-linear scaling to millions of concepts.

ARCHITECTURAL PRINCIPLES

Key Features of Bi-Encoder Architectures

The bi-encoder, or dual-tower, architecture forms the backbone of scalable semantic search and entity linking. By encoding queries and documents independently, it enables sub-linear retrieval times against massive knowledge bases.

01

Independent Dual-Tower Encoding

The defining characteristic of a bi-encoder is its two separate neural networks operating in parallel. One tower encodes the text mention (e.g., 'heart attack'), while the other independently encodes the knowledge base entity (e.g., 'Myocardial Infarction'). This decoupling allows the computationally expensive encoding of all entities in a corpus to be performed offline, once, as a pre-computation step. At inference time, only the query mention needs to be encoded, enabling real-time retrieval against millions of pre-indexed vectors.

02

Efficient Approximate Nearest Neighbor Search

Bi-encoders rely on ANN algorithms like HNSW or FAISS to trade a marginal amount of accuracy for orders-of-magnitude gains in search speed. The model outputs dense vectors where semantic similarity is measured via cosine similarity or dot product. Instead of comparing a query vector against every entity vector in the database (an O(N) operation), ANN indexes cluster vectors in a graph structure, enabling retrieval in O(log N) time. This is critical for clinical entity linking against ontologies like UMLS, which contain millions of concepts.

< 10ms
Query Latency
99%
Recall@100
03

Contrastive Training with Hard Negatives

Bi-encoders are trained using contrastive loss functions that pull positive pairs together and push negative pairs apart in vector space. The key to a high-performing model is hard negative mining—selecting negative examples that are lexically similar but semantically distinct (e.g., 'hypertension' vs. 'hypotension'). Without hard negatives, the model learns trivial distinctions. Advanced training regimens use in-batch negatives and global hard negatives retrieved from the full index to teach the model fine-grained disambiguation, directly improving its ability to distinguish between confusable UMLS concepts.

04

Asymmetric Model Sizing

A practical advantage of the bi-encoder is the ability to use asymmetric architectures for the two towers. The query encoder can be a lightweight, low-latency model optimized for CPU inference, while the document encoder can be a massive, high-precision transformer. This allows the heavy lifting of encoding a vast corpus of medical entities to be done offline with a powerful model, while the real-time query path remains fast and cost-effective. This separation of concerns is impossible in a cross-encoder architecture.

05

Dense Semantic Hashing

The output of a bi-encoder is a fixed-size dense vector, typically 768 or 1024 dimensions. This vector acts as a semantic fingerprint, where the spatial proximity of two vectors directly corresponds to conceptual similarity. Unlike sparse lexical methods like BM25, which rely on exact token overlap, bi-encoders map synonyms and paraphrases to the same region of vector space. For clinical text, this means 'elevated blood pressure' and 'hypertension' will have high cosine similarity, enabling robust retrieval even when terminology varies drastically between physician notes and formal ontology labels.

06

Pre-computed Index Architecture

The operational workflow of a bi-encoder system is split into an offline indexing phase and an online query phase. During indexing, every entity in the target knowledge base (e.g., all SNOMED CT descriptions) is passed through the frozen document encoder to generate a static vector index. This index is then loaded into memory for the online phase. When a new clinical mention arrives, only the query encoder runs, and the resulting vector is used to search the pre-built index. This architecture decouples corpus size from query latency, making it the standard for production clinical NLP systems.

ARCHITECTURAL COMPARISON

Bi-Encoder vs. Cross-Encoder Architecture

A technical comparison of dual-tower and joint-encoding paradigms for clinical entity linking candidate generation and ranking.

FeatureBi-EncoderCross-EncoderHybrid Pipeline

Encoding Strategy

Mention and entity encoded independently

Mention-candidate pair encoded jointly

Bi-encoder for retrieval, cross-encoder for reranking

Inference Speed

< 10 ms per query

100 ms per pair

< 50 ms per query

Index Pre-computation

Approximate Nearest Neighbor Compatible

Symmetric Representations

Pairwise Interaction Depth

Shallow (dot product only)

Deep (full cross-attention)

Shallow then deep

Scalability to 1M+ Entities

Recall@100 Performance

0.85-0.92

0.95-0.98

0.94-0.97

BI-ENCODER ARCHITECTURE

Frequently Asked Questions

Explore the core mechanics of dual-tower neural networks used for high-speed clinical entity linking. These questions address the architecture's design, training, and operational deployment for mapping unstructured medical text to standardized ontologies.

A bi-encoder architecture is a dual-tower neural network that independently encodes a text mention and a knowledge base entity into separate dense vector representations for efficient semantic similarity search. Unlike cross-encoders that process pairs jointly, the bi-encoder generates a fixed-dimensional embedding for each input in isolation. The architecture consists of two identical or distinct transformer-based encoders: one processes the clinical mention (e.g., 'chest pain'), and the other encodes the canonical entity description (e.g., 'Chest Pain - C0008031'). During inference, the similarity between a mention and all candidate entities is computed using a fast dot product or cosine similarity between their respective vectors. This decoupling allows the entity embeddings to be pre-computed and indexed using Approximate Nearest Neighbor (ANN) search algorithms, enabling sub-linear retrieval from millions of concepts. The primary trade-off is speed versus precision: bi-encoders sacrifice the deep cross-attention of cross-encoders for the ability to scale to massive biomedical ontologies like the UMLS Metathesaurus.

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.