LearnAI ToolsCareerPractice BuildsPlayContact
Lesson 1224 min read

Vector Databases: Pinecone & Weaviate

Learn Pinecone and Weaviate, two managed vector databases, with a working example of storing and querying embeddings in each.

Introduction

A vector database is what makes retrieval-augmented generation possible at scale — it stores embeddings (numeric representations of meaning, covered fully in lesson 14) and can find the most similar ones to a query in milliseconds, even across millions of records. Pinecone and Weaviate are two of the most widely used managed options.

What You Will Learn
  • What a vector database actually stores and searches, at a conceptual level.
  • How to install and query Pinecone.
  • What Weaviate offers as an open-source alternative with managed hosting.

A Real-Life Analogy First

Imagine a giant library with no organization at all — every book dumped in one room, in no particular order. Finding a book about "cooking Italian food" means checking every single book by hand. Now imagine that same library organized by a librarian who has grouped every book by how similar its subject matter is to every other book's, so "Italian cooking," "pasta recipes," and "Mediterranean cuisine" all sit physically near each other on the shelf, even though they don't share the exact same words in their titles. A vector database is that second, meaning-organized library, but for pieces of text (or images) instead of books, and searchable in milliseconds instead of by walking the aisles.

What a Vector Database Actually Stores

Each record is a vector — a list of a few hundred to a few thousand numbers produced by an embedding model — plus optional metadata (like the original text or a source URL). A query is itself embedded into the same kind of vector, and the database returns the stored vectors whose numbers are mathematically closest to it, which corresponds to "most similar in meaning."

Pinecone: Managed Vector Search

Use case: Pinecone is a fully managed, serverless vector database — no infrastructure to run yourself, built specifically and only for vector search, with strong performance at large scale.

pip install pinecone

Pinecone in Action

from pinecone import Pinecone
pc = Pinecone() # reads PINECONE_API_KEY from the environment
index = pc.Index("product-docs")
# Each vector: an id, its embedding, and optional metadata
index.upsert(vectors=[
{"id": "doc-1", "values": [0.02, 0.91, -0.13, 0.44], "metadata": {"text": "Refunds are processed within 5-7 business days."}},
{"id": "doc-2", "values": [0.88, -0.12, 0.30, 0.09], "metadata": {"text": "Shipping takes 3-5 business days domestically."}},
])
results = index.query(vector=[0.03, 0.89, -0.10, 0.41], top_k=1, include_metadata=True)
print(results.matches[0].metadata["text"])
Terminal Output

Click Run to see what this code prints.

Real Embeddings Are Much Longer

The 4-number vectors above are shortened for readability — real embeddings from a model like OpenAI's text-embedding-3-small are 1536 numbers long. Lesson 14 covers generating real embeddings to feed into a database like this one.

Weaviate: Open-Source With Managed Hosting

Use case: Weaviate is an open-source vector database you can self-host or run through Weaviate's managed cloud — a good fit when you want the option to move off a fully proprietary managed service later, or need it to run inside your own infrastructure for compliance reasons.

pip install weaviate-client
import weaviate
client = weaviate.connect_to_weaviate_cloud(
cluster_url="https://your-cluster.weaviate.network",
auth_credentials=weaviate.auth.AuthApiKey("your-api-key"),
)
docs = client.collections.get("ProductDocs")
response = docs.query.near_text(query="how long do refunds take", limit=1)
print(response.objects[0].properties["text"])
client.close()
Terminal Output

Click Run to see what this code prints.

Pinecone vs Weaviate

AspectPineconeWeaviate
HostingManaged only, fully serverlessSelf-hosted or managed cloud
Open sourceNoYes
near_text style built-in text embeddingBring your own embedding stepCan auto-embed via built-in modules
Best forZero-ops, large-scale managed searchTeams wanting self-host flexibility or an open-source core

Where You've Already Seen This Idea

Similarity search is not a brand-new concept invented for AI — you have already relied on it, often without realizing.

Spotify "Recommended for you"

Finds songs whose "sound" is mathematically close to what you already listen to — the same nearest-neighbor idea, applied to audio instead of text.

"Customers also bought" on shopping sites

Finds other products that are similar to the one you're viewing, based on purchase patterns or descriptions.

Google Photos' "search by description"

Typing "dog on a beach" finds matching photos without anyone manually tagging every image — an image embedding search under the hood.

Common Mistakes

Avoid These Mistakes
  • Storing embeddings without any metadata, making it impossible to trace a match back to its original source text.
  • Using mismatched embedding models between what generated the stored vectors and what generates the query vector — similarity search only works if both use the same model.
  • Not setting top_k thoughtfully — too low can miss relevant context, too high can flood a prompt with irrelevant chunks.

Best Practices

  • Always store the original text (or a pointer to it) as metadata alongside a vector, not just the raw numbers.
  • Keep the embedding model consistent for every vector in an index — mixing models produces meaningless similarity scores.
  • Start with a managed service (Pinecone or Weaviate Cloud) before considering self-hosting, unless you have a specific compliance requirement.

Frequently Asked Questions

No — only when you need to search over your own data at scale. Lesson 13 covers Chroma and FAISS, which are lighter options for smaller, local projects.

Pinecone offers a limited free tier, sufficient for learning and small projects, with paid tiers for larger scale — check their current pricing page for specifics.

Yes, though it requires re-generating and re-uploading your vectors, since each service's storage format and client API differ.

That is a fair way to think about it — it is a search engine that ranks results by meaning ("semantic" similarity) instead of by matching exact keywords the way a traditional database search or Ctrl+F would.

Key Takeaways

  • A vector database stores embeddings plus metadata and finds the closest matches to a query vector.
  • Pinecone is a fully managed, serverless option built only for vector search.
  • Weaviate is open-source and can be self-hosted or run through a managed cloud.
  • You have already relied on this same underlying idea in Spotify, shopping recommendations, and photo search.
  • Always keep the embedding model consistent between stored vectors and query vectors.

Summary

Pinecone and Weaviate both solve the same core problem — fast similarity search over embeddings at scale — with different tradeoffs around hosting and openness. The next lesson covers lighter-weight, local-first alternatives.

Lesson 12 Completed
  • You understand what a vector database stores and searches.
  • You can store and query vectors with Pinecone.
  • You know what Weaviate offers as an open-source alternative.
Next Lesson →

Vector Databases: Chroma & FAISS