No history yet

Persistent Tables and Types

Beyond Dataframes

If you've worked with data in Python, you're familiar with dataframes. They're great for manipulating data in memory. But once your script finishes, the dataframe vanishes. For any serious AI workflow, you need persistence—a way for your data to live on between sessions, just like in a traditional database.

Pixeltable replaces the temporary nature of dataframes with persistent tables. Think of them as database tables supercharged for unstructured, multimodal data. Instead of juggling CSV files, S3 buckets for images, and local folders for videos, you get a single, unified interface. Everything lives in a managed environment on your machine, ready to be queried and processed.

The core idea: Treat your unstructured data with the same seriousness and structure as your relational data.

Creating Your First Table

Creating a table requires defining a schema. Unlike a schemaless system where you can throw anything in, Pixeltable asks you to declare the structure of your data upfront. This ensures data integrity and enables powerful, type-aware operations down the line. We use the pxt.create_table() function to do this.

import pixeltable as pxt

# Define a schema for a table to hold product information
schema = {
    'product_name': pxt.String(),
    'product_image': pxt.Image(),
    'description_video': pxt.Video()
}

# Create the table
# The 'if_not_exists=True' prevents an error if the table already exists
products = pxt.create_table('products', schema, if_not_exists=True)

Here, we've defined a table named products with three columns. product_name is a standard string. But product_image and description_video are special Pixeltable types. These multimodal types are the key to handling unstructured data.

Multimodal Types

Pixeltable has built-in types for the kinds of data you'll encounter in AI projects. These aren't just labels; they tell Pixeltable how to store, process, and display the data. The main ones are:

TypeDescription
pxt.Image()For still images (JPG, PNG, etc.). Can be resized on insertion.
pxt.Video()For video files (MP4, MOV, etc.).
pxt.Audio()For audio files (MP3, WAV, etc.).
pxt.Document()For text documents (PDF, DOCX, etc.).

By declaring a column as pxt.Image(), you're not just creating a spot for a filename. You're creating a column that understands image data, allowing you to later perform operations like running object detection models directly on the column's contents.

Adding Data to Your Table

Once a table is created, you can add data to it. Pixeltable makes it easy to ingest files from your local filesystem or directly from a URL. You provide the data as a list of dictionaries, where each dictionary represents a row.

Let's add a row to our products table. Notice how we just provide file paths and URLs. Pixeltable handles the rest, fetching and storing the data according to the schema.

# Assume 'products' table from the previous example exists

# Data for a new row
new_data = [
    {
        'product_name': 'Super Whisk 3000',
        'product_image': '~/images/whisk.png',
        'description_video': 'https://example.com/videos/whisk_promo.mp4'
    }
]

# Add the data to the table
status = products.insert(new_data)

# Check the status to see if the insertion was successful
print(status)

The table now persistently stores not just the product name, but the actual image and video data. This data is now cataloged, typed, and ready for the next step in your AI workflow, which we'll cover later: running computations and models directly on your new table.

Quiz Questions 1/5

What is the primary advantage of Pixeltable tables over traditional in-memory dataframes?

Quiz Questions 2/5

Which function is used to create a new, persistent table in Pixeltable?