use super::{
IndexModel,
tests::{document, embedding_index, two_elections},
};
use crate::{model::NodeKind, prefix::EmissionPrefix};
fn emitted(model: &IndexModel) -> String {
model.emit().to_string()
}
#[test]
fn every_election_gets_its_own_similar_door() {
let emission = emitted(&two_elections());
for field in ["caption_embedding", "image_embedding"] {
assert_eq!(
emission
.matches(&format!("async fn retrieve_similar_by_{field} <"))
.count(),
2,
"`retrieve_similar_by_{field}` is not written once per gate half: {emission}"
);
}
}
#[test]
fn a_kind_with_no_election_gets_no_similar_door() {
for model in [
document(),
IndexModel {
prefix: EmissionPrefix::default(),
kind: NodeKind::Blob,
..document()
},
] {
let emission = emitted(&model);
assert!(
!emission.contains("retrieve_similar"),
"{:?} carries a door it cannot answer: {emission}",
model.kind
);
}
}
#[test]
fn the_body_is_the_ruled_recipe() {
let emission = emitted(&embedding_index());
let door = emission
.split("async fn retrieve_similar_by_image_embedding <")
.nth(1)
.expect("the door is emitted");
let body = door.split("async fn").next().expect("the door has a body");
for call in [
"get_image_embedding",
"knn",
"vector_keyed",
"ranked_keys_excluding",
] {
assert!(
body.contains(call),
"the recipe is missing `{call}`: {body}"
);
}
}
#[test]
fn the_similar_door_never_reaches_the_plain_walk() {
let emission = emitted(&embedding_index());
let door = emission
.split("async fn retrieve_similar_by_image_embedding")
.nth(1)
.expect("the door is emitted");
let body = door.split("async fn").next().expect("the door has a body");
assert!(
body.contains("ranked_keys_excluding"),
"the door does not exclude: {body}"
);
assert!(
!body.contains("retain"),
"the door filters instead of seeding the membership: {body}"
);
}
#[test]
fn the_similar_door_takes_no_store() {
let emission = emitted(&embedding_index());
let door = emission
.split("async fn retrieve_similar_by_image_embedding")
.nth(1)
.expect("the door is emitted");
let signature = door.split('{').next().expect("the door has a signature");
assert!(
!signature.contains("AsyncGather"),
"a tier-A door gathers: {signature}"
);
assert!(
!signature.contains("filter"),
"a tier-A door filters: {signature}"
);
}
#[test]
fn the_similar_door_takes_a_scope_per_crossing() {
let emission = emitted(&embedding_index());
let door = emission
.split("async fn retrieve_similar_by_image_embedding")
.nth(1)
.expect("the door is emitted");
let signature = door.split('{').next().expect("the door has a signature");
assert!(
signature.contains("own :"),
"no own-read scope: {signature}"
);
assert!(signature.contains("scope :"), "no knn scope: {signature}");
assert!(signature.contains("key : &"), "{signature}");
}
#[test]
fn the_door_restates_no_judgment_and_narrows_no_refusal() {
let emission = emitted(&embedding_index());
let door = emission
.split("async fn retrieve_similar_by_image_embedding <")
.nth(1)
.expect("the door is emitted");
let signature = door.split('{').next().expect("the door has a signature");
assert!(
signature.contains("OwnReadError"),
"the door hands back some other vocabulary: {signature}"
);
let end = [door.find("# [doc"), door.find("async fn")]
.into_iter()
.flatten()
.min()
.unwrap_or(door.len());
let body = &door[..end];
for judgment in ["Unindexed", "Several", "Width", "DIM"] {
assert!(
!body.contains(judgment),
"the door decides `{judgment}` for itself, so two doors can drift about it: {body}"
);
}
}
#[test]
fn the_similar_door_mints_no_fold_vocabulary() {
let emission = emitted(&two_elections());
assert!(!emission.contains("Semantics"), "{emission}");
assert!(!emission.contains("FoldedQuery"), "{emission}");
}
#[test]
fn the_similar_door_names_itself_in_its_span() {
let emission = emitted(&embedding_index());
assert!(
emission.contains("entry = \"retrieve_similar_by_image_embedding\""),
"the door opens no span of its own: {emission}"
);
}