From ef737c4aad3af904a9925c476dc37c0dddc6ad8c Mon Sep 17 00:00:00 2001 From: buhe Date: Wed, 14 Feb 2024 13:26:05 +0800 Subject: [PATCH] "Refactor loadIndex method to directly assign loaded index items to indexItems" (#36) --- .../SimilaritySearchKit/Core/Index/SimilarityIndex.swift | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Sources/SimilaritySearchKit/Core/Index/SimilarityIndex.swift b/Sources/SimilaritySearchKit/Core/Index/SimilarityIndex.swift index cb1559e..cd665c1 100644 --- a/Sources/SimilaritySearchKit/Core/Index/SimilarityIndex.swift +++ b/Sources/SimilaritySearchKit/Core/Index/SimilarityIndex.swift @@ -326,11 +326,9 @@ extension SimilarityIndex { public func loadIndex(fromDirectory path: URL? = nil, name: String? = nil) throws -> [IndexItem]? { if let indexPath = try getIndexPath(fromDirectory: path, name: name) { - let loadedIndexItems = try vectorStore.loadIndex(from: indexPath) - addItems(loadedIndexItems) {[self] in - print("Loaded \(indexItems.count) index items from \(indexPath.absoluteString)") - } - return loadedIndexItems + indexItems = try vectorStore.loadIndex(from: indexPath) + print("Loaded \(indexItems.count) index items from \(indexPath.absoluteString)") + return indexItems } return nil