Skip to content

Commit

Permalink
Remove fatalerror on setup + cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ZachNagengast committed Aug 5, 2023
1 parent d591adc commit aef8b0e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Examples/PDFExample/PDFExample/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ struct ContentView: View {
}

for (idx, chunk) in chunks.enumerated() {
await index.addItem(id: "id\(idx)", text: chunk, metadata: ["source": fileName], embedding: embeddings[idx])
let vector = embeddings[idx]
await index.addItem(id: "id\(idx)", text: chunk, metadata: ["source": fileName], embedding: vector)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
//

import Foundation
import SimilaritySearchKit

public class RecursiveCharacterSplitter: TextSplitterProtocol {
let characterSplitter: CharacterSplitter
Expand Down
6 changes: 3 additions & 3 deletions Sources/SimilaritySearchKit/Core/Index/SimilarityIndex.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public class SimilarityIndex {
if let testVector = await indexModel.encode(sentence: "Test sentence") {
dimension = testVector.count
} else {
fatalError("Failed to generate a test input vector.")
print("Failed to generate a test input vector.")
}
}

Expand Down Expand Up @@ -225,7 +225,7 @@ extension SimilarityIndex {
}

if let embeddings = embeddings, embeddings.count != ids.count {
fatalError("Embeddings array length must be the same as ids array length. \(embeddings.count) vs \(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
Expand Down Expand Up @@ -268,7 +268,7 @@ extension SimilarityIndex {
public 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 {
fatalError("Dimension mismatch, expected \(dimension), saw \(embedding.count)")
print("Dimension mismatch, expected \(dimension), saw \(embedding.count)")
}

// Find the item with the specified id
Expand Down

0 comments on commit aef8b0e

Please sign in to comment.