pub(crate) static WEIGHTS_SAFETENSORS: &[u8] =
include_bytes!(concat!(env!("OUT_DIR"), "/model-fp16.safetensors"));
pub(crate) static TOKENIZER_JSON: &[u8] =
include_bytes!(concat!(env!("OUT_DIR"), "/tokenizer.json"));
pub(crate) static CONFIG_JSON: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/config.json"));
pub(crate) const SOURCE_REPO: &str = include_str!(concat!(env!("OUT_DIR"), "/repo.txt"));
pub(crate) const SOURCE_REVISION: &str = include_str!(concat!(env!("OUT_DIR"), "/revision.txt"));
#[cfg(test)]
mod tests {
use super::{CONFIG_JSON, SOURCE_REPO, SOURCE_REVISION, TOKENIZER_JSON, WEIGHTS_SAFETENSORS};
#[test]
fn weights_are_an_fp16_bert_safetensors_blob() {
let len = WEIGHTS_SAFETENSORS.len();
assert!(
(40_000_000..100_000_000).contains(&len),
"embedded weights are {len} bytes"
);
let header_len = u64::from_le_bytes(
WEIGHTS_SAFETENSORS[..8]
.try_into()
.expect("slice of 8 bytes"),
);
let header_len = usize::try_from(header_len).expect("header fits in usize");
let header: serde_json::Value =
serde_json::from_slice(&WEIGHTS_SAFETENSORS[8..8 + header_len])
.expect("safetensors header is JSON");
assert_eq!(header["embeddings.word_embeddings.weight"]["dtype"], "F16");
assert_eq!(header["embeddings.position_ids"]["dtype"], "I64");
}
#[test]
fn tokenizer_and_config_parse_as_json() {
let tokenizer: serde_json::Value =
serde_json::from_slice(TOKENIZER_JSON).expect("tokenizer.json parses");
assert!(tokenizer.get("model").is_some());
let config: serde_json::Value =
serde_json::from_slice(CONFIG_JSON).expect("config.json parses");
assert_eq!(config["model_type"], "bert");
assert_eq!(config["hidden_size"], 384);
}
#[test]
fn provenance_is_a_pinned_commit_from_the_source_repository() {
assert_eq!(SOURCE_REPO, "BAAI/bge-small-en-v1.5");
assert_eq!(SOURCE_REVISION.len(), 40);
assert!(SOURCE_REVISION.chars().all(|c| c.is_ascii_hexdigit()));
}
}