Embeddings and RAG
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) Example output:
Embedding dimension: 768Number of vectors: 5Token usage: Usage(prompt_tokens=41, total_tokens=41) 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 embedding models
Section titled “Example embedding models”| Model (example) | Dimensions | Languages | Use case |
|---|---|---|---|
jina- | 768 | German & English | German-language RAG |
text- | 1024 | Multilingual | Cross-language search |
Each model returns vectors with the dimensions listed in Example embedding models.
Embed a passage, then send that passage to a chat model with the question. Both calls use the same client.
Minimal example
Section titled “Minimal example”text- and gpt- both run on T Cloud. BGE-M3 has an 8K context window.
import math
from openai import OpenAI
client = OpenAI()
passages = ["T Cloud models in this catalog run in Germany." ]query = "Where do T Cloud models run?"
embedded = client.embeddings.create( input=passages + [query], model="text-embedding-bge-m3" )passage_vecs = [item.embedding for item in embedded.data[: - 1 ]]query_vec = embedded.data[ -1 ].embedding
def cos(a, b): return sum(x *y for x, y in zip(a, b)) / (math.sqrt( sum(x *x for x in a)) * math.sqrt( sum(y *y for y in b)))best = max( range( len(passages)), key=lambda i: cos(query_vec, passage_vecs[i])) context = passages[best] print( "vectors:" , len(embedded.data))
response = client.chat.completions.create( model="gpt-oss-120b" , messages=[ {"role": "system", "content": "Answer only from the passage." }, {"role": "user", "content": f"Passage:\n{ context}\n\n Question: {query}" }, ],)print(response.choices[ 0].message.content) BGE-M3 returns 1024-dimensional vectors. Jina Embeddings v2 Base DE returns 768. The chat answer is in choices.
Parameters
Section titled “Parameters”Embeddings take model and input. Chat takes model and messages.
Limitations and troubleshooting
Section titled “Limitations and troubleshooting”Qwen3 Embedding 8B also runs on T Cloud, with a 32K context window.
For charts and scanned pages, use OCR.