Semantic SQL in Practice: Jev, Databricks AI Functions, and Snowflake Cortex
Traditional SQL is excellent at filtering structured data.
SELECT * FROM support_tickets WHERE status = 'OPEN' AND priority = 'HIGH'; But what if the question is not a simple comparison?
Imagine you want to find tickets where the customer is asking for a refund, even when the ticket never contains the word refund.
A customer might write:
- "I was charged twice."
- "Please return the money to my card."
- "I don't want to keep this subscription."
- "The payment went through, but I never received my order."
Traditional keyword matching can miss these cases. You can build increasingly complicated LIKE conditions, but that approach becomes difficult to maintain as language and business requirements evolve.
What if you could express the business condition in natural language directly inside SQL?
SELECT * FROM support_tickets WHERE jev( support_tickets, 'The customer is requesting a refund' ); This is the idea behind semantic SQL: combining the familiar relational query model with AI-powered interpretation of unstructured text.
In this article, we'll explore three approaches:
- Jev for PostgreSQL — semantic predicates, probability estimates, choices, and scores.
- Databricks AI Functions — natural-language decisions and AI-powered data processing.
- Snowflake Cortex AI Functions — semantic filtering, classification, and structured model outputs.
We'll use the same support-ticket scenario to understand the concepts, write example queries, compare the platforms, and discuss production considerations.
Note: The PostgreSQL
jev()function discussed here comes from thepg-jevproject. It is not a built-in PostgreSQL function. Databricks and Snowflake provide their own AI function interfaces, so their syntax and behavior are different.
1. What is semantic SQL?
Semantic SQL extends traditional filtering by allowing a model to interpret the meaning of a record.
Consider this table:
| ticket_id | message |
|---|---|
| 101 | Please return my money. |
| 102 | I was charged twice this month. |
| 103 | How do I change my profile picture? |
| 104 | The package arrived damaged. |
| 105 | I want to cancel and get my last payment back. |
A conventional query might be:
SELECT * FROM support_tickets WHERE message ILIKE '%refund%'; This returns only messages containing the word refund. It may miss tickets 101, 102, and 105.
A semantic query instead asks whether each record satisfies a business-defined condition.
SELECT * FROM support_tickets WHERE jev( support_tickets, 'The customer is requesting money back for a payment' ); The model interprets the message in context rather than relying only on literal word matching.
This is useful for tasks such as:
- Identifying refund requests.
- Detecting complaints and escalations.
- Finding messages that indicate cancellation intent.
- Categorizing product feedback.
- Identifying potentially fraudulent or suspicious descriptions for further review.
- Extracting business signals from free-form text.
Semantic SQL is not a replacement for every ordinary SQL predicate. It is an additional tool for questions that depend on meaning.
2. Understanding the Jev functions in PostgreSQL
The pg-jev project exposes functions for different kinds of semantic questions.
The core idea is to choose a function based on the answer your application needs.
| Function | Purpose | Typical result |
|---|---|---|
jev() | Test a semantic condition | Boolean |
jev_prob() | Estimate how likely a condition is to be true | Probability-like numeric value |
jev_choice() | Choose among candidate answers | Selected option |
jev_score() | Evaluate a record against a scoring instruction | Score |
jev_stats() | Inspect extension statistics | Statistics |
These functions are not interchangeable.
Use jev() when you want a filter, jev_prob() when you need a ranking signal, jev_choice() when you need a selection, and jev_score() when you need a score derived from an instruction.
Exact return types, arguments, configuration options, and model behavior should be checked against the installed version of the extension.
2.1 jev(): Semantic Boolean filtering
A conventional predicate checks a known value:
WHERE status = 'OPEN' A semantic predicate checks whether a record matches a natural-language condition:
WHERE jev( support_tickets, 'The customer is requesting a refund' ) Conceptually, the function evaluates the record against the supplied instruction and produces a Boolean result.
The database can then use that result as part of a normal WHERE clause.
This makes semantic filtering feel familiar to SQL users.
2.2 jev_prob(): Probability-oriented evaluation
Sometimes a Boolean result is not enough.
Suppose the business team wants to review the most likely refund requests first.
SELECT ticket_id, message, jev_prob( support_tickets, 'The customer is requesting a refund' ) AS refund_probability FROM support_tickets ORDER BY refund_probability DESC; This illustrates the intended workflow: compute a probability-like value and rank records by it.
Do not automatically interpret this value as a statistically calibrated probability. Its meaning, scale, and calibration depend on the extension's documented implementation and model behavior.
For important business decisions, validate the score against labeled examples.
2.3 jev_choice(): Choose among candidate answers
Suppose every ticket needs a primary category.
Possible categories include:
REFUNDTECHNICAL_ISSUESHIPPINGACCOUNT_ACCESSOTHER
A choice function is useful when the task is to select one option rather than independently test multiple conditions.
Illustrative query:
SELECT ticket_id, message, jev_choice( support_tickets, 'Choose the most appropriate category: REFUND, TECHNICAL_ISSUE, SHIPPING, ACCOUNT_ACCESS, OTHER' ) AS predicted_category FROM support_tickets; Check the installed pg-jev documentation for the precise choice syntax supported by your version.
2.4 jev_score(): Evaluate records against a scoring instruction
Some use cases require a score rather than a Boolean or category.
For example, a support team might want to prioritize messages based on urgency.
SELECT ticket_id, message, jev_score( support_tickets, 'Score the urgency of this support ticket' ) AS urgency_score FROM support_tickets; This is an illustrative example of the scoring workflow. Confirm the expected score format and argument conventions in the version you install.
A model-generated score should not be assumed to have a fixed numeric range or consistent interpretation unless the implementation explicitly guarantees it.
3. Set up Jev with PostgreSQL
Let's build the example from the beginning.
Step 1: Install the extension
Start with the project repository and its current installation instructions:
- GitHub: https://github.com/realZachi/pg-jev
- Documentation: https://pgjev.com/docs
A source-based installation commonly begins with:
git clone https://github.com/realZachi/pg-jev.git cd pg-jev Follow the repository's README for prerequisites, configuration, and installation. Depending on your environment, you may need PostgreSQL development headers and the appropriate build tools.
If the repository's current instructions support a standard Makefile installation, the workflow may include:
make sudo make install Use the exact commands documented for your operating system and PostgreSQL version.
Step 2: Create the extension
Connect to the target database and run:
CREATE EXTENSION jev CASCADE; If the extension is not found, verify that it was installed into the extension directory used by the PostgreSQL server you are connecting to.
Step 3: Configure credentials
The extension may require an API key or other model-provider configuration.
For example, if supported by your installed version:
SET jev.api_key = 'YOUR_TYPESAFE_API_KEY'; Replace the placeholder with your actual credential and follow the extension's current configuration documentation.
Production security tip: Don't commit API keys to source control or hard-code them in application SQL. Use your organization's approved secrets-management approach and verify whether the setting is session-scoped, role-scoped, or database-scoped.
Step 4: Create sample data
CREATE TABLE support_tickets ( ticket_id INTEGER PRIMARY KEY, customer_id INTEGER, status TEXT, message TEXT ); INSERT INTO support_tickets (ticket_id, customer_id, status, message) VALUES (101, 1001, 'OPEN', 'Please return the money I paid yesterday.'), (102, 1002, 'OPEN', 'I was charged twice for the same order.'), (103, 1003, 'OPEN', 'How can I change my profile picture?'), (104, 1004, 'CLOSED', 'The package arrived with a broken item.'), (105, 1005, 'OPEN', 'I want to cancel and get my last payment back.'); Step 5: Run a semantic query
SELECT ticket_id, message FROM support_tickets WHERE status = 'OPEN' AND jev( support_tickets, 'The customer is requesting a refund' ); The ordinary status predicate and semantic predicate work together.
The status condition restricts the search to open tickets. The semantic condition asks whether each remaining ticket expresses refund intent.
The exact output depends on the model, prompt, implementation, and runtime configuration.
Step 6: Inspect performance and behavior
If your installed version provides statistics, you can inspect them with:
SELECT jev_stats(); Consult the project's documentation for the fields returned and how to interpret them.
Before using this in production, test the extension on a labeled dataset. Include clear positive cases, clear negative cases, ambiguous messages, and examples that contain misleading keywords.
4. Databricks: AI functions for semantic decisions
Databricks provides AI functions that bring model-backed operations into SQL workflows.
One relevant function is ai_decide(), which is documented as a Beta feature. Its interface is different from Jev's: it accepts a state and a set of questions and returns structured decision results.
Official references:
- AI functions: https://docs.databricks.com/aws/en/large-language-models/ai-functions
-
ai_decide(): https://docs.databricks.com/aws/en/sql/language-manual/functions/ai_decide
4.1 The mental model
Instead of calling a PostgreSQL extension predicate, you describe a decision for Databricks to evaluate.
For example, the decision could be:
Does this support ticket represent a refund request?
The output can include fields such as a decision, a choice, or a score, depending on the question definition and the supported response structure.
Because ai_decide() is Beta, confirm the current syntax and availability for your Databricks workspace and compute environment.
4.2 Prepare the data
The example below uses the same support-ticket concept:
CREATE OR REPLACE TABLE support_tickets AS SELECT * FROM VALUES (101, 'Please return the money I paid yesterday.'), (102, 'I was charged twice for the same order.'), (103, 'How can I change my profile picture?'), (104, 'The package arrived with a broken item.'), (105, 'I want to cancel and get my last payment back.') AS t(ticket_id, message); 4.3 Use ai_decide()
The function takes a state and a set of questions. The state can be represented as a string or supported structured value, while the questions are supplied in the documented JSON format.
The following is a structural example to demonstrate the approach. Validate the question schema and result paths against the current Databricks documentation before executing it.
SELECT ticket_id, message, ai_decide( TO_JSON( NAMED_STRUCT( 'ticket_message', message ) ), '[ { "id": "refund_request", "question": "Is the customer requesting a refund?" } ]' ) AS decision FROM support_tickets; The result is a structured response. It is not simply a PostgreSQL Boolean.
Depending on the documented response schema, you may be able to access decision fields and associated metadata through the returned structure.
For example, a conceptual output might contain:
{ "response": { "answers": { "refund_request": { "choice": "yes", "probability": 0.94 } } } } This JSON is illustrative, not a guaranteed literal response. Actual fields and values depend on the current function contract.
4.4 Filter using the decision result
Once you've confirmed the actual response schema in your workspace, extract the appropriate answer field and use it in a filter.
Conceptually:
SELECT * FROM evaluated_tickets WHERE refund_request = 'yes'; In a real query, refund_request would need to be derived from the documented output structure or a previously materialized result.
For production pipelines, it is often clearer to separate the AI evaluation from the downstream filtering step. That makes the decision output easier to inspect, test, and reuse.
4.5 When Databricks is a good fit
Databricks is particularly relevant when the data is already part of a lakehouse workflow and you want to apply model-backed decisions to datasets using SQL.
Potential use cases include:
- Enriching customer-support data.
- Categorizing incoming text.
- Extracting information from semi-structured records.
- Adding semantic signals to analytics tables.
- Building AI-assisted data-processing pipelines.
Before deploying, verify feature availability, permissions, supported models, cost behavior, and the current Beta limitations.
5. Snowflake Cortex: Semantic filtering and classification
Snowflake offers Cortex AI functions that can be used from SQL to filter, classify, and process text.
For this article, three functions are particularly useful:
| Function | Purpose |
|---|---|
AI_FILTER | Evaluate whether a record satisfies a natural-language condition |
AI_CLASSIFY | Assign text to one or more defined categories |
AI_COMPLETE | Generate a model response, including supported structured output |
Official documentation:
-
AI_FILTER: https://docs.snowflake.com/en/sql-reference/functions/ai_filter -
AI_CLASSIFY: https://docs.snowflake.com/en/sql-reference/functions/ai_classify -
AI_COMPLETE: https://docs.snowflake.com/en/sql-reference/functions/ai_complete
These are Snowflake functions, not aliases for Jev. Their syntax, supported inputs, return values, and model behavior differ.
5.1 AI_FILTER(): Natural-language filtering
Suppose you want to find support tickets that indicate refund intent.
SELECT ticket_id, message FROM support_tickets WHERE AI_FILTER( PROMPT( 'Does this support ticket indicate that the customer is requesting a refund? {0}', message ) ); The PROMPT() expression supplies the natural-language instruction and inserts the message into the prompt.
This is the closest conceptual comparison to a semantic Boolean predicate.
It is still important to understand the distinction: similar intent does not mean identical execution semantics. Evaluate the function's documented behavior and test its output against your data.
5.2 AI_CLASSIFY(): Categorize a ticket
Now suppose the support team needs a category for each ticket.
SELECT ticket_id, message, AI_CLASSIFY( message, [ 'REFUND', 'TECHNICAL_ISSUE', 'SHIPPING', 'ACCOUNT_ACCESS', 'OTHER' ] ) AS classification FROM support_tickets; AI_CLASSIFY() is designed for classification against a set of categories. The exact accepted argument types and result structure should be checked against the Snowflake version and function syntax in use.
The output can be used to enrich a table or support downstream reporting.
For example, once classification is stored in a normalized column, the support team can count tickets by category or route them to the appropriate queue.
5.3 AI_COMPLETE(): Return structured information
Sometimes a label is not enough. You may want a short explanation and an urgency estimate.
AI_COMPLETE() can be used for model-generated responses, including structured output where supported.
An illustrative pattern is:
SELECT ticket_id, AI_COMPLETE( 'Return a structured assessment of this support ticket.', message, { 'type': 'object', 'properties': { 'urgency': { 'type': 'string' }, 'explanation': { 'type': 'string' } }, 'required': ['urgency', 'explanation'] } ) AS assessment FROM support_tickets; Check the current AI_COMPLETE() signature for your Snowflake environment, including the supported structured-output argument and model selection options. This example illustrates the intended shape; it should not be treated as a version-independent copy-and-run guarantee.
A structured response is useful because downstream SQL can work with named fields instead of trying to interpret an unstructured paragraph.
5.4 When Snowflake is a good fit
Snowflake Cortex is worth considering when your data and analytics already live in Snowflake and you want AI capabilities close to that data.
Potential use cases include:
- Semantic filtering of customer feedback.
- Categorization of support messages.
- Extraction of structured fields from text.
- AI-assisted enrichment of analytical datasets.
- Generating structured summaries for downstream workflows.
As with any model-backed operation, test quality, review access controls, and monitor cost and latency before scaling up.
6. Comparing the three approaches
The following table compares the concepts rather than claiming that the APIs are interchangeable.
| Capability | Jev / PostgreSQL | Databricks | Snowflake |
|---|---|---|---|
| Semantic predicate | jev() | ai_decide()-based decision workflow | AI_FILTER() |
| Probability-like result | jev_prob() | Depends on the supported decision response | Not a direct jev_prob() equivalent |
| Choice or category | jev_choice() | Structured decision output | AI_CLASSIFY() |
| Score | jev_score() | Depends on the question and output schema | Custom structured output with AI_COMPLETE() |
| Primary environment | PostgreSQL with the extension installed | Databricks SQL and supported AI-function environment | Snowflake with supported Cortex features |
| Portability | PostgreSQL-specific extension | Databricks-specific API | Snowflake-specific API |
The key distinction is that conceptual equivalence is not API equivalence.
A function with a similar purpose may have a different signature, output schema, error behavior, model configuration, or execution cost.
If you need portability across databases, design a small application-level interface for your business operations rather than expecting identical SQL to run unchanged everywhere.
7. An end-to-end implementation strategy
Let's return to the original problem: finding refund requests in support tickets.
A reliable implementation has more steps than writing one semantic predicate.
Step 1: Define the business question
Write a precise instruction.
For example:
Return true only when the customer is asking to recover money already paid. Do not classify general cancellation questions as refund requests unless a payment return is implied.
This helps distinguish refund intent from related but different situations.
Step 2: Build a labeled test dataset
Create examples that cover more than obvious positive cases.
Include:
- Explicit refund requests.
- Duplicate charges.
- Cancellation without a refund request.
- Damaged goods without a request for money back.
- Questions about refund policy.
- Sarcastic, incomplete, or ambiguous messages.
Have domain experts label the expected result.
Step 3: Establish a baseline
Compare the AI approach with a simple SQL baseline.
SELECT ticket_id, message, message ILIKE '%refund%' AS keyword_match FROM support_tickets; The baseline is cheap, understandable, and useful as a point of comparison.
It also shows which examples require semantic interpretation.
Step 4: Evaluate model results
For a binary classification task, measure:
- Precision: Of the tickets predicted to be refund requests, how many actually are?
- Recall: Of all actual refund requests, how many did the system identify?
- False-positive rate: How often did it flag an unrelated ticket?
- Latency and cost: How expensive is the operation at the expected volume?
For customer-support routing, false positives and false negatives may have different business costs. Choose thresholds and review policies accordingly.
Step 5: Separate evaluation from action
Do not automatically issue refunds just because a model predicts refund intent.
A safer workflow is:
- Detect likely intent.
- Record the model result and relevant metadata.
- Apply deterministic business rules.
- Route ambiguous cases for human review.
- Allow downstream systems to act only after the required checks pass.
Semantic SQL should help interpret language, not silently replace authorization or financial controls.
Step 6: Materialize expensive results when appropriate
Repeatedly evaluating the same message may increase latency and cost.
Where the platform and function semantics permit, consider storing evaluated results in a table with fields such as:
- Ticket ID.
- Prediction.
- Model or function version.
- Evaluation timestamp.
- Prompt or instruction version.
- Review status.
Then re-evaluate records when the message changes, the instruction changes, or your evaluation policy requires it.
Do not assume that every AI function automatically caches results or behaves deterministically.
8. Production considerations
Semantic SQL introduces model-related concerns that do not exist in the same form for ordinary equality predicates.
Cost and latency
A model-backed operation is generally more expensive than comparing two strings. Test realistic row counts and avoid assuming that an AI predicate behaves like a low-cost native SQL operator.
Prompt design
Business instructions should be precise and testable. Vague questions can produce inconsistent or unexpected decisions.
Data privacy
A function's data handling depends on the platform, configuration, model provider, and applicable service terms. Review your organization's privacy and data-processing requirements before sending customer text to a model.
Security and prompt injection
Treat text being evaluated as untrusted input. A customer message may contain instructions such as "ignore all previous rules." The model should evaluate the message as data, not follow instructions embedded inside it.
For sensitive workflows, use explicit instructions, constrained output schemas where supported, deterministic validation, and human review.
Observability
Track quality, latency, failures, and cost. Keep enough metadata to reproduce or investigate a decision without unnecessarily retaining sensitive customer content.
Versioning
Model behavior and platform APIs can change. Pin supported configurations where possible, maintain regression tests, and re-run evaluations before changing models or prompts.
9. Which approach should you choose?
Choose Jev if you want to experiment with semantic predicates directly in PostgreSQL and the extension's features fit your application.
Choose Databricks AI functions if your workflow is already centered on Databricks and you want to integrate model-backed decisions into lakehouse SQL processing.
Choose Snowflake Cortex if your data platform is Snowflake and you want to use its built-in AI filtering, classification, and completion functions.
For all three, the best choice depends on your data location, security requirements, model support, operational cost, and measured accuracy.
Don't choose solely by how short the SQL looks. Choose based on how reliably the solution answers your business question.
10. Final thoughts
Semantic SQL offers a useful shift in how we express data questions.
Instead of building a long list of keywords and exceptions, we can describe the business meaning we want to detect and evaluate records with model-backed functions.
Jev, Databricks AI functions, and Snowflake Cortex approach this idea differently, but they point toward a similar workflow: combining structured querying with semantic understanding.
The practical path is to start small, evaluate against labeled examples, measure quality and cost, and keep deterministic controls around consequential actions.
The goal is not to replace SQL with AI. It is to make SQL-based data workflows more capable when the data's meaning matters.
References
- Jev / PostgreSQL: https://github.com/realZachi/pg-jev
- Jev documentation: https://pgjev.com/docs
- Databricks AI functions: https://docs.databricks.com/aws/en/large-language-models/ai-functions
- Databricks
ai_decide(): https://docs.databricks.com/aws/en/sql/language-manual/functions/ai_decide - Snowflake
AI_FILTER: https://docs.snowflake.com/en/sql-reference/functions/ai_filter - Snowflake
AI_CLASSIFY: https://docs.snowflake.com/en/sql-reference/functions/ai_classify - Snowflake
AI_COMPLETE: https://docs.snowflake.com/en/sql-reference/functions/ai_complete
Let's discuss
Would you use natural-language predicates directly in SQL, or would you keep semantic decisions in an application or feature pipeline?
I'd be interested to hear how you're approaching semantic search, classification, and AI-assisted data processing in production.