Skip to content

Commit 29f00a6

Browse files
committed
Add VectorStore protocol
1 parent bdd9d6f commit 29f00a6

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import Foundation
2+
3+
protocol VectorStore {
4+
func add(_ documents: [EmbeddedDocument]) async throws
5+
func set(_ documents: [EmbeddedDocument]) async throws
6+
func clear() async throws
7+
func searchWithDistance(embeddings: [Float], count: Int) async throws
8+
-> [(document: Document, distance: Float)]
9+
}
10+
11+
extension VectorStore {
12+
func search(embeddings: [Float], count: Int) async throws -> [Document] {
13+
try await searchWithDistance(embeddings: embeddings, count: count).map { $0.document }
14+
}
15+
16+
func add(_ document: EmbeddedDocument) async throws {
17+
try await add([document])
18+
}
19+
}
20+

0 commit comments

Comments
 (0)