Voyage AI
VoyageEmbeddings 类使用 Voyage AI REST API 为给定文本生成嵌入。
inputType 参数允许您指定输入文本的类型,以获得更好的嵌入结果。您可以将其设置为 query、document 或保持未定义(相当于 None)。
query:用于搜索或检索查询。Voyage AI 将预先添加提示以优化查询用例的嵌入。document:用于您希望可检索的文档或内容。Voyage AI 将预先添加提示以优化文档用例的嵌入。None(默认):输入文本将直接编码,无需任何额外的提示。
此外,该类还支持新参数,用于进一步自定义嵌入过程
- truncation:是否将输入文本截断到模型允许的最大长度。
- outputDimension:输出嵌入的所需维度。
- outputDtype:输出嵌入的数据类型。可以是
"float"或"int8"。 - encodingFormat:输出嵌入的格式。可以是
"float"、"base64"或"ubinary"。
import { VoyageEmbeddings } from "@langchain/community/embeddings/voyage";
const embeddings = new VoyageEmbeddings({
apiKey: "YOUR-API-KEY", // In Node.js defaults to process.env.VOYAGEAI_API_KEY
inputType: "document", // Optional: specify input type as 'query', 'document', or omit for None / Undefined / Null
truncation: true, // Optional: enable truncation of input texts
outputDimension: 768, // Optional: set desired output embedding dimension
outputDtype: "float", // Optional: set output data type ("float" or "int8")
encodingFormat: "float", // Optional: set output encoding format ("float", "base64", or "ubinary")
});