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. Create SecretID & SecretKey here.
  3. Set SecretID and SecretKey as environment variables named TENCENT_SECRET_ID and TENCENT_SECRET_KEY, respectively.
npm
npm install @langchain/community @langchain/core
If you are using LangChain.js in a browser environment, you’ll also need to install the following dependencies:
npm
npm install crypto-js
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 });