✔ PASS Vector & Embeddings task_031_Q31_semantic_deduplication_support_tickets Scaled: 1M+ Records Ordered: Yes

Semantic Deduplication of IT Incident Tickets via Vector Cosine Threshold

Candidate Latency (1M Rows)
2009.86 ms
(1.1x faster than golden)
Golden Latency (1M Rows)
2118.56 ms
DuckDB in-memory engine
Underlying Data Volume
2,500 rows
87.9 KiB across 1 table
Evaluated Model
gemini-3.8-flash-low
Gen Latency: 21.7s
✔ 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 Trap
Business Scenario & Problem

During service outages, hundreds of users submit identically phrased IT support tickets ('login down', 'cannot access account'). Clustering tickets with vector similarity > 0.88 consolidates duplicates into a single incident.

⚡ The Frontier Trap (Why LLMs Fail)

Quadratic N x N self-joins without ordering check (`t1.id < t2.id`) double compute and compare tickets to themselves.

Prompt / User Request Given to Model
During service outages, hundreds of users submit identically phrased IT support tickets ('login down', 'cannot access account'). Clustering tickets with vector similarity > 0.88 consolidates duplicates into a single incident.

Execute the required analytical SQL calculation in DuckDB.
Expected output columns: primary_ticket_id, primary_subject, duplicate_ticket_id, duplicate_subject, similarity.
Results should be ordered as specified.

2. Underlying Tables, Row Counts & Data Volume

1 Tables (2,500 rows • 87.9 KiB)

Production-scale fixtures loaded into the isolated DuckDB sandbox with at least 1,000,000 records per table:

📊 support_tickets 2,500 rows 87.9 KiB Data Volume
ticket_id (INTEGER) subject (VARCHAR) vector (FLOAT[3])
Data Preview (showing sample rows from 2,500 total rows):
# ticket_id subject vector
1 1 Cannot log into customer portal [0.9 0.1 0. ]
2 2 Portal login failing with 500 error [0.89 0.12 0.01]
3 3 Billing address invoice update [0.1 0.8 0.2]
4 4 Unable to authenticate on website [0.91 0.09 0.02]
5 4 Cannot log into customer portal [0.8282 0.1152 0.1039]
6 5 Portal login failing with 500 error [ 0.8069 -0.0033 0.1082]
7 6 Billing address invoice update [0.9232 0.0376 0.0835]
8 7 Unable to authenticate on website [0.8369 0.0983 0.0371]
9 8 Cannot log into customer portal [0.8274 0.0975 0.0204]
10 9 Portal login failing with 500 error [ 0.906 -0.0207 0.0377]
11 10 Billing address invoice update [0.8207 0.0257 0.1209]
12 11 Unable to authenticate on website [ 0.831 -0.0147 -0.0213]
13 12 Cannot log into customer portal [0.8224 0.0125 0.0708]
14 13 Portal login failing with 500 error [ 8.706e-01 2.220e-02 -4.000e-04]
15 14 Billing address invoice update [0.7503 0.0703 0.0235]

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:

Pipeline Latency Distribution (Total Plan Time: 940.65 ms) Nodes consuming ≥ 20% of query runtime are highlighted with glowing borders
📐 PROJECTION 0.2%
Latency: 2.26 ms
Rows In/Out: 3,121,250
Data Vol: 130.97 MB
📁 Projections: ['CAST(#0 AS INTEGE...
⏳ ORDER_BY 🔥 66.0% Cost
Latency: 620.94 ms
Rows In/Out: 3,121,250
Data Vol: 119.07 MB
⚠️ Heavy Execution Bottleneck (66.0% of query runtime)
📐 PROJECTION 0.4%
Latency: 3.73 ms
Rows In/Out: 3,121,250
Data Vol: 119.07 MB
📁 Projections: ['CAST(#0 AS SMALLI...
📐 PROJECTION 🔥 14.7% Cost
Latency: 138.54 ms
Rows In/Out: 3,121,250
Data Vol: 130.97 MB
📁 Projections: ['primary_ticket_id...
⚠️ Heavy Execution Bottleneck (14.7% of query runtime)
⚡ PIECEWISE_MERGE_JOIN 🔥 18.6% Cost
Latency: 175.02 ms
Rows In/Out: 3,121,250
Data Vol: 190.51 MB
⚠️ Heavy Execution Bottleneck (18.6% of query runtime)
🔍 TABLE_SCAN 0.0%
Latency: 0.08 ms
Rows In/Out: 2,500
Data Vol: 0.08 MB
📁 memory.main.support_tickets
🔍 TABLE_SCAN 0.0%
Latency: 0.07 ms
Rows In/Out: 2,500
Data Vol: 0.08 MB
📁 memory.main.support_tickets
Operator Cost % Latency Processed Rows Data Volume Details / Table Status
ORDER_BY 66.0% 620.94 ms 3,121,250 119.07 MB - 🔥 BOTTLENECK
PIECEWISE_MERGE_JOIN 18.6% 175.02 ms 3,121,250 190.51 MB - 🔥 BOTTLENECK
PROJECTION 14.7% 138.54 ms 3,121,250 130.97 MB Projections: ['primary_ticket_id', 'primary_subj 🔥 BOTTLENECK
PROJECTION 0.4% 3.73 ms 3,121,250 119.07 MB Projections: ['CAST(#0 AS SMALLINT)', '#1', 'CAS Normal
PROJECTION 0.2% 2.26 ms 3,121,250 130.97 MB Projections: ['CAST(#0 AS INTEGER)', '#1', 'CAST Normal
TABLE_SCAN 0.0% 0.08 ms 2,500 0.08 MB memory.main.support_tickets Normal
TABLE_SCAN 0.0% 0.07 ms 2,500 0.08 MB memory.main.support_tickets Normal

4. Queries Executed (Candidate vs Golden Ground Truth)

Beautified & Syntax Highlighted
Candidate SQL Executed by gemini-3.8-flash-low (Runtime on 1M Rows: 2009.86 ms)
-- Detect duplicate ticket pairs with cosine similarity >= 0.88

SELECT t1.ticket_id AS primary_ticket_id,
       t1.subject AS primary_subject,
       t2.ticket_id AS duplicate_ticket_id,
       t2.subject AS duplicate_subject,
       round(array_cosine_similarity(t1.vector, t2.vector), 4) AS similarity
FROM support_tickets t1
JOIN support_tickets t2 ON t1.ticket_id < t2.ticket_id
AND array_cosine_similarity(t1.vector, t2.vector) >= 0.88
ORDER BY similarity DESC;
Golden Reference Ground Truth SQL (Runtime on 1M Rows: 2118.56 ms)
-- Detect duplicate ticket pairs with cosine similarity >= 0.88

SELECT t1.ticket_id AS primary_ticket_id,
       t1.subject AS primary_subject,
       t2.ticket_id AS duplicate_ticket_id,
       t2.subject AS duplicate_subject,
       round(array_cosine_similarity(t1.vector, t2.vector), 4) AS similarity
FROM support_tickets t1
JOIN support_tickets t2 ON t1.ticket_id < t2.ticket_id -- strictly upper triangle to avoid duplicates and self-matching

AND array_cosine_similarity(t1.vector, t2.vector) >= 0.88
ORDER BY similarity DESC;
DuckDB Fixture Setup DDL & Data Population
CREATE TABLE support_tickets (ticket_id INT, subject VARCHAR, vector FLOAT[3]);


INSERT INTO support_tickets
VALUES (1, 'Cannot log into customer portal', [0.9, 0.1, 0.0]::FLOAT[3]),
       (2, 'Portal login failing with 500 error', [0.89, 0.12, 0.01]::FLOAT[3]),
       (3, 'Billing address invoice update', [0.1, 0.8, 0.2]::FLOAT[3]),
       (4, 'Unable to authenticate on website', [0.91, 0.09, 0.02]::FLOAT[3]);

5. Query Results & Expected Ground Truth

Tabular Comparison
Actual Candidate Output (3,121,250 rows × 5 cols)
# primary_ticket_id primary_subject duplicate_ticket_id duplicate_subject similarity
1 6 Billing address invoice update 15 Unable to authenticate on website 1
2 5 Portal login failing with 500 error 22 Billing address invoice update 1
3 8 Cannot log into customer portal 33 Portal login failing with 500 error 1
4 13 Portal login failing with 500 error 41 Portal login failing with 500 error 1
5 31 Unable to authenticate on website 42 Billing address invoice update 1
6 21 Portal login failing with 500 error 43 Unable to authenticate on website 1
7 19 Unable to authenticate on website 47 Unable to authenticate on website 1
8 43 Unable to authenticate on website 48 Cannot log into customer portal 1
9 39 Unable to authenticate on website 50 Billing address invoice update 1
10 36 Cannot log into customer portal 51 Unable to authenticate on website 1
11 20 Cannot log into customer portal 55 Unable to authenticate on website 1
12 54 Billing address invoice update 55 Unable to authenticate on website 1
13 53 Portal login failing with 500 error 56 Cannot log into customer portal 1
14 35 Unable to authenticate on website 58 Billing address invoice update 1
15 38 Billing address invoice update 60 Cannot log into customer portal 1
16 13 Portal login failing with 500 error 61 Portal login failing with 500 error 1
17 9 Portal login failing with 500 error 64 Cannot log into customer portal 1
18 32 Cannot log into customer portal 68 Cannot log into customer portal 1
19 21 Portal login failing with 500 error 70 Billing address invoice update 1
20 43 Unable to authenticate on website 70 Billing address invoice update 1
21 48 Cannot log into customer portal 70 Billing address invoice update 1
22 7 Unable to authenticate on website 71 Unable to authenticate on website 1
23 33 Portal login failing with 500 error 71 Unable to authenticate on website 1
24 53 Portal login failing with 500 error 72 Cannot log into customer portal 1
25 56 Cannot log into customer portal 72 Cannot log into customer portal 1
Showing first 25 of 3,121,250 total rows.
Expected Golden Output (3,121,250 rows × 5 cols)
# primary_ticket_id primary_subject duplicate_ticket_id duplicate_subject similarity
1 6 Billing address invoice update 15 Unable to authenticate on website 1
2 5 Portal login failing with 500 error 22 Billing address invoice update 1
3 8 Cannot log into customer portal 33 Portal login failing with 500 error 1
4 13 Portal login failing with 500 error 41 Portal login failing with 500 error 1
5 31 Unable to authenticate on website 42 Billing address invoice update 1
6 21 Portal login failing with 500 error 43 Unable to authenticate on website 1
7 19 Unable to authenticate on website 47 Unable to authenticate on website 1
8 43 Unable to authenticate on website 48 Cannot log into customer portal 1
9 39 Unable to authenticate on website 50 Billing address invoice update 1
10 36 Cannot log into customer portal 51 Unable to authenticate on website 1
11 20 Cannot log into customer portal 55 Unable to authenticate on website 1
12 54 Billing address invoice update 55 Unable to authenticate on website 1
13 53 Portal login failing with 500 error 56 Cannot log into customer portal 1
14 35 Unable to authenticate on website 58 Billing address invoice update 1
15 38 Billing address invoice update 60 Cannot log into customer portal 1
16 13 Portal login failing with 500 error 61 Portal login failing with 500 error 1
17 9 Portal login failing with 500 error 64 Cannot log into customer portal 1
18 32 Cannot log into customer portal 68 Cannot log into customer portal 1
19 21 Portal login failing with 500 error 70 Billing address invoice update 1
20 43 Unable to authenticate on website 70 Billing address invoice update 1
21 48 Cannot log into customer portal 70 Billing address invoice update 1
22 7 Unable to authenticate on website 71 Unable to authenticate on website 1
23 33 Portal login failing with 500 error 71 Unable to authenticate on website 1
24 53 Portal login failing with 500 error 72 Cannot log into customer portal 1
25 56 Cannot log into customer portal 72 Cannot log into customer portal 1
Showing first 25 of 3,121,250 total rows.
← Prev: Adaptive Similarity Thres... ⊞ Back to Benchmark Dashboard Next: Multi-Merchant Near-Dupli... →