本页面介绍了 AlloyDB AI 自然语言,借助该功能,您可以使用自然语言创建面向用户的生成式 AI 应用来查询数据库。
AlloyDB AI 自然语言功能会针对应用终端用户的自然语言问题生成情境感知型 SQL 查询,并提供一个安全 API 来执行这些查询。自然语言可将自然语言转换为 SQL 的复杂性从应用层转移到数据库层,从而简化生成式 AI 应用的开发。自然语言到 SQL (NL2SQL) 编排功能嵌入在数据库中。您可以查询结构化数据和非结构化数据。
AlloyDB AI 自然语言还为 SQL 开发者提供了一个直观的界面,可将自然语言转换为 SQL,如以下示例所示:
SELECTalloydb_ai_nl.get_sql(...,'What is the sum that client number 4''s account has following transaction 851?');
AlloyDB AI 自然语言支持通过 AlloyDB for PostgreSQL 扩展程序 alloydb_ai_nl, 提供。该扩展程序依赖于 google_ml_integration、vector, 和 pg_trgm 等 PostgreSQL 扩展程序。
使用场景
AlloyDB AI 自然语言非常适合希望执行以下操作的开发者:
使用自然语言生成查询,快速构建客户聊天界面。
优化自动生成的查询,并执行全面测试,以提供准确的回答。
通过添加模板和上下文信息来调优生成的结果。
部署直观且准确的聊天体验,让客户可以用自然语言询问有关其关系型数据的问题。
主要功能
主要功能
说明
语义层
维护丰富的架构和应用上下文,以提高准确性。
存储数据库的含义(架构、表、列和关系)。
使 AlloyDB 能够理解用户问题的上下文。
概念搜索
智能解析用户问题,以识别关键值短语。
将这些值映射到您的数据,并根据概念类型消除歧义,从而提高准确性。
查询存储区
支持针对各种常见的自然语言问题生成准确的查询。
使用模板和查询片段(手动生成和自动生成)来更快、更准确地构建 SQL。
限制
您必须在每个 AlloyDB for PostgreSQL 实例上启用 AlloyDB AI 自然语言标志。在主实例上创建的 AlloyDB AI 自然语言对象会传播到只读副本和跨区域副本。但是,alloydb_ai_nl.enabled 标志设置不会自动复制,因此您必须在每个实例上手动复制该标志设置。如需了解详情,请参阅生成可回答自然语言问题的 SQL 查询。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-09-03。"],[],[],null,["# AlloyDB AI natural language overview\n\n| **Preview**\n|\n|\n| This feature is subject to the \"Pre-GA Offerings Terms\" in the General Service Terms section\n| of the [Service Specific Terms](/terms/service-terms#1).\n|\n| Pre-GA features are available \"as is\" and might have limited support.\n|\n| For more information, see the\n| [launch stage descriptions](/products#product-launch-stages).\n|\n|\n| For information about access to this\n| release, see the\n| [access request page](https://docs.google.com/forms/d/16wliam2vok6sdBjYwJIgWV4hw7MW9x5iQ29UwPAKqB0/viewform).\n\nThis page describes AlloyDB AI natural language, which lets you\ncreate user-facing generative AI applications using natural language to query\ndatabases.\n\nAlloyDB AI natural language generate context-aware SQL queries\nfor application end users' natural language questions, and it provides a\nsecurity API to execute these queries. Natural\nlanguage streamlines the development of generative AI applications by\ntransferring the complexity of converting natural language to SQL from the\napplication layer to the database layer. Natural language-to-SQL (NL2SQL)\norchestration is embedded in the database. You can query structured and\nunstructured data.\n\nAlloyDB AI natural language also provides an intuitive interface\nto SQL developers that translates natural language to SQL, as shown in the\nfollowing example: \n\n SELECT\n alloydb_ai_nl.get_sql(\n ...,\n 'What is the sum that client number 4''s account has following transaction 851?'\n );\n\nAlloyDB AI natural language support is provided through\n`alloydb_ai_nl,` which is an AlloyDB for PostgreSQL extension. The extension has a\ndependency on PostgreSQL extensions like `google_ml_integration`, `vector,` and\n`pg_trgm`.\n| **Note:** The `alloydb_ai_nl` extension issues prediction requests to Vertex AI models. For more information, see [Integrate with Vertex AI](/alloydb/docs/ai/configure-vertex-ai).\n\n### Use cases\n\nAlloyDB AI natural language is well-suited for developers who\nwant to do the following:\n\n- Rapidly build a customer chat interface by using query generation from natural language.\n- Refine automatically generated queries and perform thorough testing to provide accurate responses.\n- Tune generated results by adding templates and context information.\n- Deploy an intuitive, accurate chat experience that lets customers ask natural language questions about their relational data.\n\nKey capabilities\n----------------\n\nLimitations\n-----------\n\nYou must enable the AlloyDB AI natural language flag\non every instance of AlloyDB for PostgreSQL.\nAlloyDB AI natural\nlanguage objects created on the primary instance are propagated to read-only\nreplicas and cross-region replicas. However, the\n`alloydb_ai_nl.enabled` flag setting isn't replicated automatically, so you must replicate\nit manually on each instance. For more information, see [Generate SQL queries that answer natural language questions](/alloydb/docs/ai/generate-sql-queries-natural-language#before-you-begin).\n\nWhat's next\n-----------\n\n- [Generate SQL queries that answer natural language questions](/alloydb/docs/ai/generate-sql-queries-natural-language).\n- [Use AlloyDB AI natural language to generate SQL](/alloydb/docs/ai/use-natural-language-generate-sql-queries).\n- Learn how to [search your relational data stored in AlloyDB in Google Agentspace using AlloyDB AI natural language](/agentspace/agentspace-enterprise/docs/create-data-store#alloydb-ai-nl-setup) ([Preview](https://cloud.google.com/products#product-launch-stages))."]]