Aidp Ai Sql

作者 oracle-samples90b42d6c24d4無授權條款收錄於 2026年10月8日更新於 2026年10月8日

Run LLM functions inside Spark SQL on AIDP via ai_generate(). Use when the user wants to summarize/classify/extract/enrich rows with an LLM directly in SQL, generate narratives over aggregated results, or do grounded RAG-style analysis in the lakehouse. Signature is model-first; available models must be confirmed live before relying on it.

僅含說明Data & Analytics
AI 產生的概覽

透過 ai_generate() 在 AIDP 的 Spark SQL 中呼叫大型語言模型,對湖倉資料進行摘要、分類、擷取或敘述。

功能
此技能指導如何在 AIDP 的 Spark SQL 中直接呼叫大型語言模型,使用模型在前的 ai_generate(' ', ' ') 函式。內容涵蓋將提示詞建立在聚合或篩選後的查詢資料列上、以資料行運算式方式進行逐列增強,以及針對聚合結果產生敘述。互動式儲存格透過隨附的輔助指令碼 scripts/aidp_sql.py 執行,回傳包含狀態、輸出與 Spark 作業 ID 的 JSON。它也規定煙霧測試以及可靠性規則,例如限制資料列數量,並展示 AI 敘述背後的原始資料。
適用情境
適用於使用者希望在 SQL 中直接用大型語言模型對資料列進行摘要、分類、擷取或增強,或針對聚合後的湖倉結果產生有依據的敘述。也適用於在不離開 SQL 的情況下於湖倉內進行有依據的 RAG 式分析。
執行需求
需要具備 Spark 叢集的 AIDP 環境,以及隨附的輔助指令碼 scripts/aidp_sql.py;該指令碼會使用 api_key DEFAULT 設定檔取得 UPST,並自動建立臨時筆記本。需要提供 region、datalake OCID、workspace 與 cluster key 參數,並能存取 AIDP 控制平面網路。不需要 aidp MCP 或 AIDP_SESSION。可用模型名稱必須在目標叢集上即時確認。

aidp-ai-sql — LLM-in-SQL with ai_generate()

Call an LLM directly inside Spark SQL on AIDP — summarize, classify, extract, or narrate over lakehouse data without leaving SQL. A signature differentiator: most competitor agents can't do this inline.

This is a SQL-helper skill. Interactive Spark SQL runs through the bundled helper scripts/aidp_sql.py (it mints a UPST from the api_key DEFAULT profile, auto-creates a scratch notebook, and returns JSON). No aidp MCP and no AIDP_SESSION required.

When to use

  • "Summarize / classify / extract / enrich these rows with AI in SQL."
  • Generate a grounded narrative over an aggregate (e.g. a finance summary over a spend rollup).

Signature (model FIRST)

sql
ai_generate('<model>', '<prompt>')

e.g. ai_generate('openai.gpt-5.4', 'Summarize this supplier spend: ...').

LIVE-VERIFIED model-first (model, prompt) signature with openai.gpt-5.4, openai.gpt-4o, and xai.grok-4.

Verify before relying on it (no-fabrication): confirm the exact signature and the available model names live on the target cluster before treating this as guaranteed — run a trivial SELECT ai_generate('<model>', 'hello') cell first (see smoke test below). Model availability varies by environment. If a model name fails, list/ask for the correct one rather than guessing.

Don't gate on the /models REST catalog. ai_generate resolves the model at the Spark engine level, so it can work even when aidp-models-catalog's GET /models?modelType=GENERATIVE_AI returns an empty list. The smoke test (not the catalog endpoint) is the source of truth for whether ai_generate works.

How to run a cell

bash
python "$PLUGIN_DIR/scripts/aidp_sql.py" \  --region <region> --datalake <DATALAKE_OCID> --workspace <ws> --cluster <cluster-key> \  --code "<python/spark code>"

Returns JSON: {"status":"ok|error","outputs":[...],"spark_job_ids":[...]}. Exit 0 on success, 1 on cell error. See scripts/aidp_sql.py for full flags (--profile, --session-profile, --notebook, --timeout).

Smoke test (do this first)

bash
python "$PLUGIN_DIR/scripts/aidp_sql.py" --region <region> --datalake <ocid> --workspace <ws> --cluster <key> \  --code "spark.sql(\"SELECT ai_generate('openai.gpt-5.4', 'hello')\").show(truncate=False)"

Workflow (grounded RAG pattern)

  1. Ensure cluster RUNNING (cluster-ops via oci raw-request; see references/no-mcp-rest-map.md).
  2. Ground first: aggregate/select the rows you want the LLM to reason over (small, relevant set).
  3. Embed that grounded context into the prompt and call ai_generate('<model>', '<grounded prompt>'). For per-row enrichment, call it as a column expression over a bounded set.
  4. Present the generated text alongside the underlying data so the user can verify it.

Pass the cell to --code:

python
ctx = spark.sql("SELECT ... FROM gold.supplier_spend ...").toPandas().to_string()res = spark.sql(f"SELECT ai_generate('openai.gpt-5.4', 'As a finance analyst, summarize: {ctx}') AS summary")res.show(truncate=False)

Reliability rules

  • Always ground the prompt in real query output — don't ask the model to recall data it can't see.
  • Bound row counts for per-row ai_generate (cost + latency).
  • Show the data behind any AI narrative; never present generated numbers as ground truth without the SQL.

References

  • scripts/aidp_sql.py — the SQL/notebook-cell executor (bundled helper)
  • references/oci-raw-request.md — REST control-plane (clusters, auth)
  • references/no-mcp-rest-map.md · pairs with aidp-analyzing-data

來源與署名

來源:oracle-samples/oracle-aidp-samples位於ai/claude-code-plugins/oracle-ai-data-platform-workbench-engineer-agent/skills/aidp-ai-sql提交90b42d6

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架

更多來自 oracle-samples/oracle-aidp-samples 的技能

Aidp Workspace Admin

oracle-samples

Provision and inspect AIDP DataLake instances and workspaces, including private-network workspaces attached to a customer VCN/subnet. Use when the user wants to create/list/get a workspace or DataLake instance, set up a new (e.g. private) AIDP environment, or replicate a customer setup. Create/delete are guarded — confirm before any provisioning.

待分類2026年10月8日

Aidp Volumes

oracle-samples

Work with AIDP volumes — list volumes, browse files inside a volume, upload/download via the PAR flow, and create directories. Use when the user mentions volumes, needs to stage large/binary files, or move data in/out of a volume (distinct from the workspace filesystem). Control-plane via the official `aidp` CLI.

待分類2026年10月8日

Aidp Verified Queries

oracle-samples

維護經過驗證的問題到 Spark SQL 配對庫,讓代理在產生新 SQL 前優先重用可信查詢。

Data & Analytics2026年10月8日

Aidp User Settings

oracle-samples

透過 aidp CLI 或 oci raw-request 備援方式管理 AIDP DataLake 使用者設定與偏好。

Productivity & Workflow2026年10月8日

Aidp Spark Optimization

oracle-samples

指導 Apache Spark 3.5.0 效能調校:分割區、shuffle、join、資料傾斜、記憶體、檔案配置、AQE 與 Delta Lake。

Data & Analytics2026年10月8日

Aidp Semantic Model

oracle-samples

維護 .aidp/semantic.md 業務語意層,定義指標、連接、同義詞與值字典,為自然語言轉 SQL 提供依據。

Data & Analytics2026年10月8日