AlejandroMorgante opened a new pull request, #60311:
URL: https://github.com/apache/spark/pull/60311
### What changes were proposed in this pull request?
Prototype `pyspark.sql.ai.ai_query` as a column expression backed by an
iterator Pandas UDF. A model alias registered with `register_model` selects
either a Databricks Model Serving endpoint or an Amazon Bedrock model. The
branch also contains an optional agent adapter. Feedback is welcome on the
initial API surface, including whether to move agent support to a follow-up.
### Why are the changes needed?
Applications that summarize or classify text in a DataFrame currently need
to write their own UDF and provider integration. A common column API lets users
change the registered provider while keeping the DataFrame transformation the
same.
### Does this PR introduce _any_ user-facing change?
Yes. The prototype adds this PySpark API:
```python
from pyspark.sql.ai import ai_query, register_model
from pyspark.sql.functions import col, concat, lit
register_model("summarizer", "amazon.nova-micro-v1:0", provider="bedrock",
region="us-east-1")
df.withColumn(
"summary",
ai_query(
endpoint="summarizer",
request=concat(lit("Summarize in one sentence: "),
col("description")),
),
)
```
Null prompts produce null. Calls run on Python workers using the provider's
credentials. Spark task retries and repeated actions can make additional
billable calls.
### How was this patch tested?
- 19 unit tests passed, including a simulated Bedrock SDK call and an HTTP
test against a local server.
- `dev/ai_query_e2e.py` passed with Databricks Model Serving (GPT OSS 20B)
and Amazon Bedrock Converse (Nova Micro). Both runs used local Spark 4.3.0 with
the prototype installed on the driver and workers. Both plans used
`ArrowEvalPython` and both runs returned `APPLE`, `BANANA`, and null.
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: OpenAI Codex (GPT-6)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]