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 style | Technique | Strengths | Weaknesses |
|---|---|---|---|
| Keyword (sparse) | BM25-based inverted index | Strong on exact matches and proper nouns | Weak on synonyms and paraphrasing |
| Semantic (dense) | Vector embeddings with approximate nearest-neighbor search | Strong on semantic similarity | Weak on exact proper nouns and model numbers |
| Hybrid (Cortex Search) | Fuses both scores | Combines precision with semantic understanding | Higher 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 rankingYou 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
);| Parameter | Description | Required |
|---|---|---|
| ON | Text column targeted by both full-text and semantic search | Yes |
| ATTRIBUTES | Columns available for metadata filtering (used in WHERE-style conditions) | No |
| WAREHOUSE | Warehouse used to build the index | Yes |
| TARGET_LAG | Maximum delay before source-table changes appear in the index | Yes |
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("---")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"}}
]}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)| Approach | Retrieval style | Embedding management | Best-fit use case |
|---|---|---|---|
| Cortex Search | Hybrid (automatic) | Automatic | RAG retrievers and document search |
| VECTOR type + distance functions | Semantic only | Manual | Custom embeddings and image search |
| SEARCH OPTIMIZATION | Keyword only (point-lookup optimization) | Not needed | Speeding up equality and LIKE lookups |
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?
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.
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.
Practice with certification-focused question sets
Try free questionsNicheeLab Editorial Team
NicheeLab editorial team focused on data engineering and cloud certification learning. Content is structured around practical study needs and official exam domains.
Snowflake Certifications: All 11 Exams Explained (2026)
Every SnowPro certification — Associate, Core, Specialty, Ad...
Snowflake Exam Difficulty Ranking: All 11 Certs Compared (2026)
All 11 SnowPro exams ranked by difficulty with study-time es...
Snowflake Study Guide: Fastest Pass Route by Exam (2026)
How to pass SnowPro certifications efficiently — official ma...
SnowPro Core (COF-C03): Complete Exam Guide (2026)
Pass the SnowPro Core exam — six domains, scope, sample ques...
SnowPro Associate Platform (SOL-C01): Complete Guide (2026)
The entry-level SnowPro Associate exam — scope, weighting, s...