Snowflake Cortex AI Rules
## what it does
tl;dr: pull snowflake-cortex-ai-cursorrules-prompt-file.mdc from awesome-cursorrules before writing Cortex queries in a Cursor project. Models reach for deprecated names like COMPLETE and CLASSIFY_TEXT, which 404 in current Snowflake.
What it does
This rule set configures Cursor to use Snowflake Cortex AI the way it ships today: SQL-callable AI Functions with the AI_* prefix, Cortex Search for managed hybrid (vector + keyword) retrieval, and the standard RAG pattern (search → context → AI_COMPLETE). Without it, models default to deprecated function names, hardcode model IDs that aren’t deployed in the user’s region, and row-by-row feed tables into prompts.
Sourced from PatrickJS/awesome-cursorrules — the community registry for .mdc Project Rules.
The rules
// Available Functions (use these names — they are the current versions):
// AI_COMPLETE — General-purpose LLM completion (text, images, documents).
// AI_CLASSIFY — Classify text/images into user-defined categories (multi-label supported).
// AI_FILTER — Returns TRUE/FALSE for text/image input. Use in WHERE clauses.
// AI_AGG — Aggregate insights across rows of text (no context window limit).
// AI_EMBED — Generate embedding vectors (similarity search, clustering).
// AI_EXTRACT — Extract structured info from text, images, or documents.
// AI_SENTIMENT — Sentiment score from text (-1 to 1).
// AI_SUMMARIZE_AGG — Summarize across rows (no context window limit).
// AI_SIMILARITY — Embedding similarity between two inputs.
// AI_TRANSCRIBE — Transcribe audio/video from stages.
// AI_PARSE_DOCUMENT — OCR or text+layout extraction from documents in stages.
// AI_REDACT — Redact PII from text.
// AI_TRANSLATE — Translate between supported languages.
// Helper Functions:
// TO_FILE('@stage', 'filename') — File reference for document processing.
// AI_COUNT_TOKENS(model, text) — Check token count before calling a model.
// PROMPT('template {0}', arg) — Build prompt objects for AI_COMPLETE.
// TRY_COMPLETE — Returns NULL on failure instead of error.
// Privileges: USE AI FUNCTIONS account privilege + SNOWFLAKE.CORTEX_USER database role.
// Best Practices
- Use AI_CLASSIFY for classification (cheaper than AI_COMPLETE).
- Check token counts with AI_COUNT_TOKENS before large batch jobs.
- Set PRIMARY KEY on Cortex Search for optimized incremental refresh.
- Use ATTRIBUTES for filterable columns. Use SEARCH_PREVIEW for testing, Python/REST for production.
- Use dedicated warehouse (no larger than MEDIUM) per search service.
// Anti-Patterns
- Do NOT use old function names (COMPLETE, CLASSIFY_TEXT, etc.) — use AI_* versions.
- Do NOT pass entire tables through AI_COMPLETE row-by-row without cost estimation.
- Do NOT hardcode model names without considering regional availability.
Installation
Drop the .mdc into .cursor/rules/ of your project:
mkdir -p .cursor/rules
curl -sL \
https://raw.githubusercontent.com/PatrickJS/awesome-cursorrules/main/rules/snowflake-cortex-ai-cursorrules-prompt-file.mdc \
-o .cursor/rules/snowflake-cortex-ai.mdc
Cursor picks up files in .cursor/rules/ automatically.
AI_COMPLETE — text and documents
-- Text completion
SELECT AI_COMPLETE(
MODEL => 'claude-4-sonnet',
PROMPT => 'Summarize: ' || review_text
) AS summary
FROM reviews;
-- Document processing (PDF in stage)
SELECT AI_COMPLETE(
MODEL => 'claude-4-sonnet',
PROMPT => PROMPT('Extract the invoice total from {0}', TO_FILE('@docs', 'invoice.pdf'))
) AS total
FROM @docs;
Cortex Search — single index
CREATE OR REPLACE CORTEX SEARCH SERVICE my_search
ON transcript_text
ATTRIBUTES region, agent_id
WAREHOUSE = my_wh
TARGET_LAG = '1 day'
EMBEDDING_MODEL = 'snowflake-arctic-embed-l-v2.0'
AS (SELECT transcript_text, region, agent_id FROM support_transcripts);
RAG pattern (Python)
from snowflake.core import Root
root = Root(session)
service = root.databases["db"].schemas["schema"].cortex_search_services["my_search"]
results = service.search(
query="internet connection issues",
columns=["transcript_text", "region"],
filter={"@eq": {"region": "North America"}},
limit=5,
)
context = "\n\n".join(r["transcript_text"] for r in results)
answer = session.sql(
"SELECT AI_COMPLETE(MODEL => 'claude-4-sonnet', "
"PROMPT => 'Answer from context: ' || :1 || ' Q: ' || :2)"
).bind((context, question)).collect()
Why it helps
Without Cortex-aware rules, models will:
- Call deprecated
COMPLETE/CLASSIFY_TEXT— these no longer exist in current Snowflake - Skip
AI_COUNT_TOKENSand run a 50k-row batch that blows the warehouse budget - Hardcode
claude-4-opusin a region where onlyclaude-sonnet-4-5is deployed - Run
AI_COMPLETErow-by-row withoutAI_AGG/AI_SUMMARIZE_AGGfor cross-row aggregations - Skip
PRIMARY KEYon Cortex Search, slowing incremental refresh
These rules keep Cortex queries on the supported function surface and budget-aware.
Gotchas
- These are Cursor
.mdcrules, not a Claude CodeCLAUDE.mdfile. For Claude Code, paraphrase into your project’sCLAUDE.md. - The rule list quotes the current model roster from the fetched
.mdc— verify model availability per region before shipping. - Cortex Search Python API needs the
snowflake-core-pythonpackage; REST hits/api/v2/databases/<db>/schemas/<schema>/cortex-search-services/<service>:query.
Related
- TanStack Query v5 Rules — client-side caching layer for Cortex RAG answers in a React UI
- React Router v7 Rules — route loaders can call the Cortex REST API to prefetch RAG context
## embed this badge
