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.
Glossary
Bi-Encoder Architecture

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.
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.
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.
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.
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.
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.
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.
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.
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.
Bi-Encoder vs. Cross-Encoder Architecture
A technical comparison of dual-tower and joint-encoding paradigms for clinical entity linking candidate generation and ranking.
| Feature | Bi-Encoder | Cross-Encoder | Hybrid 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 |
| < 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 |
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.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
Explore the core building blocks and complementary techniques that form the bi-encoder ecosystem for high-performance clinical entity linking.
Cross-Encoder Reranker
A high-precision neural architecture that processes a mention-candidate pair jointly through a transformer to produce a relevance score. Unlike bi-encoders, cross-encoders apply full self-attention across both sequences simultaneously, enabling rich token-level interactions.
- Role: Serves as the second-stage ranker in a two-stage retrieval pipeline
- Trade-off: 10-100x slower than bi-encoders but significantly more accurate
- Architecture: Typically fine-tuned BERT-style models with a classification head
- Example: A bi-encoder retrieves 100 candidates; the cross-encoder reranks them to select the correct SNOMED CT code
Dense Passage Retrieval (DPR)
A dual-encoder framework trained to retrieve relevant knowledge base passages by maximizing the inner product of query and context embeddings. DPR uses in-batch negatives and hard negatives to learn discriminative representations.
- Training Objective: Contrastive loss that pulls positive pairs together and pushes negatives apart
- Indexing: Entity descriptions are pre-encoded and stored in a vector index for fast ANN search
- Clinical Adaptation: Entity descriptions from UMLS or SNOMED CT serve as the passage corpus
- Performance: Achieves high recall@k with k=100, making it ideal for candidate generation
Approximate Nearest Neighbor Search
An indexing algorithm that trades a small amount of accuracy for massive speed gains when searching for the closest dense vectors in high-dimensional embedding space. ANN is the retrieval backbone that makes bi-encoder inference scalable.
- Common Libraries: FAISS (Facebook), ScaNN (Google), Annoy (Spotify)
- Index Types: IVF (Inverted File), HNSW (Hierarchical Navigable Small World), PQ (Product Quantization)
- Latency Profile: Sub-millisecond search across millions of vectors
- Clinical Scale: Enables real-time linking against the full UMLS Metathesaurus of 4M+ concepts
Contrastive Learning
A self-supervised training paradigm that learns representations by pulling positive mention-entity pairs together and pushing negative pairs apart in vector space. This is the foundational training strategy for modern bi-encoder entity linking models.
- Positive Pairs: A clinical mention and its correct UMLS CUI description
- Hard Negatives: Confusable entities like 'DM' (Diabetes Mellitus vs. Dermatomyositis) that share lexical overlap
- Loss Functions: InfoNCE, Triplet Loss, or Multiple Negatives Ranking Loss
- Biomedical Example: SapBERT uses contrastive learning to align synonymous concepts from different ontologies into a unified embedding space
Candidate Generation
The initial high-recall retrieval stage that uses fast, approximate methods to fetch a small set of plausible knowledge base entries for a given text mention. This stage determines the upper bound of the linking pipeline's accuracy.
- Bi-Encoder Role: Encodes the mention and performs ANN search over pre-indexed entity embeddings
- Hybrid Approaches: Combine dense retrieval with sparse lexical baselines like BM25 for robustness
- Constraints: Semantic type filtering restricts candidates to relevant UMLS categories (e.g., only 'Disease or Syndrome')
- Output: Typically 50-200 candidates passed to the ranking stage

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.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us