This repository contains a compact ONNX Runtime export of
abhinand/MedEmbed-small-v0.1
for local semantic search in
Smart Search for Anki — Medical.
It is an independently produced derivative, not an official export from the
upstream author. The source revision, every source and output checksum, the
complete conversion recipe, and a numerical parity sanity check are included
in this repository.
The model accepts input_ids, attention_mask, and token_type_ids with
dynamic batch and sequence dimensions. It returns one
sentence_embedding tensor with 384 dimensions. The maximum configured
sequence length is 512 tokens.
The graph already applies the upstream Sentence Transformers pipeline:
use the encoder's CLS token (last_hidden_state[:, 0, :]);
L2-normalize the 384-dimensional vector; and
dynamically quantize weights to signed INT8 for compact local inference.
The FP32 ONNX intermediate is reproducible but intentionally omitted to reduce
the download by approximately 127 MB.
See PROVENANCE.json for source file hashes, transform
parameters, tool versions, and validation results. See NOTICE.md
and the included license files for attribution and modification notices.
Reproduce the artifact
Use CPython 3.11 on macOS arm64 to reproduce the verified release environment:
The script downloads only the pinned upstream revision, verifies every required
source file, checks the upstream pooling and normalization configuration,
exports the FP32 graph, performs the documented INT8 quantization, runs ONNX
validation and numerical parity checks, and refuses to complete unless both
output files match their expected byte sizes and SHA-256 digests.
Bit-for-bit reproduction was confirmed in the pinned environment recorded in
PROVENANCE.json. Other operating systems, Python patch versions, or package
builds may produce a numerically equivalent graph with different serialized
bytes; such an output is not the release artifact unless its digest matches.
Numerical parity sanity check
Twelve short, synthetic medical and general-language sentences were embedded
through the same Rust tokenizers plus ONNX Runtime path used by the add-on.
The resulting vectors were compared with:
the pinned upstream PyTorch encoder using the exact same token IDs, its
configured CLS pooling, and L2 normalization;
the FP32 ONNX export; and
the INT8 ONNX export, followed by the add-on's final L2 normalization.
Export
Minimum cosine vs upstream
Mean cosine vs upstream
Maximum absolute element error
FP32 ONNX
0.999999881
1.000000000
0.000000209
INT8 ONNX
0.995368898
0.997062981
0.015785374
Both exports returned finite 12 × 384 arrays. After the same final
normalization used by Smart Search, the maximum INT8 unit-norm error was
5.96e-8. This is an export-integrity sanity check on a small synthetic set.
It is not a clinical evaluation, a retrieval benchmark, or evidence that
quantization preserves every ranking on every collection.
Minimal local inference
python
1import numpy as np
2import onnxruntime as ort
3from tokenizers import Tokenizer
45tokenizer = Tokenizer.from_file("tokenizer.json")6tokenizer.enable_truncation(max_length=512)7tokenizer.enable_padding()89encodings = tokenizer.encode_batch(["What causes elevated creatinine?"])10feeds ={11"input_ids": np.asarray([item.ids for item in encodings], dtype=np.int64),12"attention_mask": np.asarray(13[item.attention_mask for item in encodings], dtype=np.int64
14),15"token_type_ids": np.asarray(16[item.type_ids for item in encodings], dtype=np.int64
17),18}1920session = ort.InferenceSession(21"onnx/model_int8.onnx",22 providers=["CPUExecutionProvider"],23)24embedding = session.run(["sentence_embedding"], feeds)[0]
Intended use
This export is intended for local English-language semantic retrieval, such as
finding related material within a user's own study notes. It produces text
embeddings; it does not answer clinical questions or provide medical facts.
Limitations and safety
The model can miss relevant text or rank unrelated text highly.
INT8 quantization changes embeddings slightly and can change close rankings.
The source model card reports medical retrieval training, but this export has
not been independently clinically validated.
The upstream model card names several training/evaluation datasets, and the
upstream project describes synthetic training triplets derived from PubMed
Central material. This conversion does not redistribute those datasets and
did not independently audit their exact snapshots, provenance, or license
chain.
Performance outside English and beyond the 512-token configuration is not
established here.
Do not use embeddings as medical advice, diagnosis, treatment guidance,
medication reconciliation, or an emergency decision tool.
Do not infer that the upstream authors, BAAI, Hugging Face, Anki, or any
named dataset endorses this export or Smart Search.
Privacy
The model files contain no Anki collection data. In Smart Search, embedding
inference runs locally. Downloading these public files may expose ordinary
network metadata, such as an IP address and user agent, to the hosting
provider; card text and search queries are not included in model download
requests.