Velamuvi AIAcademy

Lesson 7 of 9 · Tools

Pinecone and Qdrant

Use Pinecone (managed, serverless) and Qdrant (open source) from Python: create an index or collection, upsert vectors with metadata, query with filters, batch.

  • 8 min read
  • Intermediate
  • Reviewed
In this lesson you will learn
  • Explain the difference between a managed service and a self-hosted database
  • Create a Pinecone index, upsert vectors and query with a metadata filter
  • Create a Qdrant collection, upsert points with payloads and query with a filter
  • Upload large datasets in batches

Dedicated vector databases

Chroma and pgvector are easy to start with. When you need very large collections, heavy traffic or less work running servers, teams often choose a dedicated vector database. Two of the most widely used are Pinecone and Qdrant.

Both need an account or a running server, so the code here is shown without a Run button. The Qdrant output comes from a real run.

Pinecone: fully managed

Pinecone is a managed, closed-source service. You install the client with pip install pinecone and create an API key in its web console.

import os
from pinecone import Pinecone, ServerlessSpec

pc = Pinecone(api_key=os.environ["PINECONE_API_KEY"])     # never paste keys into code

if not pc.has_index("help-articles"):
    pc.create_index(
        name="help-articles",
        dimension=1536,                  # must match your embedding model
        metric="cosine",
        spec=ServerlessSpec(cloud="aws", region="us-east-1"),
    )

index = pc.Index("help-articles")

index.upsert(
    vectors=[
        {"id": "a1", "values": embedding_1, "metadata": {"category": "travel", "year": 2026}},
        {"id": "a2", "values": embedding_2, "metadata": {"category": "hotels", "year": 2024}},
    ],
    namespace="acme",                   # keeps each customer's data separate
)

response = index.query(
    vector=query_embedding,
    top_k=3,
    filter={"category": {"$eq": "travel"}, "year": {"$gte": 2025}},
    include_metadata=True,
    namespace="acme",
)
for match in response.matches:
    print(match.id, round(match.score, 3), match.metadata)

Here embedding_1, embedding_2 and query_embedding stand for lists of 1,536 numbers from your embedding model. Two Pinecone ideas to know:

  • Serverless indexes: you don't choose servers; storage and queries are billed by use.
  • Namespaces split one index into separate partitions. A query only searches one namespace, which makes them a clean way to separate tenants.

Pinecone's filters use operators like $eq, $in, $gte and $and, the same style as Chroma's.

Qdrant: open source, run it anywhere

Install the client with pip install qdrant-client. For learning, QdrantClient(":memory:") runs a local Qdrant inside your program, with no server at all:

from qdrant_client import QdrantClient, models

client = QdrantClient(":memory:")          # or QdrantClient(url="http://localhost:6333")

client.create_collection(
    collection_name="help_articles",
    vectors_config=models.VectorParams(size=3, distance=models.Distance.COSINE),
)

client.upsert(
    collection_name="help_articles",
    points=[
        models.PointStruct(id=1, vector=[0.9, 0.1, 0.0], payload={"title": "Booking flights", "category": "travel"}),
        models.PointStruct(id=2, vector=[0.1, 0.9, 0.0], payload={"title": "Hotel check-in", "category": "hotels"}),
        models.PointStruct(id=3, vector=[0.0, 0.2, 0.9], payload={"title": "Weather forecast", "category": "weather"}),
    ],
)

hits = client.query_points(
    collection_name="help_articles",
    query=[0.8, 0.2, 0.0],
    limit=3,
).points
for hit in hits:
    print(hit.id, round(hit.score, 3), hit.payload["title"])
Output
1 0.991 Booking flights
2 0.348 Hotel check-in
3 0.053 Weather forecast

Qdrant calls records points and metadata the payload. With cosine distance, the score is a similarity, so higher is better (unlike Chroma's distances). Point IDs must be whole numbers or UUIDs.

Filters are built from objects. This keeps only travel articles:

hits = client.query_points(
    collection_name="help_articles",
    query=[0.8, 0.2, 0.0],
    query_filter=models.Filter(
        must=[models.FieldCondition(key="category", match=models.MatchValue(value="travel"))]
    ),
    limit=3,
).points

must means every condition must hold; should means at least one; must_not excludes. Ranges use models.Range(gte=2025).

Uploading large datasets

Services limit how much data one request may carry, so large uploads are sent in batches, usually of around 100 to a few hundred vectors:

Try it yourselfPython
# Managed vector databases limit how much you can send in one request,
# so large uploads are split into batches.
records = [{"id": f"doc-{i}", "values": [0.1, 0.2, 0.3], "metadata": {"page": i}} for i in range(1, 1051)]

def batches(items, size):
    for start in range(0, len(items), size):
        yield items[start:start + size]

requests = 0
for batch in batches(records, 100):
    requests += 1
    # In real code: index.upsert(vectors=batch)
    if requests <= 2 or len(batch) < 100:
        print(f"Request {requests}: {len(batch)} records, {batch[0]['id']} to {batch[-1]['id']}")
print("Total requests:", requests)

Pinecone or Qdrant?

PineconeQdrant
LicenceClosed source, managed onlyOpen source; self-host or managed cloud
Running itNothing to runYou run it (Docker, Kubernetes), or use its cloud
Local testingNeeds the service (a local emulator also exists)In-memory mode inside Python
RecordsVectors with metadataPoints with payloads
TenantsNamespacesPayload filters, or separate collections
Good fitTeams that want zero operationsTeams that want control, or must keep data on their own servers

Common mistakes

Practice exercise

Implement the two filter operators so only travel records from 2025 or later are printed.

Your solutionPython
# Pinecone filters use operators such as $eq, $in and $gte.
filter = {"category": {"$eq": "travel"}, "year": {"$gte": 2025}}

records = [
    {"id": "a1", "metadata": {"category": "travel", "year": 2026}},
    {"id": "a2", "metadata": {"category": "travel", "year": 2023}},
    {"id": "a3", "metadata": {"category": "food",   "year": 2026}},
    {"id": "a4", "metadata": {"category": "travel", "year": 2025}},
]

def passes(meta, filter):
    # Return True if meta satisfies every condition ($eq and $gte only)
    return True

for r in records:
    if passes(r["metadata"], filter):
        print(r["id"])
Knowledge check

In Pinecone, what is a namespace mainly used for?

Summary

  • Pinecone is a fully managed service: create an index, upsert vectors with metadata, query with top_k and filter, and use namespaces for tenants.
  • Qdrant is open source: collections of points with payloads, queried with query_points and Filter objects; it can even run in memory for tests.
  • Upload large datasets in batches.
  • Choose between them on operations, control, data location and cost.

Next: combining keyword and vector search in one query.

Finished reading? Tick it off to track your progress.