To use the OpenAI embedding models, you need a API key from OpenAI. You can alternatively use Azure OpenAI to run most of the OpenAI embedding models. Read the Azure OpenAI section to learn more about this.

To get started, obtain an API Key from OpenAI. You can do this by visiting their API Portal. Once you obtain a key, set it in an environment variable, like so -

OPENAI_API_KEY="<Your key>"

Install OpenAI addon

npm install @llm-tools/embedjs-openai

Usage

import { RAGApplicationBuilder } from '@llm-tools/embedjs';
import { OpenAiEmbeddings } from '@llm-tools/embedjs-openai';
import { HNSWDb } from '@llm-tools/embedjs-hnswlib';

const app = await new RAGApplicationBuilder()
.setEmbeddingModel(new OpenAiEmbeddings({
    model: 'text-embedding-3-large'
}))

The following embedding models do not require you to pass a dimension parameter -

  • text-embedding-3-large
  • text-embedding-3-small
  • text-embedding-ada-002

All other models require you provide one.