Skip to content
RAG infrastructure on Kubernetes · Chapter 5 of 20 Day 4: Running Qdrant – the Card Cabinet

Day 4: Running Qdrant – the Card Cabinet

Goal: Install Qdrant with Helm as a StatefulSet, create a collection, store the four cards with payload, search and filter – and check that the data survives a restart · Duration: approx. 75 min · Prerequisite: Day 3

State before this chapter

# on rag1
kubectl -n rag get pods

Expected: the pod embed-… with 1/1 Running and the helper pod curl.

# on rag1
ls ~/kurs/01/karten-embed.json ~/kurs/01/frage1-embed.json ~/kurs/01/frage4-embed.json

Expected: the three files from Day 1.

Introduction

On Day 1 you computed the similarity with jq: every card against the question, one after the other. That works for four cards. For four million you need a place that stores vectors permanently, links them to additional data and quickly finds the nearest ones – a vector database. Today you run the first one: Qdrant.

You will see that Qdrant does nothing magical. The hits are exactly the numbers you computed by hand on Day 1. What is new is everything around them: storage on a volume, filters on additional data, and an index that only comes into being above a certain amount.

Today you learn:

  • to install Qdrant with the official Helm chart as a StatefulSet,
  • to create a collection with dimension and distance measure,
  • to store points with vector and payload,
  • to search and narrow down with a payload filter,
  • to read the state of a collection, including its HNSW index,
  • why a port-forward breaks when the pod restarts.

Background

The picture for today: the card cabinet with a floor plan

So far, the index cards lay loose on the table, and the librarian compared each one individually with the question. Today they get a card cabinet: every card has a number, its place on the shelf (the vector) and stamps (the payload) – for example, which department it comes from. The cabinet stands in a room of its own with a solid foundation (StatefulSet with volume): if the room is renovated, the cards are still there afterwards.

Above a certain number of cards, the cabinet draws up a floor plan (the HNSW index): signposts with which the librarian finds the nearest cards without looking at all of them. With four cards that is not worth it – he simply goes through all of them.

The terms

Term Meaning in the picture
Collection set of points with the same dimension and the same distance measure a card cabinet
Point ID, vector and payload an index card
Payload freely chosen additional data as JSON stamps on the card
Distance measure Cosine similarity as on Day 1 closeness of two places
HNSW index of connected neighbours for fast search floor plan with signposts
StatefulSet pods with a fixed name and their own volume per pod room with a solid foundation
Port-forward forwards a local port to a pod in the cluster serving hatch into one particular room

Remember: A vector database computes the same similarity as you did on Day 1. What it adds is storage, filters and – once there is enough data – an index.

Drill 1: Qdrant with Helm

Where you are: on rag1.

What you have afterwards: Qdrant as a StatefulSet with a 2 GiB volume in the namespace rag.

Step 1 – today’s folder.

# on rag1
mkdir -p ~/kurs/04
# on rag1
cd ~/kurs/04

Step 2 – the chart repository.

# on rag1
helm repo add qdrant https://qdrant.github.io/qdrant-helm

Expected:

"qdrant" has been added to your repositories
# on rag1
helm repo update
# on rag1
helm search repo qdrant/qdrant --versions

Expected (excerpt, the first lines):

NAME            CHART VERSION   APP VERSION DESCRIPTION
qdrant/qdrant   1.20.3          v1.20.3     Qdrant - Vector Database for the next generatio...
qdrant/qdrant   1.20.2          v1.20.2     Qdrant - Vector Database for the next generatio...

You use 1.20.3.

Step 3 – what the chart does on its own.

# on rag1
helm show values qdrant/qdrant --version 1.20.3 > qdrant-standard-werte.yaml

helm show values prints the chart’s default values; > writes them to a file for reading.

# on rag1
less qdrant-standard-werte.yaml

The persistence section says size: 10Gi, the storageClassName line is commented out, and resources: {} means: no requests, no limits. You set this up to suit the lab.

Step 4 – your own values.

# on rag1
nano qdrant-werte.yaml
~/kurs/04/qdrant-werte.yaml new file
replicaCount: 1
persistence:
  size: 2Gi
  storageClassName: local-path
resources:
  requests:
    cpu: 250m
    memory: 256Mi
  limits:
    memory: 1Gi
Setting Meaning
replicaCount: 1 one Qdrant pod; two nodes with replicas come on Day 11
persistence.size: 2Gi enough for many thousands of cards in this course
storageClassName: local-path folder on the node, as for the models
requests / limits.memory Qdrant is guaranteed little and may take at most 1 GiB of memory

You do not set a CPU limit – since Day 3 you know why.

Step 5 – install.

# on rag1
helm install qdrant qdrant/qdrant --version 1.20.3 -n rag -f qdrant-werte.yaml

Expected (excerpt):

NAME: qdrant
NAMESPACE: rag
STATUS: deployed
REVISION: 1
DESCRIPTION: Install complete
# on rag1
kubectl -n rag rollout status statefulset/qdrant --timeout=400s

Expected:

Waiting for 1 pods to be ready...
partitioned roll out complete: 1 new pods have been updated...

In the lab after 33 seconds.

Step 6 – what has been created.

# on rag1
kubectl -n rag get statefulset,pods,pvc -o wide

Expected (excerpt, only the lines about Qdrant):

NAME                      READY   AGE   CONTAINERS   IMAGES
statefulset.apps/qdrant   1/1     33s   qdrant       docker.io/qdrant/qdrant:v1.20.3

pod/qdrant-0                 1/1     Running   0          33s     10.42.1.4    rag2

persistentvolumeclaim/qdrant-storage-qdrant-0   Bound    pvc-48a95998-cdb1-468d-afba-542c27954fce   2Gi        RWO            local-path

What you see: the pod is not called qdrant-<random> but qdrant-0, and its volume qdrant-storage-qdrant-0. A StatefulSet gives every pod a fixed name and a volume of its own that is assigned to this pod again after a restart. Qdrant landed on rag2 – there is free memory there, rag1 carries the model.

# on rag1
kubectl -n rag get svc

Expected (excerpt):

NAME              TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)                      AGE
qdrant            ClusterIP   10.43.110.149   <none>        6333/TCP,6334/TCP,6335/TCP   33s
qdrant-headless   ClusterIP   None            <none>        6333/TCP,6334/TCP,6335/TCP   33s
Port Purpose
6333 REST API – that is what you use in this course
6334 gRPC API
6335 connection between the Qdrant nodes (Day 11)

Remember: Databases run as a StatefulSet: fixed name, own volume per pod. That is the foundation on which replication and backup build.

Save your progress? Sign up for free

Drill 2: The first collection

Where you are: on rag1, in ~/kurs/04.

What you have afterwards: the collection handbuch with the four cards from Day 1.

Step 1 – open a serving hatch. Open a second terminal on rag1 and leave this running there:

# on rag1, second terminal
kubectl -n rag port-forward svc/qdrant 6333:6333

Expected:

Forwarding from 127.0.0.1:6333 -> 6333
Forwarding from [::1]:6333 -> 6333

port-forward svc/qdrant 6333:6333 forwards port 6333 on rag1 to port 6333 of Qdrant. The command keeps running as long as the hatch is open. You enter all further commands in the first terminal.

Step 2 – does Qdrant answer?

# on rag1
curl -s http://127.0.0.1:6333/

Expected:

{"title":"qdrant - vector search engine","version":"1.20.3","commit":"0e7061a7ad2e0660ca7507ad154eb2e95e6f51c6"}

Step 3 – create the collection.

# on rag1
curl -s -X PUT http://127.0.0.1:6333/collections/handbuch -H 'Content-Type: application/json' -d '{"vectors":{"size":1024,"distance":"Cosine"}}'
Option Meaning
-X PUT …/collections/handbuch create a collection named handbuch (manual)
"size":1024 dimension of the vectors – matching bge-m3
"distance":"Cosine" similarity as on Day 1

Expected:

{"result":true,"status":"ok","time":0.121626771}

Step 4 – build points. Every card becomes a point: ID, vector from Day 1 and a payload with text and department (abteilung).

# on rag1
jq -n --slurpfile e ../01/karten-embed.json --slurpfile a ../01/karten-anfrage.json '{points: [range(0;4) as $i | {id: ($i + 1), vector: $e[0].embeddings[$i], payload: {text: $a[0].input[$i], abteilung: (["IT","IT","Personal","IT"][$i])}}]}' > punkte.json
Part Meaning
range(0;4) as $i for cards 0 to 3
id: ($i + 1) Qdrant IDs from 1 to 4
vector: $e[0].embeddings[$i] the card’s vector from Day 1
payload: {text: …, abteilung: …} card text and a department stamp; the leave card belongs to “Personal” (HR)

Step 5 – check what is in it.

# on rag1
jq -c '[.points[] | {id, abteilung: .payload.abteilung, dim: (.vector | length)}]' punkte.json

Expected:

[{"id":1,"abteilung":"IT","dim":1024},{"id":2,"abteilung":"IT","dim":1024},{"id":3,"abteilung":"Personal","dim":1024},{"id":4,"abteilung":"IT","dim":1024}]

Step 6 – store.

# on rag1
curl -s -X PUT 'http://127.0.0.1:6333/collections/handbuch/points?wait=true' -H 'Content-Type: application/json' -d @punkte.json

?wait=true waits until Qdrant has really written the points instead of answering immediately.

Expected:

{"result":{"operation_id":1,"status":"completed"},"status":"ok","time":0.007017324}

Remember: You set dimension and distance measure when you create the collection – they apply to every point in the collection and cannot be changed afterwards.

Save your progress? Sign up for free

Drill 3: Searching and filtering

Where you are: on rag1, in ~/kurs/04.

What you have afterwards: the same hits as on Day 1 – and a filter on the department.

Step 1 – build the search request. The question vector from Day 1 becomes a request to /points/query:

# on rag1
jq '{query: .embeddings[0], limit: 3, with_payload: ["abteilung"]}' ../01/frage1-embed.json > suche1.json
Field Meaning
query the vector of the question “Wie starte ich den Druckdienst neu?” (How do I restart the print service?)
limit: 3 the three nearest points
with_payload: ["abteilung"] return only the field abteilung from the payload

Step 2 – search.

# on rag1
curl -s -X POST http://127.0.0.1:6333/collections/handbuch/points/query -H 'Content-Type: application/json' -d @suche1.json -o treffer1.json
# on rag1
jq '.result.points' treffer1.json

Expected (excerpt, the first two hits):

[
  {
    "id": 1,
    "version": 1,
    "score": 0.75449586,
    "payload": {
      "abteilung": "IT"
    }
  },
  {
    "id": 4,
    "version": 1,
    "score": 0.4635017,

What you see: point 1 (print) with 0.75449586 – on Day 1 you had 0.7544958303555799 by hand. The difference in the eighth decimal place comes from Qdrant computing with 32-bit numbers. Second place is backup again (point 4) with 0.4635.

# on rag1
jq '.time' treffer1.json

Expected:

0.003339911

3 milliseconds for the search itself.

Step 3 – the laptop question.

# on rag1
jq '{query: .embeddings[0], limit: 3, with_payload: ["abteilung"]}' ../01/frage4-embed.json > suche4.json
# on rag1
curl -s -X POST http://127.0.0.1:6333/collections/handbuch/points/query -H 'Content-Type: application/json' -d @suche4.json -o treffer4.json
# on rag1
jq -c '[.result.points[] | {id, score}]' treffer4.json

Expected:

[{"id":3,"score":0.43492997},{"id":2,"score":0.43197948},{"id":1,"score":0.42799926}]

As on Day 1: the leave card narrowly ahead, everything in the background noise.

Step 4 – only IT cards. A filter in the request restricts the search to points with a matching stamp:

# on rag1
jq '. + {filter: {must: [{key: "abteilung", match: {value: "IT"}}]}}' suche4.json > suche4-it.json
Part Meaning
filter.must all conditions must hold
key: "abteilung" the payload field
match: {value: "IT"} exactly this value
# on rag1
curl -s -X POST http://127.0.0.1:6333/collections/handbuch/points/query -H 'Content-Type: application/json' -d @suche4-it.json -o treffer4-it.json
# on rag1
jq -c '[.result.points[] | {id, score, abteilung: .payload.abteilung}]' treffer4-it.json

Expected:

[{"id":2,"score":0.43197948,"abteilung":"IT"},{"id":1,"score":0.42799926,"abteilung":"IT"},{"id":4,"score":0.38078123,"abteilung":"IT"}]

What you see: point 3 (leave, “Personal”) has disappeared. The filter acts before the ranking: Qdrant only compares cards that carry the stamp. Later this is how you separate departments, tenants or validity periods (Day 14).

Remember: Payload filters narrow down before sorting by similarity. A filter does not turn a bad search into a good one – but it reliably keeps other people’s cards out.

Save your progress? Sign up for free

Drill 4: The state of the collection

Where you are: on rag1, in ~/kurs/04.

What you have afterwards: the key figures of the collection – and the insight that there is no index yet.

Step 1 – fetch the description.

# on rag1
curl -s http://127.0.0.1:6333/collections/handbuch -o info.json

Step 2 – the important fields.

# on rag1
jq '{status: .result.status, points_count: .result.points_count, indexed_vectors_count: .result.indexed_vectors_count, segments_count: .result.segments_count, hnsw: .result.config.hnsw_config, indexing_threshold: .result.config.optimizer_config.indexing_threshold}' info.json

Expected:

{
  "status": "green",
  "points_count": 4,
  "indexed_vectors_count": 0,
  "segments_count": 2,
  "hnsw": {
    "m": 16,
    "ef_construct": 100,
    "full_scan_threshold": 10000,
    "max_indexing_threads": 0,
    "on_disk": false
  },
  "indexing_threshold": 10000
}
Field Value Meaning
status green all is well; yellow means Qdrant is optimising, red an error
points_count 4 stored points
indexed_vectors_count 0 vectors in the HNSW index – none
segments_count 2 Qdrant splits a collection internally into segments
hnsw.m 16 number of neighbours per point in the index: more means more accurate and larger
hnsw.ef_construct 100 how thoroughly it searches while building
indexing_threshold 10000 Qdrant only builds an index above this threshold

What you see: with four cards there is no floor plan. Qdrant simply compares all of them – exactly, and at 3 ms more than fast enough. You experience the index and its effect on hits and duration when a whole manual is ingested on Day 6.

Remember: indexed_vectors_count: 0 is not an error for small collections. An HNSW index only pays off with many points – and then it is an approximation, no longer an exact search.

Save your progress? Sign up for free

Drill 5: Do the cards survive a restart?

Where you are: on rag1, in ~/kurs/04.

What you have afterwards: proof that the collection lives on the volume.

Step 1 – delete the pod.

# on rag1
kubectl -n rag delete pod qdrant-0

Expected:

pod "qdrant-0" deleted from rag namespace
# on rag1
kubectl -n rag wait --for=condition=Ready pod/qdrant-0 --timeout=180s

Expected:

pod/qdrant-0 condition met

In the lab after 15 seconds – again as qdrant-0, again on rag2.

Step 2 – the serving hatch. Look at the second terminal. It now says:

error: lost connection to pod

A port-forward svc/qdrant actually hangs on one pod that was selected at start. If that pod is gone, the hatch is closed. Restart the command from Drill 2, step 1.

Step 3 – are the cards still there?

# on rag1
curl -s http://127.0.0.1:6333/collections/handbuch -o info-danach.json
# on rag1
jq '{status: .result.status, points_count: .result.points_count}' info-danach.json

Expected:

{
  "status": "green",
  "points_count": 4
}

Step 4 – where they are stored.

# on rag1
kubectl -n rag exec qdrant-0 -- ls /qdrant/storage/collections

Expected:

Defaulted container "qdrant" out of: qdrant, ensure-dir-ownership (init)
handbuch

The first line is a note from kubectl: the pod also has an init container, and exec automatically takes the main container. Below it is the collection’s folder.

Remember: The data belongs to the volume, not to the pod. A port-forward, on the other hand, belongs to a pod – reopen it after every restart.

If it does not work

  • After a restart, the second terminal shows error: lost connection to pod, in the lab together with failed to find sandbox … in store: not found. Simply restart the port-forward.
  • If you start the port-forward a second time while the first one is still running, it reports bind: address already in use. First end the old one with Ctrl+C.

Save your progress? Sign up for free

Diagnosis task

A colleague has created a second collection and asks: “Why does the search return errors when I store the vectors from nomic-embed-text?” You have ten minutes.

Solution: Read the description of the collection (Drill 4) and look at config.params.vectors:

# on rag1
jq '.result.config.params.vectors' info-danach.json

Expected:

{
  "size": 1024,
  "distance": "Cosine"
}

If it says 1024, no 768-dimensional vector from nomic (Day 2) fits in. In the lab, Qdrant rejected the attempt like this:

{"status":{"error":"Wrong input: Vector dimension error: expected dim: 1024, got 768"},"time":0.000409453}

The dimension is fixed when the collection is created; another model needs a collection of its own – which is exactly what the re-indexing on Day 13 does.

Challenge

Create a second collection handbuch-nomic with size: 768, classify the four cards with nomic-embed-text (Day 2) and store them. Search with the paraphrased question from Day 1 in both collections. Does Qdrant return the same results that you computed by hand on Day 2?

Save your progress? Sign up for free

Checkpoint

# on rag1
kubectl -n rag get statefulset qdrant

Expected: READY 1/1.

# on rag1
jq '.result.points_count' info-danach.json

Expected:

4

Test yourself

  1. Why is the print card rated 0.75449586 in Qdrant but 0.7544958303555799 on Day 1?
  2. What does a payload filter do to the order of the hits?
  3. What does indexed_vectors_count: 0 mean, and is it a problem?
  4. Why is the pod called qdrant-0 and not qdrant-<random>?
  5. Why does the port-forward break even though it points to a service?

Answers:

  1. The same calculation; Qdrant works with 32-bit numbers, jq with 64-bit.
  2. It narrows down beforehand: only points with a matching stamp are compared. The order of the remaining ones stays by similarity.
  3. There is no HNSW index; Qdrant compares all points. For small collections below the threshold (indexing_threshold) that is correct and exact.
  4. A StatefulSet assigns fixed names and always attaches the same volume to each pod.
  5. kubectl port-forward picks one pod behind the service at start and sticks to it. If that pod is deleted, the connection breaks.

Interview note

“What does a vector database store, and what does it do better than an array in memory?” – Vector, ID and payload; plus persistence, filters on the payload before ranking, and an ANN index such as HNSW that speeds up the search once there are many points – at the expense of exactness. If you can explain indexed_vectors_count and indexing_threshold, you show that you have operated a vector database, not just used one.

Enterprise note

In production, Qdrant runs with several nodes, replicas per shard, an API key and TLS; the REST API is never reachable without authentication. Port-forwards are a tool for humans, not a path for applications: services talk through the service in the cluster, here qdrant.rag:6333. Replication comes on Day 11, API keys and network rules on Day 14.

Summary

You installed Qdrant 1.20.3 with Helm as a StatefulSet, with its own 2 GiB volume on rag2. The collection handbuch stores the four cards with vector and payload. The search returned exactly the values from Day 1, in 3 ms; a filter on the department kept the leave card out. With four points there is no HNSW index – Qdrant compares all of them. After the pod was deleted, all points were back; only the port-forward had to be restarted.

Commands at a glance

Command What it does Parameters
helm repo add qdrant https://qdrant.github.io/qdrant-helm register the Qdrant charts –
helm show values qdrant/qdrant --version 1.20.3 default values of the chart –
helm install qdrant qdrant/qdrant --version 1.20.3 -n rag -f qdrant-werte.yaml install Qdrant -f values
kubectl -n rag rollout status statefulset/qdrant wait for the StatefulSet –
kubectl -n rag port-forward svc/qdrant 6333:6333 local access to the REST API local:remote port
curl -X PUT …/collections/<name> -d '{"vectors":{…}}' create a collection size, distance
curl -X PUT '…/points?wait=true' -d @punkte.json store points wait=true
curl -X POST …/points/query -d @suche.json search query, limit, filter, with_payload
curl …/collections/<name> state of the collection –
kubectl -n rag exec qdrant-0 -- ls /qdrant/storage/collections collections on the volume –

Contents

More