Skip to content

Commit a1a2d18

Browse files
authored
fix: ollama embedding provider issue (#195)
1 parent 95fe480 commit a1a2d18

File tree

3 files changed

+47
-16
lines changed

3 files changed

+47
-16
lines changed

packages/core/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"@node-rs/jieba": "^2.0.1",
2525
"@tg-search/common": "workspace:*",
2626
"@xsai-ext/providers-cloud": "catalog:",
27+
"@xsai-ext/providers-local": "0.3.0-beta.2",
2728
"@xsai/embed": "catalog:",
2829
"big-integer": "^1.6.52",
2930
"defu": "^6.1.4",

packages/core/src/utils/embed.ts

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,36 @@
1+
import type { EmbedManyResult } from '@xsai/embed'
2+
3+
import { EmbeddingProvider } from '@tg-search/common'
14
import { useConfig } from '@tg-search/common/composable'
5+
import { createOllama } from '@xsai-ext/providers-local'
26
import { embedMany } from '@xsai/embed'
37

48
import { Ok } from './monad'
59

610
export async function embedContents(contents: string[]) {
711
const embeddingConfig = useConfig().api.embedding
812

9-
const embeddings = await embedMany({
10-
apiKey: embeddingConfig.apiKey,
11-
baseURL: embeddingConfig.apiBase || '',
12-
input: contents,
13-
model: embeddingConfig.model,
14-
})
13+
let embeddings: EmbedManyResult
14+
switch (embeddingConfig.provider) {
15+
case EmbeddingProvider.OPENAI:
16+
embeddings = await embedMany({
17+
apiKey: embeddingConfig.apiKey,
18+
baseURL: embeddingConfig.apiBase || '',
19+
input: contents,
20+
model: embeddingConfig.model,
21+
})
22+
break
23+
case EmbeddingProvider.OLLAMA: {
24+
const ollama = createOllama()
25+
embeddings = await embedMany({
26+
...ollama.chat(embeddingConfig.model),
27+
input: contents,
28+
})
29+
}
30+
break
31+
default:
32+
throw new Error(`Unsupported embedding model: ${embeddingConfig.provider}`)
33+
}
1534

1635
return Ok({
1736
...embeddings,

pnpm-lock.yaml

Lines changed: 21 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)