calculateSimilarity function
Calculates the similarity between an embedding and a list of embeddings.
The similarity is calculated using the provided similarityFunction
.
The default similarity function is cosineSimilarity.
Implementation
List<double> calculateSimilarity(
final List<double> embedding,
final List<List<double>> embeddings, {
final double Function(List<double> a, List<double> b) similarityFunction =
cosineSimilarity,
}) {
return embeddings
.map((final vector) => similarityFunction(vector, embedding))
.toList(growable: false);
}