← Blog

Claude API + Pinecone: Vector Database Integration Guide

2026-11-17 · 5 min read · SubToAPI Team

Connecting the Claude API to Pinecone lets you ground Claude's responses in your own data instead of relying only on what the model learned during training. Pinecone stores embeddings of your documents; when a user asks a question, you embed the query, search Pinecone for the most similar vectors, and pass that retrieved text to Claude as context. Claude then answers using the real, current information you provided rather than guessing.

This pattern — often called retrieval-augmented generation (RAG) — is the standard way to give Claude access to internal docs, support tickets, product catalogs, or any dataset too large to fit in a single prompt. Below is a concrete implementation showing exactly how the pieces fit together, plus the tradeoffs you should know before shipping it.

How the integration works

The flow has four steps that repeat on every user query:

  1. Embed the query using an embedding model (OpenAI's text-embedding-3-small, Cohere, or Pinecone's own hosted embeddings).
  2. Query Pinecone with that vector to get the top-k most similar chunks from your indexed documents.
  3. Build a prompt that includes the retrieved chunks as context, plus the user's original question.
  4. Send that prompt to Claude and return the generated answer.

Claude itself never talks to Pinecone directly — there's no native driver for this. Your application code is the glue between the two services.

Indexing your documents

Before you can query anything, you need vectors in Pinecone. This is a one-time (or periodically refreshed) batch job:

import { Pinecone } from "@pinecone-database/pinecone";
import OpenAI from "openai";

const pinecone = new Pinecone({ apiKey: process.env.PINECONE_API_KEY });
const index = pinecone.index("docs-index");
const openai = new OpenAI();

async function indexDocument(id, text) {
  const embedding = await openai.embeddings.create({
    model: "text-embedding-3-small",
    input: text,
  });

  await index.upsert([
    {
      id,
      values: embedding.data[0].embedding,
      metadata: { text },
    },
  ]);
}

Chunk long documents into 300–800 token pieces before embedding — Pinecone similarity search works better on focused passages than on entire pages, and it keeps the context you eventually feed Claude manageable.

Querying at request time

When a user asks a question, embed it the same way and search:

async function retrieveContext(question, topK = 5) {
  const embedding = await openai.embeddings.create({
    model: "text-embedding-3-small",
    input: question,
  });

  const results = await index.query({
    vector: embedding.data[0].embedding,
    topK,
    includeMetadata: true,
  });

  return results.matches.map((m) => m.metadata.text).join("\n\n---\n\n");
}

Sending retrieved context to Claude

Once you have the matched chunks, build a prompt and call the Claude API. If you're using SubToAPI as your gateway, the request looks like a standard OpenAI-style call against https://api.subtoapi.app/v1/messages:

async function askClaude(question) {
  const context = await retrieveContext(question);

  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. If the context doesn't contain the answer, say so.\n\nContext:\n${context}\n\nQuestion: ${question}`,
        },
      ],
    }),
  });

  const data = await response.json();
  return data.content[0].text;
}

This works identically whether you call the Claude API directly or route through SubToAPI — the difference is that SubToAPI wraps your underlying Claude access in a standard HTTPS API with application keys (sub_live_...), so your RAG backend doesn't need separate credential management or billing logic for Claude calls. See /docs/messages for the full request format.

Design decisions that matter

Chunk size and top-k: too few chunks and Claude lacks context; too many and you waste tokens or exceed the context window. Start with 4–6 chunks of 400–600 tokens and tune based on answer quality.

Metadata filtering: Pinecone supports filtering by metadata fields (date, source, user ID) alongside vector similarity. Use this to scope retrieval — for example, only search documents belonging to the current tenant in a multi-tenant app.

Re-ranking: raw vector similarity isn't always the best proxy for relevance. If answer quality is inconsistent, add a re-ranking step (Cohere Rerank or a cross-encoder) between Pinecone's results and what you send to Claude.

Streaming the final answer: once context is retrieved, the Claude call itself can stream just like any other request. See /docs/streaming if you want tokens to appear incrementally in your UI rather than waiting for the full response.

Tool use instead of static retrieval: for more dynamic cases, you can expose a "search_documents" tool to Claude and let the model decide when to query Pinecone mid-conversation, rather than always retrieving upfront. This is described in /docs/tools and works well when questions sometimes need retrieval and sometimes don't.

Where SubToAPI fits

SubToAPI doesn't replace Pinecone or your embedding pipeline — it sits on the Claude side of the architecture. If your team is already paying for Claude access and wants a stable HTTPS endpoint with usage tracking, streaming support, and per-project API keys instead of sharing raw credentials across services, SubToAPI gives you that without changing anything about how you talk to Pinecone. You keep your retrieval logic exactly as shown above and just point the final generation call at https://api.subtoapi.app/v1/messages. Plans start at €9/month for solo use, with team seats at €19 and €49 for larger setups — see /pricing. A free trial is available at /signup, and /docs/quickstart walks through getting your first key.

questions

Does Claude have built-in support for Pinecone? No. Claude has no native vector database connector. Your application code handles embedding, querying Pinecone, and inserting the retrieved text into the prompt sent to Claude.

Which embedding model should I use with Pinecone and Claude? Any embedding model works as long as you use it consistently for both indexing and querying. OpenAI's text-embedding-3-small, Cohere embeddings, and Pinecone's own hosted models are all common choices — pick one based on cost and the language/domain of your data.

How many retrieved chunks should I send to Claude? Start with 4–6 chunks of 400–600 tokens each. Too few and the model lacks context; too many wastes tokens and can dilute relevance. Measure answer accuracy and adjust from there.

Turn your Claude access into an HTTPS API

SubToAPI gives you application API keys, streaming, tool use and usage insights on top of your existing Claude access — set up in minutes.

Start free  Read the quickstart →