Skip to content

Commit

Permalink
fix: Add completion callback to addItems(_:items) (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
brn authored Dec 17, 2023
1 parent 919740d commit 224e95e
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions Sources/SimilaritySearchKit/Core/Index/SimilarityIndex.swift
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,12 @@ extension SimilarityIndex {
}
}

public func addItems(_ items: [IndexItem]) {
public func addItems(_ items: [IndexItem], completion: (() -> Void)? = nil) {
Task {
for item in items {
await self.addItem(id: item.id, text: item.text, metadata: item.metadata, embedding: item.embedding)
}
completion?()
}
}

Expand Down Expand Up @@ -326,8 +327,9 @@ extension SimilarityIndex {
public func loadIndex(fromDirectory path: URL? = nil, name: String? = nil) throws -> [IndexItem]? {
if let indexPath = try getIndexPath(fromDirectory: path, name: name) {
let loadedIndexItems = try vectorStore.loadIndex(from: indexPath)
addItems(loadedIndexItems)
print("Loaded \(indexItems.count) index items from \(indexPath.absoluteString)")
addItems(loadedIndexItems) {[self] in
print("Loaded \(indexItems.count) index items from \(indexPath.absoluteString)")
}
return loadedIndexItems
}

Expand Down

0 comments on commit 224e95e

Please sign in to comment.