From 1c9d4fcbaaf56fa13635bdda359c480c562d1851 Mon Sep 17 00:00:00 2001 From: buhe Date: Mon, 12 Feb 2024 13:44:47 +0800 Subject: [PATCH] "\"Update Package.swift, README.md, Distilbert.swift, and SimilaritySearchKit.swift: Fix Distilbert embedding and vector store loading/saving.\"" --- Package.swift | 2 +- README.md | 2 +- Sources/LangChain/embeddings/Distilbert.swift | 39 ++++++++++--------- .../vectorstores/SimilaritySearchKit.swift | 4 +- 4 files changed, 24 insertions(+), 23 deletions(-) diff --git a/Package.swift b/Package.swift index 6a31313..14999d3 100644 --- a/Package.swift +++ b/Package.swift @@ -42,7 +42,7 @@ let package = Package( .product(name: "SwiftSoup", package: "SwiftSoup"), .product(name: "SwiftFileStore", package: "swift-filestore"), .product(name: "SimilaritySearchKit", package: "similarity-search-kit", condition: .when(platforms: [.macOS, .iOS, .visionOS])), -// .product(name: "SimilaritySearchKitDistilbert", package: "similarity-search-kit", condition: .when(platforms: [.macOS, .iOS, .visionOS])), + .product(name: "SimilaritySearchKitDistilbert", package: "similarity-search-kit", condition: .when(platforms: [.macOS, .iOS, .visionOS])), .product(name: "GoogleGenerativeAI", package: "generative-ai-swift"), .product(name: "SwiftyNotion", package: "SwiftyNotion"), .product(name: "FeedKit", package: "FeedKit"), diff --git a/README.md b/README.md index 4932ac4..bbd431d 100644 --- a/README.md +++ b/README.md @@ -402,7 +402,7 @@ Task(priority: .background) { - [x] FileStore - Embedding - [x] OpenAI - - [ ] Distilbert + - [x] Distilbert - Chain - [x] Base - [x] LLM diff --git a/Sources/LangChain/embeddings/Distilbert.swift b/Sources/LangChain/embeddings/Distilbert.swift index 64d7973..2ededc9 100644 --- a/Sources/LangChain/embeddings/Distilbert.swift +++ b/Sources/LangChain/embeddings/Distilbert.swift @@ -1,21 +1,22 @@ -//// -//// File.swift -//// -//// -//// Created by 顾艳华 on 2/11/24. -//// // -//import Foundation -//import SimilaritySearchKitDistilbert +// File.swift +// // -//public struct Distilbert: Embeddings { -// let n = DistilbertEmbeddings() -// public init() { -// -// } -// -// -// public func embedQuery(text: String) async -> [Float] { -// await n.encode(sentence: text)! -// } -//} +// Created by 顾艳华 on 2/11/24. +// + +import Foundation +import SimilaritySearchKitDistilbert + +@available(macOS 13.0, *) +public struct Distilbert: Embeddings { + let n = DistilbertEmbeddings() + public init() { + + } + + + public func embedQuery(text: String) async -> [Float] { + await n.encode(sentence: text)! + } +} diff --git a/Sources/LangChain/vectorstores/SimilaritySearchKit.swift b/Sources/LangChain/vectorstores/SimilaritySearchKit.swift index 871b37a..78e3315 100644 --- a/Sources/LangChain/vectorstores/SimilaritySearchKit.swift +++ b/Sources/LangChain/vectorstores/SimilaritySearchKit.swift @@ -47,7 +47,7 @@ public class SimilaritySearchKit: VectorStore { ) if #available(macOS 13.0, *) { if autoLoad { - try? vs.loadIndex() + let _ = try? vs.loadIndex() } } else { // Fallback on earlier versions @@ -64,7 +64,7 @@ public class SimilaritySearchKit: VectorStore { @available(macOS 13.0, *) public func writeToFile() { - try? vs.saveIndex() + let _ = try? vs.saveIndex() } } #endif