{"slug": "introducing-new-ai-functions-for-alloydb-ai-classify-and-ai-extract", "title": "Introducing new AI functions for AlloyDB: ai.classify and ai.extract", "summary": "Google announced the preview of two new SQL functions, ai.classify and ai.extract, in the AlloyDB AI query engine, available in the google_ml_integration extension version 1.6.1 or later on PostgreSQL 18. The functions let developers run single- or multi-label text classification and JSON-schema-based structured extraction directly inside the database using Gemini models, with smart batching that groups inputs into optimized micro-batches to cut query latency and model token spend. Google said the native functions target operational workflows in healthcare, financial services, legal technology and real estate, keeping sensitive text within the database rather than exporting it to external model endpoints.", "body_md": "Transactional databases store vast amounts of unstructured text — clinical notes, customer reviews, support tickets, invoices, and property descriptions. Historically, working with this text meant building complex application code: You had to export data from the database, call external model endpoints, write custom prompt wrappers, parse unpredictable responses, manage retry logic, and update database records. This application-side loop creates operational friction. It introduces query latency, bloats application code, increases model token costs, and creates data compliance risks by moving sensitive information across multiple network boundaries.\n\nWe built [AlloyDB AI](https://cloud.google.com/alloydb/ai) to bring Gemini world knowledge directly into your operational database. Rather than treating artificial intelligence as a disconnected external service, we integrated model intelligence directly into the database engine. Today, we are announcing the preview of two new SQL functions in the AlloyDB AI query engine — `ai.classify` and `ai.extract` — available in the `google_ml_integration` extension (version 1.6.1 or later) on PostgreSQL 18, allowing you to perform classification and structured extraction directly inside your database using standard SQL. Supported by smart batching for AI functions (previously known as AI Function Acceleration), these functions deliver production scalability and performance. \n\nNow, let’s take a look at these new functions and how to use them.\n\nThe `ai.classify` function categorizes text into user-defined classes without requiring manual prompt engineering. You can specify categories as a simple list of labels or provide a list containing label names and descriptions to guide model context.\n\nKey capabilities include:\n\nSingle-label classification (`output_mode => 'single'`) to assign the single best category\n\nMulti-label classification (`output_mode => 'multi'`) to return all matching categories\n\nCategory descriptions using 2D arrays to provide explicit context for each label\n\nFew-shot prompting by supplying inline examples\n\nFlexible execution modes for individual rows (`TEXT`), arrays (` TEXT[]`), and cursors (` REFCURSOR`)\n\nHere’s a quick example showing how you can classify customer feedback directly within a SQL query:\n\nThe `ai.extract` function transforms unstructured text into structured JSON data matching your target schema — specified as a JSON schema or a text list of fields. It handles system instructions internally, saving you from writing prompt templates or response parsers.\n\nSchema flexibility supporting standard JSON schemas or plain text field lists\n\nAutomatic transformation of unstructured text into machine-readable JSON\n\nOverloaded function signatures for single rows, arrays, and cursor batching\n\nHere’s an example extracting clinical fields from free-form medical notes:\n\nRunning AI evaluations row-by-row can slow down query execution. AlloyDB addresses this with smart batching for AI functions. When you use `ai.classify` or `ai.extract` in SQL `WHERE` clause expressions, the database engine automatically groups inputs into optimized micro-batches before sending them to Gemini Enterprise Agent Platform models.\n\nSmart batching delivers significant performance and efficiency improvements:\n\nFaster inference for query execution compared to row-at-a-time evaluations\n\nReduces total model token spend by optimizing input prompt overhead\n\nNative classification and extraction functions support operational workflows across key industry sectors:\n\n**Healthcare:** Securely convert free-text clinical notes into structured records containing patient names, symptoms, and prescribed medications, keeping patient data safely within the confines of the database.\n\n**Financial services:** Extract vendor details, invoice dates, and line-item totals from scanned document text.\n\n**Legal technology:** Pull governing law, liability caps, and termination notice periods from contract documents.\n\n**Real estate:** Extract property types, bedroom counts, and price ranges from descriptive listing text.\n\n**Knowledge graphs:** Extract entities and relationships from documents to populate PostgreSQL Property Graph (PGQ) structures.\n\nWe are continuing to expand in-database AI capabilities in AlloyDB, with upcoming enhancements planned for advanced cost optimization, line-level provenance tracking, and query pushdowns beyond `WHERE` clauses.\n\nTo start using `ai.classify` and `ai.extract` in your database:\n\nReview the [AlloyDB AI Query Engine documentation](https://docs.cloud.google.com/alloydb/docs/ai).\n\nExplore the [AlloyDB release notes](https://docs.cloud.google.com/alloydb/docs/release-notes).", "url": "https://wpnews.pro/news/introducing-new-ai-functions-for-alloydb-ai-classify-and-ai-extract", "canonical_source": "https://cloud.google.com/blog/products/databases/ai-classify-and-ai-extract-functions-in-alloydb-ai/", "published_at": "2026-11-11 17:00:00+00:00", "updated_at": "2026-11-11 17:25:08.203303+00:00", "lang": "en", "topics": ["artificial-intelligence", "ai-products", "ai-tools", "large-language-models", "ai-infrastructure"], "entities": ["Google", "AlloyDB", "AlloyDB AI", "Gemini", "google_ml_integration", "PostgreSQL 18", "Gemini Enterprise Agent Platform"], "also_reported_by": [], "alternates": {"html": "https://wpnews.pro/news/introducing-new-ai-functions-for-alloydb-ai-classify-and-ai-extract", "markdown": "https://wpnews.pro/news/introducing-new-ai-functions-for-alloydb-ai-classify-and-ai-extract.md", "text": "https://wpnews.pro/news/introducing-new-ai-functions-for-alloydb-ai-classify-and-ai-extract.txt", "jsonld": "https://wpnews.pro/news/introducing-new-ai-functions-for-alloydb-ai-classify-and-ai-extract.jsonld"}}