Snowflake for Gen AI · Topic 2 of 13

Cortex Search for RAG and Unstructured Data

What Cortex Search is, how its hybrid search works, how to create a service, and how it powers RAG and unstructured data use cases in Snowflake.

  • 4 min
In a nutshell
  • Cortex Search is hybrid: vector plus keyword plus semantic reranking.
  • Key clauses: ON, ATTRIBUTES, WAREHOUSE, TARGET_LAG, EMBEDDING_MODEL.
  • Default embedding model is snowflake-arctic-embed-m-v1.5.

What it is

Cortex Search is a managed service for low latency "fuzzy" search over text in Snowflake. You point it at a table or query, and it builds and refreshes the indexes for you. Snowflake lists three uses: retrieval for RAG chatbots, enterprise search bars, and retrieval for Cortex Agents.

Each query is hybrid. It combines vector search (meaning), keyword search (exact terms) and a semantic reranking of the top results. That is why it finds a paragraph that never uses the words in the question.

Source tabletext columnindexed byCortex Searchservicehybrid queryRanked resultstext and attributes

How it works

Why hybrid matters

Keyword search alone misses paraphrases, and vector search alone can miss exact product codes or names. Combining them, then reranking the top results, gives better answers for both kinds of query. This is why a service is usually a better retrieval layer for RAG than a plain LIKE query or a hand built vector column. You still choose the text column, the attributes and the refresh lag, but Snowflake manages the embeddings and indexes.

Creating a service

CREATE OR REPLACE CORTEX SEARCH SERVICE docs_search
  ON chunk_text
  ATTRIBUTES region, doc_type
  WAREHOUSE = search_wh
  TARGET_LAG = '1 hour'
  EMBEDDING_MODEL = 'snowflake-arctic-embed-l-v2.0'
AS (SELECT chunk_text, region, doc_type, doc_url FROM doc_chunks);
ClauseMeaning
ONThe text column that is searched
ATTRIBUTESColumns that can be returned and used as filters
WAREHOUSEWarehouse that builds and refreshes the service; the docs advise a dedicated warehouse no larger than MEDIUM
TARGET_LAGHow far the service may trail the base data
EMBEDDING_MODELHosted embedding model; the default is snowflake-arctic-embed-m-v1.5
ASThe source query

Change tracking must be enabled on the source data, and the source query must follow dynamic table restrictions. Services cannot be cloned, and a base table must not be modified or dropped while the service depends on it.

Privileges

Creating needs the SNOWFLAKE.CORTEX_USER or SNOWFLAKE.CORTEX_EMBED_USER database role, CREATE CORTEX SEARCH SERVICE on the schema, SELECT on the source and USAGE on the warehouse. Querying needs USAGE on the service, its database and its schema. Suspending and resuming needs OPERATE on the service.

Watch out

A service runs with owner's rights. A role with USAGE on the service can read indexed data even without SELECT on the source table. Use attribute filters and careful grants when different audiences share a service.

RAG use case

Retrieval Augmented Generation answers from your documents instead of the model's memory. The search service finds the passages, and an LLM writes the answer from them.

User questionCortex Searchretrieve top chunksPromptquestion plus chunksAI_COMPLETELLMGrounded answerwith source

RAG is the right choice when knowledge changes often, is private, or must be cited. It avoids fine-tuning and keeps answers current as the table refreshes. Including a doc_url style attribute lets the application show the source.

Unstructured data use case

Unstructured data (PDF, Word, web pages, transcripts) must become text before it can be searched. The usual chain parses the file, splits it into chunks and indexes the chunks.

StagePDF filesparseAI_PARSE_DOCUMENTtext or layoutchunkChunk tableone row per passageindexCortex Searchservice

Chunk size matters. The embedding models behind Cortex Search have limited context windows, so short focused passages retrieve better than whole documents. Use a chunk table with one passage per row and keep metadata columns (file name, section, date) as attributes so users can filter.

Cortex Search suits text and documents. For numbers in tables and "how many" questions, use Cortex Analyst instead.

Common mistakes

Using Cortex Search for aggregation. Totals and averages need SQL, so Cortex Analyst is the fit.

Indexing whole documents as one row. Retrieval quality drops; chunk first.

Forgetting attributes. A column that is not in ATTRIBUTES cannot be used as a filter.

Sizing the warehouse too large. The docs recommend a dedicated warehouse no larger than MEDIUM.

Assuming SELECT on the source is needed to query. Querying needs USAGE on the service, database and schema.

What to remember for the exam

  • Cortex Search is hybrid: vector plus keyword plus semantic reranking.
  • Key clauses: ON, ATTRIBUTES, WAREHOUSE, TARGET_LAG, EMBEDDING_MODEL.
  • Default embedding model is snowflake-arctic-embed-m-v1.5.
  • Query privilege is USAGE on service, database and schema; services run with owner's rights.
  • RAG = retrieve with Search, then generate with AI_COMPLETE.
  • Unstructured pipeline: parse, chunk, index.

Check yourself

  • Why use Cortex Search for RAG instead of fine-tuning?

    It retrieves current, private passages and can cite them, while fine-tuning does not reliably add facts.

  • Which clause makes a column usable as a filter?

    ATTRIBUTES.

  • What must happen to PDFs before they can be searched?

    They must be parsed to text and split into chunks, then indexed.

Topic 2 of 13 in Snowflake for Gen AI

Test yourself on Snowflake for Gen AI

The full Snowflake GES-C02 question bank has 585 questions, with timed practice exams and an explanation for every answer.

This study guide is independent and is not affiliated with, endorsed by, or sponsored by Snowflake. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.