Calendar Module 0

Implementing a Basic Vector Search

In this lesson you’ll build your very first search, one small step at a time. You’ll connect to Qdrant, create a place to store data, add a few example vectors, and then ask Qdrant to find the closest match. Every step has runnable code, so follow along in a notebook or script.

A quick vocabulary note before you start: a vector is just a list of numbers that represents something (a piece of text, an image, a product). Searching by vectors means finding the entries whose numbers are closest to your query’s numbers. That’s the whole idea, and the code below makes it concrete.

Before You Start

This course requires Python 3.11 or above installed

Step 1: Install the Qdrant Client

The client is the Python library that lets your code talk to Qdrant. Install it first:

!pip install qdrant-client

Step 2: Import the Libraries You’ll Need

Import two things from the package: QdrantClient, which opens the connection, and models, which holds the building blocks you’ll use to describe collections and points.

from qdrant_client import QdrantClient, models

Step 3: Connect to Qdrant Cloud

Use the cluster URL and API key from the previous lesson. If you saved them in a .env file, this reads them automatically:

import os

client = QdrantClient(url=os.getenv("QDRANT_URL"), api_key=os.getenv("QDRANT_API_KEY"))

# For Colab:
# from google.colab import userdata
# client = QdrantClient(url=userdata.get("QDRANT_URL"), api_key=userdata.get("QDRANT_API_KEY"))

Tip: For quick experiments with no cloud account at all, you can use client = QdrantClient(":memory:"). It runs entirely in memory, but your data disappears when the program stops.

Step 4: Create a Collection

A collection is where your vectors live. It’s a lot like a table in a regular database: a named container for related data. When you create one, you tell Qdrant two things:

  • Size: how many numbers each vector has.
  • Distance metric: how Qdrant measures whether two vectors are “close.”
# Name your collection
collection_name = "my_first_collection"

# Create it, describing the vectors it will hold
client.create_collection(
    collection_name=collection_name,
    vectors_config=models.VectorParams(
        size=4,  # each vector has 4 numbers
        distance=models.Distance.COSINE  # how we measure closeness
    )
)

This returns True when it works.

If completed correctly, you will now have an established Qdrant environment for the rest of the course. Later modules will explain collections, points, distance metrics, and more. Keep going to find out more!

Congratulations! You’ve completed Module 0. 🎉