INNER CODE UNIT · Swift
updateItem
ZachNagengast/similarity-search-kit · Sources/SimilaritySearchKit/Core/Index/SimilarityIndex.swift:279
func updateItem(id: String, text: String? = nil, embedding: [Float]? = nil, metadata: [String: String]? = nil) {
// Check if the provided embedding has the correct dimension
if let embedding = embedding, embedding.count != dimension {
print("Dimension mismatch, expected \(dimension), saw \(embedding.count)")
}
// Find the item with the specified id
if let index = indexItems.firstIndex(where: { $0.id == id }) {
// Update the text if provided
if let text = text {
indexItems[index].text = text
}
// Update the embedding if provided
if let embedding = embedding {
indexItems[index].embedding = embedding
}