Skip to content

Commit

Permalink
"\"Update Package.swift, README.md, Distilbert.swift, and SimilarityS…
Browse files Browse the repository at this point in the history
…earchKit.swift: Fix Distilbert embedding and vector store loading/saving.\""
  • Loading branch information
buhe committed Feb 12, 2024
1 parent 8e92a99 commit 1c9d4fc
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ Task(priority: .background) {
- [x] FileStore
- Embedding
- [x] OpenAI
- [ ] Distilbert
- [x] Distilbert
- Chain
- [x] Base
- [x] LLM
Expand Down
39 changes: 20 additions & 19 deletions Sources/LangChain/embeddings/Distilbert.swift
Original file line number Diff line number Diff line change
@@ -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)!
}
}
4 changes: 2 additions & 2 deletions Sources/LangChain/vectorstores/SimilaritySearchKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -64,7 +64,7 @@ public class SimilaritySearchKit: VectorStore {

@available(macOS 13.0, *)
public func writeToFile() {
try? vs.saveIndex()
let _ = try? vs.saveIndex()
}
}
#endif

0 comments on commit 1c9d4fc

Please sign in to comment.