All Products
Search
Document Center

ApsaraDB for SelectDB:AI_FILTER

Last Updated:Mar 28, 2026

Filters rows by evaluating text against a natural-language condition using a Large Language Model (LLM). Returns true if the condition is met, false otherwise.

Syntax

AI_FILTER(<text>)
AI_FILTER(<resource_name>, <text>)

Use the first form when no specific model resource is configured. Use the second form to target a named resource.

Parameters

ParameterRequiredDescription
<text>YesThe text to evaluate. Typically a string that combines a natural-language condition with column data.
<resource_name>NoThe name of the model resource to use.

Return value

  • Returns a Boolean value: true if the condition is met, false otherwise.

  • Returns NULL if the input is NULL.

  • Results are non-deterministic. Because the LLM generates each result independently, the same input may return different values across runs.

Usage notes

The quality of filtering depends on how clearly the condition is expressed. Follow these guidelines to get more accurate results:

  • Be specific. Instead of 'positive comment', use 'This is a positive customer review of a delivery service'.

  • Use question form. Phrasing the condition as a question often improves accuracy, for example: 'Does this comment express satisfaction with the delivery service?'

  • Avoid NULL inputs. Filter out NULL values before passing them to AI_FILTER to prevent unexpected NULL returns.

Examples

Quick test

Run this without any table setup to verify the function works:

SELECT AI_FILTER('resource_name', 'Is this a positive statement: Absolutely fantastic service!');

Filter rows in a table

The following example filters customer comments from a courier company.

Create the table:

CREATE TABLE user_comments (
    id      INT,
    comment VARCHAR(500)
) DUPLICATE KEY(id)
DISTRIBUTED BY HASH(id) BUCKETS 10
PROPERTIES (
    "replication_num" = "1"
);

Query positive comments:

SELECT id, comment FROM user_comments
WHERE  AI_FILTER('resource_name', CONCAT('This is a positive comment: ', comment));

Output:

+------+--------------------------------------------+
| id   | comment                                    |
+------+--------------------------------------------+
|    1 | Absolutely fantastic, highly recommend it. |
|    3 | This product is amazing and I love it.     |
+------+--------------------------------------------+