SQL functions: AI, bot detection and masking
aiClassify and embedText, isLikelyBot, getTrafficType, getBotName and friends, and how restricted properties are masked in SQL.
These are on top of the ClickHouse functions allowed in SQL over the API.
AI functions
The model never sees SQL, and ClickHouse never calls a model. Lucida finds the AI calls in your query, asks your project's AI provider for the answers first, then substitutes them into the SQL. AI must be configured for the project, or the call fails: 403 when AI is switched off, 429 over the budget or spend cap, 422 for bad input (see AI providers).
Function | What it returns |
|---|---|
| For each row, the one of your choices that fits |
| A float array (vector) for one literal text; compare it with |
SELECT aiClassify(properties.message, ['bug', 'billing', 'praise']) AS topic, count() AS n
FROM events
WHERE event = 'support_message_sent' AND timestamp >= now() - INTERVAL 7 DAY
GROUP BY topicLimits, enforced when the query is compiled:
aiClassifytakes 1 to 50 string literals as choices, must sit inside aSELECTwith aFROM, and classifies at most 500 distinct inputs per call (taken from the sameFROMandWHERE). Each input is cut to 8 KB before it goes to the model.embedTexttakes a string literal only, not a column.At most 3 AI calls in one query.
Calls use your provider and are subject to the project's AI settings and spend cap.
Bot and traffic functions
Each takes an optional properties column (default properties) and classifies the stored user agent against the built-in bot catalog at query time, so a catalog update also applies to old events. Events with no catalog hit use what ingestion stored (IP ranges, heuristics, your custom rules).
Function | Returns |
|---|---|
| 1 when the traffic is not regular, or the event carries |
|
|
| The catalog category, for example |
| The bot's name |
| The operator behind it |
Categories map to types: ai_assistant is ai_agent; http_client, headless_browser and no_user_agent are automation; empty or regular is regular; any other category is bot.
SELECT getTrafficType() AS type, getBotName() AS bot, count() AS n
FROM events
WHERE event = '$pageview' AND timestamp >= now() - INTERVAL 30 DAY
GROUP BY type, bot
ORDER BY n DESCMasking
Masking is not a function you call. When a key's access rules hide a property (for example an email property) or a warehouse table, the events and persons tables (including person_properties and the hot property columns) under your SQL replace that property's value with [masked], and warehouse_rows leaves the hidden tables out. Keys are matched case-insensitively and the key itself stays visible. Because masking happens below your query, no projection, filter or aggregate can read the real value. Access rules are described in Access control.