You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

导入自定义嵌入模型至Ollama遇两类问题:embeddings报错与generate不支持

问题解决方案

问题1:调用embeddings接口返回ResponseError

排查与修复步骤:

  • 确认模型名称一致性:执行ollama list查看已安装的模型列表,确保代码中指定的model参数(如MiniLM-L6:v2)与列表中的名称完全匹配(注意大小写差异,比如你导入的是MiniLM-L6:V2,代码里用小写v2会导致模型找不到)。
  • 修正prompt参数格式:Ollama Python SDK的embeddings接口中,单条文本无需用列表包裹,直接传入字符串即可。修改后的代码:
import ollama

embeddings = ollama.embeddings(
  model='MiniLM-L6:v2',  # 与ollama list中的名称保持一致
  prompt='Llamas are members of the camelid family',
)

print(embeddings)
  • 验证环境可用性:先用已确认导入成功的m3e-large模型测试embeddings接口,排除环境问题:
import ollama

embeddings = ollama.embeddings(
  model='m3e-large',
  prompt='Llamas are members of the camelid family',
)

print(embeddings)

问题2:执行ollama run MiniLM-L6:V2返回不支持generate错误

原因与正确用法:

  • 模型类型限制:MiniLM属于文本嵌入模型(Sentence Transformer),仅具备生成文本嵌入的能力,不支持对话生成功能。而ollama run命令是用于调用对话生成模型的,因此会触发错误。
  • 正确调用方式:通过embeddings接口使用该模型,示例代码:
import ollama

embeddings = ollama.embeddings(
  model='MiniLM-L6:V2',
  prompt='Your text here'
)
print(embeddings)

内容的提问来源于stack exchange,提问作者IronSpiderMan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.16 16:49:59