Skip to content

Beginner · 15 min

Build an incremental AI pipeline that only reprocesses new or changed files

An incremental pipeline tracks each file as a row, stores model outputs as computed columns, and recomputes only new or changed rows and their dependents. A new file, a changed file, or a changed prompt reruns that work; unchanged rows keep their stored results. Pixeltable is the unified multimodal AI backend for apps and agents that need this cache.

The Challenge

The usual answer to "only reprocess new or changed files" is a stitch: cron or Airflow/Prefect to list a folder, hash each file, skip known hashes, call a model, write vectors into pgvector or another store, then hope the skip list matches the table. Ray or Spark will scan a lake; skip logic is yours. Databricks jobs on Delta can MERGE, if you write that job. cocoindex-style frameworks track source files and rebuild derived index entries for what changed; you still own serving. A Python loop that restarts from file zero pays the model again.

The Solution

Declare a Document (or other media) column, a computed column that calls a model, and an optional embedding index. Insert a new file and only that row runs. Update the file or its source text and only that row and its dependents recompute. After you edit a prompt or a model expression, pxt recompute reruns that column. The catalog, not a hash file you maintain, is the cache. Keep Ray, Spark, Daft, or Databricks for a lake backfill and load the result.

Implementation Guide

Step-by-step walkthrough with code examples

Step 1 of 4

Track each file as a row

Store the file as a typed Document column. Apply the file with pxt schema update; do not call create_table at import.

python
1import pixeltable as pxt
2from pixeltable.functions.document import document_splitter
3from pixeltable.functions.openai import chat_completions, embeddings
4
5TableModel = pxt.model_base()
6embed = embeddings.using(model='text-embedding-3-small')
7
8class Docs(TableModel, name='docs'):
9 title: pxt.String
10 document: pxt.Document
The catalog records the file. A path string in isolation is not enough: splitting and models need a typed Document column. Detection of a "changed file" is an insert or an update of that row, not a filesystem mtime watcher.

What reruns when a file, a prompt, or a model changes

Cron + Airflow/Prefect + hashes + vector DBRay / Spark batchDatabricks (Delta + jobs)cocoindex-style frameworkPixeltable computed columns
New fileYour skip list must miss it, then you write the vectorThe job you launch; skip logic is yoursAuto Loader can ingest new files; you still write the pipeline that embedsRecomputes derived entries for that sourceInsert the row; only that row runs
Changed fileHash must change, then you overwrite the vectorRerun the scan unless you key the sinkA Delta Sync index re-embeds changed rows; MERGE or a job still owns the tableRebuilds derived entries for that sourceUpdate the Document column; the splitter view and dependents of that file recompute
Changed prompt or modelYou invalidate caches and replay the DAGRelaunch the jobRelaunch the jobRebuild the derived indexpxt recompute on that column; unrelated columns stay cached
Where state livesHash file, object store, orchestrator, vector DBThe sink you writeDelta tables, Auto Loader, jobs, and an optional Delta Sync indexThe framework store plus the store you serve fromThe catalog: source columns, computed columns, indexes

Key Benefits

A new file computes only itself; existing rows keep stored results
An updated row recomputes only its dependent columns
pxt recompute reruns a prompt or model change without a folder scan
The embedding index updates with the row, so a separate vector-DB sync job is optional
Airflow or Prefect can still insert rows; the table is the skip list

Real Applications

Document collections that gain files every day
RAG indexes that must not re-embed the corpus on each drop
LLM summaries over a live table rather than a lake scan
Pipelines that used to hash files in Airflow before calling a model

Prerequisites

Basic understanding of AI pipelines
Python programming
Python 3.11+
pip install -U 'pixeltable[serve]'
OpenAI API key for chat_completions and embeddings in this sample

How-to guides

Frequently asked questions

What happens when I change the model or prompt?

Edit the computed-column expression and apply it with pxt schema update. pxt recompute reruns that column and the columns that depend on it. Unrelated columns keep their stored results. Changing string_embed on an EmbeddingIndex drops and rebuilds that index (pxt schema update app.py docs --allow-destructive -f); that is not the same as inserting a file.

How does it detect changed files?

It does not watch filesystem mtime. A new file is an insert of a row. A changed file is an update of that row's Document column. Those writes rebuild the splitter view and recompute dependents of that file. A path you never insert is not a row.

Can I keep Airflow or Prefect?

Yes. Use the orchestrator to land files and insert rows (or call an HTTP insert route). The table is the skip list: unchanged rows are not recomputed. You do not need Airflow to hash files before the model call unless that DAG is already the contract.

Do I still need Ray, Spark, or Databricks?

Use a batch engine when the work is a scan over a lake you do not want as a live application catalog. Use computed columns when new files arrive as rows and the cache must survive the next insert. You can backfill with Ray, Spark, Daft, or Databricks and then serve new rows from the table.

Does a new insert reprocess the whole table?

No. A computed column recomputes the row that changed and the columns that depend on it. Unchanged rows keep the cached result. A full refresh is a different operation you would have to ask for.

Do I still need a separate vector database?

You need an embedding index so similar chunks can be ranked. That index can live on the splitter view that holds the extracted text. A separate vector database is optional when something else is already the source of truth.

Ready to get started?

Install Pixeltable and start building in minutes. One Python file for tables, indexes, and HTTP.