INNER CODE UNIT · Swift

sample

ZachNagengast/similarity-search-kit · Sources/SimilaritySearchKit/Core/Index/SimilarityIndex.swift:273

    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 }) {
            // Update the text if provided
            if let text = text {
                indexItems[index].text = text
            }

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…