r/synapcores • u/Alternative_Pin9598 • 1d ago
Ask the maintainers #5: can I tag support tickets in SQL, more than one tag per ticket, without an API? One NLI query tagged 20 tickets in 1.67 s, no wrong tags, 7 sent to a person (real output)
Fifth "Ask the maintainers" thread: ask anything about SynapCores (install, a query that misbehaves, "can it do X") or show what you built. We answer here; good questions get a longer answer in the Wednesday build log.
(This sub is run by the SynapCores team. Everything below ran today on 2.5.1 on a Mac mini (Apple M4), real output.)
This week's starter question: "Can I tag support tickets inside SQL, more than one tag per ticket, without sending them to an API?"
Yes. Black Friday is when the support inbox triples. NLI_CLASSIFY runs an NLI model inside the engine and scores whether a ticket says a sentence is true, so a tag is a sentence and tagging is a CROSS JOIN. On 20 sample tickets:
1. Tickets, and one row per tag sentence
CREATE TABLE am5_tickets (id INTEGER PRIMARY KEY, body TEXT);
-- 20 tickets, full INSERT in the first comment
CREATE TABLE am5_tags (tag TEXT, hypothesis TEXT);
INSERT INTO am5_tags (tag, hypothesis) VALUES
('payment', 'I was charged twice.'),
('payment', 'My card was declined.'),
('refund', 'Someone wants their money back.'),
('delivery', 'The tracking has not updated.'),
('delivery', 'The package is missing.'),
('promo code', 'A discount code did not work.'),
('damaged', 'The item arrived damaged.'),
('damaged', 'The product does not work.'),
('login', 'The customer cannot log in to their account.');Write what the customer says, not a topic. Our first try:
SELECT id,
ROUND(JSON_EXTRACT(NLI_CLASSIFY('nli-default', body, 'The customer has a problem with a charge or a payment.'), '$.scores.entailment'), 2) AS topic,
ROUND(JSON_EXTRACT(NLI_CLASSIFY('nli-default', body, 'I was charged twice.'), '$.scores.entailment'), 2) AS claim
FROM am5_tickets WHERE id = 1;
id topic claim
1 0.09 1.0Ticket 1 is "I was charged twice for order 5521. Please send one of them back." Its claim scores 1.0, the category 0.09.
2. Every ticket against every sentence, tags above 0.7
WITH scores AS (
SELECT t.id, g.tag,
MAX(JSON_EXTRACT(NLI_CLASSIFY('nli-default', t.body, g.hypothesis), '$.scores.entailment')) AS score
FROM am5_tickets t CROSS JOIN am5_tags g
GROUP BY t.id, g.tag),
tagged AS (SELECT id, STRING_AGG(tag, ', ') AS tags FROM scores WHERE score > 0.7 GROUP BY id)
SELECT t.id, COALESCE(x.tags, 'needs a person') AS tags
FROM am5_tickets t LEFT JOIN tagged x ON x.id = t.id
ORDER BY t.id;
1 payment, refund
2 promo code
3 delivery
4 damaged
5 login
6 promo code, refund
7 damaged, refund
8 payment
9 delivery
10 refund
11 needs a person
12 login
13 damaged
14 needs a person
15 needs a person
16 needs a person
17 payment
18 needs a person
19 needs a person
20 needs a person
(20 rows, 180 NLI calls, 1.67 s)MAX keeps each tag's best sentence. Why 0.7: we tagged the 20 by hand first. The 16 tags it found scored 0.87 to 1.0, and nothing we wouldn't tag scored above 0.62 ("Please cancel my order" as damaged), so 0.7 sits in the gap.
Four hand tags scored 0.04 or less (14 payment, 17 refund, 18 delivery, 19 login): no sentence in the table says what those tickets say. None lands in a wrong queue, and each shows the sentence to add.
3. Today's queue at a glance
-- same WITH scores AS (...) as step 2, then:
hits AS (SELECT id, tag FROM scores WHERE score > 0.7)
SELECT COALESCE(h.tag, 'needs a person') AS tag, COUNT(*) AS tickets
FROM am5_tickets t LEFT JOIN hits h ON h.id = t.id
GROUP BY COALESCE(h.tag, 'needs a person')
ORDER BY tickets DESC, tag;
needs a person 7
refund 4
damaged 3
payment 3
delivery 2
login 2
promo code 2Tickets 1, 6 and 7 count twice, so 20 tickets make 23.
Free Community Edition: https://synapcores.com/download?utm_source=reddit&utm_medium=owned&utm_campaign=synapcores-ask-1127
Ask us anything below. Our question for you: which tag would your support queue need first?