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.
- Maximum number of chunks per request: 100
- Maximum length per chunk: 8192 characters
- Available embedding models:
openai:text-embedding-3-large
cohere:embed-v4.0
cohere:embed-multilingual-v3.0
cohere:embed-multilingual-light-v3.0
google:text-embedding-004
You will need to generate an API key to authenticate your requests. For more information, visit the User/Org API key documentation.
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
Install the SDK
npm i langbase
Environment variables
.env file
LANGBASE_API_KEY="<YOUR_API_KEY>"
Generate embeddings
Embedding
curl https://api.langbase.com/v1/embed \
-X POST \
-H 'Authorization: Bearer <YOUR_API_KEY>' \
-H 'Content-Type: application/json' \
-d '{
"chunks": [
"The quick brown fox",
"jumps over the lazy dog"
],
"embeddingModel": "openai:text-embedding-3-large"
}'
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, ...],
]