Embeddings
The full list of models can be viewed on the Models page or retrieved dynamically via API endpoints: https://openai.bothub.chat/v1/models and https://bothub.chat/api/v2/replicate/v1/models
Embeddings are numerical representations of text that allow models to understand meaning and semantic proximity between words, sentences, or entire documents.
When text is converted into an embedding vector, the model preserves not the words themselves, but their semantic representation. This allows you to compare texts with each other, find similar content, and perform intelligent searches.
Embeddings are actively used in AI applications, search systems, and RAG (Retrieval-Augmented Generation) scenarios, where the model works with an external knowledge base.
Where Embeddings Are Used
Embeddings are especially useful in tasks where understanding the meaning of text is important, rather than just matching words. For example, they are used for semantic search, finding similar documents, content recommendations, intelligent chatbots, text clustering, and data classification.
Embeddings are also an essential part of RAG systems, where the model first searches for relevant information in a knowledge base and then uses it when generating a response.
Available Models
We have the following embedding models available:
text-embedding-3-small(for fast and low-cost tasks)text-embedding-3-large(for higher quality and search accuracy)text-embedding-ada-002
Generating Embeddings
To create an embedding vector, send text via the API and specify the embedding model. The API will return an array of numbers that can be used for searching, comparing, or storing in a vector database.
Below is a basic example of generating embeddings using the text-embedding-3-large model.
- JS
- Python
- Go
- cURL
async function main() {
const response = await openai.embeddings.create({
model: 'text-embedding-3-large',
input: 'The food was delicious and the waiter...',
encoding_format: 'float'
});
const embedding = response.data[0].embedding;
console.log(embedding);
}
main();
def main():
response = client.embeddings.create(
model="text-embedding-3-large",
input="The food was delicious and the waiter...",
encoding_format="float"
)
embedding = response.data[0].embedding
print(embedding)
main()
package main
import (
"context"
"fmt"
"github.com/openai/openai-go"
"github.com/openai/openai-go/option"
)
func main() {
client := openai.NewClient(
option.WithAPIKey("YOUR_BOTHUB_API_KEY"),
option.WithBaseURL("https://openai.bothub.chat/v1"),
)
response, err := client.Embeddings.New(context.Background(), openai.EmbeddingNewParams{
Model: openai.EmbeddingModelTextEmbedding3Large,
Input: openai.EmbeddingNewParamsInputUnion{OfString: openai.String("The food was delicious and the waiter...")},
EncodingFormat: openai.EmbeddingNewParamsEncodingFormatFloat,
})
if err != nil {
panic(err)
}
fmt.Println(response.Data[0].Embedding)
}
curl https://openai.bothub.chat/v1/embeddings \
-X POST \
-H "Authorization: Bearer <your access token>" \
-H "Content-Type: application/json" \
-d '{
"input": "The food was delicious and the waiter...",
"model": "text-embedding-3-large",
"encoding_format": "float"
}'
Response Format
The API returns an object containing the embedding vector. The vector itself is an array of floating-point numbers (float) that describes the meaning of the text in a multi-dimensional space.
The resulting embeddings are typically stored in an external vector database or used to calculate semantic proximity between texts.
Example of accessing the embedding vector:
const embedding = response.data[0].embedding;
Main Parameters
| Parameter | Type | Description |
|---|---|---|
model | string | Embedding model |
input | string | array | Text or array of texts |
encoding_format | string | Format of the embedding vector (float or base64) |
Recommendations
For most tasks, text-embedding-3-large is recommended if you require maximum accuracy for searching and comparing texts.
If speed and cost are priorities, text-embedding-3-small is a better choice.
You can view the official OpenAI documentation on embeddings here