From d0985eae417a0b0e9c9526adffe0bf194183277b Mon Sep 17 00:00:00 2001 From: Madeleine Corneli Date: Mon, 6 Apr 2026 14:55:42 -0700 Subject: [PATCH 1/2] feat(gen-ai): add Gemma 4 sentiment classification example Add a worked example showing how to use Google's Gemma 4 (e4b) via Ollama for sentiment classification directly in SQL. Includes CONNECTION object, UDF, sample data, and expected output. Co-Authored-By: Claude Opus 4.6 (1M context) --- doc/gen_ai/ai_text_summary/index.rst | 87 +++++++++++++++++++++++++++- 1 file changed, 86 insertions(+), 1 deletion(-) diff --git a/doc/gen_ai/ai_text_summary/index.rst b/doc/gen_ai/ai_text_summary/index.rst index d9ec176..ae7c362 100644 --- a/doc/gen_ai/ai_text_summary/index.rst +++ b/doc/gen_ai/ai_text_summary/index.rst @@ -557,6 +557,90 @@ Explore Ollama's model library: # Smaller, faster models ollama pull phi3 +Example: Sentiment Classification with Gemma 4 +------------------------------------------------ + +Google's `Gemma 4 `_ works well for classification tasks and supports 140+ languages out of the box. The ``e4b`` variant (4.5B effective parameters, Apache 2.0 license) is a good fit for UDF workloads. + +Download the model: + +.. code-block:: bash + + ollama pull gemma4:e4b + +Create a CONNECTION object and a lightweight UDF: + +.. code-block:: sql + + -- Store the Ollama endpoint in a CONNECTION object + CREATE OR REPLACE CONNECTION OLLAMA_CONNECTION + TO 'http://YOUR_IP:11434'; + +.. code-block:: text + + CREATE OR REPLACE PYTHON3 SCALAR SCRIPT DEMO.OLLAMA_QUERY(prompt VARCHAR(10000)) + RETURNS VARCHAR(10000) AS + import json + import urllib.request + + def run(ctx): + conn = exa.get_connection('OLLAMA_CONNECTION') + payload = json.dumps({ + 'model': 'gemma4:e4b', + 'prompt': ctx.prompt, + 'stream': False + }).encode() + req = urllib.request.Request( + conn.address + '/api/generate', + data=payload, + headers={'Content-Type': 'application/json'} + ) + with urllib.request.urlopen(req, timeout=120) as resp: + return json.loads(resp.read())['response'] + / + +.. important:: + Replace ``YOUR_IP`` with your machine's IP address, as described in Step 4. + +Now classify sentiment directly in SQL: + +.. code-block:: sql + + CREATE OR REPLACE TABLE DEMO.FEEDBACK ( + id INTEGER, + text_val VARCHAR(1000) + ); + + INSERT INTO DEMO.FEEDBACK VALUES + (1, 'The dashboard loads fast now. Great improvement.'), + (2, 'Installation was very complicated. Documentation is outdated.'), + (3, 'Support responded in under an hour. Excellent service.'); + + SELECT id, + DEMO.OLLAMA_QUERY( + 'Classify sentiment as POSITIVE, NEGATIVE, or NEUTRAL. One word only. Text: ' + || text_val + ) AS sentiment + FROM DEMO.FEEDBACK + ORDER BY id; + +Expected output: + +.. list-table:: + :header-rows: 1 + :widths: 10 90 + + * - ID + - Sentiment + * - 1 + - POSITIVE + * - 2 + - NEGATIVE + * - 3 + - POSITIVE + +Gemma 4 handles multilingual input without translation or separate models. You can swap in German, Spanish, Japanese, or any of its 140+ supported languages and the same UDF works unchanged. + Optimize Performance -------------------- @@ -616,6 +700,7 @@ Resources * `Ollama GitHub `_ * `Ollama API Reference `_ * `Mistral AI Documentation `_ +* `Gemma 4 on Ollama `_ Feedback ======== @@ -624,4 +709,4 @@ Feedback --- -*Last updated: January 2026* \ No newline at end of file +*Last updated: April 2026* \ No newline at end of file From 70e9cc18ca135b3bdab5fd006f9279c5f88d5470 Mon Sep 17 00:00:00 2001 From: Madeleine Corneli Date: Mon, 6 Apr 2026 15:01:28 -0700 Subject: [PATCH 2/2] fix: correct Gemma 4 parameter count and language support figures E4B has 4B effective parameters (not 4.5B). Native language support is 35+ (not 140+, which is the pre-training data scope). Co-Authored-By: Claude Opus 4.6 (1M context) --- doc/gen_ai/ai_text_summary/index.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/gen_ai/ai_text_summary/index.rst b/doc/gen_ai/ai_text_summary/index.rst index ae7c362..f267bd5 100644 --- a/doc/gen_ai/ai_text_summary/index.rst +++ b/doc/gen_ai/ai_text_summary/index.rst @@ -560,7 +560,7 @@ Explore Ollama's model library: Example: Sentiment Classification with Gemma 4 ------------------------------------------------ -Google's `Gemma 4 `_ works well for classification tasks and supports 140+ languages out of the box. The ``e4b`` variant (4.5B effective parameters, Apache 2.0 license) is a good fit for UDF workloads. +Google's `Gemma 4 `_ works well for classification tasks and supports 35+ languages out of the box. The ``e4b`` variant (4B effective parameters, Apache 2.0 license) is a good fit for UDF workloads. Download the model: @@ -639,7 +639,7 @@ Expected output: * - 3 - POSITIVE -Gemma 4 handles multilingual input without translation or separate models. You can swap in German, Spanish, Japanese, or any of its 140+ supported languages and the same UDF works unchanged. +Gemma 4 handles multilingual input without translation or separate models. You can swap in German, Spanish, Japanese, or any of its 35+ natively supported languages and the same UDF works unchanged. Optimize Performance --------------------