INNER CODE UNIT · Swift

encode

ZachNagengast/similarity-search-kit · Sources/SimilaritySearchKit/Core/Embeddings/EmbeddingProtocols.swift:33

    func encode(sentence: String) async -> [Float]?
}

/// A protocol for arbitrary methods of calculating similarities between vectors.
public protocol DistanceMetricProtocol {
    /// Find the nearest neighbors given a query embedding vector and a list of embeddings vectors.
    ///
    /// - Parameters:
    ///   - queryEmbedding: A `[Float]` array representing the query embedding vector.
    ///   - itemEmbeddings: A `[[Float]]` array representing the list of embeddings vectors to search within.
    ///   - resultsCount: An Int representing the number of nearest neighbors to return.
    ///
    /// - Returns: A `[(Float, Int)]` array, where each tuple contains the similarity score and the index of the corresponding item in `neighborEmbeddings`. The array is sorted by decreasing similarity ranking.
    func findNearest(for queryEmbedding: [Float], in neighborEmbeddings: [[Float]], resultsCount: Int) -> [(Float, Int)]

    /// Calculate the distance between two embedding vectors.
    ///
    /// - Parameters:

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…