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

  1. Text lives in a table, e.g. support_transcripts
  2. CREATE CORTEX SEARCH SERVICE ... ON transcript_text
  3. Snowflake embeds the text and builds the index on the warehouse
  4. Has the source changed beyond TARGET_LAG? Yes: Refresh the index with changed rows only. No: Keep serving the current index.
  5. Query runs vector plus keyword search, then reranks
  6. 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

Snowflake topics

Snowflake Fundamentals

Warehouses & Performance

Staging & SnowSQL

Tables & Data Handling

Cloud Integrations

Storage & Optimization

Security & Governance

Views, Pipelines & Automation

Data Types & SQL Fundamentals

Semi-Structured Data Deep Dive

Advanced Features

Data Sharing & Collaboration

Cost Management & Monitoring

Databases, Schemas & Objects

Performance Deep Dive

Advanced Security & Governance

Stored Procedures & UDFs

Ecosystem & Integrations

SnowPro Certification Prep

T
Tech Town
Log InSign Up Free
Home SQL Python DSA Power BI Snowflake Databricks Spark Gen AI Practice Problems Contest Blog

Mastering Snowflake

The modern data cloud, from architecture to SnowPro certification. Click any topic in the sidebar to open it right here.

{{ sectionCount }}
Sections
{{ topicCount }}
Topics
Free
Forever
Hands-on practice Practice Snowflake SQL Sharpen the SQL you use in Snowflake: 150 query problems in a live editor with instant checking. Start practising →
Section {{ sec.num }}

{{ sec.label }}

Snowflake  /  {{ current.sectionLabel }}  /  {{ current.name }}

{{ current.name }}

Theory

{{ current.def }}

Why we use it

{{ rich.why }}

When to use it

{{ rich.when }}

{{ sec.h }}

{{ sec.body }}

{{ sec.body }}

Diagram

{{ rich.dg.caption }}

{{ tb.title }}
{{ c.v }}
{{ rich.dg.op }}
➜
{{ rich.dg.output.title }}
{{ c.v }}
{{ nd.label }}
{{ nd.sub }}
{{ nd.label }}
{{ nd.sub }}
{{ rich.dg.left.title }}
{{ it }}
{{ rich.dg.right.title }}
{{ it }}
On screen — where to click

{{ rich.ui.title }}

{{ u.text }}
  1. {{ st.n }}{{ st.text }}
{{ rich.ui.title }}
{{ u.text }}
Flowchart — how it works
{{ nd.text }}
{{ nd.text }}
◇ {{ nd.text }}
Yes → {{ nd.yes }}
No → {{ nd.no }}
Syntax
{{ current.syntax }}
Example
{{ current.example }}
Want to run this yourself? Unlike the SQL and Python courses, Snowflake needs a real account — there's no in-browser engine for it. Click Copy above, then paste it into a free Snowflake trial (30 days, no card required) and run it in Snowsight.
Key Points — click to check off as you learn
  • {{ pt.mark }} {{ pt.text }}

Share this topic