使用 AI/LLM 从文档列提取结构化数据。
有关相应的 Databricks SQL 函数,请参阅 ai_extract 函数。
Syntax
from pyspark.sql import functions as dbf
dbf.ai_extract(col=<col>, schema=<schema>, options=<options>)
Parameters
| 参数 | 类型 | 说明 |
|---|---|---|
col |
pyspark.sql.Column 或 str |
包含要从中提取的文档内容的列。 |
schema |
dict 或 list |
Python听写(字段名称为{"type": ..., "description": ...})或字段名称字符串列表。 自动序列化为 JSON 文本。 |
options |
dict自选 |
用于控制提取行为的选项字典。 |
Returns
pyspark.sql.Column:包含提取字段的 VariantType 的新列。
示例
df.select(ai_extract("text", {"name": {"type": "string", "description": "Name"}}))
df.select(ai_extract("text", ["name", "age"]))