Skip to main content

TencentHunyuan

TencentHunyuanEmbeddings 类使用腾讯混元 API 为给定文本生成嵌入向量。

¥The TencentHunyuanEmbeddings class uses the Tencent Hunyuan API to generate embeddings for a given text.

设置

¥Setup

  1. 注册腾讯云账号 此处

    ¥Sign up for a Tencent Cloud account here.

  2. 创建 SecretID 和 SecretKey 此处

    ¥Create SecretID & SecretKey here.

  3. 将 SecretID 和 SecretKey 分别设置为名为 TENCENT_SECRET_IDTENCENT_SECRET_KEY 的环境变量。

    ¥Set SecretID and SecretKey as environment variables named TENCENT_SECRET_ID and TENCENT_SECRET_KEY, respectively.

npm install @langchain/community @langchain/core

如果你在浏览器环境中使用 LangChain.js,则还需要安装以下依赖:

¥If you are using LangChain.js in a browser environment, you'll also need to install the following dependencies:

npm install crypto-js

然后确保从 web 导入,如下所示。

¥And then make sure that you import from the web as shown below.

用法

¥Usage

以下是一个例子:

¥Here's an example:

// in nodejs environment
import { TencentHunyuanEmbeddings } from "@langchain/community/embeddings/tencent_hunyuan";

// in browser environment
// import { TencentHunyuanEmbeddings } from "@langchain/community/embeddings/tencent_hunyuan/web";

/* Embed queries */
const embeddings = new TencentHunyuanEmbeddings();
const res = await embeddings.embedQuery("你好,世界!");
console.log(res);
/* Embed documents */
const documentRes = await embeddings.embedDocuments(["你好,世界!", "再见"]);
console.log({ documentRes });

API Reference:

¥Related