Skip to content

Add missing AISQL function wrappers: ai_count_tokens, ai_multi_embed, ai_redact#4261

Open
sfc-gh-yixie wants to merge 1 commit into
mainfrom
feature/aisql-function-wrappers
Open

Add missing AISQL function wrappers: ai_count_tokens, ai_multi_embed, ai_redact#4261
sfc-gh-yixie wants to merge 1 commit into
mainfrom
feature/aisql-function-wrappers

Conversation

@sfc-gh-yixie

Copy link
Copy Markdown
Collaborator

Summary

  • Added three missing AISQL function wrappers to snowflake.snowpark.functions: ai_count_tokens, ai_multi_embed, and ai_redact
  • Added corresponding DataFrame.ai.multi_embed and DataFrame.ai.redact high-level DataFrame methods
  • Fixed DataFrame.ai.count_tokens to call the new AI_COUNT_TOKENS SQL function instead of the deprecated SNOWFLAKE.CORTEX.COUNT_TOKENS
  • Added DataframeAiMultiEmbed and DataframeAiRedact proto messages to ast.proto and regenerated ast_pb2.py

Motivation

Snowflake now exposes 15 AI_* functions. Prior to this PR, the Snowpark Python client was missing three of them:

Function Status
AI_COUNT_TOKENS Missing standalone wrapper; DataFrame method used deprecated API
AI_MULTI_EMBED Missing entirely
AI_REDACT Missing entirely

Test plan

  • test_ai_count_tokens_basic — verifies ai_count_tokens returns a positive integer
  • test_ai_count_tokens_no_model — verifies functions that don't require a model
  • test_ai_count_tokens_column_input — verifies column references and relative token counts
  • test_ai_redact_basic — verifies PII placeholders appear in output
  • test_ai_redact_with_categories — verifies category-scoped redaction
  • test_ai_redact_detect_mode — verifies span metadata returned in detect mode
  • test_ai_redact_column_input — verifies column references
  • test_dataframe_ai_redact_basic / _detect_mode / _with_categories / _default_output_column
  • test_ai_multi_embed_basic — verifies embedding object structure
  • test_dataframe_ai_multi_embed_basic / _default_output_column

🤖 Generated with Claude Code

…ti_embed, ai_redact)

- Add standalone `ai_count_tokens`, `ai_multi_embed`, and `ai_redact` to `functions.py`
- Add `DataFrame.ai.multi_embed` and `DataFrame.ai.redact` DataFrame methods
- Fix `DataFrame.ai.count_tokens` to use new `AI_COUNT_TOKENS` instead of deprecated `SNOWFLAKE.CORTEX.COUNT_TOKENS`
- Add `DataframeAiMultiEmbed` and `DataframeAiRedact` proto messages; regenerate `ast_pb2.py`
- Add integration tests for all new functions

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant