AlloyDB AI previews ai.classify and ai.extract for in-database text processing

AlloyDB AI announces the preview of two new SQL functions in its query engine — ai.classify and ai.extract — available through the google_ml_integration extension version 1.6.1 or later on PostgreSQL 18. The functions bring Gemini model intelligence directly into the database, allowing developers to perform text classification and structured extraction using standard SQL, without building application-side loops that export data, call external endpoints, parse responses, and manage retries. The stated motivation is reducing operational friction, query latency, token costs, and data compliance risks associated with moving sensitive information across network boundaries.

ai.classify categorizes text into user-defined classes without manual prompt engineering. Users specify categories as a simple label list or as label-description pairs, and the function supports single-label classification with output_mode => ‘single’, multi-label with output_mode => ‘multi’, category descriptions via 2D arrays, few-shot prompting with inline examples, and flexible execution modes for individual rows (TEXT), arrays (TEXT[]), and cursors (REFCURSOR). An example shows classifying customer feedback directly in a SQL query.

ai.extract transforms unstructured text into structured JSON matching a target schema, specified either as a JSON schema or a plain text field list. The function handles system instructions internally, removing the need for prompt templates and response parsers. It also provides overloaded signatures for single rows, arrays, and cursor batching. An example illustrates extracting clinical fields from free-form medical notes.

Performance is addressed through smart batching for AI functions, previously called AI Function Acceleration. When ai.classify or ai.extract appears in SQL WHERE clause expressions, the database engine automatically groups inputs into optimized micro-batches before sending them to Gemini Enterprise Agent Platform models. This yields faster inference compared to row-at-a-time evaluation and reduces total model token spend by optimizing input prompt overhead.

The article highlights real-world industry applications. In healthcare, free-text clinical notes can be converted into structured records containing patient names, symptoms, and prescribed medications while keeping data within the database. Financial services can extract vendor details, invoice dates, and line-item totals from scanned document text. Legal technology can pull governing law, liability caps, and termination notice periods from contracts. Real estate can extract property types, bedroom counts, and price ranges from listings. Knowledge graphs can use these functions to extract entities and relationships for populating PostgreSQL Property Graph structures.

Planned enhancements include advanced cost optimization, line-level provenance tracking, and query pushdowns beyond WHERE clauses. To get started, the article points to the AlloyDB AI Query Engine documentation and the AlloyDB release notes.

ai.classify and ai.extract functions in AlloyDB AI

View Original