✔ PASS
Vector & Embeddings
task_048_Q48_vector_quantization_distortion
Scaled: 1M+ Records
Ordered: Yes
Vector Quantization Precision Distortion & Reconstruction Error
Candidate Latency (1M Rows)
60.20 ms
(1.2x slower than golden)
Golden Latency (1M Rows)
51.89 ms
DuckDB in-memory engine
Underlying Data Volume
1,000,000 rows
26.7 MiB across 1 table
Evaluated Model
gemini-3.8-flash-low
Gen Latency: 23.3s
✔ Correctness Verified on 1M+ Records
Candidate SQL output matches ground truth golden query across all multiset rows and numeric tolerances (tol=1e-3). Zero data skew or anti-patterns detected on full dataset scale.
1. Analytical Significance & What It Means
Scenario & Frontier TrapBusiness Scenario & Problem
To compress embeddings from 32-bit floats to 8-bit integers, engineers evaluate the reconstruction error (distance between uncompressed and quantized vector) to measure fidelity loss.
⚡ The Frontier Trap (Why LLMs Fail)
Deploying quantized embeddings without evaluating distortion leads to silent degradation in search accuracy.
Prompt / User Request Given to Model
To compress embeddings from 32-bit floats to 8-bit integers, engineers evaluate the reconstruction error (distance between uncompressed and quantized vector) to measure fidelity loss. Execute the required analytical SQL calculation in DuckDB. Expected output columns: vector_id, l2_quantization_error, cosine_distortion. Results should be ordered as specified.
2. Underlying Tables, Row Counts & Data Volume
1 Tables (1,000,000 rows • 26.7 MiB)Production-scale fixtures loaded into the isolated DuckDB sandbox with at least 1,000,000 records per table:
📊 vector_compression_test
1,000,000 rows
26.7 MiB Data Volume
vector_id (INTEGER) fp32_vec (FLOAT[3]) quantized_vec (FLOAT[3])Data Preview (showing sample rows from 1,000,000 total rows):
| # | vector_id | fp32_vec | quantized_vec |
|---|---|---|---|
| 1 | 1 | [0.12345 0.67891 0.44332] | [0.12 0.68 0.44] |
| 2 | 2 | [0.99123 0.02111 0.11005] | [0.99 0.02 0.11] |
| 3 | 2 | [0.7553 0.0597 0.0299] | [0.7553 0.0597 0.0299] |
| 4 | 3 | [0.9254 0.0531 0.0495] | [0.9254 0.0531 0.0495] |
| 5 | 4 | [ 0.8503 0.0391 -0.0012] | [ 0.8503 0.0391 -0.0012] |
| 6 | 5 | [0.8341 0.065 0.1105] | [0.8341 0.065 0.1105] |
| 7 | 6 | [ 0.8646 -0.0248 -0.0306] | [ 0.8646 -0.0248 -0.0306] |
| 8 | 7 | [0.8941 0.0856 0.0119] | [0.8941 0.0856 0.0119] |
| 9 | 8 | [0.8255 0.0444 0.0235] | [0.8255 0.0444 0.0235] |
| 10 | 9 | [ 0.8169 -0.0374 0.1182] | [ 0.8169 -0.0374 0.1182] |
| 11 | 10 | [0.8098 0.0563 0.0613] | [0.8098 0.0563 0.0613] |
| 12 | 11 | [0.8978 0.0433 0.0307] | [0.8978 0.0433 0.0307] |
| 13 | 12 | [0.8621 0.0939 0.086 ] | [0.8621 0.0939 0.086 ] |
| 14 | 13 | [0.8453 0.0448 0.0774] | [0.8453 0.0448 0.0774] |
| 15 | 14 | [0.8726 0.0797 0.0881] | [0.8726 0.0797 0.0881] |
3. Graphical Query Execution Plan & Cost Bottlenecks
Physical Operator Tree (DuckDB 2.0 Profiler)Visual flowchart of the physical execution pipeline. Operators with high relative costs (≥ 20% of query runtime or heavy latency) are visually highlighted:
🔥 29.4% Cost
Latency: 43.23 ms
Rows In/Out: 1,000,000
Data Vol: 11.44 MB
🔥 67.3% Cost
Latency: 98.92 ms
Rows In/Out: 1,000,000
Data Vol: 11.44 MB
📁 Projections: ['vector_id', 'l2_q...
3.4%
Latency: 4.93 ms
Rows In/Out: 1,000,000
Data Vol: 26.70 MB
📁 memory.main.vector_compression_t...
| Operator | Cost % | Latency | Processed Rows | Data Volume | Details / Table | Status |
|---|---|---|---|---|---|---|
| PROJECTION | 67.3% | 98.92 ms | 1,000,000 | 11.44 MB | Projections: ['vector_id', 'l2_quantization_erro | 🔥 BOTTLENECK |
| ORDER_BY | 29.4% | 43.23 ms | 1,000,000 | 11.44 MB | - | 🔥 BOTTLENECK |
| TABLE_SCAN | 3.4% | 4.93 ms | 1,000,000 | 26.70 MB | memory.main.vector_compression_test | Normal |
4. Queries Executed (Candidate vs Golden Ground Truth)
Beautified & Syntax HighlightedSELECT vector_id,
round(array_distance(fp32_vec, quantized_vec), 6) AS l2_quantization_error,
round(1.0 - array_cosine_similarity(fp32_vec, quantized_vec), 6) AS cosine_distortion
FROM vector_compression_test
ORDER BY l2_quantization_error DESC;
-- Evaluate Euclidean distortion and cosine fidelity loss per vector
SELECT vector_id,
round(array_distance(fp32_vec, quantized_vec), 6) AS l2_quantization_error,
round(1.0 - array_cosine_similarity(fp32_vec, quantized_vec), 6) AS cosine_distortion
FROM vector_compression_test
ORDER BY l2_quantization_error DESC;
CREATE TABLE vector_compression_test (vector_id INT, fp32_vec FLOAT[3], quantized_vec FLOAT[3]);
INSERT INTO vector_compression_test
VALUES (1, [0.12345, 0.67891, 0.44332]::FLOAT[3], [0.12, 0.68, 0.44]::FLOAT[3]),
(2, [0.99123, 0.02111, 0.11005]::FLOAT[3], [0.99, 0.02, 0.11]::FLOAT[3]);
5. Query Results & Expected Ground Truth
Tabular Comparison
Actual Candidate Output
(1,000,000 rows × 3 cols)
| # | vector_id | l2_quantization_error | cosine_distortion |
|---|---|---|---|
| 1 | 1 | 0.0049 | 0 |
| 2 | 2 | 0.0017 | 0 |
| 3 | 2 | 0 | 0 |
| 4 | 3 | 0 | 0 |
| 5 | 4 | 0 | 0 |
| 6 | 5 | 0 | 0 |
| 7 | 6 | 0 | 0 |
| 8 | 7 | 0 | 0 |
| 9 | 8 | 0 | 0 |
| 10 | 9 | 0 | 0 |
| 11 | 10 | 0 | 0 |
| 12 | 11 | 0 | 0 |
| 13 | 12 | 0 | 0 |
| 14 | 13 | 0 | 0 |
| 15 | 14 | 0 | 0 |
| 16 | 15 | 0 | 0 |
| 17 | 16 | 0 | 0 |
| 18 | 17 | 0 | 0 |
| 19 | 18 | 0 | 0 |
| 20 | 19 | 0 | 0 |
| 21 | 20 | 0 | 0 |
| 22 | 21 | 0 | 0 |
| 23 | 22 | 0 | 0 |
| 24 | 23 | 0 | 0 |
| 25 | 24 | 0 | 0 |
Showing first 25 of 1,000,000 total rows.
Expected Golden Output
(1,000,000 rows × 3 cols)
| # | vector_id | l2_quantization_error | cosine_distortion |
|---|---|---|---|
| 1 | 1 | 0.0049 | 0 |
| 2 | 2 | 0.0017 | 0 |
| 3 | 122,882 | 0 | 0 |
| 4 | 122,883 | 0 | 0 |
| 5 | 122,884 | 0 | 0 |
| 6 | 122,885 | 0 | 0 |
| 7 | 122,886 | 0 | 0 |
| 8 | 122,887 | 0 | 0 |
| 9 | 122,888 | 0 | 0 |
| 10 | 122,889 | 0 | 0 |
| 11 | 122,890 | 0 | 0 |
| 12 | 122,891 | 0 | 0 |
| 13 | 122,892 | 0 | 0 |
| 14 | 122,893 | 0 | 0 |
| 15 | 122,894 | 0 | 0 |
| 16 | 122,895 | 0 | 0 |
| 17 | 122,896 | 0 | 0 |
| 18 | 122,897 | 0 | 0 |
| 19 | 122,898 | 0 | 0 |
| 20 | 122,899 | 0 | 0 |
| 21 | 122,900 | 0 | 0 |
| 22 | 122,901 | 0 | 0 |
| 23 | 122,902 | 0 | 0 |
| 24 | 122,903 | 0 | 0 |
| 25 | 122,904 | 0 | 0 |
Showing first 25 of 1,000,000 total rows.