By RAGStarter ยท 7th October 2026
Most RAG tutorials rush past the vector database. They give you one line that says index.upsert(...), tell you it “stores your embeddings,” and move on to the chatbot. That’s fine until something breaks, and then you realise you never understood the part that holds your data.
This tutorial slows down on that part. We’ll sign up for Pinecone’s free plan, create an index, store a handful of text snippets as vectors, and search them by meaning. We won’t build a full chatbot here. The goal is simpler: by the end you should know what each Pinecone call does, what the free plan lets you do, and how to avoid the usual beginner errors.
Everything below uses Python and a free, local embedding model, so the only account you need is Pinecone itself.
What you’ll need
- Python 3.9 or newer and
pip - A free Pinecone account
- About 30 minutes
- A terminal, and a code editor or a Jupyter notebook
No credit card should be needed for the free plan, but check the sign-up page when you register, since plans change.
What is a vector database, in plain words?
When a language model reads a sentence, it can turn it into a long list of numbers called an embedding (or vector). Sentences with similar meaning end up with similar numbers. “How do I reset my password?” and “I forgot my login” look different as text but land close together as vectors.
A vector database stores those lists and answers one kind of question really fast: which stored vectors are closest to this one? That’s what powers semantic search, and it’s the retrieval half of RAG.
Pinecone is a hosted vector database. You don’t install or run a server. You create an index through their API, send vectors in, and ask for the nearest ones back.
What the free plan gives you
Pinecone’s free plan is called Starter. At the time of writing, its pricing page lists roughly the following. Plans change, so always confirm on pinecone.io/pricing before you rely on a number.
| Item | Starter (free) |
|---|---|
| Storage | 2 GB included |
| Write units | 2 million per month |
| Read units | 1 million per month |
| Projects per organization | 1 |
| Indexes per project | 5 |
| Namespaces per index | 100 |
| Region | AWS us-east-1 only |
| Embedding API | 5 million tokens per month |
A few things worth noticing:
- One region. On the free plan your index lives on AWS in us-east-1. You can’t pick another. That matters for speed only slightly, and not at all for a learning project.
- Inactive indexes can be paused. Some third-party summaries report that free indexes get paused after about three weeks without activity. If your project sits idle for a while, check your index before a demo.
- Reads and writes are metered. Upserts use write units, and queries and fetches use read units. Small projects rarely come close to the limits, but a loop that queries thousands of times can.
For a student project with a few hundred or a few thousand text chunks, these limits are generous.
Step 1: Create an account and get an API key
- Sign up at pinecone.io and verify your email.
- Open the console and go to API Keys.
- Copy the default key.
Treat that key like a password. Don’t paste it into a blog post, a screenshot or a public GitHub repo. Instead, store it in an environment variable.
On Windows PowerShell:
$env:PINECONE_API_KEY = "paste-your-key-here"On macOS or Linux:
export PINECONE_API_KEY="paste-your-key-here"The variable only lasts for that terminal session, which is fine for a tutorial.
[Add your own screenshot here: the Pinecone console API Keys page with the key value hidden or blurred.]
Step 2: Install the libraries
We need two packages: Pinecone’s client and a library for making embeddings locally.
pip install pinecone sentence-transformersOlder tutorials tell you to install pinecone-client. That is the old package name. The current package is called pinecone, so if you copy older code and imports fail, this is the first thing to check.
Step 3: Create an index
An index is the container for your vectors. When you create one, you make two decisions that you can’t casually change later: the dimension and the metric.
import os
from pinecone import Pinecone, ServerlessSpec
pc = Pinecone(api_key=os.environ["PINECONE_API_KEY"])
INDEX_NAME = "ragstarter-demo"
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"),
)
index = pc.Index(INDEX_NAME)
print(index.describe_index_stats())Let’s go through the important arguments.
dimension=384 must match your embedding model exactly. The model we’ll use in a moment, all-MiniLM-L6-v2, produces vectors with 384 numbers. If you create the index with a different dimension, your upserts will be rejected. This is the single most common beginner error, so it’s worth remembering: the index dimension is decided by the model, not by you.
metric="cosine" tells Pinecone how to measure “closeness.” Cosine similarity compares the direction of two vectors and ignores their length, which suits text embeddings well. Other options exist (euclidean and dotproduct), but cosine is a safe default for sentences.
ServerlessSpec says this is a serverless index, meaning Pinecone manages the capacity for you. On the free plan the region must be us-east-1 on AWS.
If everything worked, describe_index_stats() prints a small summary showing the dimension and a total vector count of 0.
Step 4: Turn text into vectors
Next we need something to store. Here are eight short notes about RAG and vector search. Using your own notes or a few paragraphs from a course would be even better, because you’ll recognise whether the search results make sense.
docs = [
{"id": "n1", "topic": "rag",
"text": "RAG lets a language model answer using documents you provide instead of only its training data."},
{"id": "n2", "topic": "rag",
"text": "Chunking splits long documents into smaller pieces so retrieval can return focused context."},
{"id": "n3", "topic": "embeddings",
"text": "An embedding turns a piece of text into a list of numbers that captures its meaning."},
{"id": "n4", "topic": "embeddings",
"text": "Similar sentences have embeddings that sit close together in vector space."},
{"id": "n5", "topic": "database",
"text": "A vector database stores embeddings and finds the nearest ones to a query very quickly."},
{"id": "n6", "topic": "database",
"text": "Metadata filters let you narrow a vector search to records with a certain label."},
{"id": "n7", "topic": "cooking",
"text": "To make a good tomato sauce, simmer the tomatoes slowly with garlic and olive oil."},
{"id": "n8", "topic": "cooking",
"text": "Rest the dough for an hour so the gluten relaxes and the bread rises evenly."},
]I added two cooking notes on purpose. A good search should ignore them when you ask about RAG, and it’s a nice way to see semantic search working.
Now create the embeddings:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("all-MiniLM-L6-v2")
vectors = model.encode([d["text"] for d in docs]).tolist()
print(len(vectors), len(vectors[0])) # expect: 8 384The first run downloads the model, which takes a minute. After that it works offline and costs nothing. The .tolist() call converts the NumPy arrays into plain Python lists, which the Pinecone client expects.
The printed output should read 8 384: eight vectors, each with 384 numbers. If the second number isn’t 384, stop and fix it before going further.
Step 5: Store the vectors (upsert)
“Upsert” is a mash-up of update and insert. If the ID is new, Pinecone adds the record. If the ID already exists, Pinecone overwrites it. That makes it safe to re-run your script.
Each record has three parts:
- an id, which is a string you choose
- the values, which is the vector
- optional metadata, which is any small JSON-like data you want to get back with the result
records = [
{
"id": d["id"],
"values": v,
"metadata": {"text": d["text"], "topic": d["topic"]},
}
for d, v in zip(docs, vectors)
]
index.upsert(vectors=records, namespace="notes")Two details are easy to miss.
First, store the original text in the metadata. Pinecone stores vectors, not your sentences. If you don’t save the text somewhere, a search will give you IDs and scores and you’ll have no readable answer. For small projects, putting the text in metadata is the simplest fix. (There’s a size cap per vector’s metadata, roughly 40 KB at the time of writing, so very large chunks may need a different approach.)
Second, the namespace is like a folder inside your index. Everything we write to "notes" stays separate from other namespaces. It’s useful for keeping different datasets apart in a single index, and the free plan allows up to 100 per index.
Upserts are not always visible instantly. If you check the stats a second after writing, the count might still show 0. Wait a few seconds and run:
print(index.describe_index_stats())You should now see 8 vectors under the notes namespace.
[Add your own screenshot here: the output of describe_index_stats() showing the vector count, or the Pinecone console index page.]
Step 6: Search by meaning
This is the fun part. We’ll embed a question with the same model, then ask Pinecone for the three closest vectors.
question = "How can I make a model answer from my own files?"
q_vec = model.encode(question).tolist()
results = index.query(
vector=q_vec,
top_k=3,
include_metadata=True,
namespace="notes",
)
for match in results.matches:
print(round(match.score, 3), "|", match.metadata["text"])Notice that the question shares almost no words with the stored note about RAG. It doesn’t say “RAG,” “language model” or “documents.” The search should still bring that note to the top, because the meanings are close. That’s the whole point of vector search, and it’s worth trying a few questions of your own to see where it works and where it doesn’t.
A few things to try:
- Ask about tomatoes or bread. The cooking notes should now win.
- Ask something vague, like “tell me about data.” Notice how the scores drop and the top results get less convincing.
- Change
top_kto 5 and see where the relevant results stop.
The score here is cosine similarity. A higher number means closer. As a loose guide, a score near 1 means very similar and a score near 0 means unrelated, but there’s no magic cutoff. Judge it by reading the results.
Step 7: Narrow results with a metadata filter
Sometimes you only want results from one category. That’s what the filter is for:
results = index.query(
vector=q_vec,
top_k=3,
include_metadata=True,
namespace="notes",
filter={"topic": {"$eq": "database"}},
)
for match in results.matches:
print(round(match.score, 3), "|", match.metadata["topic"], "|", match.metadata["text"])Now only records labelled database can come back, no matter how similar the others are. In a real RAG app you might filter by document name, course, author or date.
Step 8: Update, delete and clean up
To change a record, upsert it again with the same ID. To remove records:
# delete specific records
index.delete(ids=["n7", "n8"], namespace="notes")
# or wipe the whole namespace
index.delete(delete_all=True, namespace="notes")When you’re completely done experimenting, delete the index. Free accounts have a limit of five, and an unused index is just clutter:
pc.delete_index(INDEX_NAME)How to stay inside the free limits
You’re unlikely to hit the free limits by accident with a small project, but a few habits keep it that way.
- Don’t re-embed and re-upsert everything on every run. Upsert once, then query as often as you like. Because upserts are idempotent, re-running is safe, but it still uses write units.
- Avoid query loops during testing. If you’re printing results for 5,000 test questions, you’re spending read units. Test with a small list first.
- Keep chunks reasonably sized. Smaller chunks mean smaller metadata and cheaper storage. A few hundred words per chunk is a common starting point.
- Check usage in the console. The Pinecone dashboard shows how much of your monthly allowance you’ve used.
- Remember the inactivity pause. If your project is on hold for weeks, log in and check the index before you present it.
As a rough sense of scale: a 384-dimension vector is about 1.5 KB of numbers (384 values at 4 bytes each), plus your metadata. A few thousand of them is a tiny fraction of 2 GB.
Common errors and what they mean
| What you see | Likely cause | Fix |
|---|---|---|
| Message saying the vector dimension doesn’t match the index | The index dimension and your model’s output size are different | Recreate the index with the correct dimension (384 for all-MiniLM-L6-v2) |
| Unauthorized or 401 error | Wrong or missing API key | Re-copy the key and check the environment variable is set in this terminal |
| Index not found | Typo in the name, or the index was deleted or is still initialising | Run pc.list_indexes().names() to see what exists |
| Query returns zero matches right after upserting | Writes haven’t become visible yet, or you queried a different namespace | Wait a few seconds, and make sure the namespace matches |
ModuleNotFoundError for pinecone | Package not installed in the Python you’re running | Run pip install pinecone with the same interpreter, and check you didn’t install the old pinecone-client |
| Quota or limit error | You’ve hit a free plan cap | Check the console usage page and the current plan limits |
Where this fits in a RAG app
What we just built is the retrieval half of RAG. In a full application the flow looks like this:
- Load your documents and split them into chunks.
- Embed each chunk and upsert it into Pinecone, with the chunk text in metadata.
- When a user asks a question, embed it and query Pinecone for the top few chunks.
- Paste those chunks into a prompt and send it to a language model.
Steps 1 to 3 are exactly what you did in this tutorial. Step 4 is just a normal model call with the retrieved text added to the prompt. If you want to see how LangChain and LlamaIndex wrap this flow, read our comparison: [add internal link to the LangChain vs LlamaIndex post].
Try it yourself
[Add 2 to 3 sentences about what you noticed when you ran this: which question surprised you, what error you hit and how you fixed it.]
[Add a screenshot of your own query results here.]
A good exercise is to replace the eight sample notes with a few paragraphs from your own course material, then write five questions and check whether the top result is actually the right one. Counting how many of the five it gets right will tell you more about retrieval quality than any tutorial can.
FAQ
Is Pinecone really free? There’s a free Starter plan with monthly allowances for storage, reads and writes. Paid plans exist for larger projects. Check the pricing page for current numbers.
Do I need a credit card? The free plan was advertised without one when this was written, but confirm on the sign-up page.
Can I use OpenAI embeddings instead of a local model? Yes. The only rule is that the index dimension must match the model’s output size. Check that model’s documentation for its dimension, and create a new index accordingly.
What happens if I choose the wrong dimension? Pinecone rejects the upserts. You’ll need to create a new index with the right dimension, because the dimension can’t be changed on an existing one.
Is Pinecone the only option? No. Chroma, Qdrant, Weaviate and FAISS are popular alternatives, and some run entirely on your own machine. Pinecone is a good first choice mainly because there’s nothing to host.
How many records can I store for free? It’s limited by the 2 GB storage allowance rather than a fixed record count, as far as the current pricing page shows. Small text chunks mean you can store a lot.
Wrapping up
A vector database sounds intimidating, but at the beginner level it comes down to five calls: create an index, embed your text, upsert, query, and delete. Get the dimension right, store your text in metadata, and watch your usage, and the free plan is more than enough for a course project.
Once this feels comfortable, the next step is feeding real document chunks into the same index and sending the retrieved text to a language model. That’s the full RAG loop, and you’ve already built the hard part.