Embeddings
The Embedding API converts text into vector representations that capture semantic meaning. Use embeddings for semantic search, clustering, and RAG applications.
What you’ll learn:
- How to generate embeddings from text
- Available embedding models and their use cases
- How to use embeddings for semantic search and RAG
Basic Usage
Section titled “Basic Usage”curl -X POST "$OPENAI_BASE_URL/embeddings" \ -H "Authorization: Bearer $OPENAI_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "jina-embeddings-v2-base-de", "input": ["The quick brown fox jumps over the lazy dog", "Data science is fun!"] }'from openai import OpenAI
client = OpenAI()
texts = [ "I am Batman and I'm rich", "I am Spiderman", "I am Ironman and I'm a billionaire", "I am Flash", "I am the president of USA",]
embeddings = client.embeddings.create(input=texts, model="jina-embeddings-v2-base-de")
print("Embedding dimension:", len(embeddings.data[0].embedding))print("Number of vectors:", len(embeddings.data))print("Token usage:", embeddings.usage)import OpenAI from "openai";
const client = new OpenAI();
const result = await client.embeddings.create({ model: "jina-embeddings-v2-base-de", input: ["The quick brown fox jumps over the lazy dog", "Data science is fun!"],});
console.log("Embedding dimension:", result.data[0].embedding.length);console.log("Token usage:", result.usage);Example output:
Embedding dimension: 768Number of vectors: 5Token usage: Usage(prompt_tokens=41, total_tokens=41)Available Embedding Models
Section titled “Available Embedding Models”| Model | Dimensions | Languages | Use Case |
|---|---|---|---|
jina-embeddings-v2-base-de | 768 | German & English | German-language RAG |
text-embedding-bge-m3 | 1024 | Multilingual | Cross-language search |
Check Available Models for the latest list.
Next Steps
Section titled “Next Steps”- LangChain Integration — Use embeddings with LangChain for RAG
- LlamaIndex Integration — Use embeddings with LlamaIndex for RAG