Reference · API

OpenAI Embeddings API

Turn text into vectors for semantic search and RAG.

Turn text into vectors for semantic search and RAG.

#Endpoint

POST https://api.openai.com/v1/embeddings

#Request

| Field | Purpose |

|-------|---------|

| `model` | e.g. `text-embedding-3-small` |

| `input` | String or array of strings |

#Python example

from openai import OpenAI
client = OpenAI()
emb = client.embeddings.create(
    model="text-embedding-3-small",
    input="Annual refund policy for pro plans",
)
vector = emb.data[0].embedding
print(len(vector), "dimensions")

#Usage in RAG

1. Embed all document chunks once → store vectors + text

2. Embed user question at query time

3. Cosine similarity → top-k chunks → LLM prompt

#Tips

  • Batch inputs to save requests
  • Keep the **same model** for index and queries
  • Store raw text alongside vectors for prompt packing

#Try it yourself

Change the input text and re-run — this executes real Python against a small local stand-in for the OpenAI client, so you can see the response shape (a vector plus its length) without an API key.

Try it yourself — runs in your browser. Simulated response, not a live API call.