Skip to main content

Gradient AI

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

Setup

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

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

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>

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:


Was this page helpful?


You can also leave detailed feedback on GitHub.