Introducing new AI functions for AlloyDB: ai.classify and ai.extract
Google Cloud introduces ai.classify and ai.extract SQL functions in AlloyDB AI, enabling in-database text classification and extraction to reduce latency and compliance risks.
Transactional databases often store unstructured text such as clinical notes or customer reviews, which historically required exporting data to external AI services for processing. This approach introduced operational friction, including increased latency, bloated application code, and elevated model token costs due to repeated data transfers. By integrating AI capabilities directly into the AlloyDB database engine, Google Cloud aims to eliminate these inefficiencies and reduce compliance risks associated with moving sensitive data across network boundaries.
The new ai.classify and ai.extract functions are now available in preview as part of the google_ml_integration extension for PostgreSQL 18, requiring version 1.6.1 or later. These functions allow users to perform classification and structured extraction directly within SQL queries, removing the need for external model calls or custom prompt engineering. The ai.classify function categorizes text into user-defined classes using flexible execution modes for individual rows, arrays, or cursors, while ai.extract converts unstructured text into structured JSON data based on a specified schema.
To address performance challenges, AlloyDB employs smart batching for AI functions, which automatically groups inputs into optimized micro-batches when used in SQL WHERE clauses. This approach minimizes query execution delays and reduces token costs by consolidating model interactions. The integration with the Gemini Enterprise Agent Platform ensures that AI evaluations are handled efficiently within the database environment, improving scalability for production workloads.
Use cases span multiple industries, including healthcare for converting clinical notes into structured records, financial services for extracting invoice details, legal technology for pulling contract terms, and real estate for processing property listings. The functions also support knowledge graph applications by extracting entities and relationships to populate PostgreSQL Property Graph structures, demonstrating the versatility of in-database AI processing.