Embeddings

Create Embeddings

POST /embeddings

Generate embeddings using the selected Large Language Model (LLM).

This endpoint allows you to generate embeddings for text inputs using a specific model. The response will be an Embedding Object consistent with OpenAI's Embedding Object format.

SDK Usage

The embeddings.create method in the Portkey SDK facilitates the generation of embeddings using various LLMs. This method provides a straightforward interface similar to the OpenAI API for generating embeddings.

Method Signature

portkey.embeddings.create(requestParams[, configParams]);

Parameters

  1. requestParams (Object): Parameters for the embedding request. All OpenAI params are supported. These parameters include the input text and model, and are automatically transformed by Portkey for LLMs other than OpenAI. Parameters not supported by other LLMs will be omitted.

  2. configParams (Object): Additional configuration options for the request. This is an optional parameter that can include custom config options for this specific request. These will override the configs set in the Portkey Client.

Example Usage

import Portkey from 'portkey-ai';

// Initialize the Portkey client
const portkey = new Portkey({
    apiKey: "PORTKEY_API_KEY",  // Replace with your Portkey API key
    virtualKey: "VIRTUAL_KEY"   // Optional: For virtual key management
});

// Generate embeddings
async function getEmbeddings() {
    const embeddings = await portkey.embeddings.create({
        input: "embed this",
        model: "text-embedding-ada-002",
    });

    console.log(embeddings);
}
await getEmbeddings();

// Generate embeddings with config params
async function getEmbeddingsWithConfig() {
    const embeddings = await portkey.embeddings.create({
        input: "embed this",
        model: "text-embedding-ada-002",
    }, {config: "custom-config-123"});

    console.log(embeddings);
}
await getEmbeddingsWithConfig();

Response Format

The response will conform to the Embedding Object schema from the Portkey API, typically including a list of embedding vectors consistent with the format provided by OpenAI for embedding objects.

Last updated