By Sagar Shankaran, Founder of CallSphere
A hands-on guide to setting up Pinecone, creating serverless indexes, upserting embeddings, running similarity queries, and filtering results with metadata for production AI applications.
Key takeaways
Pinecone is a fully managed, cloud-native vector database designed specifically for AI applications. Unlike self-hosted solutions, Pinecone handles index scaling, replication, and infrastructure management automatically. You get a simple API for upserting vectors and querying by similarity, without provisioning servers or tuning storage engines.
For teams that want to ship a RAG pipeline or semantic search feature quickly without operating database infrastructure, Pinecone is one of the fastest paths to production.
Sign up at pinecone.io and grab your API key from the dashboard. Then install the Python client:
flowchart LR
Q(["User query"])
EMB["Embed query<br/>text-embedding-3"]
VEC[("Vector DB<br/>pgvector or Pinecone")]
RET["Top-k retrieval<br/>k = 8"]
PROMPT["Augmented prompt<br/>system plus context"]
LLM["LLM generation<br/>Claude or GPT"]
CITE["Inline citations<br/>and page anchors"]
OUT(["Grounded answer"])
Q --> EMB --> VEC --> RET --> PROMPT --> LLM --> CITE --> OUT
style EMB fill:#ede9fe,stroke:#7c3aed,color:#1e1b4b
style VEC fill:#ede9fe,stroke:#7c3aed,color:#1e1b4b
style LLM fill:#4f46e5,stroke:#4338ca,color:#fff
style OUT fill:#059669,stroke:#047857,color:#fff
pip install pinecone-client openai
Initialize the client:
from pinecone import Pinecone
pc = Pinecone(api_key="your-api-key-here")
An index in Pinecone is where your vectors live. Create a serverless index specifying the dimension and distance metric:
Hear it before you finish reading
Talk to a live CallSphere AI voice agent in your browser — 60 seconds, no signup.
from pinecone import ServerlessSpec
pc.create_index(
name="documents",
dimension=1536,
metric="cosine",
spec=ServerlessSpec(
cloud="aws",
region="us-east-1"
)
)
The dimension must match your embedding model output. OpenAI text-embedding-3-small uses 1536 dimensions. Serverless indexes scale automatically based on usage — you pay per query rather than for always-on pods.
Connect to the index and upsert vectors with optional metadata:
from openai import OpenAI
index = pc.Index("documents")
openai_client = OpenAI()
def embed_text(text: str) -> list[float]:
response = openai_client.embeddings.create(
model="text-embedding-3-small",
input=text
)
return response.data[0].embedding
# Upsert a single document
index.upsert(vectors=[
{
"id": "doc-001",
"values": embed_text("Pinecone is a vector database for AI."),
"metadata": {
"source": "tutorial",
"category": "databases",
"word_count": 8
}
}
])
For bulk ingestion, batch your upserts to reduce API calls:
def batch_upsert(documents: list[dict], batch_size: int = 100):
vectors = []
for doc in documents:
vectors.append({
"id": doc["id"],
"values": embed_text(doc["content"]),
"metadata": doc["metadata"]
})
# Upsert in batches
for i in range(0, len(vectors), batch_size):
batch = vectors[i:i + batch_size]
index.upsert(vectors=batch)
print(f"Upserted batch {i // batch_size + 1}")
Pass a query vector and get back the most similar results:
def search(query: str, top_k: int = 5):
query_vector = embed_text(query)
results = index.query(
vector=query_vector,
top_k=top_k,
include_metadata=True
)
for match in results["matches"]:
print(f"ID: {match['id']}, Score: {match['score']:.4f}")
print(f"Metadata: {match['metadata']}")
return results
search("How do vector databases work?")
The score represents cosine similarity (0 to 1 for cosine metric), where higher means more similar.
One of Pinecone's strengths is combining vector similarity with metadata filters. Filters are applied before the ANN search, so they do not degrade performance:
results = index.query(
vector=embed_text("database performance tuning"),
top_k=10,
include_metadata=True,
filter={
"category": {"$eq": "databases"},
"word_count": {"$gte": 100}
}
)
Supported filter operators include $eq, $ne, $gt, $gte, $lt, $lte, $in, and $nin. You can combine them with $and and $or:
Still reading? Stop comparing — try CallSphere live.
CallSphere ships complete AI voice agents per industry — 14 tools for healthcare, 10 agents for real estate, 4 specialists for salons. See how it actually handles a call before you book a demo.
filter={
"$and": [
{"category": {"$in": ["databases", "ai"]}},
{"source": {"$ne": "deprecated"}}
]
}
Namespaces partition an index into separate segments. Each query only searches within one namespace:
# Upsert into a specific namespace
index.upsert(
vectors=[{"id": "doc-1", "values": embedding, "metadata": meta}],
namespace="tenant-abc"
)
# Query within that namespace
results = index.query(
vector=query_vec,
top_k=5,
namespace="tenant-abc"
)
This is useful for multi-tenant applications where each customer's data must be isolated without creating separate indexes.
Remove vectors by ID or by metadata filter:
# Delete specific IDs
index.delete(ids=["doc-001", "doc-002"])
# Delete all vectors in a namespace
index.delete(delete_all=True, namespace="tenant-abc")
Serverless indexes charge per query and per GB stored, with no minimum monthly cost. For workloads under a few million queries per month, serverless is significantly cheaper than pod-based indexes. Pod indexes make sense when you need guaranteed low-latency at sustained high throughput.
Yes. Use the update method with the vector ID and new metadata. You do not need to re-upload the vector values unless the underlying content has changed.
Pinecone overwrites the existing vector with the new values and metadata. This is an upsert (update or insert) operation, so you do not need to check for existence before writing.
#Pinecone #VectorDatabase #Cloud #Embeddings #RAG #AgenticAI #LearnAI #AIEngineering

Written by
Sagar Shankaran· Founder, CallSphere
LinkedInSagar Shankaran is the founder of CallSphere, where he builds production AI voice and chat agents deployed across healthcare, hospitality, real estate, and home services. He writes about agentic AI, LLM engineering, and shipping voice agents that handle real calls in production.
See how AI voice agents work for your industry. Live demo available -- no signup required.
A founder's guide to building a chatbot for answering questions on your website: RAG, voice, and how CallSphere ships one in 3-5 days.
Graphiti is the open-source temporal knowledge graph for AI agents in 2026. Learn how bi-temporal memory beats vector RAG for voice agents and long-running LLMs.
A founder's guide on how to create a chatbot in 2026. Build options, AI stack, integration patterns, and when buying a managed agent wins over building.
Deploy GPT-Realtime-2 on Azure AI Foundry. Region availability, networking, data residency, BAA, and the gotchas teams hit in the first 48 hours.
Haystack 2.7's Agent component plus an Ollama-served Llama 3.2 gives you tool-calling RAG with citations. Here's a complete pipeline against your own document store.
Build a production RAG agent with LangChain, then measure faithfulness, answer relevance, and context precision with RAGAS. The four metrics that matter and how to wire them up.
© 2026 CallSphere Inc. All rights reserved.
Made within San Francisco
Watch how CallSphere handles real customer calls, schedules appointments, and processes payments — live.
Try Live DemoBook a DemoCalculate Your ROI