Skip to main content
VoyageEmbeddings 类使用 Voyage AI REST API 为给定文本生成嵌入。 inputType 参数允许你指定输入文本的类型以获得更好的嵌入结果。你可以将其设置为 querydocument,或者保留为未定义(相当于 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")
});

相关