TencentHunyuan
The TencentHunyuanEmbeddings
class uses the Tencent Hunyuan API to generate embeddings for a given text.
Setupβ
- Sign up for a Tencent Cloud account here.
- Create SecretID & SecretKey here.
- Set SecretID and SecretKey as environment variables named
TENCENT_SECRET_ID
andTENCENT_SECRET_KEY
, respectively.
If you are using langchain-js in browser environment, you'll also need to install the following dependencies:
- npm
- Yarn
- pnpm
npm install @langchain/community crypto-js
yarn add @langchain/community crypto-js
pnpm add @langchain/community crypto-js
Usageβ
Here's an example:
import { TencentHunyuanEmbeddings } from "@langchain/community/embeddings/tencent_hunyuan";
// in nodejs environment
import { sign } from "@langchain/community/utils/tencent_hunyuan/index";
// in browser environment
// import { sign } from "@langchain/community/utils/tencent_hunyuan/web";
export const run = async () => {
/* Embed queries */
const embeddings = new TencentHunyuanEmbeddings({ sign });
const res = await embeddings.embedQuery("δ½ ε₯½οΌδΈηοΌ");
console.log(res);
/* Embed documents */
const documentRes = await embeddings.embedDocuments(["δ½ ε₯½οΌδΈηοΌ", "εθ§"]);
console.log({ documentRes });
};
API Reference:
- TencentHunyuanEmbeddings from
@langchain/community/embeddings/tencent_hunyuan
- sign from
@langchain/community/utils/tencent_hunyuan/index