Voyage AI
VoyageEmbeddings
类使用 Voyage AI REST API 为给定文本生成嵌入向量。
¥The VoyageEmbeddings
class uses the Voyage AI REST API to generate embeddings for a given text.
inputType
参数允许你指定输入文本的类型,以获得更好的嵌入结果。你可以将其设置为 query
、document
,或保留未定义(相当于 None
)。
¥The inputType
parameter allows you to specify the type of input text for better embedding results. You can set it to query
, document
, or leave it undefined (which is equivalent to None
).
query
:将此 API 用于搜索或检索查询。Voyage AI 将在前面添加一个提示,以优化查询用例的嵌入。¥
query
: Use this for search or retrieval queries. Voyage AI will prepend a prompt to optimize the embeddings for query use cases.document
:将此 API 用于你希望可检索的文档或内容。Voyage AI 将在前面添加一个提示,以优化文档用例的嵌入。¥
document
: Use this for documents or content that you want to be retrievable. Voyage AI will prepend a prompt to optimize the embeddings for document use cases.None
(默认):输入文本将直接进行编码,无需任何额外提示。¥
None
(default): The input text will be directly encoded without any additional prompt.
此外,该类支持新的参数,以便进一步自定义嵌入过程:
¥Additionally, the class supports new parameters for further customization of the embedding process:
截断:是否将输入文本截断为模型允许的最大长度。
¥truncation: Whether to truncate the input texts to the maximum length allowed by the model.
输出维度:输出嵌入所需的维度。
¥outputDimension: The desired dimension of the output embeddings.
输出类型:输出嵌入的数据类型。可以是
"float"
或"int8"
。¥outputDtype: The data type of the output embeddings. Can be
"float"
or"int8"
.编码格式:输出嵌入的格式。可以是
"float"
、"base64"
或"ubinary"
。¥encodingFormat: The format of the output embeddings. Can be
"float"
,"base64"
, or"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")
});
相关
¥Related
嵌入模型 概念指南
¥Embedding model conceptual guide
嵌入模型 操作指南
¥Embedding model how-to guides