Cohere
Cohere 提供多种 Embedding 模型,可用于文本语义检索、聚类与推荐等场景。seekdb 提供 CohereEmbeddingFunction 封装,用于在写入 documents 或使用 query_texts 查询时,自动调用 Cohere 生成向量并完成相似性检索。
提示
使用 Cohere 服务需要遵循 Cohere 的收费规则,可能产生相应费用。请在继续前,访问其官网或查阅相关文档,确认并接受其收费标准。如不同意,请勿继续操作。
依赖与鉴权
使用该 Embedding Function 通常需要:
- 已获取 Cohere API Key,并具备调用目标 Embedding 模型的权限
- 鉴权可通过参数传入 API Key,或通过环境变量提供(默认读取
COHERE_API_KEY);若使用其他环境变量名,可通过apiKeyEnvVar指定
安装
npm i seekdb @seekdb/cohere
示例:创建 Cohere Embedding Function
import { CohereEmbeddingFunction } from "@seekdb/cohere";
const ef = new CohereEmbeddingFunction({
modelName: "embed-english-v3.0",
inputType: "search_document",
});
配置项说明:
- apiKey:Cohere API Key(可选;若不提供,则尝试从环境变量读取)
- apiKeyEnvVar:API Key 的环境变量名(默认:
"COHERE_API_KEY") - modelName:Embedding 模型名称(默认:
"embed-english-v3.0") - inputType:输入类型提示,用于优化检索效果。可选值:
"search_document"|"search_query"|"classification"|"clustering"|"image"(默认:"search_document") - truncate:过长输入时的截断策略,可选:
"NONE"|"START"|"END"(可选) - embeddingType:输出向量类型,可选:
"float"|"int8"|"uint8"|"binary"|"ubinary"(可选)