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
- Yarn
- pnpm
npm i @langchain/community @langchain/core @gradientai/nodejs-sdk
yarn add @langchain/community @langchain/core @gradientai/nodejs-sdk
pnpm add @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:
- GradientEmbeddings from
@langchain/community/embeddings/gradient_ai
Related
- Embedding model conceptual guide
- Embedding model how-to guides