Qdrant: create a collection and query vectors in Python

A vector database stores embeddings next to a small payload and returns the closest matches for a query vector. This tutorial creates a collection in Qdrant, inserts two points and queries them with the Python client, which forms the base of an internal document search.

Niklas Schult4 min read

Illustration: A magnet pulls two small pins out of one jar on a shelf of jars, while the others stay untouched.

What you will have at the end and what you need

At the end you have a running Qdrant server, a collection named dokumente and two stored points. A Python query then returns the payload of the point closest to a query vector. Earlier articles on this blog covered only the Docker start and metadata filters, so this one fills the gap between them.

You need Docker on a machine you can reach, Python and the Python client package. The Qdrant README names the official client libraries, among them one for Python, and the module used below is qdrant_client. The example vectors have four dimensions and are made up. A real document search needs vectors from an embedding model, which the README does not cover.

Start the server and connect the client

The README starts Qdrant locally with a single container command. It publishes port 6333 so that the client can reach the server.

Shell
docker run -p 6333:6333 qdrant/qdrant

The README warns that this command starts an insecure deployment without authentication, open to all network interfaces. Use it on a test machine only. Before any production use, the README points to the installation and security guides of Qdrant.

Python
from qdrant_client import QdrantClient

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

Next, the Python client connects to the server by its URL. The following lines import the client class and create a connection to the local container.

Create the collection and insert points

A collection holds points, and a point is a vector with an additional payload. The next block creates the collection dokumente with vectors of size 4 and cosine distance. It then upserts two points, each with an id, a vector and a payload holding a title.

The size in the collection settings has to match the length of every vector you insert. In a real setup it equals the output size of your embedding model. The payload can carry any JSON, which later allows filtering on fields such as the title.

Python
from qdrant_client.models import Distance, VectorParams, PointStruct

client.create_collection(
    collection_name="dokumente",
    vectors_config=VectorParams(size=4, distance=Distance.COSINE),
)

client.upsert(
    collection_name="dokumente",
    points=[
        PointStruct(id=1, vector=[0.1, 0.2, 0.3, 0.4], payload={"titel": "Urlaubsregel"}),
        PointStruct(id=2, vector=[0.9, 0.1, 0.1, 0.0], payload={"titel": "Reisekosten"}),
    ],
)

Query the collection and check the result

The query sends a vector and asks for the single nearest point. The code below uses the vector of the first point as query, limits the answer to one hit and prints the payload of that hit.

Python
treffer = client.query_points(
    collection_name="dokumente",
    query=[0.1, 0.2, 0.3, 0.4],
    limit=1,
).points

print(treffer[0].payload)

Because the query vector is identical to the first point, the output should show the payload with the title Urlaubsregel. If you change the query to the second vector, the title Reisekosten should appear instead. The README also describes a Web UI for exploring collections visually, which gives you a second way to confirm that both points exist.

Typical pitfalls

The README itself flags the open default deployment, with no authentication and all network interfaces exposed. Anyone who can reach port 6333 can read and change data, so keep the test container off shared networks. Its security guide explains how to secure an instance.

A second pitfall is a mismatch between the configured vector size and the vectors you insert. The example uses size 4 in both places, and a different embedding model needs a different number. The README does not describe the exact error message, so check the Qdrant documentation if an insert fails. It also says nothing about running create_collection twice for the same name, so plan how your script handles an existing collection.

Where this fits in a company

A single container suits a trial. Production operation needs authentication, persistent storage, backups and a person who owns updates. The README points to the installation and security guides for these topics, and it lists sharding and replication for larger deployments. If payloads contain personal data, the usual data protection checks apply to the vector store as well, and our page on GDPR and AI at work outlines them.

A vector database is one building block of knowledge search. Chunking documents, creating embeddings, keeping permissions and citing sources still have to be built around it. souveraen.ai is a platform by clouditiv GmbH that answers questions from connected sources with a source reference for each answer. If you prefer not to build this yourself, you can read more about knowledge management software, answers with sources and local AI.

Sources

More articles

All articles

GDPR fines in November 2026 and what they mean for you

In November 2026 European data protection authorities fined companies from social media, banking, energy and dating, with amounts from 675,000 euros to 805 million euros. The cases point to three duties that any company using software or AI with personal data should secure first.

Data protection5 min

AI Act nudification ban: what it means for companies

Since 2 December 2026, the EU AI Act prohibits AI systems that generate non-consensual intimate images of identifiable people and child sexual abuse material. Companies that allow staff to use image generators should check which tools are in use and under what rules.

Regulation4 min

Managing Ollama models through the REST API with curl

Ollama exposes model management and chat through a small REST API, so IT teams can script what runs on a local server. This tutorial lists models, loads and unloads one, and tests the chat endpoint with curl.

Tutorial4 min

Test it with your own documents.

Free for 3 days, then from €24.90 per user per month. Cancellable monthly.