Google adds AI classification and extraction functions to AlloyDB

Google Cloud is previewing two SQL functions for AlloyDB that can classify text and extract structured JSON directly inside the database. The functions, ai.classify and ai.extract, are available through the google_ml_integration extension on PostgreSQL 18.
- Google Cloud is previewing ai.classify and ai.extract for AlloyDB.
- The functions run through standard SQL on PostgreSQL 18.
- ai.classify supports single-label, multi-label and few-shot classification.
- ai.extract converts unstructured text into schema-based JSON.
- Smart batching groups inputs into micro-batches for Gemini Enterprise Agent Platform models.
AI text processing inside SQL
Google Cloud says the new functions are designed for unstructured text stored in transactional databases, including clinical notes, customer reviews, support tickets, invoices and property descriptions. Previously, processing this information often required applications to export database records, call external model endpoints, parse responses and write the results back.
According to Google Cloud, that application-side process can add query latency, increase application code and model token costs, and create compliance risks by moving sensitive information across multiple network boundaries. AlloyDB AI instead brings Gemini world knowledge into the operational database, allowing classification and extraction through standard SQL.
The preview is available in the google_ml_integration extension, version 1.6.1 or later, on PostgreSQL 18.
ai.classify supports single and multiple labels
The ai.classify function categorizes text using classes defined by the user. Categories can be supplied as a simple list of labels or as label names paired with descriptions that provide additional context for the model.
The function supports single-label classification, which returns the best category, and multi-label classification, which returns every matching category. Developers can also provide inline examples for few-shot prompting. Google Cloud says the function can run against individual rows, arrays and cursors through the TEXT, TEXT[] and REFCURSOR execution modes.
In the company's example, a table of product reviews is classified into positive, neutral and negative categories in a SQL query. The expected results classify one review as positive and two as negative.
ai.extract turns free text into JSON
The ai.extract function converts unstructured text into structured JSON matching a target schema. The schema can be supplied as a standard JSON schema or as a plain text list of fields, while overloaded signatures support single rows, arrays and cursor batching.
Google Cloud's example uses a clinical note to extract a patient's name, age, symptoms and prescribed medications. The expected JSON includes Jane Smith, age 52, mild fever, persistent cough, severe body aches, Ibuprofen and Amoxicillin.
Both functions support smart batching, previously called AI Function Acceleration. When they are used in SQL WHERE clause expressions, AlloyDB automatically groups inputs into optimized micro-batches before sending them to Gemini Enterprise Agent Platform models. Google Cloud says this can speed inference compared with row-by-row evaluation and reduce model token spend by optimizing prompt overhead.
Google Cloud identifies healthcare, financial services, legal technology, real estate and knowledge graphs as potential application areas. The company says planned enhancements include advanced cost optimization, line-level provenance tracking and query pushdowns beyond WHERE clauses. Users can get started with the AlloyDB AI Query Engine documentation and AlloyDB release notes.
Google Cloud: Introducing new AI functions for AlloyDB: ai.classify and ai.extract


