Skip to content
Get API key API key

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
Terminal
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!"]
}'
Model (example)DimensionsLanguagesUse case
jina-embeddings-v2-base-de768German & EnglishGerman-language RAG
text-embedding-bge-m31024MultilingualCross-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.

text-embedding-bge-m3 and gpt-oss-120b both run on T Cloud. BGE-M3 has an 8K context window.

Python
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\nQuestion: {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[0].message.content.

Embeddings take model and input. Chat takes model and messages.

Qwen3 Embedding 8B also runs on T Cloud, with a 32K context window.

For charts and scanned pages, use OCR.