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.
Generate concise summaries of long text, articles, or documents using
large language models.
Problem
You have long text content—articles, transcripts, documents—that needs
to be summarized. Processing each piece manually is time-consuming and
inconsistent.
Solution
What’s in this recipe:
- Summarize text using OpenAI GPT models
- Customize summary style with prompts
- Process multiple documents automatically
You add a computed column that calls an LLM to generate summaries. When
you insert new text, summaries are generated automatically.
Setup
WARNING: Ignoring invalid distribution ~orch (/opt/miniconda3/envs/pixeltable/lib/python3.11/site-packages)
WARNING: Ignoring invalid distribution ~orch (/opt/miniconda3/envs/pixeltable/lib/python3.11/site-packages)
WARNING: Ignoring invalid distribution ~orch (/opt/miniconda3/envs/pixeltable/lib/python3.11/site-packages)
WARNING: Ignoring invalid distribution ~orch (/opt/miniconda3/envs/pixeltable/lib/python3.11/site-packages)
WARNING: Ignoring invalid distribution ~orch (/opt/miniconda3/envs/pixeltable/lib/python3.11/site-packages)
WARNING: Ignoring invalid distribution ~orch (/opt/miniconda3/envs/pixeltable/lib/python3.11/site-packages)
Note: you may need to restart the kernel to use updated packages.
Load sample text
Connected to Pixeltable database at: postgresql+psycopg://postgres:@/pixeltable?host=/Users/pjlb/.pixeltable/pgdata
Created directory ‘summarize_demo’.
<pixeltable.catalog.dir.Dir at 0x30d758b10>
Created table ‘articles’.
Inserting rows into `articles`: 2 rows [00:00, 316.21 rows/s]
Inserted 2 rows with 0 errors.
2 rows inserted, 4 values computed.
Generate summaries
Add a computed column that generates summaries using GPT:
Added 2 column values with 0 errors.
2 rows updated, 2 values computed.
Added 2 column values with 0 errors.
2 rows updated, 2 values computed.
Custom summary styles
You can customize the summary format by changing the prompt:
Added 2 column values with 0 errors.
Added 2 column values with 0 errors.
2 rows updated, 2 values computed.
Automatic processing
New articles are automatically summarized when inserted:
Inserting rows into `articles`: 1 rows [00:00, 411.57 rows/s]
Inserted 1 row with 0 errors.
1 row inserted, 6 values computed.
Explanation
Prompt engineering for summaries:
Cost optimization:
- Use
gpt-4o-mini for most summarization tasks (fast and affordable)
- Use
gpt-4o for complex documents requiring deeper understanding
- Summaries are cached—you only pay once per article and stuand toofor
trL para
See also