AI / Core OpenAI Codex Application Fundamentals Interview Questions
What are embeddings in the OpenAI API and what are they used for?
Embeddings convert text (or other content) into dense numerical vectors that capture semantic meaning. Texts with similar meaning produce similar vectors, enabling mathematical operations on language: search, clustering, classification, and anomaly detection without requiring labelled training data for each task.
from openai import OpenAI import numpy as np client = OpenAI() # Generate embeddings response = client.embeddings.create( model="text-embedding-3-large", # 3072 dimensions # model="text-embedding-3-small", # 1536 dimensions, cheaper input=[ "OpenAI Codex is an agentic coding assistant.", "GitHub Copilot helps developers write code.", "The stock market rose 2% today.", ] ) # Extract vectors vectors = [item.embedding for item in response.data] # Semantic similarity via cosine similarity def cosine_similarity(a, b): return np.dot(a, b) / (np.linalg.norm(a) * np.linalg.norm(b)) sim_coding = cosine_similarity(vectors[0], vectors[1]) # high - both about coding AI sim_unrelated = cosine_similarity(vectors[0], vectors[2]) # low - different topic print(f"Coding similarity: {sim_coding:.3f}") # e.g. 0.89 print(f"Unrelated similarity: {sim_unrelated:.3f}") # e.g. 0.21 # Dimension reduction (for storage/speed tradeoff): response = client.embeddings.create( model="text-embedding-3-large", input="example text", dimensions=512, # reduce from 3072 to 512 )
| Model | Dimensions | Use case |
|---|---|---|
| text-embedding-3-large | 3072 (reducible) | Highest quality; production RAG, reranking |
| text-embedding-3-small | 1536 (reducible) | Fast, cheaper; good for classification, clustering |
Common use cases: RAG (Retrieval-Augmented Generation) where documents are embedded and stored in a vector database, then the most relevant chunks are retrieved for a query; semantic search; clustering documents; recommendation systems; and classifying content without labelled training data.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
