tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Generative AI > OpenAI API > OpenAI Embeddings API

OpenAI Embeddings API

Author: Venkata Sudhakar

An embedding is a list of floating-point numbers that represents the semantic meaning of a piece of text as a point in high-dimensional space. Texts with similar meanings have embeddings that are close together in that space, even if they use completely different words. The OpenAI Embeddings API converts any text string into one of these embedding vectors, which you can then store in a vector database and search with cosine similarity to find semantically related content.

OpenAI offers several embedding models. text-embedding-3-small produces 1536-dimensional vectors and is fast and cheap - ideal for most RAG pipelines and semantic search applications. text-embedding-3-large produces 3072-dimensional vectors for higher accuracy on complex retrieval tasks. Both support dimension reduction: you can request fewer dimensions (e.g. 256 or 512) to reduce storage cost with a small accuracy trade-off. The API accepts a single string or a list of strings per call - batching multiple texts in one call is more efficient than separate calls per text.

The below example shows embedding a set of documentation snippets and then finding the most relevant one for a user query using cosine similarity.


It gives the following output,

Embedded 5 documents
Vector dimensions: 1536

It gives the following output,

Query: How do I monitor if my data replication is falling behind?

[0.8412] CDC replication lag is how many seconds the consumer is behind the source database.
[0.7234] Debezium reads the MySQL binlog to capture row-level changes in real time.

# "falling behind" matched "replication lag" semantically
# No shared keywords needed - meaning drives the match

Pricing tip: text-embedding-3-small costs around $0.02 per million tokens. For a 1000-document corpus with average 200 words per document, the total embedding cost is roughly $0.004 - nearly free. The main cost in a RAG pipeline is the LLM generation step, not the embedding step. Embed documents once, store the vectors, and re-embed only when documents change.


 
  


  
bl  br