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 |
検索フロー:
[ユーザークエリ: "Snowflakeのデータ保護機能"]
│
├──→ キーワード検索 ──→ BM25スコア
│ └─ "Snowflake", "データ", "保護" で転置インデックスを走査
│
├──→ セマンティック検索 ──→ ベクトル類似度スコア
│ └─ クエリをエンベディング化 → 近似近傍探索
│
└──→ スコア融合(Reciprocal Rank Fusion)
└─ 最終ランキング結果を返却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 -- 検索対象のテキストカラム
ATTRIBUTES doc_title, category -- フィルタ用カラム(任意)
WAREHOUSE = search_wh -- インデックス構築用WH
TARGET_LAG = '1 hour' -- ソースデータの反映遅延
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.
# 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="Snowflakeのタイムトラベル機能について",
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.
# 完全一致
{"@eq": {"category": "security"}}
# OR条件(複数値)
{"@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パイプライン構成:
[ユーザー質問]
│
▼
[Cortex Search] ← リトリーバ
│ 関連ドキュメント Top-K を取得
▼
[プロンプト構築]
│ "以下のコンテキストに基づいて回答してください:
│ {検索結果のdoc_content}"
▼
[SNOWFLAKE.CORTEX.COMPLETE()] ← ジェネレータ
│ コンテキスト付きで回答を生成
▼
[回答をユーザーに返却]# RAGパイプラインの実装例(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("質問を入力してください")
if user_question:
# Step 1: 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: COMPLETE関数で回答生成
prompt = f"""以下のコンテキストのみに基づいて質問に回答してください。
コンテキストに情報がない場合は「情報が見つかりませんでした」と回答してください。
コンテキスト:
{context}
質問: {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
問題 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?
正解: 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
無料で問題を解いてみる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.
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...