mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-24 10:40:07 +08:00
Co-authored-by: icarus <eurfelux@gmail.com> Co-authored-by: eeee0717 <chentao020717@outlook.com>
26 lines
830 B
TypeScript
26 lines
830 B
TypeScript
import type { Embeddings as BaseEmbeddings } from '@langchain/core/embeddings'
|
|
import { TraceMethod } from '@mcp-trace/trace-core'
|
|
import { ApiClient } from '@types'
|
|
|
|
import EmbeddingsFactory from './EmbeddingsFactory'
|
|
|
|
export default class TextEmbeddings {
|
|
private sdk: BaseEmbeddings
|
|
constructor({ embedApiClient, dimensions }: { embedApiClient: ApiClient; dimensions?: number }) {
|
|
this.sdk = EmbeddingsFactory.create({
|
|
embedApiClient,
|
|
dimensions
|
|
})
|
|
}
|
|
|
|
@TraceMethod({ spanName: 'embedDocuments', tag: 'Embeddings' })
|
|
public async embedDocuments(texts: string[]): Promise<number[][]> {
|
|
return this.sdk.embedDocuments(texts)
|
|
}
|
|
|
|
@TraceMethod({ spanName: 'embedQuery', tag: 'Embeddings' })
|
|
public async embedQuery(text: string): Promise<number[]> {
|
|
return this.sdk.embedQuery(text)
|
|
}
|
|
}
|