Quantisierung und Komprimierung von Vektoren
Reduzieren Sie den Speicherbedarf von Vektoren und beschleunigen Sie die Suche mit Skalar- und Produktquantisierung, während Sie den Genauigkeitsverlust kontrollieren.
Quantisierung und Komprimierung von Vektoren ist eine kostenlose LangChain / RAG / Vector DBs-Lektion auf CoddyKit. Dies ist Lektion 4 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des LangChain / RAG / Vector DBs-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der LangChain / RAG / Vector DBs-Kurs umfasst insgesamt 4 Lektionen.
Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.
The Memory Problem
A million 1536-dimension vectors stored as 32-bit floats need about 6 GB of RAM. Quantization compresses vectors so they fit in far less memory and search faster.
Float32 Baseline
By default each dimension is a 4-byte float. Storage equals vectors x dims x 4 bytes. Reducing the bytes per dimension is the path to compression.
vectors = 1_000_000
dims = 1536
bytes_total = vectors * dims * 4
print(bytes_total / 1e9, "GB") # ~6.14 GBScalar Quantization
Scalar quantization maps each float to an 8-bit integer using the min and max range of that dimension. This is a 4x reduction with modest accuracy loss.
def quantize(x, lo, hi):
span = hi - lo
return round((x - lo) / span * 255)
print(quantize(0.3, -1.0, 1.0)) # 165Dequantization
To compare vectors you can dequantize back to an approximate float, or compute distances directly in integer space for speed.
def dequantize(q, lo, hi):
return lo + (q / 255) * (hi - lo)
print(round(dequantize(165, -1.0, 1.0), 3)) # ~0.294Product Quantization (PQ)
PQ splits each vector into sub-vectors and replaces each with the id of its nearest centroid from a small learned codebook. Compression can reach 16x or more.
How PQ Encodes
For 8 sub-vectors with 256 centroids each, every vector becomes 8 bytes regardless of original dimension. Distances are estimated from precomputed centroid tables.
Binary Quantization
The most aggressive option keeps only the sign of each dimension: positive becomes 1, negative becomes 0. A 1536-dim vector fits in 192 bytes and uses fast Hamming distance.
def binarize(vec):
return [1 if v > 0 else 0 for v in vec]
print(binarize([0.4, -0.1, 0.9, -2.0])) # [1, 0, 1, 0]The Accuracy Tradeoff
More compression means more approximation error. Measure recall against an uncompressed baseline to ensure the quality loss is acceptable for your use case.
Rescoring with Full Vectors
A common pattern: search fast with quantized vectors to get a candidate set, then rescore the top candidates using the original float vectors for precision.
candidates = quantized_search(query, k=100)
rescored = sorted(
candidates,
key=lambda c: exact_distance(query, full_vec[c]),
)[:10]Configuring in a Store
Production stores expose quantization as a collection setting. You pick the type and any rescore depth at index creation.
# pseudo-config
collection.create(
vectors={"size": 1536, "distance": "Cosine"},
quantization={"scalar": {"type": "int8"}},
)Choosing a Strategy
Start with scalar quantization for an easy 4x win. Move to PQ or binary only when memory is critical and you can afford rescoring to recover accuracy.
Quick Check
Test your understanding of vector compression.
Recap
You explored vector compression:
- Scalar quantization: float to int8, 4x smaller
- PQ: codebook ids, big compression
- Binary: sign bits, Hamming distance
- Rescore with full vectors to regain accuracy
Häufig gestellte Fragen
Ist die Lektion „Quantisierung und Komprimierung von Vektoren“ kostenlos?
Ja — der vollständige Text von „Quantisierung und Komprimierung von Vektoren“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des LangChain / RAG / Vector DBs-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der LangChain / RAG / Vector DBs-Kurs umfasst insgesamt 4 Lektionen.
Was lerne ich in „Quantisierung und Komprimierung von Vektoren“?
Reduzieren Sie den Speicherbedarf von Vektoren und beschleunigen Sie die Suche mit Skalar- und Produktquantisierung, während Sie den Genauigkeitsverlust kontrollieren. Du übst LangChain / RAG / Vector DBs mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.
Brauche ich Erfahrung, um LangChain / RAG / Vector DBs zu starten?
Keine Vorkenntnisse erforderlich. LangChain / RAG / Vector DBs auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 4 von 4.
Wie lange dauert die Lektion „Quantisierung und Komprimierung von Vektoren“?
Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.
Kann ich in dieser LangChain / RAG / Vector DBs-Lektion Code schreiben und ausführen?
Ja. Jede LangChain / RAG / Vector DBs-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.
Alle Lektionen in diesem Kurs
- Speicherarchitekturen für Vektordatenbanken
- Algorithmen für die Nachbarschaftssuche (HNSW, IVFFlat)
- Persistenz und Skalierbarkeit von Vektordatenbanken
- Quantisierung und Komprimierung von Vektoren