Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
env:
CARGO_TERM_COLOR: always
RUSTFLAGS: "-Dwarnings"
ONNX_VERSION: v1.22.0
ONNX_VERSION: v1.22.1

jobs:
test:
Expand Down
11 changes: 9 additions & 2 deletions src/output/embedding_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use super::{OutputKey, OutputPrecedence};
/// pooling etc. This struct should contain all the necessary information for the
/// post-processing to be performed.
pub struct SingleBatchOutput {
pub outputs: std::collections::HashMap<String, ort::value::Value>,
pub outputs: std::collections::BTreeMap<String, ort::value::Value>,
pub attention_mask_array: Array2<i64>,
}

Expand All @@ -26,7 +26,14 @@ impl SingleBatchOutput {
let ort_output: &ort::value::Value = precedence
.key_precedence()
.find_map(|key| match key {
OutputKey::OnlyOne => self.outputs.values().next(),
// Only select the sole output if and only if there is exactly one.
OutputKey::OnlyOne => {
if self.outputs.len() == 1 {
self.outputs.values().next()
} else {
None
}
}
OutputKey::ByOrder(idx) => self.outputs.values().nth(*idx),
OutputKey::ByName(name) => self.outputs.get(*name),
})
Expand Down
21 changes: 21 additions & 0 deletions tests/embeddings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -659,3 +659,24 @@ fn test_allminilml6v2_match_python_counterpart() {
assert!((expected - actual).abs() < tolerance);
}
}

// Ref: https://github.com/Anush008/fastembed-rs/issues/171#issue-3209484009
#[test]
fn clip_vit_b32_deterministic_across_calls() {
let q = "red car";
let mut fe = TextEmbedding::try_new(InitOptions::new(EmbeddingModel::ClipVitB32)).unwrap();
let mut first: Option<Vec<f32>> = None;
for i in 0..100 {
let vecs = fe.embed(vec![q], None).unwrap();
if first.is_none() {
first = Some(vecs[0].clone());
} else {
assert_eq!(
vecs[0],
*first.as_ref().unwrap(),
"Embedding changed after {} iterations",
i
);
}
}
}
Loading