Cortex Search
Snowflake · Advanced Features
Theory
Cortex Search is a managed search service over text data in Snowflake. You create a CORTEX SEARCH SERVICE from a query: ON names the text column to search, ATTRIBUTES lists columns you can filter on, and TARGET_LAG sets how fresh the index must be. Snowflake embeds the text, builds the index on the warehouse you name and keeps it refreshed as the source changes.
Each search combines vector search for meaning, keyword search for exact terms and a semantic reranking step, so a question like "refund for damaged laptop" finds support transcripts even when they use different words. Results can be fetched from SQL with SEARCH_PREVIEW, or from the Python and REST APIs, and Cortex Search is the usual retrieval step for chatbots and Cortex Agents.
Why we use it
Building retrieval for a chatbot or search bar usually means running an embedding pipeline, a vector database and refresh jobs. Cortex Search does all of that inside Snowflake with one statement, under the same roles as the source table.
When to use it
Use it for retrieval-augmented generation (RAG), enterprise search over documents, tickets or notes, and as a tool for Cortex Agents. For exact lookups on structured columns use normal SQL or search optimization; for questions about numbers use Cortex Analyst.
How it works
- Text lives in a table, e.g. support_transcripts
- CREATE CORTEX SEARCH SERVICE ... ON transcript_text
- Snowflake embeds the text and builds the index on the warehouse
- Has the source changed beyond TARGET_LAG? Yes: Refresh the index with changed rows only. No: Keep serving the current index.
- Query runs vector plus keyword search, then reranks
- Top results go to the app, chatbot or agent
Example
CREATE OR REPLACE CORTEX SEARCH SERVICE transcript_search
ON transcript_text
ATTRIBUTES region
WAREHOUSE = cortex_search_wh
TARGET_LAG = '1 day'
AS (
SELECT transcript_text, region, agent_id
FROM support_transcripts
);
SELECT SNOWFLAKE.CORTEX.SEARCH_PREVIEW(
'support_db.public.transcript_search',
'{"query": "refund for damaged laptop", "columns": ["transcript_text", "region"],
"filter": {"@eq": {"region": "North"}}, "limit": 3}');Key points
- One CREATE CORTEX SEARCH SERVICE statement replaces an embedding and vector-index pipeline
- Hybrid retrieval: vector and keyword search plus reranking
- ATTRIBUTES columns can be used as filters in queries
- TARGET_LAG controls index freshness; unchanged data is not re-embedded
- Costs include warehouse refreshes, embedding tokens and serving per GB indexed
- Query with SEARCH_PREVIEW in SQL or the Python and REST APIs