跳到主要内容

HuggingFace Inference

此 Embeddings 集成使用 HuggingFace Inference API,默认使用 sentence-transformers/distilbert-base-nli-mean-tokens 模型为给定文本生成嵌入。您可以将不同的模型名称传递给构造函数以使用不同的模型。

设置

您首先需要安装 @langchain/community 包和所需的 peer dependency

提示

请参阅此部分以获取有关安装集成包的通用说明。

npm install @langchain/community @langchain/core @huggingface/inference@2

用法

import { HuggingFaceInferenceEmbeddings } from "@langchain/community/embeddings/hf";

const embeddings = new HuggingFaceInferenceEmbeddings({
apiKey: "YOUR-API-KEY", // In Node.js defaults to process.env.HUGGINGFACEHUB_API_KEY
});

此页是否对您有帮助?


您也可以留下详细的反馈 在 GitHub 上.