Skip to main content

VillageSQL is a drop-in replacement for MySQL with extensions.

All examples in this guide work on VillageSQL. Install Now →
Summarization converts long text into a shorter version that captures the key points. Support tickets, customer feedback, articles, and log entries all benefit from a short summary field that lets you scan content quickly. MySQL has no summarization function. VillageSQL’s ai_prompt() adds one.

With VillageSQL: Summaries in SQL

A summarization prompt specifies the desired length and what to keep:
Query summaries like any other column — no AI call at read time:

Structured summaries

For use cases where you need to extract specific fields, ask for JSON output:

Summarizing multi-column content

Build richer context for the model by joining multiple fields:
LEFT(body, 3000) avoids sending excessively long text to the model. Most AI models have a token limit; for very long documents, summarize the first few thousand characters or chunk the content.

Length and Style Control

Prompt phrasing controls output length and tone: For summaries used in UI previews, specify a character limit to avoid overflow.

Model Selection

Summarization is generally well-handled by faster, cheaper models. Use claude-haiku-4-5-20251001 or gpt-4o-mini for bulk summarization. Step up to claude-sonnet-4-5-20250929 when:
  • The source text is long and complex
  • You need structured JSON extraction with nuanced fields
  • Accuracy of extracted facts matters more than cost
For setup and provider options, see Connecting MySQL to AI APIs.

Frequently Asked Questions

How long can the source text be?

Practical limit is a few thousand words per call. AI models have token limits (typically 100K–200K tokens for current models), but very long inputs cost more and take longer. For documents over ~5000 words, summarize the first section or chunk and summarize each chunk.

Can I use summaries in a full-text search index?

Yes — add a FULLTEXT index on the summary column after populating it. Summaries are often better targets for full-text search than raw content because they’re shorter and more keyword-dense.

Will the same document always produce the same summary?

No — AI models are probabilistic. The same prompt can produce slightly different output on different calls. If consistency matters, generate the summary once and store it; don’t regenerate on each read.

How do I summarize rows that have already been summarized?

Don’t re-summarize unless the source content changed. Use WHERE summary IS NULL to only process new or updated rows. If you need to track changes, add a summary_updated_at column and compare it to the content’s last-modified timestamp.

Troubleshooting

See also