What an Embedding Is, Without the Maths

Ma Mahalakshmi V Updated 16 Sep 2026
9 min read ·Lesson 42 of 224

Behind File Search: What Actually Makes Retrieval Work

Unit 9, Lesson 2 covered file search as a built-in tool: upload documents to a vector store, and the platform automatically retrieves the passages relevant to a given question. That lesson deliberately treated the retrieval mechanism as a black box — the platform handles chunking, indexing, and similarity search internally, and nothing about using file search requires understanding what happens inside it. This unit opens that box. Embeddings are the underlying representation that makes semantic retrieval possible at all, and understanding them directly is what lets you build custom retrieval systems beyond what the built-in file search tool covers — a specialized similarity metric, a hybrid search combining several signals, retrieval over data that isn't naturally organized as uploadable files.

The Problem: Comparing Meaning, Not Just Words

Suppose you want to find, out of a thousand stored customer support tickets, the ones most similar in meaning to a new incoming ticket. A simple approach — checking whether the same words appear in both — fails in an obvious way: "my package hasn't arrived" and "shipment is delayed" describe the same underlying problem but share almost no words in common. Any retrieval approach based purely on literal word overlap misses this kind of match entirely, even though a human reading both sentences would immediately recognize them as related.

Embeddings solve this by representing meaning numerically rather than representing words literally. An embedding model converts a piece of text into a list of numbers — a vector, typically with hundreds or thousands of dimensions — positioned in a high-dimensional space such that pieces of text with similar meaning end up close together in that space, and pieces of text with different meaning end up far apart, regardless of whether they share any specific words at all. Nothing here requires understanding the underlying mathematics of how that positioning is learned; what matters practically is the behavior it produces — similar meaning maps to nearby vectors — and how to make use of that behavior, which is exactly what this lesson and the two that follow it cover.

Generating an Embedding

response = client.embeddings.create(
    model="text-embedding-4",
    input="My package hasn't arrived yet.",
)

embedding_vector = response.data[0].embedding
print(f"Vector length: {len(embedding_vector)}")
print(f"First five values: {embedding_vector[:5]}")

Note: The exact embedding model name, the resulting vector's dimensionality, and the exact response shape can vary by SDK version and by which embedding model is current. Confirm the current model name and its output dimensionality against your installed SDK version's documentation before relying on these specifics.

Running this produces a list of floating-point numbers — not a summary, not a category label, just a long list of numbers with no individually meaningful interpretation on their own. The vector as a whole is what carries meaning, and that meaning only becomes useful in comparison to other vectors, which is the subject of Lesson 3. A single embedding vector in isolation tells you almost nothing; the value comes entirely from measuring how close or far two (or more) embedding vectors are from each other.

Why Similar Meanings End Up Close Together

An embedding model is trained on enormous amounts of text, learning statistical patterns in which words and phrases co-occur and in what contexts. Through this training, the model learns to place text with related meaning near each other in the vector space — not because anyone manually labeled "these two sentences mean the same thing," but because the patterns of real language usage the model was trained on make semantically related text naturally cluster together as a side effect of learning to predict and represent language well. This is the same underlying kind of model as the language models this course has used throughout (in the sense that both are trained on large amounts of text to capture patterns in language), but an embedding model's job is specifically to produce a fixed-length numerical representation of a piece of text, rather than to generate new text as client.responses.create() does.

pairs_to_compare = [
    ("My package hasn't arrived yet.", "The shipment is delayed."),
    ("My package hasn't arrived yet.", "What's your refund policy?"),
]

for text_a, text_b in pairs_to_compare:
    response = client.embeddings.create(model="text-embedding-4", input=[text_a, text_b])
    vector_a = response.data[0].embedding
    vector_b = response.data[1].embedding
    print(f"'{text_a}' vs '{text_b}': vectors generated, length {len(vector_a)} each")

Passing a list of strings to a single embeddings.create() call, as shown here, generates an embedding for each string in one request rather than requiring a separate call per string — worth doing whenever multiple pieces of text need embedding at once, since it's both more efficient and typically cheaper than issuing one request per string. Lesson 3 covers actually computing how similar vector_a and vector_b are to each other; for now, the important idea is that the first pair (both about a delayed shipment) would be expected to produce vectors much closer together than the second pair (a shipment complaint versus a refund policy question), purely because of what each sentence means, independent of shared vocabulary.

Embeddings Are Not the Same as Structured Outputs

It's worth being precise about how embeddings relate to structured outputs (Unit 6), since both involve the SDK producing something other than free-form text, and conflating the two is an easy early mistake.

AspectStructured Outputs (Unit 6)Embeddings (this unit)
What's producedA JSON object matching a defined schemaA fixed-length numerical vector
PurposeExtract or generate data in a predictable, parseable shapeRepresent text's meaning for comparison, search, or clustering
InterpretabilityEvery field has a clear, human-readable meaningIndividual numbers in the vector have no meaningful interpretation on their own
Typical useClassification, extraction, generating a structured answerSemantic search, similarity comparison, clustering, recommendation

A structured output is meant to be read and used directly — a category field, an amount field, each with a clear meaning. An embedding vector is not meant to be read directly at all; it exists purely as an intermediate representation to be compared against other embedding vectors.

What Embeddings Are Used For

Embeddings underlie a range of tasks beyond the retrieval-augmented generation Unit 9, Lesson 2 covered: semantic search (finding documents or passages similar in meaning to a query, which is exactly what powers file search internally), clustering (grouping a large set of texts into naturally occurring topics without predefined categories), classification (comparing a new piece of text's embedding against embeddings of known example categories), recommendation (finding items similar to ones a user has previously engaged with), and deduplication (identifying near-duplicate pieces of text that differ in wording but say essentially the same thing). Each of these tasks reduces, at its core, to the same underlying operation: compute embeddings for the relevant pieces of text, then measure and compare distances between them. This course focuses in depth on the first of these — semantic search — across Lessons 2 through 5, since it is the most immediately practical starting point and the one that most directly extends Unit 9's built-in file search.

Vectors From Different Embedding Models Are Not Comparable

An easy mistake once a collection of embeddings has been built up over time is assuming any two embedding vectors can be meaningfully compared, regardless of which model produced them. They cannot. Two different embedding models place text in entirely different, unrelated vector spaces — even if both happen to produce vectors of the same length, a vector from one model and a vector from another have no consistent geometric relationship to each other, since each model learned its own positioning during its own training process.

response_model_a = client.embeddings.create(model="text-embedding-4", input="Return policy inquiry")
# A different embedding model, hypothetically:
# response_model_b = client.embeddings.create(model="some-other-embedding-model", input="Return policy inquiry")

# Comparing response_model_a's vector against a vector from a different model
# would produce a similarity score with no meaningful interpretation, even
# though both vectors describe the exact same input text.

Note: If an application ever changes which embedding model it uses — whether deliberately, or because a model is deprecated — every previously stored embedding needs to be regenerated with the new model before being compared against anything newly embedded. Mixing vectors from two different embedding models in the same collection silently produces meaningless similarity scores rather than an obvious error, which makes this an easy mistake to miss until search results start looking wrong for no apparent reason.

This is a practical, recurring concern for any long-lived application built on embeddings: a model upgrade is not a drop-in replacement the way upgrading a language model version usually is, since the entire stored collection depends on having been embedded consistently with whatever model is currently in use.

Common Mistakes

Treating an embedding vector as something to read or interpret directly, when its only meaningful use is in comparison to other embedding vectors, not as a standalone summary or feature extraction of a text's content.

Confusing embeddings with structured outputs, expecting a vector's individual values to have the same kind of direct, human-readable meaning a structured-output field has.

Assuming literal word overlap and semantic similarity are the same thing, missing the entire point of embeddings, which exist specifically to capture meaning that plain keyword matching cannot.

Expecting to need to understand the underlying mathematics of how embeddings are learned before using them productively, when what actually matters for building with them is their practical behavior — similar meaning maps to nearby vectors — not the training process that produces that behavior.

Comparing or mixing embedding vectors produced by two different models, which silently produces a meaningless similarity score rather than a visible error, since nothing about the vectors themselves signals which model produced them.

Best Practices

Batch multiple texts into a single embeddings.create() call when embedding several pieces of text at once, rather than issuing one request per string.

Reach for embeddings specifically when a task requires comparing meaning rather than exact text, and reach for structured outputs (Unit 6) when a task requires extracting or generating data in a predictable, directly readable shape.

Remember that file search (Unit 9, Lesson 2) already handles embedding generation and comparison internally — build a custom embeddings pipeline only when a specific requirement (a custom similarity metric, a non-file-based data source, a need to inspect or manipulate the vectors directly) goes beyond what the built-in tool already provides.

Regenerate every stored embedding with the new model whenever an embedding model changes, rather than mixing vectors from an old and a new model in the same collection.

0 Comments

Reviewed before they appear

No comments yet.

OpenAI SDK
Introduction to the OpenAI SDK Setting Up Python Creating an API Key Your First Call — client.responses.create() and response.output_text Understanding Billing, Credits, and What a Request Costs Why Responses Replaced Chat Completions Anatomy of a Request: model, input, and instructions Anatomy of a Response: The Typed output Array, Not Just Text Roles: User, Assistant, and Developer/System Choosing a Model, and Reading the Models Page Instead of Memorizing Names Instructions vs. Input Writing Prompts That Get Consistent Results Few-Shot Examples Reasoning Models and the reasoning Parameter Debugging a Prompt That Misbehaves Why Streaming Matters for User Experience stream=True and Iterating Over Events Handling the Event Types You Actually Care About Background Mode for Long-Running Jobs Project — Add Live Streaming to Your Chatbot The Problem With Parsing Free Text JSON Schema and Strict Mode Pydantic Models With the SDK's Parse Helpers Handling Refusals and Validation Failures Project — A Resume-to-JSON Extractor Working With input_image input_file, PDFs, and the Files API Image Generation Speech-to-Text and Text-to-Speech Project: A PDF Question-Answering Script What Function Calling Is Defining a Tool Schema The Full Loop Multiple Tools Errors, Timeouts, and Untrusted Arguments Project: A Weather Assistant Web Search File Search and Vector Stores Code Interpreter Remote MCP Servers and Connectors Project: A Research Assistant What an Embedding Is, Without the Maths Generating and Storing Embeddings Similarity Search From Scratch Hosted Vector Stores vs. Rolling Your Own A Small RAG App Over a Folder of Notes Agents vs. a Single API Call — When You Need One pip install openai Giving Agents Tools Handoffs and Multi-Agent Triage Guardrails and Approvals Tracing and Observing What Your Agent Did A Multi-Agent Support Desk Error Codes and What Each One Means Retries, Timeouts, and Backoff Rate Limits and Spend Limits Prompt Caching and Cost Optimisation The Batch API for Bulk Work Async Clients and Concurrency Moderation and Safety Best Practices Designing the App Backend With FastAPI Streaming to a Simple Frontend Deploying and a Cost/Safety Checklist Why Web Search Is Useful for Current Information Using the Web Search Tool with the Responses API Configuring Search Behavior for Application Use Cases Understanding Citations and Source Attribution Where to Go Next Building a Research Assistant with Web Search Combining Web Search with Structured Outputs Handling Conflicting or Low-Quality Web Sources Reducing Unsupported Claims with Grounded Generation Testing Freshness-Sensitive AI Answers Production Considerations for Web-Grounded Applications Understanding File Search and Retrieval-Augmented Generation Creating and Organizing Vector Stores Uploading Documents for Retrieval Connecting Vector Stores to Responses API Requests Designing Document Metadata and Filtering Strategies Building a PDF Question-Answering Application Improving Retrieval Quality With Better Document Preparation Handling Missing Evidence and Retrieval Failures Combining File Search With Web Search Building a Production Knowledge-Base Assistant What the Code Interpreter Tool Is Designed For Running Python-Based Analysis Through the OpenAI SDK Uploading Datasets for Analysis Analyzing CSV and Spreadsheet Data Generating Charts and Data Summaries Handling Generated Files and Downloadable Artifacts Building a Data-Analysis Assistant Combining Code Execution with Structured Outputs Validating Generated Calculations and Results Security and Sandbox Considerations for Code Execution Understanding Multimodal Input with the OpenAI SDK Sending Images to a Model Image Analysis from URLs and Uploaded Files Extracting Text and Information from Screenshots Building an Image-Question-Answering Application Combining Image Input with Structured Output Analyzing Multiple Images in One Request Handling Image Quality and Input Limitations Designing Multimodal Prompts for Reliable Results Building a Practical Vision-Powered Python Application Understanding Speech-to-Text and Text-to-Speech Workflows Transcribing Audio with the OpenAI SDK Working with Uploaded Audio Files Handling Timestamps and Transcription Metadata Building a Meeting Transcription Workflow Generating Spoken Responses from Text Handling Long Audio and Processing Failures Combining Audio with Text and Tool Calling Building an End-to-End Python Voice Application What Embeddings Are and When to Use Them Generating Embeddings With the OpenAI API Preparing Text for Embedding Comparing Vectors With Cosine Similarity Building a Simple Semantic Search Engine in Python Storing Embeddings in a Database Metadata Filtering for Semantic Search Chunking Strategies for Better Retrieval Evaluating Semantic Search Quality Building a Document Similarity Application When Batch Processing Makes Sense Designing Large-Volume AI Processing Pipelines Using Asynchronous Python with the OpenAI SDK Running Concurrent Requests Safely Controlling Concurrency and Avoiding Rate Limits Tracking Batch Job Progress Handling Partial Failures in Bulk Workloads Retrying Failed Items Without Duplicating Successful Work Designing Resumable AI Processing Jobs Building a Production Batch-Processing Pipeline Batch Processing Makes Sense Large-Scale AI Processing Pipelines Async Python with OpenAI SDK Safe Concurrent Requests Concurrency & Rate Limits Batch Progress Tracking Partial Failure Handling Safe Retry Handling Resumable AI Jobs Production Batch Pipeline System–User Data Separation Reusable App Instructions Prompt Templates & Variables Extraction & Classification Prompts Summarization & Transformation Prompts Explicit Output Requirements Prompt Version Management Prompt Testing & Evaluation Reusable Python Prompt Library API Key Security Secure API Key Storage Secure Secret Management Prompt Injection Prevention Trusted vs. Untrusted Content Tool Argument Validation Sensitive Data Handling Secure Logging AI Action Authorization Production AI Security Checklist Why AI Applications Need Evaluation Beyond Unit Tests Unit Testing OpenAI SDK Integration Code Mocking API Responses in Python Tests Testing Structured Outputs Against Schemas Testing Tool-Calling Workflows Building a Small Evaluation Dataset Measuring Accuracy, Consistency, and Failure Rates Regression Testing Prompts and Model Changes Human Evaluation Versus Automated Evaluation Creating a Repeatable Evaluation Pipeline AI Request Monitoring Token Cost Management Usage Metrics Design Reducing Model Calls Prompt & Context Optimization Model Selection & Optimization AI Caching Strategies Interactive Latency Optimization Usage Dashboards & Budget Alerts Performance & Cost Checklist Every API Call Starts Fresh Fixing API Statelessness Server-Side Conversation Memory Limits of Response Chaining What We're Building Conversation Memory Challenges Preparing an OpenAI SDK Application for Deployment Environment-Specific Configuration for Development and Production Deploying a Python AI Service with Docker Container Health Checks and Startup Configuration Managing Secrets in Cloud Deployments Background Workers for Long-Running AI Tasks Queues and Asynchronous Job Architectures Scaling AI Workloads Horizontally Monitoring Production Incidents and Failures Production Deployment Checklist for OpenAI SDK Applications Reusable OpenAI Service Classes AI Client Dependency Injection Typed AI Responses Python Configuration Management AI Request Decorators Centralized AI Error Handling Clean SDK Abstractions Reusable OpenAI Utilities Internal AI Python Libraries SDK Integration Maintenance Production AI Chatbot Document Q&A System Web Research Assistant Customer Support Agent AI Data Analysis Assistant Image Analysis App Meeting Transcription & Summary Semantic Document Search Multi-Tool AI Agent Production OpenAI SDK App Why "It Looked Fine When I Tested It" Isn't Enough Timing Note Status Note Pre-Decision Status Note Current Availability Note
Ask about this post
AI Ask about this post

Ask questions about What an Embedding Is, Without the Maths and get answers drawn from it.

Signed-in readers only.