How Pixeltable Works
Discover the core principles that make complex AI workflows simple. By connecting directly to your existing data and providing automatic orchestration, see how we've reimagined data processing for the AI era.
Build Your First AI Workflow
Follow these four essential steps to create powerful multimodal AI applications with Pixeltable's declarative approach.
1. Create a Table & Add a Computed Column
The Declarative Foundation
Start by defining a table for any kind of data—structured, unstructured, or multimodal. Then, add computed columns that transform your data using simple Python expressions. Pixeltable's declarative engine automatically orchestrates the computation for all existing and future rows, forming the foundation of your AI pipeline.
- Unified Schema: Manage diverse data types—images, videos, documents, and structured data—in a single table.
- Declarative Logic: Define data transformations with simple Python expressions that run automatically.
- Automated Orchestration: Pixeltable handles the dependency graph and executes computations for new and existing data.
1import pixeltable as pxt23# Create a table for films with revenue and budget4t = pxt.create_table(5 'films',6 {'name': pxt.String, 'revenue': pxt.Float, 'budget': pxt.Float},7 if_exists="replace"8)910# Insert some data into the table11t.insert([12 {'name': 'Inside Out', 'revenue': 800.5, 'budget': 200.0},13 {'name': 'Toy Story', 'revenue': 1073.4, 'budget': 200.0}14])1516# Add a computed column for profit.17# Pixeltable calculates this automatically for new and existing rows.18t.add_computed_column(profit=(t.revenue - t.budget), if_exists="replace")1920# Query the results to see the computed profit21# print(t.select(t.name, t.profit).collect())22#23# +------------+--------+24# | name | profit |25# +------------+--------+26# | Inside Out | 600.5 |27# | Toy Story | 873.4 |28# +------------+--------+
2. Run an AI Vision Pipeline
Bring Your Own AI Model
Extend Pixeltable's capabilities by wrapping any Python code—from simple data cleaning to complex AI model inference—in a `@pxt.udf`. Pixeltable seamlessly integrates this User-Defined Function into its declarative framework, automatically managing dependencies, execution, and even model downloads.
- Seamless Integration: Use the `@pxt.udf` decorator to turn any Python function into a reusable pipeline component.
- Bring Your Own Model: Integrate any custom logic, from simple data cleaning to complex AI models like YOLOX.
- Managed Execution: Pixeltable handles dependencies, parallelization, and even downloads required model files.
1import PIL2import pixeltable as pxt3from yolox.models import Yolox4from yolox.data.datasets import COCO_CLASSES56# Assumes table 't' exists with an 'image' column7# t = pxt.get_table('my_images')8# t.insert([{'image': 'path/to/cat.jpg'}])910# Wrap any Python code in a UDF11@pxt.udf12def detect(image: PIL.Image.Image) -> list[str]:13 # Load a pre-trained YOLOX model14 model = Yolox.from_pretrained("yolox_s")15 # Run inference16 result = model([image])17 # Return a list of detected class labels18 coco_labels = [COCO_CLASSES[label] for label in result[0]["labels"]]19 return coco_labels2021# Apply the UDF as a computed column22t.add_computed_column(classification=detect(t.image))2324# The 'classification' column is now automatically populated25# with the object detection results for each image.26#27# +----------------------+------------------+28# | image | classification |29# +----------------------+------------------+30# | <Image: cat.jpg> | ['cat', 'couch'] |31# | <Image: birds.png> | ['bird'] |32# +----------------------+------------------+
3. Perform Multimodal Vector Search
Built-in Vector Search
Add a multimodal embedding index to any column with a single line of code, eliminating the need for a separate vector DB. Pixeltable handles the entire lifecycle: generating embeddings, storing them efficiently, and keeping them automatically in sync with your data. This enables powerful, co-located semantic search across all your data types.
- No Separate Vector DB: Create a multimodal embedding index with a single line of code, right next to your data.
- Automatic Syncing: Embeddings are automatically created and updated when your source data changes, ensuring consistency.
- Powerful Search: Perform text-to-image, image-to-image, and other semantic searches using a simple `.similarity()` method.
1import pixeltable as pxt2from pixeltable.functions.huggingface import clip34# Assumes table 'images' exists with an 'img' column of type Image5# images = pxt.get_table('my_images')67# 1. Add a CLIP embedding index to the image column8images.add_embedding_index(9 'img',10 embedding=clip.using(model_id='openai/clip-vit-base-patch32')11)1213# 2. Perform text-to-image similarity search14query_text = "a dog playing fetch"15sim_text = images.img.similarity(query_text)16results = images.order_by(sim_text, asc=False).limit(1).collect()1718# 3. Perform image-to-image similarity search19query_image = 'https://path/to/another/dog.jpg'20sim_image = images.img.similarity(query_image)21results = images.order_by(sim_image, asc=False).limit(1).collect()
4. Build an Incremental RAG Workflow
Incremental & Automated RAG
Build powerful, end-to-end RAG systems with just a few declarative statements. Pixeltable orchestrates the entire workflow, from chunking documents and generating embeddings to retrieving relevant context and prompting an LLM. Because the pipeline is incremental, your RAG application is always efficient and up-to-date.
- Declarative RAG: Define the entire RAG workflow—chunking, embedding, retrieval, and generation—with a few lines of code.
- Incremental Processing: Only new or updated documents are processed, making your RAG system highly efficient and cost-effective.
- Co-located Data: Keep your source documents, chunks, embeddings, and Q&A history unified and perfectly in sync.
1import pixeltable as pxt2from pixeltable.functions import openai, huggingface3from pixeltable.iterators import DocumentSplitter45# 1. Create tables for documents and Q&A6docs = pxt.create_table('docs', {'doc': pxt.Document})7docs.insert([{'doc': 's3://my-data/annual-report.pdf'}])8qa = pxt.create_table('qa', {'prompt': pxt.String})910# 2. Create a view to chunk documents into sentences11chunks = pxt.create_view('chunks', docs,12 iterator=DocumentSplitter.create(document=docs.doc, separators='sentence'))1314# 3. Create an embedding index on the text chunks15embed_model = huggingface.sentence_transformer.using(model_id='all-MiniLM-L6-v2')16chunks.add_embedding_index('text', string_embed=embed_model)1718# 4. Define a query function to retrieve context19@pxt.query20def get_context(query_text: str, limit: int = 3):21 sim = chunks.text.similarity(query_text)22 return chunks.order_by(sim, asc=False).limit(limit)2324# 5. Build the RAG pipeline on the Q&A table25qa.add_computed_column(context=get_context(qa.prompt))26qa.add_computed_column(27 answer=openai.chat_completions(28 model='gpt-4o-mini',29 messages=[{30 'role': 'user',31 'content': f"Context: {qa.context.text}\nQuestion: {qa.prompt}"32 }]33 ).choices[0].message.content34)3536# 6. Ask a question - Pixeltable runs the whole pipeline!37qa.insert([{'prompt': 'What were the key takeaways from the report?'}])38# print(qa.select(qa.answer).collect())
Explore Pixeltable Concepts
Dive deeper into how Pixeltable works with this interactive explorer. Learn core concepts, see multimodal data handling, and understand AI integration.
Explore Pixeltable
What is Pixeltable?
Pixeltable is a declarative data infrastructure for building multimodal AI applications. It unifies data storage, transformation, and AI orchestration in a single Python framework.
The Problem It Solves
- • Separate ETL pipelines
- • Multiple vector databases
- • Complex orchestration
- • Brittle data flows
- • Unified data tables
- • Declarative transformations
- • Built-in orchestration
- • Incremental computation