Reference · How-to · ~8 min

How to upsert vectors in Pinecone

Last updated

Store embeddings in a managed vector index and query by semantic similarity.

Store embeddings in a managed vector index and query by semantic similarity.

#Steps

1. **Create index** — match embedding dimension (e.g. 1536 for `text-embedding-3-small`)

2. **Prepare records** — each needs `id`, `values` (float vector), optional `metadata` (text, source, date)

3. **Batch upsert** — send 100–500 vectors per request to reduce API calls

4. **Query** — pass query embedding + `top_k` + metadata filters

5. **Version index** — new embedding model → new index name, re-embed corpus

6. **Delete stale** — remove doc IDs when source content is retired

#Sketch

from pinecone import Pinecone
pc = Pinecone(api_key=os.environ["PINECONE_API_KEY"])
index = pc.Index("support-docs")
index.upsert(vectors=[
    {"id": "chunk-1", "values": vec, "metadata": {"text": chunk_text, "doc": "faq.md"}},
])
hits = index.query(vector=query_vec, top_k=5, include_metadata=True)

#Watch out

Metadata is for filtering and display — still pass chunk text to the LLM from `metadata`, not from IDs alone.

**Try the lessons:** `vector-db-lab` (Lane D) · `vector-databases` (Lane C)