mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-10-03 18:45:35 +00:00
* feat: return matching scores from jev Replace the experimental three-argument Boolean function with jev(text, prompt) returning a Float64 probability in [0, 1]. Move threshold comparisons into SQL and update tests and migration examples. Signed-off-by: Lei, HUANG <ratuthomm@gmail.com> * feat: add Jev choice and score functions Share asynchronous execution across Noul, Choice, and Score. Validate JSON criteria before requests and return typed scalar answers. Add SQL and HTTP mock coverage with usage examples. Signed-off-by: Lei, HUANG <ratuthomm@gmail.com> * refactor: use generic AI SQL function names Expose ai_match, ai_choose, and ai_score and move their implementation, tests, and usage guide under generic AI names. Document the current unreleased interface without migration history. Signed-off-by: Lei, HUANG <ratuthomm@gmail.com> * fix: share constant AI criteria within each batch Borrow scalar string arguments and lazily parse constant criteria once per batch. Share the parsed allocation across requests while preserving NULL propagation and batch validation before HTTP calls. Signed-off-by: Lei, HUANG <ratuthomm@gmail.com> * feat: preserve AI score uncertainty in JSONB results Return score, confidence, and probabilities in criteria-level order from one evaluation. Validate the distribution and preserve provider precision. Add JSON extraction, uncertainty, and single-request regressions, and document confidence-aware ranking. Signed-off-by: Lei, HUANG <ratuthomm@gmail.com> * docs: explain reuse of volatile AI evaluations Document repeated SELECT and WHERE evaluation costs as N + M requests, and show subquery aliases for reusing scalar or structured AI results without additional model calls. Signed-off-by: Lei, HUANG <ratuthomm@gmail.com> --------- Signed-off-by: Lei, HUANG <ratuthomm@gmail.com>
66 lines
2.5 KiB
SQL
66 lines
2.5 KiB
SQL
-- No credentials or external service needed: NULL propagates without an API call.
|
|
SELECT ai_match(NULL, 'The event reports a failed payment.') AS score;
|
|
|
|
SELECT ai_match('message', NULL) AS score;
|
|
|
|
SELECT arrow_typeof(ai_match(NULL, 'condition')) AS score_type;
|
|
|
|
SELECT ai_choose(NULL, 'Route the ticket', '{"billing":null}') AS null_text,
|
|
ai_choose('message', NULL, 'invalid JSON') AS null_prompt,
|
|
ai_choose('message', 'Route the ticket', NULL) AS null_criteria;
|
|
|
|
SELECT ai_score(NULL, 'Rate severity', '["low","high"]') AS null_text,
|
|
ai_score('message', NULL, 'invalid JSON') AS null_prompt,
|
|
ai_score('message', 'Rate severity', NULL) AS null_criteria;
|
|
|
|
SELECT arrow_typeof(ai_choose(NULL, 'prompt', '{"billing":null}')) AS choice_type,
|
|
arrow_typeof(ai_score(NULL, 'prompt', '["low","high"]')) AS score_type;
|
|
|
|
SELECT json_to_string(rating) AS rating,
|
|
json_get_float(rating, 'score') AS score,
|
|
json_get_float(rating, 'confidence') AS confidence,
|
|
json_get_float(rating, 'probabilities[2]') AS high_probability
|
|
FROM (SELECT ai_score(NULL, 'prompt', '["low","medium","high"]') AS rating) AS rated;
|
|
|
|
-- Validate SQL registration, coercion, and asynchronous filtering on a real table.
|
|
CREATE TABLE ai_events (
|
|
occurred_at TIMESTAMP TIME INDEX,
|
|
"service" STRING,
|
|
"message" STRING,
|
|
PRIMARY KEY ("service")
|
|
);
|
|
|
|
INSERT INTO ai_events VALUES
|
|
('2026-09-19T01:00:00Z', 'payments', NULL),
|
|
('2026-09-19T02:00:00Z', 'auth', NULL);
|
|
|
|
SELECT occurred_at, service, message FROM ai_events
|
|
WHERE occurred_at >= '2026-09-19T00:00:00Z'
|
|
AND occurred_at < '2026-09-20T00:00:00Z'
|
|
AND service = 'payments'
|
|
AND ai_match((message), 'The event reports that a payment still failed after retries.') >= 0.8
|
|
ORDER BY occurred_at;
|
|
|
|
SELECT occurred_at,
|
|
ai_choose(message, 'Route the ticket', '{"billing":"Payments","technical":"Errors"}') AS team,
|
|
ai_score(message, 'Rate severity', '["low","medium","high"]') AS rating
|
|
FROM ai_events
|
|
ORDER BY occurred_at;
|
|
|
|
DROP TABLE ai_events;
|
|
|
|
-- Matching uses two arguments; thresholds are expressed as SQL comparisons.
|
|
SELECT ai_match('message', 'condition', 0.8);
|
|
|
|
-- Invalid criteria fail locally before any HTTP request.
|
|
SELECT ai_choose('message', 'prompt', 'not json');
|
|
|
|
SELECT ai_choose('message', 'prompt', '{}');
|
|
|
|
SELECT ai_score('message', 'prompt', '["only one level"]');
|
|
|
|
-- Both additional modes require criteria.
|
|
SELECT ai_choose('message', 'prompt');
|
|
|
|
SELECT ai_score('message', 'prompt');
|