Skip to content

Commit

Permalink
Removed deprecated methods & added logger for save / load index opera…
Browse files Browse the repository at this point in the history
…tions.
  • Loading branch information
johnbean393 committed Jun 3, 2024
1 parent bf50730 commit f73e4bb
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ public struct DotProduct: DistanceMetricProtocol {
return sortedScores(scores: scores, topK: resultsCount)
}

// public func distance(between firstEmbedding: [Float], and secondEmbedding: [Float]) -> Float {
// let dotProduct = zip(firstEmbedding, secondEmbedding).map(*).reduce(0, +)
// return dotProduct
// }

public func distance(between firstEmbedding: [Float], and secondEmbedding: [Float]) -> Float {
// Ensure the embeddings have the same length
Expand Down Expand Up @@ -53,14 +49,6 @@ public struct CosineSimilarity: DistanceMetricProtocol {
return sortedScores(scores: scores, topK: resultsCount)
}

// public func distance(between firstEmbedding: [Float], and secondEmbedding: [Float]) -> Float {
// // Calculate cosine distance
// let dotProduct = zip(firstEmbedding, secondEmbedding).map(*).reduce(0, +)
// let firstMagnitude = sqrt(firstEmbedding.map { $0 * $0 }.reduce(0, +))
// let secondMagnitude = sqrt(secondEmbedding.map { $0 * $0 }.reduce(0, +))
//
// return dotProduct / (firstMagnitude * secondMagnitude)
// }

public func distance(between firstEmbedding: [Float], and secondEmbedding: [Float]) -> Float {
// Ensure the embeddings have the same length
Expand Down Expand Up @@ -98,11 +86,6 @@ public struct EuclideanDistance: DistanceMetricProtocol {
let distances = neighborEmbeddings.map { distance(between: queryEmbedding, and: $0) }
return sortedDistances(distances: distances, topK: resultsCount)
}

// public func distance(between firstEmbedding: [Float], and secondEmbedding: [Float]) -> Float {
// let squaredDifferences = zip(firstEmbedding, secondEmbedding).map { ($0 - $1) * ($0 - $1) }
// return sqrt(squaredDifferences.reduce(0, +))
// }

public func distance(between firstEmbedding: [Float], and secondEmbedding: [Float]) -> Float {
// Ensure the embeddings have the same length
Expand Down
4 changes: 3 additions & 1 deletion Sources/SimilaritySearchKit/Core/Index/SimilarityIndex.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import Foundation
import OSLog

// MARK: - Type Aliases

Expand All @@ -23,7 +24,6 @@ public class SimilarityIndex: Identifiable, Hashable {
return lhs.id == rhs.id
}


public func hash(into hasher: inout Hasher) {
hasher.combine(id)
}
Expand Down Expand Up @@ -333,6 +333,8 @@ extension SimilarityIndex {

let savedVectorStore = try vectorStore.saveIndex(items: indexItems, to: basePath, as: indexName)

let bundleId: String = Bundle.main.bundleIdentifier ?? "com.similarity-search-kit.logger"
let logger: Logger = Logger(subsystem: bundleId, category: "similarityIndexSave")

return savedVectorStore
}
Expand Down

0 comments on commit f73e4bb

Please sign in to comment.