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