This documentation page is also available as an interactive notebook. You can launch the notebook in
Kaggle or Colab, or download it for use with an IDE or local Jupyter installation, by clicking one of the
above links.
Automatically create descriptive captions for images using AI vision
models.
Problem
You have a collection of images that need captions—for accessibility,
SEO, content management, or searchability. Writing captions manually
doesn’t scale.
Solution
What’s in this recipe:
- Generate captions using OpenAI’s vision models
- Customize caption style (short, detailed, SEO-focused)
- Process images in batch automatically
You add a computed column that sends each image to a vision model with a
captioning prompt. New images are captioned automatically on insert.
Setup
Load images
Connected to Pixeltable database at: postgresql+psycopg://postgres:@/pixeltable?host=/Users/asiegel/.pixeltable/pgdata
Created directory ‘caption_demo’.
<pixeltable.catalog.dir.Dir at 0x11fba5840>
Created table ‘images’.
Inserted 3 rows with 0 errors in 0.12 s (25.17 rows/s)
3 rows inserted.
Generate captions
Add a computed column that generates captions using the vision model:
Added 3 column values with 0 errors in 4.62 s (0.65 rows/s)
3 rows updated.
Different caption styles
You can generate multiple caption styles for different uses:
Added 3 column values with 0 errors in 3.51 s (0.85 rows/s)
3 rows updated.
Added 3 column values with 0 errors in 11.28 s (0.27 rows/s)
3 rows updated.
Explanation
Caption prompt patterns:
Model selection:
gpt-4o-mini: Fast and affordable, good for most captioning tasks
gpt-4o: Higher quality for complex images or detailed descriptions
See also