Skip to content
PhilipGAQPublic

About

CMedTEB & CARE: Benchmarking and Enabling Efficient Chinese Medical Retrieval via Asymmetric Encoders

Resources

Stars

7 stars

Watchers

0 watching

Forks

Latest commit

 

History

10 Commits

Folders and files

Repository files navigation

CARE: Benchmarking and Enabling Efficient Chinese Medical Retrieval via Asymmetric Encoders

Overview

This repository provides code to train and run CARE designed for Chinese medical retrieval tasks. The system trains a compact query encoder and a larger document encoder.

Requirements

  • Python 3.8+
  • packages: torch, transformers, huggingface_hub, numpy, tqdm, FlagEmbedding.
pip install -r requirements.txt

Training

  1. scripts/stage1-query-alignment.sh are training scripts for stage I. Set ROOT and model paths (query encoder and document encoder seperately). FIX_DOC_ENCODER should set to be True at this stage.
  2. scripts/stage2-joint-finetuning.sh are scripts for stage II. Model checkpoints of query encoder are from stage I, while model path of document encoder are same as stage I.

Both scripts requires set ROOT, MODEL_QUERY, MODEL_DOC, TRAIN_DATA, SAVE_DIR, and cluster env variables (WORLD_SIZE, RANK, MASTER_ADDR). The training entrypoint is train/main.py

export ROOT=/path/to/project
cd $ROOT/Medical-Asymmetric-Retriever/train

bash ../scripts/stage1-query-alignment.sh

bash ../scripts/stage2-joint-finetuning.sh

Inference

Use inference/asymmetric.py::CARE to load encoders and compute embeddings. Example:

from inference.asymmetric import CARE
import numpy as np
model_name_or_path_query = "path/to/query/encoder"
model_name_or_path_doc = "path/to/document/encoder"
care = CARE(
    model_name_or_path_query=model_name_or_path_query,
    model_name_or_path_doc=model_name_or_path_doc,
    trust_remote_code=True,
    use_fp16=False,
    normalize_embeddings=True,
    query_batch_size=2,
    passage_batch_size=2,
)
queries = [
    "什么是高血压?"
]
corpus = [
    "高血压是指动脉血压持续升高,通常指收缩压≥140mmHg和/或舒张压≥90mmHg。"
]
query_embeddings = care.encode_queries(queries, task_name='retrieval')
print("Query Embeddings:", query_embeddings, query_embeddings.shape)
corpus_embeddings = care.encode_corpus(corpus, task_name='retrieval')
print("Corpus Embeddings:", corpus_embeddings, corpus_embeddings.shape)

scores = np.dot(query_embeddings, corpus_embeddings.T)
print("Similarity Scores:", scores)

Per file descriptions

  • inference/asymmetric.py:

    • CARE inference wrapper that loads separate query and document tokenizers and encoders.
  • scripts/stage1-query-alignment.sh:

    • Example shell script for stage-1 query alignment training.
  • scripts/stage2-joint-finetuning.sh:

    • Example shell script for stage-2 joint finetuning.
  • train/arguments.py:

    • Defines dataclasses for model, data and training arguments.
  • train/dataset.py:

    • Dataset classes and collators used during training.
  • train/load_model.py:

    • Utilities to construct/load the document encoder.
  • train/main.py:

    • Training entrypoint. Parses arguments into dataclasses, initializes AsymmetricEmbedderRunner, and starts training.
  • train/modeling.py:

    • Contains AsymmetricEmbedderModel which wraps the query and document encoders.
  • train/runner.py:

    • Runner that wires together tokenizers, base models, the AsymmetricEmbedderModel, and data collators.
  • train/trainer.py:

    • Custom trainer.
  • data:

    • Sampled training data examples for stage-1 and stage-2.
    • stage1: Sampled data for stage-1. stage1-query-align-q.jsonl are query-side triples, and stage1-query-align-doc.jsonl are document-side triples.
    • stage2: Sampled data for stage-2. stage2-medteb-retrieval.jsonl are sampled from MedTEB retrieval train part. stage2-medteb-sts.jsonl are sampled from MedTEB STS train part.

Reproducibility

Use scripts/ as templates to reproduce experimental settings. Ensure paths and cluster environment variables are set correctly.

Model:

https://huggingface.co/PhilipGAQ/CARE-0.3B-4B https://huggingface.co/PhilipGAQ/CARE-0.3B-8B

Benchmark:

https://huggingface.co/datasets/PhilipGAQ/CMedTEB

License

License: CC-BY-NC-SA-4.0.

@inproceedings{jiang-etal-2026-benchmarking,
    title = "Benchmarking and Enabling Efficient {C}hinese Medical Retrieval via Asymmetric Encoders",
    author = "Jiang, Angqing  and
      Chen, Jianlyu  and
      Zhefang  and
      Wang, Yongcan  and
      Li, Xinpeng  and
      Ding, Keyu  and
      Lian, Defu",
    editor = "Liakata, Maria  and
      Moreira, Viviane P.  and
      Zhang, Jiajun  and
      Jurgens, David",
    booktitle = "Proceedings of the 64th Annual Meeting of the {A}ssociation for {C}omputational {L}inguistics (Volume 1: Long Papers)",
    month = jul,
    year = "2026",
    address = "San Diego, California, United States",
    publisher = "Association for Computational Linguistics",
    url = "https://aclanthology.org/2026.acl-long.916/",
    doi = "10.18653/v1/2026.acl-long.916",
    pages = "20000--20020",
    ISBN = "979-8-89176-390-6",
    abstract = "Effective medical text retrieval requires both high accuracy and low latency. While LLM-based embedding models possess powerful retrieval capabilities, their prohibitive latency and high computational cost limit their application in real-time scenarios. Furthermore, the lack of comprehensive and high-fidelity benchmarks hinders progress in Chinese medical text retrieval. In this work, we introduce the **C**hinese **Med**ical **T**ext **E**mbedding **B**enchmark (**CMedTEB**), a benchmark spanning three kinds of practical embedding tasks: retrieval, reranking, and semantic textual similarity (STS). Distinct from purely automated datasets, CMedTEB is curated via a rigorous multi-LLM voting pipeline validated by clinical experts, ensuring gold-standard label quality while effectively mitigating annotation noise. On this foundation, we propose the **C**hinese Medical **A**symmetric **RE**triever (**CARE**), an asymmetric architecture that pairs a lightweight BERT-style encoder for online query encoding with a powerful LLM-based encoder for offline document encoding. However, optimizing such an asymmetric retriever with two structurally different encoders presents distinctive challenges. To address this, we introduce a novel two-stage training strategy that progressively bridges the query and document representations. Extensive experiments demonstrate that CARE surpasses state-of-the-art symmetric models on CMedTEB, achieving superior retrieval performance without increasing inference latency."
}

About

CMedTEB & CARE: Benchmarking and Enabling Efficient Chinese Medical Retrieval via Asymmetric Encoders

Resources

Stars

7 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages