cosineSimilarity method
Passes two embeddings to MediaPipe for comparison. Both embeddings should have been made from embedders with the same configuration for the result to be meaningful.
Implementation
double cosineSimilarity(
Pointer<core_bindings.Embedding> a,
Pointer<core_bindings.Embedding> b,
) {
final nativeSimilarity = calloc<Double>();
final errorMessageMemory = calloc<Pointer<Char>>();
int status = bindings.text_embedder_cosine_similarity(
a,
b,
nativeSimilarity,
errorMessageMemory,
);
_log.finest('Compared similarity with status $status');
handleErrorMessage(errorMessageMemory, status);
errorMessageMemory.free(1);
final double similarity = nativeSimilarity.value;
calloc.free(nativeSimilarity);
return similarity;
}