Pinecone 101: Modern Vector Database Guide
Outdated tutorials often use deprecated packages and legacy connection calls that fail immediately. This guide shows how to set up the modern Pinecone SDK, create a serverless vector index, and handle vector records properly. By the end, you will have a working vector database pipeline with metadata filtering tested and running.
Before you start
- Python 3.10 or newer installed
- A free Pinecone account with an API key from console.pinecone.io
- Basic familiarity with Python and terminal commands
Environment Setup and SDK Installation
Start by creating and activating an isolated Python virtual environment using the commands shown below. Many older guides instruct you to install pinecone-client, but that library is deprecated. The official and actively maintained package is simply pinecone.
Run the installation command below to install the modern SDK. It bundles gRPC support directly without requiring additional dependency flags. The verification step was tested in a Debian sandbox and confirmed successful installation of version 10.3.0.
python3 -m venv .venv
# Install the modern pinecone package quietly to prevent verbose output from overflowing the terminal buffer
source .venv/bin/activate && pip install -q pinecone
# Verify the installation and display the installed Pinecone SDK version
source .venv/bin/activate && python3 -c "import pinecone; print('Pinecone version:', pinecone.__version__)"
Output from our test run
$ python3 -m venv .venv
$ source .venv/bin/activate && pip install -q pinecone
(.venv) $ source .venv/bin/activate && python3 -c "import pinecone; print('Pinecone version:', pinecone.__versio
n__)"
Pinecone version: 10.3.0
(.venv) $Core Concepts: Dimensions, Metrics, and Namespaces
Before writing your ingestion scripts, you must configure three core architectural concepts correctly: dimensions, metrics, and namespaces.
Your index dimension must strictly match the output size of your embedding model, such as 1024 or 1536 floating-point values. A dimensional mismatch will cause your upsert requests to fail immediately.
The distance metric determines how similarity is measured, with cosine serving as the standard choice for normalized text embeddings. Finally, use namespaces to partition data logically inside a single index instead of spinning up multiple indexes and exhausting account quotas.
Creating a Serverless Index
To provision an index, instantiate the client class using your exported PINECONE_API_KEY. Modern SDK versions use class-based instantiation rather than legacy global initialization methods.
Inspect your account using the provided script to verify whether the target index already exists. If it is missing, create it using ServerlessSpec configured for AWS us-east-1, which runs on the free tier.
Serverless indexes automatically scale computing resources according to demand, avoiding the ongoing maintenance costs of dedicated pods.
import os
from pinecone import Pinecone, ServerlessSpec
api_key = os.environ.get("PINECONE_API_KEY")
if not api_key:
raise ValueError("Please export PINECONE_API_KEY before running.")
pc = Pinecone(api_key=api_key)
index_name = "quickstart-101"
dimension = 1024
existing_indexes = [idx.name for idx in pc.list_indexes()]
if index_name not in existing_indexes:
print(f"Creating serverless index: {index_name}")
pc.create_index(
name=index_name,
dimension=dimension,
metric="cosine",
spec=ServerlessSpec(
cloud="aws",
region="us-east-1"
)
)
print("Index created successfully.")
else:
print(f"Index '{index_name}' already exists.")
Upserting Vectors with Metadata and Namespaces
Insert embeddings into your index by calling the upsert method shown in the script below. Each record requires a unique string identifier, a vector array matching your index dimension, and an optional metadata dictionary.
Metadata allows you to attach context such as titles, categories, and timestamps directly alongside each vector. Passing a namespace parameter isolates your records within a designated partition.
The upsert operation acts as an insert-or-replace command: existing records sharing the same ID are updated, while new IDs are added.
import os
from pinecone import Pinecone
pc = Pinecone(api_key=os.environ.get("PINECONE_API_KEY"))
index = pc.Index("quickstart-101")
# Sample mock embeddings with dimension 1024
vectors = [
{
"id": "doc-1",
"values": [0.05] * 1024,
"metadata": {"title": "Introduction to Vectors", "topic": "search", "year": 2026}
},
{
"id": "doc-2",
"values": [0.08] * 1024,
"metadata": {"title": "Retrieval-Augmented Generation", "topic": "rag", "year": 2026}
},
{
"id": "doc-3",
"values": [-0.02] * 1024,
"metadata": {"title": "Traditional Databases", "topic": "sql", "year": 2020}
}
]
response = index.upsert(vectors=vectors, namespace="kb-articles")
print(f"Upserted {response.upserted_count} vectors into 'kb-articles' namespace.")
Read-After-Write Consistency
A common pitfall is querying an index immediately after an upsert call and receiving empty matches. Pinecone serverless indexes operate on an eventual consistency model.
Although the client receives a write confirmation immediately, the underlying indexing graph requires a brief moment to process the newly added records.
Allow a few seconds between writing records and issuing similarity searches during automated tests or ingestion scripts.
Querying with Metadata Filtering
To search your vector database, provide a target query vector of matching dimensions and specify the number of neighbors using top_k. Set include_metadata to retrieve associated document attributes alongside the similarity scores.
You can refine searches deterministically by passing a filter dictionary matching your metadata keys. In the example below, results are limited to entries meeting specific date criteria while ignoring irrelevant records regardless of vector proximity.
Executing the search against your chosen namespace ensures Pinecone only traverses vectors within that specific data partition.
import os
from pinecone import Pinecone
pc = Pinecone(api_key=os.environ.get("PINECONE_API_KEY"))
index = pc.Index("quickstart-101")
# Query vector matching the index dimension (1024)
query_vector = [0.06] * 1024
results = index.query(
vector=query_vector,
top_k=2,
namespace="kb-articles",
include_metadata=True,
filter={
"year": {"$gte": 2025}
}
)
print("Search Results:")
for match in results.matches:
print(f"- ID: {match.id}, Score: {match.score:.4f}, Title: {match.metadata.get('title')}")
Checking Index Statistics and Cleanup
You can inspect index health and capacity by calling describe_index_stats as shown in the script below. This returns the total vector count and breaks down the number of stored vectors across all active namespaces.
Monitoring namespace counts helps verify that background ingestion has completed across partitions.
When finished with temporary or testing workloads, use pc.delete_index to remove the index and keep your account well within quota limits.
import os
from pinecone import Pinecone
pc = Pinecone(api_key=os.environ.get("PINECONE_API_KEY"))
index_name = "quickstart-101"
# Check index statistics
index = pc.Index(index_name)
stats = index.describe_index_stats()
print(f"Total vectors: {stats.total_vector_count}")
print(f"Namespaces: {stats.namespaces}")
# Clean up index when finished testing
# pc.delete_index(index_name)
# print(f"Index '{index_name}' deleted.")
Wrap-up
You now have a clean, working foundation for Pinecone using the modern SDK, serverless indexes, and metadata filtering. You can store high-dimensional embeddings, partition datasets with namespaces, and run filtered vector queries on your first try.
FAQ
Why is the pinecone-client package no longer recommended?
The pinecone-client package is deprecated in favor of the unified pinecone library, which contains the modern class-based client and bundled gRPC support.
What happens if my upsert vector dimensions do not match the index?
Pinecone rejects the upsert request with an error because every vector in an index must strictly match the dimension defined when the index was created.
Why do recent upserts sometimes fail to appear in query results immediately?
Pinecone serverless indexes use an eventually consistent storage model, meaning there can be a brief ingestion delay before newly upserted vectors are visible to queries.
How do namespaces help manage account limits?
Namespaces create logical data partitions inside a single index, allowing you to isolate different datasets without creating multiple indexes and exhausting free tier quotas.