Introduction to Qdrant
Our Python list search worked for 8 items, but real applications need to search millions of vectors in milliseconds. Qdrant is a purpose-built vector database that uses an algorithm called HNSW (Hierarchical Navigable Small World) to find similar vectors without checking every single one.
Qdrant is already running in Docker on port 6333 (from our setup step). You can see its dashboard at http://localhost:6333/dashboard. Now let's connect to it from Python and create our first collection.
How vector stores work
Documents are converted to embeddings, stored in a vector database, and retrieved by similarity search at query time.
You technically can, but PostgreSQL would compare your query vector against every stored vector using brute-force linear scan. Qdrant uses the HNSW algorithm to build a graph index that skips most comparisons, giving you sub-millisecond search even with millions of vectors. At scale, that difference is enormous.
from qdrant_client import QdrantClient
from qdrant_client.models import VectorParams, Distance
client = QdrantClient(url=QDRANT_URL)
# Create a collection for our restaurant policies
client.create_collection(
collection_name="green_bites_policies",
vectors_config=VectorParams(
size=768, # Must match embedding model dimensions
distance=Distance.COSINE # Cosine similarity for text
)
)
print("Collection created!")
print(client.get_collection("green_bites_policies"))Connect to Qdrant and create a collection
Qdrant architecture
How Qdrant organizes data for fast vector search.
Cosine similarity measures the angle (direction) between vectors, while Euclidean measures the straight-line distance (magnitude). For text embeddings, direction captures meaning and magnitude is just noise. Two texts about "pizza" should be similar regardless of how long the texts are. Cosine focuses on what matters: semantic direction.
Quiz: Quiz
Loading practice…
Flashcards: Flashcards
Loading practice…