Skip to content

Commit b30d42b

Browse files
committed
Update
1 parent 40fe5d4 commit b30d42b

3 files changed

Lines changed: 16 additions & 3 deletions

File tree

Tool/Sources/LangChain/VectorStore/TemporaryUSearch.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ public actor TemporaryUSearch: VectorStore {
1818
let index: USearchIndex
1919
var documents: [USearchLabel: LabeledDocument] = [:]
2020

21-
public init(identifier: String) {
21+
public init(identifier: String, dimensions: Int = 1536 /* text-embedding-ada-002 */ ) {
2222
self.identifier = calculateMD5Hash(identifier)
2323
index = .init(
2424
metric: .IP,
25-
dimensions: 1536, // text-embedding-ada-002
25+
dimensions: UInt32(dimensions),
2626
connectivity: 16,
2727
quantization: .F32
2828
)

Tool/Sources/OpenAIService/Configuration/EmbeddingConfiguration.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ public protocol EmbeddingConfiguration {
77
var model: EmbeddingModel { get }
88
var apiKey: String { get }
99
var maxToken: Int { get }
10+
var dimensions: Int { get }
1011
}
1112

1213
public extension EmbeddingConfiguration {

Tool/Sources/OpenAIService/Configuration/UserPreferenceEmbeddingConfiguration.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ public struct UserPreferenceEmbeddingConfiguration: EmbeddingConfiguration {
1414
model.info.maxTokens
1515
}
1616

17+
#warning("TODO: Support different dimensions.")
18+
public var dimensions: Int {
19+
1536 // text-embedding-ada-002
20+
}
21+
1722
public init() {}
1823
}
1924

@@ -24,15 +29,18 @@ public class OverridingEmbeddingConfiguration<
2429
public var modelId: String?
2530
public var model: EmbeddingModel?
2631
public var maxTokens: Int?
32+
public var dimensions: Int?
2733

2834
public init(
2935
modelId: String? = nil,
3036
model: EmbeddingModel? = nil,
31-
maxTokens: Int? = nil
37+
maxTokens: Int? = nil,
38+
dimensions: Int? = nil
3239
) {
3340
self.modelId = modelId
3441
self.model = model
3542
self.maxTokens = maxTokens
43+
self.dimensions = dimensions
3644
}
3745
}
3846

@@ -56,5 +64,9 @@ public class OverridingEmbeddingConfiguration<
5664
public var maxToken: Int {
5765
overriding.maxTokens ?? configuration.maxToken
5866
}
67+
68+
public var dimensions: Int {
69+
overriding.dimensions ?? configuration.dimensions
70+
}
5971
}
6072

0 commit comments

Comments
 (0)