CREATE CORTEX SEARCH SERVICE
statementpartialAI & MLCreates a new Cortex Search service or replaces an existing one.
Syntax
supportedpartialnot supportednot scored
CREATE [ OR REPLACE ] CORTEX SEARCH SERVICE [ IF NOT EXISTS ] <name>
ON <search_column>
[ PRIMARY KEY ( <col_name> [, ... ] ) ]
ATTRIBUTES <col_name> [ , ... ]
WAREHOUSE = <warehouse_name>
TARGET_LAG = '<num> { seconds | minutes | hours | days }'
[ EMBEDDING_MODEL = <embedding_model_name> ]
[ REFRESH_MODE = { FULL | INCREMENTAL } ]
[ INITIALIZE = { ON_CREATE | ON_SCHEDULE } ]
[ FULL_INDEX_BUILD_INTERVAL_DAYS = <num> ]
[ REQUEST_LOGGING = { TRUE | FALSE } ]
[ AUTO_SUSPEND = <num_seconds> ]
[ COMMENT = '<comment>' ]
AS <query>;
CREATE [ OR REPLACE ] CORTEX SEARCH SERVICE <name>
TEXT INDEXES <text_column_name> [ , ... ]
VECTOR INDEXES <column_specification> [ , ... ]
[ PRIMARY KEY ( <col_name> [, ... ] ) ]
ATTRIBUTES <col_name> [ , ... ]
WAREHOUSE = <warehouse_name>
TARGET_LAG = '<num> { seconds | minutes | hours | days }'
[ REFRESH_MODE = { FULL | INCREMENTAL } ]
[ INITIALIZE = { ON_CREATE | ON_SCHEDULE } ]
[ FULL_INDEX_BUILD_INTERVAL_DAYS = <num> ]
[ REQUEST_LOGGING = { TRUE | FALSE } ]
[ AUTO_SUSPEND = <num_seconds> ]
[ COMMENT = '<comment>' ]
AS <query>;
Parameters
| Name | Required | Description |
|---|---|---|
name | required | String that specifies the identifier (that is, the name) for the Cortex Search service; must be unique for the schema in which the service is created. In addition, the identifier must start with an alphabetic character and cannot contain spaces or special characters unless the entire identifier string is enclosed in double quotes (for example, "My object"). Identifiers enclosed in double quotes are also case-sensitive. For more information, see Identifier requirements. |
ON search_column | required | Specifies the text column in the base table that you wish to search on, for single-index Cortex Search. This column must be a text value. |
TEXT INDEXES text_column_name [, ... ] | required | Specifies comma-separated text columns in the base table to search on, for multi-index Cortex Search. Columns must be text values. |
VECTOR INDEXES column_specification [ , ... ] | required | Specifies columns for vector similarity searches. Column specifications include: Managed vector embeddings: text_column_name (model='embedding_model'): Specifies a text column and the embedding model used for vector generation. Must use one of the supported embedding models. If no model is specified, the default model snowflake-arctic-embed-m-v1.5 is used. User-provided vector embeddings: vector_column_name: Specifies a user-provided vector embedding column. User-provided vector embeddings with managed query embeddings: vector_column_name(query_model='embedding_model'): Specifies a user-provided vector embedding column and the embedding model used for embedding text at query time. The query_model must be one of the Snowflake-managed embedding models supported in Cortex Search. If no query_model is specified, then the user-provided vector column can only be used with a vector embedding query. For information on the behavior of vector embeddings, see Usage Notes. |
ATTRIBUTES col_name [ , ... ] | required | Specifies a comma-separated list of columns in the base table that you wish to filter on when issuing queries to the service. Attribute columns must be included in the source query, either via explicit enumeration or a wildcard (*). |
WAREHOUSE = warehouse_name | required | Specifies the warehouse to use for running the source query, building the search index, and keeping it refreshed per the TARGET_LAG target. |
TARGET_LAG = 'num { seconds | minutes | hours | days }' | required | Specifies the maximum amount of time that the Cortex Search service content should lag behind updates to the base tables specified in the source query. Note Ensure that the target lag is shorter than the data retention period of the source tables. If the target lag exceeds the data retention period, the service may be unable to detect changes in the source data and could require recreation. For more information, see DATA_RETENTION_TIME_IN_DAYS. |
PRIMARY KEY ( col_name [, ... ] ) | optional | Specifies a set of columns that uniquely identify each row in the source query. The combination of values in the designated columns must be unique for each row; rows with duplicate primary key values are ignored in the resulting search index. Primary key columns must be of the TEXT data type. Services with primary keys can make use of an optimized refresh path when the underlying data changes, resulting in significant reductions to the cost and latency of a refresh. For more information, see Primary keys. |
EMBEDDING_MODEL = <embedding_model_name> | optional | Optional parameter that specifies the embedding model to use in the Cortex Search Service. This property cannot be altered after you create the Cortex Search Service. To modify the property, recreate the Cortex Search Service with a CREATE OR REPLACE CORTEX SEARCH SERVICE command. Some embedding models are only available in certain cloud regions for Cortex Search. For an availability list by model by region, see Cortex Search Regional Availability. Each model may incur a different cost per million input tokens processed. Refer to the Snowflake Service Consumption Table for each function’s cost in credits per million tokens. If the EMBEDDING_MODEL is not specified, the default model is used. The default model is snowflake-arctic-embed-m-v1.5. |
REFRESH_MODE = { FULL | INCREMENTAL } | optional | Specifies the refresh mode for the Cortex Search Service. This property cannot be altered after you create the Cortex Search Service. To modify the property, recreate the Cortex Search Service with a CREATE OR REPLACE CORTEX SEARCH SERVICE command. Default: INCREMENTAL
|
INITIALIZE | optional | Specifies the behavior of the initial refresh of the Cortex Search Service. This property cannot be altered after you create the service. To modify the property, replace the cortex search service with a CREATE OR REPLACE CORTEX SEARCH SERVICE command. Default: ON_CREATE
|
FULL_INDEX_BUILD_INTERVAL_DAYS = num | optional | Specifies the target interval, in days, between full index rebuilds for a Cortex Search service with primary keys defined. This property is only applicable to services that have primary keys set. Services with primary keys use an optimized refresh path where each refresh cycle (governed by TARGET_LAG) processes only the rows that changed since the last refresh, rather than re-embedding all data. Over time, these incremental updates accumulate fragmented index segments. A full index rebuild compacts these segments into a single optimized index. The rebuild does not re-embed unchanged data. This value is a soft target. Full index rebuilds may occur more frequently than the specified interval to optimize serving performance based on factors such as service target lag, change rate in the service source data, and overall service size. Default: 1 |
REQUEST_LOGGING = { TRUE | FALSE } | optional | Enables or disables request logging for the Cortex Search Service. When enabled, the service records information about search requests, which you can query for monitoring and analysis purposes. For more information, see Monitor Cortex Search requests. Default: FALSE |
AUTO_SUSPEND = num_seconds | optional | Enables automatic suspension of the service’s serving compute after the specified number of seconds of query inactivity. The service automatically resumes when it receives a query. Minimum: 1800 (30 minutes). For more information, see Auto-suspend serving on inactivity. Default: NULL (auto-suspend disabled) |
COMMENT = 'comment' | optional | Specifies a comment for the service. |
AS query | optional | Specifies a query defining the base table from which the service is created. |
Usage notes
- Attention
- Customers should ensure that no personal data (other than for a User object), sensitive data, export-controlled data, or other regulated data is entered as metadata when using the Snowflake service. For more information, see Metadata fields in Snowflake.
- The size of the warehouse used to run the Cortex Search service source query does impact the speed and cost of each refresh. A larger warehouse decreases build and refresh time. However, during this preview, Snowflake recommends using a warehouse size no larger than MEDIUM for Cortex Search services.
- Snowflake recommends using a dedicated warehouse for each Cortex Search service so as to not interfere with other workloads.
- The search index is built as part of the create statement, which means the CREATE CORTEX SEARCH SERVICE statement may take longer to complete for larger datasets.
- When creating a multi-index search service, at least one column must be specified in the VECTOR INDEXES clause in order to ensure the highest quality of search results. Attempting to create a service with no vector indexes returns an error.
- A column can be specified in the TEXT INDEXES clause, the VECTOR INDEXES clause, or both: Columns specified as text indexes can be used for keyword (lexical) search. When querying a text index, results are scored based on the degree of lexical similarity.
- Columns specified as vector indexes can be used for vector (semantic) search. When querying a vector index, results are scored based on the degree of semantic similarity.
- Columns specified as both text and vector indexes are used for both types of search.
- Each vector index column employs one of three methods for managing embeddings: Managed vector embeddings: Snowflake calculates the vector embeddings when a text column is specified either in the ON or VECTOR INDEXES clauses. Must use one of the supported embedding models.
- User-provided vector embeddings: You are responsible for computing the vector embeddings with a Snowflake-provided vector embedding model or an externally hosted embedding model prior to ingestion by the Cortex Search Service, as well as for text inputs at query time.
- User-provided vector embeddings with managed query embeddings: You are responsible for computing the vector embeddings with one of the Snowflake-managed embedding models supported in Cortex Search prior to ingestion by the Cortex Search Service. At query time, Cortex Search will embed text queries using the specified query_model.
Access Control Requirements
Privilege | Object CREATE CORTEX SEARCH SERVICE | Schema in which you are creating the search service. SELECT | Tables and views that the service queries. USAGE | Warehouse that refreshes the service. Attention To create a Cortex Search Service, your role must have the required privileges to use the Cortex embedding functions. This requires granting the SNOWFLAKE.CORTEX_USER database role or the SNOWFLAKE.CORTEX_EMBED_USER database role to the service creator role.
Change Tracking Requirements
When creating a Cortex Search Service, if change tracking is not already enabled on the tables that it queries, Snowflake automatically attempts to enable change tracking on them. In order to support incremental refreshes, change tracking must be enabled with non-zero time travel retention on all underlying objects used by a Cortex Search Service. As base objects change, so does the Cortex Search Service. If you recreate a base object, you must re-enable change tracking. For more information about enabling change tracking, see Change tracking not enabled on base tables. Note For Cortex Search Services, the atomicity of CREATE OR REPLACE applies to the metadata transaction only. The search index for the new service is built after the transaction commits, so the previous service’s data is no longer available from the moment the statement commits until the new index finishes building. - The OR REPLACE and IF NOT EXISTS clauses are mutually exclusive. They can’t both be used in the same statement. - CREATE OR REPLACE <object> statements are atomic. That is, when an object is replaced, the old object is deleted and the new object is created in a single transaction.
Known gaps
- IF NOT EXISTS, OR REPLACE, PRIMARY KEY, REFRESH_MODE, INITIALIZE, FULL_INDEX_BUILD_INTERVAL_DAYS, REQUEST_LOGGING, AUTO_SUSPEND, COMMENT, REFRESH_MODE = FULL, REQUEST_LOGGING = TRUE are not exercised by any test