Snowflake

Snowflake Cortex Search Deep Dive: Hybrid Search and RAG Patterns

2026-03-21
Updated: 2026-03-27
NicheeLab Editorial Team

Snowflake Cortex Search delivers hybrid retrieval — fusing keyword and semantic search — as a fully managed service. Embedding generation, index building, and score fusion are all automated, so you only need a single CREATE CORTEX SEARCH SERVICE statement to add high-quality search to your application. Used as a Retrieval-Augmented Generation (RAG) retriever, it pairs cleanly with Cortex LLM functions to power internal document Q&A systems.

The hybrid search behind Cortex Search internally blends two complementary retrieval techniques.

Retrieval styleTechniqueStrengthsWeaknesses
Keyword (sparse)BM25-based inverted indexStrong on exact matches and proper nounsWeak on synonyms and paraphrasing
Semantic (dense)Vector embeddings with approximate nearest-neighbor searchStrong on semantic similarityWeak on exact proper nouns and model numbers
Hybrid (Cortex Search)Fuses both scoresCombines precision with semantic understandingHigher indexing cost
Search flow:

[User query: "Snowflake data protection features"]
       │
       ├──→ keyword search ──→ BM25 score
       │     └─ scans the inverted index for "Snowflake", "data", "protection"
       │
       ├──→ semantic search ──→ vector similarity score
       │     └─ embeds the query -> approximate nearest neighbour search
       │
       └──→ score fusion (Reciprocal Rank Fusion)
              └─ returns the final ranking

CREATE CORTEX SEARCH SERVICE

You create a Cortex Search service with DDL, specifying the source table, the column to search, optional filter columns, and the refresh cadence.

CREATE OR REPLACE CORTEX SEARCH SERVICE knowledge_base_search
  ON doc_content                    -- the text column to search
  ATTRIBUTES doc_title, category    -- columns available for filtering (optional)
  WAREHOUSE = search_wh             -- warehouse used to build the index
  TARGET_LAG = '1 hour'             -- how far behind the source data may be
AS (
  SELECT
    doc_id,
    doc_title,
    doc_content,
    category,
    updated_at
  FROM knowledge_base
  WHERE is_published = TRUE
);

Key Parameters

ParameterDescriptionRequired
ONText column targeted by both full-text and semantic searchYes
ATTRIBUTESColumns available for metadata filtering (used in WHERE-style conditions)No
WAREHOUSEWarehouse used to build the indexYes
TARGET_LAGMaximum delay before source-table changes appear in the indexYes

Running Search Queries

You query a Cortex Search service through the Python SDK (recommended) or the REST API.

# Searching from the Python SDK
from snowflake.core import Root

root = Root(session)

search_service = (
    root.databases["MY_DB"]
    .schemas["PUBLIC"]
    .cortex_search_services["KNOWLEDGE_BASE_SEARCH"]
)

results = search_service.search(
    query="About Snowflake's Time Travel feature",
    columns=["doc_id", "doc_title", "doc_content", "category"],
    filter={
        "@eq": {"category": "data_protection"}
    },
    limit=5
)

for result in results.results:
    print(f"Title: {result['doc_title']}")
    print(f"Score: {result['search_score']}")
    print(f"Content: {result['doc_content'][:200]}...")
    print("---")

Filter Syntax

The following filter operators are available on columns listed in ATTRIBUTES.

# Exact match
{"@eq": {"category": "security"}}

# OR (multiple values)
{"@or": [
  {"@eq": {"category": "security"}},
  {"@eq": {"category": "governance"}}
]}

# AND
{"@and": [
  {"@eq": {"category": "security"}},
  {"@eq": {"doc_type": "guide"}}
]}

Using Cortex Search as a RAG Retriever

By wiring Cortex Search as the retriever in front of Cortex LLM functions, you can build a RAG pipeline grounded in your internal knowledge base.

RAG pipeline:

[User question]
       │
       ▼
[Cortex Search]  <- retriever
       │ retrieve the Top-K related documents
       ▼
[Build the prompt]
       │ "Answer based on the following context:
       │  {doc_content from the search results}"
       ▼
[SNOWFLAKE.CORTEX.COMPLETE()]  <- generator
       │ generate the answer with the context attached
       ▼
[Return the answer to the user]
# Example RAG pipeline (Streamlit in Snowflake)
import streamlit as st
from snowflake.core import Root
from snowflake.snowpark.context import get_active_session

session = get_active_session()
root = Root(session)

search_service = (
    root.databases["KB_DB"]
    .schemas["PUBLIC"]
    .cortex_search_services["KB_SEARCH"]
)

user_question = st.text_input("Enter your question")

if user_question:
    # Step 1: retrieve related documents with Cortex Search
    results = search_service.search(
        query=user_question,
        columns=["doc_content"],
        limit=3
    )

    context = "\n\n".join([r["doc_content"] for r in results.results])

    # Step 2: generate the answer with the COMPLETE function
    prompt = f"""Answer the question using only the context below.
If the context does not contain the information, answer \"I could not find that information\".

Context:
{context}

Question: {user_question}"""

    answer = session.sql(
        "SELECT SNOWFLAKE.CORTEX.COMPLETE('llama3.1-70b', ?)",
        params=[prompt]
    ).collect()[0][0]

    st.write(answer)

Cost Model

  • Index build: consumes credits on the warehouse you specify
  • Incremental index refresh: consumes serverless credits, scaled to TARGET_LAG
  • Search query execution: consumes serverless credits (no warehouse needed)
  • Storage: standard storage charges apply to the index data

Cortex Search vs. Other Approaches

ApproachRetrieval styleEmbedding managementBest-fit use case
Cortex SearchHybrid (automatic)AutomaticRAG retrievers and document search
VECTOR type + distance functionsSemantic onlyManualCustom embeddings and image search
SEARCH OPTIMIZATIONKeyword only (point-lookup optimization)Not neededSpeeding up equality and LIKE lookups

Exam Prep Highlights

  • Cortex Search is a hybrid keyword + semantic search service
  • CREATE CORTEX SEARCH SERVICE specifies ON (search target) and TARGET_LAG (refresh cadence)
  • Search queries run on serverless compute — no warehouse required
  • Columns listed in ATTRIBUTES are usable for metadata filtering
  • In RAG pipelines, pair it as the retriever with the COMPLETE function
  • Understand how it differs from manual vector search built on the VECTOR type

Sample Question

Cortex Search

Question 1

In the SQL statement that creates a Cortex Search service, which parameter controls the maximum delay before source-table changes appear in the search index?

  1. A. REFRESH_INTERVAL
  2. B. TARGET_LAG
  3. C. INDEX_SYNC_PERIOD
  4. D. UPDATE_FREQUENCY

Correct answer: B

The TARGET_LAG parameter on CREATE CORTEX SEARCH SERVICE sets the maximum delay before source-table changes are reflected in the index. For example, '1 hour' guarantees that changes show up within at most one hour. A, C, and D are not real Cortex Search parameters.

Frequently Asked Questions

What is hybrid search in Cortex Search?

Hybrid search combines traditional keyword matching (sparse retrieval such as BM25) with vector-based semantic search (dense retrieval). Cortex Search fuses the two scores internally and returns results that balance keyword precision with semantic relevance. You don't have to tune the fusion weights yourself.

What is the difference between Cortex Search and vector search?

Cortex Search is a managed service purpose-built for hybrid search over text data — indexing, embedding generation, and score fusion are all automated. Snowflake's VECTOR data type and functions like VECTOR_L2_DISTANCE, on the other hand, are low-level APIs where you generate and store embeddings yourself and write the similarity logic by hand. For a RAG retriever, Cortex Search is much faster to build.

When are data updates reflected in a Cortex Search index?

You set the TARGET_LAG parameter when running CREATE CORTEX SEARCH SERVICE. For example, '1 hour' guarantees that source-table changes show up in the index within at most one hour. Shorter TARGET_LAG values give you fresher results but burn more serverless credits.

Check what you learned with practice questions

Practice with certification-focused question sets

Try free questions
Author

NicheeLab Editorial Team

NicheeLab editorial team focused on data engineering and cloud certification learning. Content is structured around practical study needs and official exam domains.


Related articles
Snowflake

Snowflake Certifications: All 11 Exams Explained (2026)

Every SnowPro certification — Associate, Core, Specialty, Ad...

Snowflake

Snowflake Exam Difficulty Ranking: All 11 Certs Compared (2026)

All 11 SnowPro exams ranked by difficulty with study-time es...

Snowflake

Snowflake Study Guide: Fastest Pass Route by Exam (2026)

How to pass SnowPro certifications efficiently — official ma...

Snowflake

SnowPro Core (COF-C03): Complete Exam Guide (2026)

Pass the SnowPro Core exam — six domains, scope, sample ques...

Snowflake

SnowPro Associate Platform (SOL-C01): Complete Guide (2026)

The entry-level SnowPro Associate exam — scope, weighting, s...

Browse all Snowflake articles (103)
© 2026 NicheeLab All rights reserved.