Palantir Foundry:
从一堆文件到 Ontology,
到底发生了什么?
拆解 Foundry 数据集成的完整链路——从原始文件落地,到结构化清洗,到 Ontology 建模。用航空运营场景贯穿始终,所有技术细节标注官方出处。
多数 Palantir 的分析文章从 Ontology 讲起,告诉你"它是组织的数字孪生",然后就直接跳到 AIP Agent。但中间那段——一堆散乱的文件是怎么变成可操作的 Ontology 对象的——很少有人完整拆解。
这条链路才是 Palantir 真正的基本功。如果你不理解 pipeline,就无法判断 Ontology 的能力边界和部署成本。
全链路:五个阶段
我们用一个航空公司运营系统的场景来走这条链路。假设你是某航空公司的数字化负责人,手上有三类数据:结构化的航班运营 CSV、半结构化的乘客预订 JSON、非结构化的维修报告 PDF。
Foundry 的第一原则是 as-is ingestion——数据从源系统拉进来时不做任何预处理。
"Foundry is also distinguished by a philosophy that data should be ingested 'as-is' from its most raw source, with no external preprocessing."— Data Connection Overview, Palantir Docs
为什么?因为一旦所有变换都在 Foundry 内部完成,从 Ontology 的任何一个 property value,都能顺着 pipeline 一路追溯到原始文件的某一行。这就是 end-to-end data lineage。
连接方式:通过 200+ 种连接器对接外部系统(数据库、ERP、API、文件系统、IoT 流),通过 Batch Sync(全量 SNAPSHOT 或增量 APPEND)将数据拉入 Foundry。
在深入 pipeline 之前,有必要先理解 Foundry 里"数据"到底是怎么存的——这直接决定了后续 pipeline 能对它做什么操作。
Dataset:Foundry 的核心存储抽象
在 Foundry 里,Dataset 不是一张表,而是一个版本化的文件容器。它可以承载三类数据:
"Datasets are used to store and represent all types of data—structured, unstructured, and semi-structured: Structured (tabular) data consists of files in an open-source format such as Parquet, along with metadata about the columns. Unstructured datasets consist of files such as images, video, or PDFs, but do not have an associated schema. Semi-structured datasets contain file formats such as XML or JSON."— Core Concepts: Datasets, Palantir Docs
| 形态 | 存储格式 | Schema | 航空场景 |
|---|---|---|---|
| 结构化 | Parquet 文件 + schema 元数据 | 有(列名 + 类型) | raw_flight_operations |
| 半结构化 | JSON / XML 原始文件 | 可推断,建议下游处理 | raw_passenger_bookings |
| 非结构化 | 原始二进制文件 | 无(unstructured dataset) | 可存,但缺乏媒体处理工作流支持 |
Dataset 的每次变更都是一个原子性 Transaction,类比 Git 的 commit。四种事务类型:SNAPSHOT(全量替换当前视图)、APPEND(增量追加)、UPDATE(更新)、DELETE(删除)。这就是 Palantir 所说的 "Git for Data"——任何中间步骤出问题,都可以回溯到历史版本。
Media Set:面向媒体处理工作流的专用抽象
Dataset 技术上可以存非结构化文件,但在面向大规模文档、图片、音视频处理的场景下,工程实践中通常使用 Media Set——因为它在 Dataset 的存储基础之上,专门提供了 media item 管理、media reference 关联、媒体格式转换、以及后续 AI 提取工作流(Document Intelligence)的集成支持。
"A media set is a collection of media files with a common schema, for example, files of the same format. Media sets are designed to work with high-scale, unstructured data and enable the processing of media items such as audio, imagery, video, and documents."— Core Concepts: Media Sets, Palantir Docs
Media Set 有两个关键属性:
Schema Type(文件类别)——定义这个 Media Set 存什么类型的文件:document、image、audio、video、spreadsheet、dicom、email。创建时必须选定,之后只接受匹配类型的文件上传。
Primary Format(主格式)——指定文件的标准格式(如 PDF、PNG、MP4)。你也可以设定 additional input formats,上传时会自动转换为主格式。
Media Set 里的每个文件叫 Media Item,有唯一的 media_item_rid。关键设计是 Media Reference——你可以在 tabular dataset 里用一个特殊列引用 media item,把非结构化内容和结构化元数据关联起来:
"You can use media references to reference media set items in datasets. This is useful for associating media items with metadata or other information in a tabular format. For example, you can associate the original PDF with its file name, page count, and extracted text as additional columns."— Media Sets Overview, Palantir Docs
航空场景:维修报告 PDF 存储在一个 schema type 为 document、primary format 为 PDF 的 Media Set 里。后续 pipeline 提取出的结构化信息(报告编号、维修日期、零件列表等)存为普通 Dataset,通过 media_reference 列指向原始 PDF。
目标:将所有数据统一变换为有 schema 的 tabular dataset。Foundry 提供两个主要的 pipeline 构建工具:
Pipeline Builder——低代码/无代码的可视化界面,拖拽式构建数据变换。两种操作类型:expressions(输入列→输出单列,如字符串拆分、类型转换)和 transforms(输入表→输出表,如 Filter、Pivot、Aggregate、Join)。
"Pipeline Builder uses a general model for describing data transformations. This backend is an intermediate layer between the tools used to write transformations and the execution of said transformations."— Pipeline Builder Overview, Palantir Docs
Code Repositories——用 Python(PySpark)或 Java 写 transform 代码。用 @transform_df 装饰器声明输入输出,返回 DataFrame 自动写入 output dataset。
根据数据类型,pipeline 走不同的路径:
路径 A:结构化数据 → Schema 自动推断 + 清洗
这是最简单的路径。CSV 或 JSON 文件已经是表格格式,Foundry 可以直接推断 schema:
"Foundry allows you to manually add a schema to datasets containing CSV or JSON files by selecting the Apply a schema button in the dataset. The Apply a schema button will automatically infer the schema based on a subset of the data."— Infer a schema, Palantir Docs
Schema 应用后,你可以进一步修改列类型、丢弃格式异常的行、添加额外列(如文件路径、导入时间戳、行号等)。
航空场景实例:航班运营数据清洗
假设 raw_flight_operations 是从 Oracle DB 同步过来的 CSV,包含 flight_id, tail_number, origin, destination, departure_time, status 等列。Pipeline 需要做的:
在 Pipeline Builder 中(无代码):选择 raw dataset 作为 Input → Apply schema(自动推断 departure_time 为 Timestamp 类型)→ Filter transform 过滤 status 不为 null 的行 → Cast expression 将 flight_id 统一为 String 类型 → 输出为 clean_flights。
在 Code Repositories 中(Python),同样的逻辑:
from transforms.api import transform_df, Input, Output
from pyspark.sql import functions as F
@transform_df(
Output('/airlines/clean/flights'),
raw=Input('/airlines/raw/flight_operations')
)
def clean_flights(raw):
return (
raw
.filter(F.col('status').isNotNull()) # 过滤空状态
.withColumn('flight_id', # 统一类型
F.col('flight_id').cast('string'))
.withColumn('departure_time', # 时间解析
F.to_timestamp('departure_time',
'yyyy-MM-dd HH:mm:ss'))
.dropDuplicates(['flight_id']) # 去重
)
@transform_df 装饰器做了三件事:声明输入 dataset 路径、声明输出 dataset 路径、把返回的 DataFrame 自动写入 output。这是 Foundry pipeline 的基本编程模型。
路径 B:半结构化数据 → JSON/XML 解析 + 摊平
半结构化数据的核心挑战是嵌套结构。一个 JSON 预订报文可能长这样:
{
"booking_id": "BK-20250601-001",
"passenger": {
"name": "Zhang Wei",
"passport": "E12345678"
},
"flights": [
{"flight_id": "CA1234", "seat": "32A"},
{"flight_id": "CA5678", "seat": "14C"}
]
}
Pipeline Builder 提供 parsing transform functions 把文件转为表格:
"Semi-structured data refers to a dataset that consists of files without a schema, making the data non-tabular. Pipeline Builder supports semi-structured data in the form of XML, JSON, and CSV files. You can use parsing transform functions to convert semi-structured files into tabular form and benefit from schema safety."— Pipeline Builder: Input datasets, Palantir Docs
航空场景实例:预订 JSON 摊平为两张表
一个 JSON 文件需要变成两个 output:
Output 1 — clean_passengers:提取 passenger 对象,取 booking_id 作为关联键。在 Pipeline Builder 中用 file transform 解析 JSON → 用 expression 提取嵌套字段 passenger.name、passenger.passport → 输出 tabular dataset。
Output 2 — clean_bookings:对 flights 数组使用 explode_array generator(Pipeline Builder 的内置功能),将数组展开为每行一条 flight 记录,附带 booking_id 和 passenger_id 作为外键。
在 Code Repositories 中,PySpark 的 explode 函数天然支持这种操作:
@transform_df(
Output('/airlines/clean/bookings'),
raw=Input('/airlines/raw/passenger_bookings')
)
def flatten_bookings(raw):
# 读取 JSON → 展开 flights 数组 → 提取嵌套字段
return (
raw
.select(
F.col('booking_id'),
F.col('passenger.name').alias('passenger_name'),
F.col('passenger.passport').alias('passport'),
F.explode('flights').alias('flight') # 数组展开
)
.select(
'booking_id', 'passenger_name', 'passport',
F.col('flight.flight_id').alias('flight_id'),
F.col('flight.seat').alias('seat')
)
)
一个 explode 调用就把嵌套的 JSON 数组"摊平"成了标准的 tabular 格式。这是处理半结构化数据最常用的模式。
路径 C:非结构化数据 → AIP Document Intelligence
这是最复杂的路径,也是 Palantir 近年投入最重的方向。非结构化数据(PDF、图片、音频)不能直接变成"行和列",需要内容提取。
AIP Document Intelligence 是 Palantir 在 AIP 层面专门为文档提取构建的产品级工具,提供两大类策略:
| 类别 | 方法 | 机制 | 适用场景 |
|---|---|---|---|
| Traditional | Raw text | 读取 PDF 元数据中的文本 | 电子生成的 PDF |
| OCR | 传统 OCR 提取文本 | 扫描件,版面不重要 | |
| Layout-aware OCR | OCR + bounding box,保留版面结构 | 表格、多栏文档 | |
| Generative AI | VLM 提取 | Vision Language Model 直接"看"页面,输出 Markdown | 复杂版面、混合内容 |
| 混合模式 | 先 OCR 预处理,再将结果 + 页面图像传给 VLM | 最高精度场景 |
"Document preprocessing essentially runs traditional OCR on the document, then passes that output in addition to the document page itself to a VLM, giving the model more context to successfully analyze the document."— AIP Document Intelligence: Core Concepts, Palantir Docs
航空场景实例:维修报告 PDF 提取全流程
第一步——在 AIP Document Intelligence UI 中导入维修报告 Media Set,选择 Layout-aware OCR + VLM 混合策略,执行提取,查看 Markdown 输出(带 bounding box 对照原文)。
第二步——用 VLM-as-judge 自动评分,评估表格、标题、代码块等不同元素的提取质量。
第三步——满意后一键部署为 Python transform。系统自动生成代码仓库:
@transform.using(
output=Output("ri.foundry.main…把这篇文章,
读到最后。
开通月度会员,继续阅读本篇剩余内容。
- 解锁会员文章的完整内容与图示
- 更高档位可下载 skill、加入 AI 咨询营