INNER CODE UNIT · Swift
addItems
ZachNagengast/similarity-search-kit · Sources/SimilaritySearchKit/Core/Index/SimilarityIndex.swift:231
func addItems(ids: [String], texts: [String], metadata: [[String: String]], embeddings: [[Float]?]? = nil, onProgress: ((String) -> Void)? = nil) async {
// Check if all input arrays have the same length
guard ids.count == texts.count, texts.count == metadata.count else {
fatalError("Input arrays must have the same length.")
}
if let embeddings = embeddings, embeddings.count != ids.count {
print("Embeddings array length must be the same as ids array length. \(embeddings.count) vs \(ids.count)")
}
await withTaskGroup(of: Void.self) { taskGroup in
for i in 0..<ids.count {
let id = ids[i]
let text = texts[i]
let embedding = embeddings?[i]
let meta = metadata[i]
taskGroup.addTask(priority: .userInitiated) {