utils library

Contains core utilities.

Classes

RetryOptions
Options to pass into retryClient to control the retry behavior.

Functions

calculateSimilarity(List<double> embedding, List<List<double>> embeddings, {double similarityFunction(List<double> a, List<double> b) = cosineSimilarity}) List<double>
Calculates the similarity between an embedding and a list of embeddings.
chunkList<T>(List<T> arr, {required int chunkSize}) List<List<T>>
Chunk a list into smaller list of a specified size.
cosineSimilarity(List<double> a, List<double> b) double
Measures the cosine of the angle between two vectors in a vector space. It ranges from -1 to 1, where 1 represents identical vectors, 0 represents orthogonal vectors, and -1 represents vectors that are diametrically opposed.
getIndexesMostSimilarEmbeddings(List<double> embedding, List<List<double>> embeddings, {double similarityFunction(List<double> a, List<double> b) = cosineSimilarity}) List<int>
Returns a sorted list of indexes of embeddings that are most similar to the provided embedding (in descending order, most similar first).
reduce<Type>(Iterable<Type> input) → Type
Reduces a list of objects to a single object by concatenating them.
retryClient<T>({required RetryOptions options, required FutureOr<T> fn()}) FutureOr<T>
A client that handles retry logic for a given function.