Embed API v1
The embed
API endpoint allows you to generate vector embeddings for text chunks. This is particularly useful for semantic search, text similarity comparisons, and other NLP tasks.
Limitations
- Maximum number of chunks per request: 100
- Maximum length per chunk: 8192 characters
- Available embedding models:
openai:text-embedding-3-large
cohere:embed-multilingual-v3.0
cohere:embed-multilingual-light-v3.0
google:text-embedding-004
Generate a User/Org API key
You will need to generate an API key to authenticate your requests. For more information, visit the User/Org API key documentation.
Generate embeddings
Generate vector embeddings for text chunks by sending them to the embed API endpoint.
Headers
- Name
Content-Type
- Type
- string
- Required
- Required
- Description
Request content type. Needs to be
application/json
.
- Name
Authorization
- Type
- string
- Required
- Required
- Description
Replace
<YOUR_API_KEY>
with your user/org API key.
Request Body
- Name
chunks
- Type
- string[]
- Required
- Required
- Description
An array of text chunks to generate embeddings for. Maximum 100 chunks per request, with each chunk limited to 8192 characters.
- Name
embeddingModel
- Type
- string
- Description
The embedding model to use. Available options:
openai:text-embedding-3-large
cohere:embed-multilingual-v3.0
cohere:embed-multilingual-light-v3.0
google:text-embedding-004
Default:
openai:text-embedding-3-large
Usage example
Install the SDK
npm i langbase
Environment variables
.env file
LANGBASE_API_KEY="<USER/ORG-API-KEY>"
Generate embeddings
Embedding
import { Langbase } from 'langbase';
const langbase = new Langbase({
apiKey: process.env.LANGBASE_API_KEY!,
});
async function main() {
const embeddings = await langbase.embed({
chunks: [
"The quick brown fox",
"jumps over the lazy dog"
]
});
console.log('Embeddings:', embeddings);
}
main();
Response
- Name
Response
- Type
- number[][]
- Description
The response is a 2D array where each inner array represents the embedding vector for the corresponding input chunk.
Embed API Response
type EmbedResponse = number[][];
API Response
[
[-0.023, 0.128, -0.194, ...],
[0.067, -0.022, 0.289, ...],
]