Skip to main content

Gradient AI

GradientEmbeddings 类使用 Gradient AI API 为给定文本生成嵌入向量。

¥The GradientEmbeddings class uses the Gradient AI API to generate embeddings for a given text.

设置

¥Setup

你需要安装官方 Gradient Node SDK 作为对等依赖:

¥You'll need to install the official Gradient Node SDK as a peer dependency:

npm i @langchain/community @langchain/core @gradientai/nodejs-sdk

你需要设置以下环境变量才能使用 Gradient AI API。

¥You will need to set the following environment variables for using the Gradient AI API.

export GRADIENT_ACCESS_TOKEN=<YOUR_ACCESS_TOKEN>
export GRADIENT_WORKSPACE_ID=<YOUR_WORKSPACE_ID>

或者,可以在 GradientAI 类实例化期间分别将它们设置为 gradientAccessKeyworkspaceId。例如:

¥Alternatively, these can be set during the GradientAI Class instantiation as gradientAccessKey and workspaceId respectively. For example:

const model = new GradientEmbeddings({
gradientAccessKey: "My secret Access Token"
workspaceId: "My secret workspace id"
});

用法

¥Usage

import { GradientEmbeddings } from "@langchain/community/embeddings/gradient_ai";

const model = new GradientEmbeddings({});
const res = await model.embedQuery(
"What would be a good company name a company that makes colorful socks?"
);
console.log({ res });

API Reference:

¥Related