TencentHunyuan
TencentHunyuanEmbeddings
类使用腾讯混元 API 为给定文本生成嵌入向量。
¥The TencentHunyuanEmbeddings
class uses the Tencent Hunyuan API to generate embeddings for a given text.
设置
¥Setup
注册腾讯云账号 此处。
¥Sign up for a Tencent Cloud account here.
创建 SecretID 和 SecretKey 此处。
¥Create SecretID & SecretKey here.
将 SecretID 和 SecretKey 分别设置为名为
TENCENT_SECRET_ID
和TENCENT_SECRET_KEY
的环境变量。¥Set SecretID and SecretKey as environment variables named
TENCENT_SECRET_ID
andTENCENT_SECRET_KEY
, respectively.
- npm
- Yarn
- pnpm
npm install @langchain/community @langchain/core
yarn add @langchain/community @langchain/core
pnpm add @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
- Yarn
- pnpm
npm install crypto-js
yarn add crypto-js
pnpm add 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:
- TencentHunyuanEmbeddings from
@langchain/community/embeddings/tencent_hunyuan
相关
¥Related
嵌入模型 概念指南
¥Embedding model conceptual guide
嵌入模型 操作指南
¥Embedding model how-to guides