Prompt
semantic search embeddings API
Latest observation
Oct 8, 2026
OpenAI APIWeb search: off
If you want to build semantic search using embeddings, the basic API flow is:
- Embed your documents
- Store vectors in a vector DB or index
- Embed the user query
- Compare query vector to document vectors using cosine similarity / dot product
- Return top matches
Typical API shape
You might expose endpoints like:
-
POST /embed- input: text or batch of texts
- output: embedding vectors
-
POST /search- input: query text, top_k
- output: ranked matching documents
Example request
POST /search
{
"query": "best way to learn machine learning",
"top_k": 5
}
Example response
{
"results": [
{"id": "doc_12", "score": 0.92, "text": "An introduction to machine learning..."},
{"id": "doc_87", "score": 0.89, "text": "How to study ML effectively..."}
]
}
If you mean OpenAI-style embeddings API
A common pattern is:
from openai import OpenAI
client = OpenAI()
resp = client.embeddings.create(
model="text-embedding-3-small",
input=["your document text", "another text"]
)
vectors = [item.embedding for item in resp.data]
Then for search:
query_vec = client.embeddings.create(
model="text-embedding-3-small",
input="best way to learn machine learning"
).data[0].embedding
Important notes
- Use the same embedding model for documents and queries.
- For retrieval, cosine similarity is common.
- For scale, store embeddings in:
- FAISS
- Pinecone
- Weaviate
- Qdrant
- Milvus
- or a DB with vector support
If you want, I can give you:
- a full semantic search API design
- a Python/FastAPI example
- a Node.js example
- a DB schema + vector search implementation