Claude API Embeddings Vector Search Integration
If you're searching for how to generate embeddings directly from the Claude API, here's the direct answer: Anthropic does not expose an embeddings endpoint. Claude is a generation model — it takes text in and produces text out. Vector search requires a separate embedding model that converts text into numeric vectors you can compare with cosine similarity or dot product.
The good news is that this isn't a blocker. The standard pattern — and the one Anthropic itself recommends — is to pair a dedicated embeddings model with Claude in a retrieval-augmented generation (RAG) pipeline: embeddings handle the "find the relevant chunks" part, and Claude handles the "understand and answer" part. This article walks through that integration end to end, including where each piece fits and how to call Claude once retrieval is done.
Why Claude has no embeddings API
Embedding models and generation models solve different problems. An embedding model is trained to map semantically similar text to nearby vectors in a high-dimensional space — that's its entire job. A generation model like Claude is trained to produce coherent, reasoned text given context. Anthropic has deliberately kept Claude focused on generation and reasoning, and recommends pairing it with purpose-built embedding providers like Voyage AI (which Anthropic has an official partnership with), OpenAI's embedding models, or open-source options like all-MiniLM or bge-large if you want to self-host.
This separation is actually a feature: you can swap embedding models independently of your generation model without touching the rest of your stack.
The architecture: embeddings + vector store + Claude
A typical Claude-based RAG/vector search system has four pieces:
- Embedding model — converts documents and queries into vectors (Voyage, OpenAI, or a local model).
- Vector store — indexes those vectors for fast nearest-neighbor search (pgvector, Pinecone, Qdrant, Weaviate, or even an in-memory array for small datasets).
- Retrieval step — embeds the incoming query, searches the vector store, pulls back the top-k chunks.
- Claude call — receives the user's question plus the retrieved chunks as context and generates the final answer.
Here's the flow in code using Voyage AI for embeddings and Claude for generation:
// 1. Embed the query
const embedRes = await fetch("https://api.voyageai.com/v1/embeddings", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.VOYAGE_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
input: [userQuery],
model: "voyage-3",
}),
});
const { data } = await embedRes.json();
const queryVector = data[0].embedding;
// 2. Search your vector store (pgvector example)
const { rows } = await db.query(
`SELECT content FROM documents
ORDER BY embedding <-> $1
LIMIT 5`,
[queryVector]
);
const context = rows.map(r => r.content).join("\n\n---\n\n");
// 3. Call Claude with the retrieved context
const response = await fetch("https://api.subtoapi.app/v1/messages", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.SUBTOAPI_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
model: "claude-sonnet-4-5",
max_tokens: 1024,
messages: [
{
role: "user",
content: `Answer the question using only the context below.\n\nContext:\n${context}\n\nQuestion: ${userQuery}`,
},
],
}),
});
const result = await response.json();
console.log(result.content[0].text);
This same pattern works whether you're building semantic document search, a support knowledge base, or a codebase Q&A tool. The embedding and vector store layer are swappable; the generation layer is where Claude does the reasoning.
Chunking strategy matters more than model choice
Most vector search quality problems come from bad chunking, not bad embeddings. A few practical rules:
- Chunk by semantic boundary, not fixed character count — paragraphs, sections, or function definitions rather than arbitrary 500-character windows.
- Overlap chunks by 10–20% so context isn't lost at boundaries.
- Store metadata alongside vectors (source, title, timestamp) so Claude can cite where information came from.
- Re-rank before sending to Claude if your top-k retrieval is noisy — a cheap cross-encoder re-rank step before the final 3-5 chunks go to Claude improves answer quality more than increasing k.
Using Claude to improve retrieval itself
Claude isn't just the end consumer of retrieved chunks — it can also improve the retrieval step:
- Query rewriting: use a fast, cheap Claude call to expand a vague user query into a more specific search query before embedding it.
- Query decomposition: for multi-part questions, have Claude split the question into sub-queries, run separate retrievals, and merge the context.
- Tool use for retrieval: define a
search_documentstool and let Claude decide when and what to search for, rather than always retrieving on every turn. See /docs/tools for how tool definitions work.
{
"tools": [
{
"name": "search_documents",
"description": "Search the knowledge base for relevant passages",
"input_schema": {
"type": "object",
"properties": {
"query": { "type": "string" }
},
"required": ["query"]
}
}
]
}
With this setup, Claude only triggers a vector search when it actually needs more information, which cuts unnecessary embedding calls and keeps latency down for simple questions.
Where SubToAPI fits in this pipeline
SubToAPI doesn't generate embeddings — nothing changes there, you still need Voyage, OpenAI, or a self-hosted model for the vector layer. What it handles is the Claude side of the pipeline: it turns your existing Claude access into an HTTPS API with sub_live_... application keys, so your RAG backend can call Claude for the generation step without managing separate billing per environment. Streaming is supported for progressively rendering long answers (see /docs/streaming), tool use works the same way shown above for triggering retrieval (/docs/tools), and usage metadata per key lets you see how much of your Claude spend is going toward RAG queries versus other features. If you're already running a vector search pipeline and just need a clean, teamwide way to call Claude, check /docs/quickstart or start a trial at /signup. Plans are listed at /pricing.
Quick checklist before you build
- Pick an embedding model and stick with it — re-embedding your whole corpus after switching models is expensive.
- Store embeddings in a database that supports vector indexes natively (pgvector, Pinecone, Qdrant) rather than brute-force comparing in application code once your corpus grows past a few thousand chunks.
- Keep chunk size and overlap tuned to your content type — code, legal text, and chat logs all chunk differently.
- Use Claude for query understanding and final synthesis, not for generating the vectors themselves.
Questions
Does Claude have a native embeddings endpoint? No. Anthropic's API is generation-only. For embeddings, use a dedicated provider such as Voyage AI (Anthropic's recommended partner) or OpenAI's embedding models.
Can I use Claude to re-rank search results instead of a cross-encoder? Yes — you can prompt Claude to score or reorder retrieved chunks by relevance, but a dedicated re-ranker is usually cheaper and faster for high-volume pipelines. Reserve Claude for final answer synthesis.
What's the simplest vector store for a small RAG project? Postgres with the pgvector extension. It avoids adding a new infrastructure dependency and scales fine up to a few million vectors before you'd need a specialized vector database.