SEARCH_PREVIEW

functionsupportedAI & ML

docs.snowflake.com ↗

String & binary functions

Given a Cortex Search service name, and a query, returns a response from the specified service.

Syntax

SNOWFLAKE.CORTEX.SEARCH_PREVIEW(
    '<service_name>',
    '<query_parameters_object>'
)

Parameters

NameRequiredDescription
service_namerequiredName of your Cortex Search service. Use the fully qualified name if the service is in a schema different from the current session.
query_parameters_objectrequiredA STRING that contains a JSON object that specifies the query parameters for invoking the service. Key Type Description Default query String Your search query, to search over the text column in the service. This is required. columns Array A comma-separated list of columns to return for each relevant result in the response. These columns must be included in the source query for the service. Search column that was specified when the service was created. filter Object A filter object for filtering results based on data in the ATTRIBUTES columns. For detailed syntax, see Filter syntax. Empty object limit Integer Maximum number of results to return in the response. 10ExpandShow lessSee more

Returns

Returns an OBJECT that contains the result of your query from your Cortex Search service and a unique request ID. See example output in Examples.

Usage notes

Filter syntax

Cortex Search supports filtering on the ATTRIBUTES columns specified in the CREATE CORTEX SEARCH SERVICE command. Cortex Search supports five matching operators: - TEXT or NUMERIC equality: @eq - ARRAY contains: @contains - NUMERIC or DATE/TIMESTAMP greater than or equal to: @gte - NUMERIC or DATE/TIMESTAMP less than or equal to: @lte - primary key equality: @primarykey These matching operators can be composed with various logical operators: - @and - @or - @not The following usage notes apply: - Matching against NaN (‘not a number’) values in the source query are handled as described in Special values. - Fixed-point numeric values with more than 19 digits (not including leading zeroes) do not work with @eq, @gte, or @lte and will not be returned by these operators. For example, if there is a large value in the source query, using @eq to match that exact value will return no results. - These large values could still be returned by the overall filter with the use of @not (e.g. while @eq X will return no values for some large X, @not @eq Y will return it). - TIMESTAMP and DATE filters accept values of the form: YYYY-MM-DD and, for timezone aware dates: YYYY-MM-DD+HH:MM. If the timezone offset is not specified, the date is interpreted in UTC. - @primarykey is only supported for services configured with a primary key. The value of the filter must be a JSON object mapping every primary key column to its corresponding value (or NULL). These operators can be combined into a single filter object.

Example

- Filtering on rows where string-like column string_col is equal to value value. Copy code { "@eq": { "string_col": "value" } } - Filtering to a row with the specified primary key, Copy code { "@primarykey": { "region": "us-west-1", "agent_id": "abc123" } } - Filtering on rows where ARRAY column array_col contains value value. Copy code { "@contains": { "array_col": "arr_value" } } - Filtering on rows where NUMERIC column numeric_col is between 10.5 and 12.5 (inclusive): Copy code { "@and": [ { "@gte": { "numeric_col": 10.5 } }, { "@lte": { "numeric_col": 12.5 } } ]} - Filtering on rows where TIMESTAMP column timestamp_col is between 2024-11-19 and 2024-12-19 (inclusive). Copy code { "@and": [ { "@gte": { "timestamp_col": "2024-11-19" } }, { "@lte": { "timestamp_col": "2024-12-19" } } ]} - Composing filters with logical operators: Copy code // Rows where the "array_col" column contains "arr_value" and the "string_col" column equals "value": { "@and": [ { "@contains": { "array_col": "arr_value" } }, { "@eq": { "string_col": "value" } } ] } // Rows where the "string_col" column does not equal "value" { "@not": { "@eq": { "string_col": "value" } } } // Rows where the "array_col" column contains at least one of "val1", "val2", or "val3" { "@or": [ { "@contains": { "array_col": "val1" } }, { "@contains": { "array_col": "val1" } }, { "@contains": { "array_col": "val1" } } ] }