
We built a RAG chatbot using FAISS, which runs locally. That works for 1,000 documents. But what if you have 100 million? You need a Vector Database. If you’re working with Pinecone RAG Python, you’ll find it handles the storage, indexing, and searching of your embeddings in the cloud, so your app is fast and stateless.
In this post, we’ll look at how to use Pinecone RAG Python to scale up your retrieval-augmented generation projects.
Step 1: Setup
- Go to Pinecone.io and get a free API Key.
- Install the libraries:
pip install pinecone-client sentence-transformers
Step 2: Initialize and Connect
import os
from pinecone import Pinecone, ServerlessSpec
from sentence_transformers import SentenceTransformer
# 1. Initialize connection
pc = Pinecone(api_key="YOUR_API_KEY")
# 2. Create an Index (if it doesn't exist)
# Dimension 384 matches the 'all-MiniLM-L6-v2' model
index_name = "my-knowledge-base"
if index_name not in pc.list_indexes().names():
pc.create_index(
name=index_name,
dimension=384,
metric="cosine",
spec=ServerlessSpec(cloud="aws", region="us-east-1")
)
# Connect to the index
index = pc.Index(index_name)Step 3: Embed and Upsert (Upload)
We convert text to numbers and send them to the cloud.
model = SentenceTransformer('all-MiniLM-L6-v2')
documents = [
{"id": "vec1", "text": "Python is great for data science."},
{"id": "vec2", "text": "Pinecone is a vector database."},
{"id": "vec3", "text": "Polars is faster than Pandas."}
]
# Prepare data for Pinecone: [(id, vector, metadata), ...]
vectors_to_upload = []
for doc in documents:
embedding = model.encode(doc['text']).tolist()
vectors_to_upload.append((doc['id'], embedding, {"text": doc['text']}))
# Upload!
index.upsert(vectors=vectors_to_upload)
print("Data uploaded to cloud!")Step 4: Query the Cloud
Now we can search our database from anywhere.
query = "What is good for big data?"
query_embedding = model.encode(query).tolist()
# Search for the top 1 match
result = index.query(
vector=query_embedding,
top_k=1,
include_metadata=True
)
print(f"Match: {result['matches'][0]['metadata']['text']}")
# Output: Match: Polars is faster than Pandas.You now have a persistent, scalable “long-term memory” for your AI agents!
Key Takeaways
- To handle 100 million documents, use a Vector Database like Pinecone.
- Pinecone stores, indexes, and searches embeddings in the cloud for efficiency.
- Get a free API Key from Pinecone.io and install the necessary libraries.
- Convert text to numbers, upload them to the cloud, and query your database from anywhere.
- This setup provides a scalable ‘long-term memory’ for your AI agents.




