INNER CODE UNIT · Swift
addItems
ZachNagengast/similarity-search-kit · Sources/SimilaritySearchKit/Core/Index/SimilarityIndex.swift:258
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?()
}
}
// MARK: Read
func getItem(id: String) -> IndexItem? {
return indexItems.first { $0.id == id }
}
func sample(_ count: Int) -> [IndexItem]? {
return Array(indexItems.prefix(upTo: count))
}