Check my levelCoursesProgramsFor teamsPricing
UKSign inSign up
Check my levelCoursesProgramsFor teamsPricingClaude quizPromptsBlogFAQSearchSign upUK
AcademlCoursesOpenAI Embeddings: Complete GuideEmbeddings: Basic Usage
Points on a plane: a query and its nearest neighboursThe agent loop: reason, act, observeOne MCP connector linking files, Git and memory
Get started free
Course

OpenAI Embeddings: Complete Guide

Module 1 · Embedding Fundamentals
01Embeddings: Basic Usage
Module 2 · Search and Reranking
02Semantic Text Search03Code Search via Embeddings04Reranking with Cross-Encoders
Module 3 · Classification and Clustering
05Text Classification via Embeddings06Transaction Clustering with Auto-generated Labels
Module 4 · RAG and Recommendations
07Q&A via Embeddings-based Search08Recommendations via Nearest Neighbor Search
OpenAI Embeddings: Complete Guide · Lesson 1

OpenAI Embeddings: Basic Usage in Python

Obtain vector representations of text via the OpenAI API. We cover the text-embedding-3 models, the dimensions parameter, prices and limits, retries (built into the SDK and via tenacity), and batch processing.

25 min readUpdated Dec 2, 20263 questions in quizReady prompt included

How do you create an embedding with the OpenAI API?

Call client.embeddings.create(model="text-embedding-3-small", input=text) and read response.data[0].embedding: a list of 1536 floats. Pass a list of strings to embed a batch in one request. OpenAI returns vectors normalized to length 1, so a plain dot product gives cosine similarity. Cache each vector: you pay per input token, so each text should be embedded once.

Start free: 7 days of full access →
Lesson 1 of 8free after sign-up

OpenAI Embeddings: Complete Guide

8 lessons on the OpenAI embeddings cookbook: semantic and code search, reranking, classification, clustering, Q&A and recommendations. Each lesson has a coding task checked by AI and a quiz.

Course program →

The rest of this lesson opens after a free sign-up

Sign up with email or Google: the first two lessons of every course stay open for good, and the whole catalog is open for 7 days. No card needed.

Sign up freeOr a trial lesson, no sign-up →

text-embedding-3-small vs text-embedding-3-large

Numbers from the OpenAI embeddings guide. Usage is priced per input token; “pages per dollar” assumes about 800 tokens per page.

ModelDefault dimensionsMax input, tokens≈ Pages per $1MTEB
text-embedding-3-small1536819262,50062.3%
text-embedding-3-large307281929,61564.6%
text-embedding-ada-002 (older)1536819212,50061.0%
Source: OpenAI API docs, Vector embeddings guide, checked 31 Oct 2026.

The embedding workflow from the lesson

  1. Split the textUp to 8192 tokens per input; count with tiktoken (cl100k_base)
    →
  2. Embed in batchesA list of strings in input, retry with exponential backoff
    →
  3. Cache the vectorsCompute once, store in Parquet or a vector database
    →
  4. CompareDot product = cosine similarity on normalized vectors
    →
The vector is computed once and reused: search, clustering and recommendations in the next lessons all start from these four steps.
In this lesson
What Are EmbeddingsSimple API CallShorter Vectors: the dimensions ParameterComparing VectorsReliable Call with RetryAnti-pattern: Loop RequestsPractical ApplicationsPracticeReady promptQuiz
CoursesLLM coursesFor teamsPricingFAQBlogAboutPrivacy
© 2026 AcademlDevelopment & promotion —MMIX — Marketing Mix

Details worth knowing

Checked on 31 Oct 2026 against the OpenAI embeddings guide.

  • The dimensions parameter shortens a vector and keeps its meaning: text-embedding-3-large cut to 256 dimensions still beats ada-002 at 1536 on MTEB. If you cut vectors by hand, renormalize them to length 1.
  • OpenAI recommends cosine similarity; on these normalized vectors cosine similarity and Euclidean distance rank results the same way.
  • Vectors from different models live in different spaces: keep one model per index and re-embed everything when you switch.
  • The similarity values in the lesson's comments (about 0.92 and 0.6) are illustrative; the practical task has you compute your own for five phrases.

Sources we checked

  • OpenAI API docs: Vector embeddings guide
  • OpenAI API reference: Embeddings
  • OpenAI Cookbook: Using embeddings
  • tiktoken on GitHub

FAQ

How many dimensions does text-embedding-3-small have?+

1536 by default; text-embedding-3-large returns 3072. Both accept the dimensions parameter, so you can request shorter vectors, for example 1024 when your vector store caps the size.

Are OpenAI embeddings normalized to length 1?+

Yes. The OpenAI guide states that embeddings are normalized to length 1, so cosine similarity can be computed with a dot product, and cosine similarity and Euclidean distance give identical rankings.

What does client.embeddings.create return?+

A response whose data list holds one embedding object per input, each with an index and the embedding as a list of floats, plus usage with the input tokens billed. With a single string, read response.data[0].embedding.

How do I embed thousands of texts without hitting rate limits?+

Send batches: input accepts a list of strings, so one call replaces many. Wrap the call in a retry with exponential backoff (the lesson uses tenacity's wait_random_exponential), and cache vectors so you never pay twice for the same text.

Should I use text-embedding-3-small or text-embedding-3-large?+

Small costs less (about 62,500 pages per dollar against 9,615) and scores 62.3% on MTEB against 64.6% for large. Start with small and measure retrieval quality on your own queries before moving to large.

What is the maximum input length?+

8192 tokens per input for text-embedding-3-small, -3-large and ada-002. Count tokens with tiktoken using the cl100k_base encoding and split longer documents into chunks.

Is this lesson free?+

Yes. It is lesson 1 of 8 in “OpenAI Embeddings: Complete Guide”, and a free account keeps the first two lessons of every Academl course open for good. A free account opens all lessons for 7 days with no card; after that Pro costs $9 a month or $79 a year.

Related lessons and courses

Next: semantic text search →OpenAI embeddings course →Vector and hybrid search →RAG with vector databases →OpenAI API course →How tokenizers split text →OpenAI embeddings guide: models, dimensions, pricing →

Build search on top of these vectors

Lessons 2–8 turn embeddings into semantic search, code search, reranking, classification, clustering, Q&A and recommendations. A free account opens all of them for 7 days.

Create a free account →

What Are Embeddings

An embedding is a vector of floating-point numbers that represents the meaning of text. The closer two vectors are in space, the more semantically similar the texts are.

Current OpenAI embedding models:

ModelDefault dimensionsMax inputPrice per 1M tokens
text-embedding-3-small15368192 tokens$0.02
text-embedding-3-large30728192 tokens$0.13

text-embedding-ada-002 is the previous generation ($0.10 per 1M tokens); use the -3 models for new projects. You pay for input tokens only.