跳到主要内容
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")
});

以编程方式连接这些文档到 Claude、VSCode 等,通过 MCP 获取实时答案。
© . This site is unofficial and not affiliated with LangChain, Inc.