Efficient Drug Terminology Mapping with Bidirectional Late-Interaction Reranking and Deterministic Reordering
Article information
Abstract
Objectives
Standardizing medication concepts across heterogeneous vocabularies is essential for interoperable analytics and observational research. In the Observational Medical Outcomes Partnership (OMOP) Common Data Model, local drug codes must be mapped to standardized RxNorm concepts, but automated mapping is challenging because drug strings encode clinically critical attributes, including strength, dosage form/route, release characteristics, and brand.
Methods
We propose THIRAWAT (Terminology Harmonization using Late-Interaction Reranker With Alignment-tuned Transformers), a fine-tuned ColBERTv1 late-interaction reranker, and embed it within THIRAWAT Mapper, a retrieval–reranking pipeline with deterministic tie-breaking and stable ordering. Candidate generation used approximate nearest-neighbor retrieval with a bi-encoder (SapBERT-XLMR or BioLORD-2023). Candidates were reranked by THIRAWAT models that were fine-tuned using one-sided MaxSim and scored at inference using our adapted Bidirectional MaxSim (BiMaxSim) pooling. Finally, a deterministic tie-breaker extracted clinically salient cues, including strength, dosage form/route, release characteristics, and bracketed brand annotations, to resolve near-ties reproducibly.
Results
We evaluated three mapping settings: Branded Drugs, Clinical Drugs, and Thai Medicines Terminology (TMT). Using SapBERT-XLMR retrieval with THIRAWAT-Sap-BERT reranking and deterministic tie-breaking, THIRAWAT Mapper achieved MRR@100 values of 0.954 (95% confidence interval [CI], 0.921–0.983), 0.898 (95% CI, 0.866–0.925), and 0.912 (95% CI, 0.891–0.931), outperforming a lexical term frequency–inverse document frequency baseline (0.491, 0.216, and 0.143, respectively). Hits@1 improved to 0.942 (95% CI, 0.899–0.978), 0.859 (95% CI, 0.817–0.898), and 0.868 (95% CI, 0.838–0.896), respectively.
Conclusions
BiMaxSim and deterministic tie-breaking improved drug mapping to RxNorm while preserving an efficient runtime profile and stable ordering. Overall, THIRAWAT Mapper offers a pragmatic combination of learned semantic matching and deterministic lexical constraints. Models and code are available on Hugging Face (https://huggingface.co/collections/sidataplus/thirawat) and GitHub (https://github.com/sidataplus/THIRAWAT-mapper).
I. Introduction
Mapping medication terms across heterogeneous clinical vocabularies is essential for interoperable observational research and health system analytics. In the Observational Health Data Sciences and Informatics (OHDSI) Observational Medical Outcomes Partnership (OMOP) Common Data Model (CDM), local or non-standard drug concepts must be mapped to standardized concepts, typically RxNorm or RxNorm Extension, to support cross-site phenotyping, medication safety surveillance, and multi-database evidence generation [1,2]. Despite mature tooling, drug mapping remains a bottleneck because source strings vary widely and encode clinically meaningful constraints.
In practice, drug strings encode ingredient, strength, dosage form, route, release mechanism, packaging, and brand information. Common OMOP mapping failures are not broad semantic confusions but rather clinically meaningful over- or under-specification, such as strength or concentration mismatches and cases in which combination products outrank single-ingredient concepts. These errors are amplified when many candidates are nearly tied, producing unstable rankings that undermine reproducibility.
Consequently, existing drug-mapping approaches often combine lexical candidate generation with human review, as exemplified by OHDSI Usagi [3]. Large language model (LLM)-based methods may improve recall and ranking [4,5], but they can be costly, non-deterministic, and sensitive to prompts, run settings, and model versions, which complicates auditing and maintenance of mappings.
As a lower-cost alternative, transformer-based encoder models can be used to measure drug-name semantic similarity [6]. Although bi-encoder retrieval improves candidate recall, compressing an input string into a single vector can blur fine-grained drug constraints. We therefore evaluated two complementary biomedical retrievers. SapBERT-XLMR is optimized for concept normalization through synonym self-alignment and provides a strong baseline for mapping heterogeneous surface forms to standardized vocabulary entries [7,8]. BioLORD-2023 is trained for biomedical semantic textual similarity using textual definitions and knowledge-graph descriptions, providing a contrasting inductive bias that may better accommodate descriptive product language and non-canonical phrasing when explicit synonyms are limited [9].
To improve ranking accuracy, late-interaction rerankers such as ColBERT preserve token-level structure and compute relevance through efficient token-wise interactions [10]. Conventional MaxSim pooling, however, is directionally asymmetric and can over-reward over-specified candidates, thereby motivating deterministic disambiguation of nearties.
We therefore developed THIRAWAT Mapper, an OHDSI drug concept-mapping pipeline designed for accuracy, deployability, and reproducibility, and THIRAWAT, a fine-tuned ColBERTv1 late-interaction reranker. Our contributions are as follows:
(1) BiMaxSim pooling: a symmetric inference-time late-interaction score that rewards mutual token coverage and reduces over-specification errors.
(2) Deterministic tie-breaking: a clinically motivated deterministic procedure that resolves near-ties using strength, dosage form/route, release characteristics, and brand cues to ensure stable rankings.
(3) Empirical evaluation and deployment profiling: evaluation across three settings (Table 1), optional LLM refinement (Table 2), and stage-wise CPU/GPU runtime analysis (Table 3).
Drug-mapping performance (MRR@100 and Hits@k with 95% bootstrap confidence intervals) in Branded Drugs (n = 139), Clinical Drugs (n = 284), and TMT (n = 500), comparing a lexical TF-IDF baseline, dense retrieval, THIRAWAT reranking with BiMaxSim pooling, and deterministic tie-breaking within near-ties
Effect of LLM reordering of the top-k = 20 candidates after THIRAWAT Mapper retrieval, reranking, and deterministic tie-breaking (MRR@100 and Hits@k with 95% bootstrap CIs)
II. Methods
1. Datasets
We used the drug-domain vocabulary dataset exported from ATHENA v20250827. ATHENA distributes the OHDSI Standardized Vocabularies used for OMOP harmonization and provides the released reference content underlying the vocabulary tables used in this study [2].
(1) Training data: From the ATHENA dataset, training queries were derived from non-standard drug concepts (sources) linked to standard drug concepts (targets; RxNorm/RxNorm Extension) through maps to relationships. Query strings were constructed from the source concept names. To minimize leakage, we reserved held-out targets for evaluation and assigned all sources mapping to those targets to the test split.
Held-out evaluation subsets were constructed from standard, valid drug targets with nonzero fan-in, defined as the number of non-standard concepts mapping to a target through Maps to. We evaluated Branded Drugs (Branded Drug, Branded Drug Comp) and Clinical Drugs (Clinical Drug, Clinical Drug Comp), sampling 500 held-out targets per task across the fan-in distribution. Positive pairs were then used to recover non-standard source queries mapping to those targets. After automated filtering, normalized-text deduplication, target-level deduplication, and manual exclusion of under-specified queries that could not support stable exact evaluation, the final sets contained 139 Branded queries and 284 Clinical queries. Here, under-specified indicates that the query lacked sufficient detail to support a unique exact target, typically because strength, dosage form, route, release characteristics, combination composition, or presentation detail was missing or ambiguous.
2. Evaluation on Thai Medicines Terminology
We additionally evaluated mapping of Thai Medicines Terminology (TMT), the Thai national standardized drug terminology maintained by the Thai Health Information Standards Development Center, using the release file RF 20251215 [11]. We extracted the 500 most frequently dispensed drugs at Siriraj Hospital that were coded in TMT. TMT strings were largely English in their ingredient-strength-form content, but many also included local brands, product descriptors, and Thai-script manufacturer or organization metadata. Of the 500 queries, 307 contained Thai script, usually within manufacturer or organization spans rather than ingredient text.
3. Mapping Process
THIRAWAT Mapper produced a ranked list of standard drug concepts for each input query through retrieval, reranking, deterministic tie-breaking, and optional reordering (Figure 1).
Overview of THIRAWAT Mapper, including query normalization, LanceDB retrieval, THIRAWAT late-interaction reranking (ColBERTv1 scored with BiMaxSim), and deterministic tie-breaking within near-ties. When ATC codes were available, an ATC-based stable preference was applied, and LLM reordering was evaluated as an additional stage. THIRAWAT: Terminology Harmonization using Late-Interaction Reranker With Alignment-tuned Transformers, LLM: large language model, ATC: Anatomical Therapeutic Chemical.
(1) Query normalization: Before retrieval, we applied case folding and whitespace canonicalization, removed parentheses, stripped non-Latin characters, and normalized selected INN/BAN variants toward USAN-like forms. In TMT, these steps mainly removed Thai-script manufacturer metadata rather than altering the core drug identity string.
(2) Candidate retrieval (retriever bi-encoder with LanceDB): We embedded the normalized query with a biomedical transformer bi-encoder and retrieved the top-k candidates from a LanceDB approximate nearest-neighbor index. We used SapBERT-UMLS-2020AB-all-langfrom-XLMR with CLS pooling [7,8] and BioLORD-2023 with mean pooling [9]. The index stored candidate text, identifiers, and metadata.
(3) ATC scoping (soft preference): When ATC codes were available, we computed the descendant set of standard drug concepts using “concept_ancestor” and applied a stable preference for in-scope candidates over out-of-scope candidates.
(4) Late-interaction reranking (THIRAWAT): THIRAWAT rescored retrieved candidates using token-level embeddings and ColBERTv1-style late interaction. THIRAWAT was fine-tuned with one-sided MaxSim, but at inference we used BiMaxSim pooling, which symmetrized MaxSim by averaging query-to-candidate and candidate-to-query coverage.
(5) Deterministic tie-breaking: Late-interaction reranking reduced, but did not eliminate, near-ties among clinically distinct drug concepts. We therefore applied a deterministic tie-breaker that extracted strength, dosage form/route, release modifiers, and bracketed brand cues from query and candidate strings and reordered only candidates whose scores fell within an ɛ near-tie threshold relative to the top score among the top-N candidates. In our analyses, the largest observed score gap among top-ranked candidates within the top-200 list was 0.007, so ɛ = 0.01 was chosen conservatively to group only very close candidates while excluding clearer non-ties. A small sweep over N = 20, 100, and 200 showed similar ranking metrics; N = 100 was therefore used as a conservative middle ground between tighter and looser reordering. Both parameters are adjustable; full details are provided in the Supplementary Materials.
(6) Optional LLM reordering: For selected experiments, an instruction-tuned LLM reordered only the top k candidates after deterministic tie-breaking (k = 20; prompt in the Supplementary Materials).
4. Reranker Training
We fine-tuned THIRAWAT as a ColBERTv1 reranker initialized from SapBERT-XLMR or BioLORD-2023. Training instances paired each query with one positive standard concept and multiple negatives sampled from hierarchy-aware siblings and in-batch negatives. We used PyLate utilities [12] with LoRA adapters [13]; full hyperparameters are reported in the Supplementary Materials.
5. BiMaxSim Pooling
Conventional ColBERT MaxSim imposed directional asymmetry in practice: queries were often under-specified, whereas candidate concepts were over-specified by strength, dosage form, route, or release tokens. One-sided coverage could therefore rank clinically over-specified candidates too highly, even when only the core ingredient matched.
Formally, let Q = {q1, …, qm} be the set of query token embeddings, D = {d1, …, dn} be the set of candidate (concept) token embeddings, and s(q, d) = cos(q, d). Conventional (one-sided) MaxSim was defined in Equation (1):
We propose BiMaxSim, which symmetrizes MaxSim to enforce mutual token coverage (see Equation 2):
The first term rewards candidates that covered query content, whereas the second term down-weights candidates that introduced unmatched tokens. BiMaxSim was applied only at inference during reranking of the top-k retrieved candidates.
6. Evaluation
To quantify mapping quality, we evaluated MRR@100 and Hits@k for k = 1, 3, 5, 10, and 100, with 95% confidence intervals computed by bootstrap over queries. Each dense run retrieved the top-k candidates from LanceDB (k = 500) and applied reranking, deterministic tie-breaking, and ATC preference only within that set. We reported five ranking conditions aligned with Tables 1 and 2: a term frequency–inverse document frequency (TF-IDF) baseline inspired by Usagi [3], dense retriever-only ranking, dense retriever-only ranking with deterministic tie-breaking, dense retrieval plus THIRAWAT reranking, and the full THIRAWAT Mapper pipeline. When evaluated, LLM reordering was applied only after deterministic tie-breaking.
For optional LLM reordering, we evaluated Gemini 3 Flash Preview (v20251217), GPT-5.2 (v20251211), and GPT-OSS-20B [14–16]. GPT-OSS-20B was executed locally, whereas the other LLMs were accessed through hosted APIs. LLMs were applied with different reasoning settings, as detailed in Table 2.
(1) Mapping adjudication: Given the possibility of one-to-many mapping, which is also present in ATHENA [2], ranked candidate lists were exported for adjudication. One annotator produced the initial labels, which were then reviewed by two clinician reviewers. Reviewers could mark one or more acceptable candidates or exclude a query from scoring when the string or candidate list did not support stable exact evaluation. Such exclusions were used only to define scored denominators and were not interpreted as ordinary model errors. A prediction was counted as correct when the top-ranked candidate matched any adjudicated acceptable target.
(2) Runtime and resource measurement: We measured stage-wise latency for retrieval, THIRAWAT reranking, and deterministic tie-breaking (N = 100) using a fixed workload of 500 TMT queries on an Intel Xeon Gold 6430 processor; GPU runs used NVIDIA L40s (48 GB).
III. Results
1. Drug Mapping Performance
We evaluated THIRAWAT Mapper, which combined LanceDB retrieval with optional THIRAWAT reranking and deterministic tie-breaking, in three drug-mapping settings: Branded Drugs (n = 139), Clinical Drugs (n = 284), and TMT (n = 500).
Table 1 summarizes performance for TF-IDF, retriever-only ranking, retriever-only ranking with deterministic tie-breaking, retriever plus THIRAWAT reranking, and the full THIRAWAT Mapper pipeline. Across all settings, dense retrieval substantially outperformed TF-IDF, THIRAWAT reranking improved ranking quality beyond dense retrieval alone, and deterministic tie-breaking provided additional gains when clinically meaningful distinctions were not fully resolved by the embeddings.
TF-IDF performed poorly, consistent with the limitations of surface-form matching under synonymy and local naming variation—MRR@100 values of 0.491/0.216/0.143 and Hits@1 values of 0.309/0.116/0.058 for Branded/Clinical/TMT. Dense retrieval substantially improved both recall and ranking quality. Using SapBERT-XLMR retriever-only ranking, performance reached MRR@100 values of 0.901/0.756/0.504 and Hits@1 values of 0.856/0.683/0.364 for Branded/Clinical/TMT. Applying deterministic tie-breaking directly to retriever scores yielded only modest gains (for example, Clinical MRR@100, 0.756→0.770; TMT, 0.504→0.523), consistent with the tie-breaker having been designed as a conservative near-tie resolver rather than a primary ranker.
Building on this, adding THIRAWAT reranking with BiMaxSim pooling produced larger improvements. With SapBERT-XLMR retrieval, THIRAWAT reranking without tie-breaking achieved MRR@100 values of 0.931/0.810/0.576 and Hits@1 values of 0.899/0.729/0.426. Combining reranking with deterministic tie-breaking yielded the best overall performance: MRR@100 values of 0.954 (95% confidence interval [CI], 0.921–0.983), 0.898 (95% CI, 0.866–0.925), and 0.912 (95% CI, 0.891–0.931) for Branded/Clinical/TMT, with Hits@1 values of 0.942 (95% CI, 0.899–0.978), 0.859 (95% CI, 0.817–0.898), and 0.868 (95% CI, 0.838–0.896), respectively (see Supplementary Materials for bootstrap CIs).
The largest marginal effect of tie-breaking was observed in TMT after reranking (MRR@100, 0.576→0.912; Hits@1, 0.426→0.868), consistent with local brand and product descriptors creating clinically meaningful near-ties. Gains for Branded Drugs and Clinical Drugs were smaller but remained consistent.
By contrast, BioLORD showed lower retriever-only performance than SapBERT in this setting (for example, retriever-only MRR@100 for SapBERT vs. BioLORD was 0.901 vs. 0.676 in Branded Drugs and 0.504 vs. 0.351 in TMT). However, BioLORD benefited substantially from reranking and deterministic tie-breaking, supporting the view that late interaction combined with explicit clinical cues can partially compensate for pooling limitations in dense retrieval.
A notable limitation of the TMT evaluation was that many branded products did not have corresponding branded entities in ATHENA. Only 113 of 500 TMT queries yielded acceptable same-brand exact matches. The remaining queries therefore relied on acceptable generic ingredient-strength-form targets that preserved core clinical identity while omitting the brand.
Failure analysis of the most effective pipeline, which combined SapBERT-XLMR retrieval, THIRAWAT-SapBERT reranking, and deterministic tie-breaking, showed that most false-at-1 cases involved candidates that were clinically close to the accepted target rather than unrelated drug errors. The largest group consisted of specificity errors, indicating that the system correctly identified the drug family but failed to select the exact accepted target because the accepted concept was more specific with respect to dosage strength, form, or release type.
2. Optional LLM Reordering
We evaluated an optional LLM reordering stage applied to the top 20 candidates ranked by THIRAWAT Mapper with deterministic tie-breaking and ATC preference, when available. Unless otherwise stated, these experiments used SapBERT-XLMR retrieval with THIRAWAT-SapBERT reranking. Table 2 summarizes the effect of LLM reordering on MRR@100 and Hits@k.
LLM reordering was evaluated only as an optional post hoc comparison and was not part of the primary pipeline because it added latency, cost, and non-determinism. Under the Gemini 3 Flash Preview condition, Branded performance decreased (MRR@100, 0.954→0.943; Hits@1, 0.942→0.921), whereas Clinical performance improved to MRR@100 of 0.934 and Hits@1 of 0.905, and TMT improved to MRR@100 of 0.935 and Hits@1 of 0.898. This pattern suggests that LLM reordering can help when several clinically plausible alternatives remain near the top, but may be less reliable when deterministic cues already capture the exact branded or presentation-specific target.
3. Runtime and Resource Usage
We also measured stage-wise latency for retrieval, THIRAWAT reranking, and deterministic tie-breaking on 500 TMT queries, reporting per-query p50/p95 latency and end-to-end throughput under CPU-only and GPU-enabled execution (Table 3).
GPU-enabled execution reduced end-to-end latency from 7.3–7.7 seconds at p50 (15.7–15.8 seconds at p95) to 1.5–1.6 seconds at p50 (2.4–2.6 seconds at p95) and increased mean throughput by approximately fivefold. Most of this speedup arose from reranking, whereas retrieval and tie-breaking changed little between CPU and GPU execution.
IV. Discussion
1. Principal Findings
Across three practical settings, dense retrieval substantially outperformed lexical TF-IDF, reinforcing that learned semantic representations are necessary for robust drug mapping under heterogeneous naming conventions. However, pooled bi-encoder similarity alone remained insufficient to consistently distinguish clinically similar candidates, particularly when strength, dosage form/route, release characteristics, and combination products differed.
In our proposed pipeline, THIRAWAT reranking improved ranking quality beyond dense retrieval by enabling token-level late interaction to recover attribute-sensitive matching that is blurred by single-vector pooling. Deterministic tie-breaking then provided additional gains at the top rank by resolving near-ties with explicit clinical cues while preserving stable ordering. The strongest pattern was that tie-breaking was most effective after reranking, because reranking concentrated a semantically plausible candidate set and thereby allowed deterministic signals to function as conservative refiners.
More specifically, two design choices were central to resolving clinically meaningful near-ties without sacrificing deployability. First, BiMaxSim addressed the asymmetry of MaxSim by requiring mutual token coverage, thereby discouraging candidates that introduced unsupported attributes. Second, deterministic tie-breaking injected explicit clinical constraints only when the model was uncertain, stabilizing rankings and aligning the top prediction with attributes that drive medication safety and phenotyping. The observation of these gains under both SapBERT and BioLORD retrieval suggests that late interaction and deterministic cues can compensate for differences in retriever training objectives and improve robustness across embedding backbones.
Notably, the largest improvements were observed in TMT, where local brand and product descriptors often lacked direct branded RxNorm mappings, shifting many correct targets toward generic clinical drug concepts. In this setting, deterministic resolution of strength, dosage form/route, and release cues appeared critical for selecting the correct generic target among semantically similar alternatives and for maintaining reproducible rankings.
The observed failure patterns suggest that the main remaining challenge is exact normalization among closely related drug concepts rather than coarse semantic retrieval. In many false-at-1 cases, the system had already reached the correct ingredient family and often a clinically plausible near neighbor, but failed to preserve the exact strength, dosage form, route, release type, combination status, or product specificity required for scoring. This pattern was especially evident in TMT, where local brands and presentation variants increased the number of plausible near-neighbor candidates and therefore necessitated further manual review of the mappings.
2. Applications
From a deployment perspective, THIRAWAT Mapper was designed for production OMOP mapping workflows that require predictable cost, stable behavior, and auditability. The pipeline can be deployed in limited-compute settings without relying on a GPU. With GPU acceleration, a single query can generally be mapped in less than 2 seconds, and 100 queries can be completed in under 3 minutes, supporting both real-time and batch applications.
More broadly, the retrieval–reranking design is applicable to alignment tasks beyond RxNorm standardization, including mapping hospital medication catalogs to national drug terminologies. In such settings, the target terminology can be indexed in the same manner, using names and synonyms, and the same retrieval–reranking pipeline can be applied with little modification. The deterministic tie-breaking component can likewise be adapted to local naming conventions by updating the extraction rules for strength, dosage form/route, release characteristics, and brand cues.
Optional LLM reordering may improve some difficult cases, but it introduces latency, cost, and non-determinism. In practice, this suggests that LLMs are better used as selective refiners than as default components. Deterministic tie-breaking is easier to explain, audit, and tune, which is advantageous in expert-reviewed mapping workflows.
3. Limitations and Future Work
Although this work focused on the development and evaluation of a terminology-mapping pipeline for drug concepts, the proposed late-interaction reranking approach with BiMaxSim pooling may also be applicable to non-drug domains. Future work should evaluate the generalizability of this approach to other clinical entities, such as conditions, procedures, and measurements, for which similar challenges of synonymy, granularity, and attribute-sensitive distinctions arise.
In addition, this work evaluated drug terminology mapping only in English. However, several retrieval models, including SapBERT-XLMR [7,8] and BioLORD-2023-M [9], support multilingual text, and the same retrieval–reranking pipeline could in principle be further fine-tuned for multilingual mapping tasks without transliteration.
In TMT, most branded products (77.4%) lacked corresponding branded entities in ATHENA. In such cases, the pipeline often identified the correct generic ingredient-strength-form concept but not the exact brand. This finding highlights the limited coverage of local branded products in current RxNorm/ATHENA vocabularies and an important barrier to precise cross-region harmonization.
Methodologically, the THIRAWAT late-interaction reranker was fine-tuned using one-sided MaxSim, whereas BiMaxSim was applied only at inference. Training directly with BiMaxSim could better align the learning objective with inference-time scoring; however, in preliminary experiments, BiMaxSim training was unstable and did not converge reliably. Future work may explore curriculum learning, in which training begins with MaxSim and then transitions to BiMaxSim during late-stage fine-tuning, as well as other stabilization strategies.
4. Conclusion
THIRAWAT Mapper mapped local drug strings to standardized OMOP drug concepts using retrieval, late-interaction reranking, and deterministic tie-breaking. BiMaxSim improved token-level alignment between queries and candidates, and deterministic tie-breaking further improved top-rank accuracy while preserving stable ordering. Together, these components provide a pragmatic, compute-efficient approach to RxNorm drug mapping.
Notes
Conflict of Interest
No potential conflict of interest relevant to this article was reported.
Acknowledgments
This work was supported by the Faculty of Medicine Siriraj Hospital, Mahidol University, through employment and computing facility. We thank the OHDSI Vocabulary Team, who provide and maintain the OHDSI Standardized Vocabularies on ATHENA. Development of the codebase for this work was facilitated by ChatGPT Codex, primarily using GPT-5.2-Codex model. The manuscript was drafted with assistance of the ChatGPT-5.2 model. The authors have reviewed, verified, and take full responsibility for the accuracy, integrity, and originality of the content, analyses, and conclusions presented in this manuscript.
