将 Spanner 与 Spanner Vertex AI 集成搭配使用时,Spanner 不会产生额外费用。但是,此功能可能会产生其他费用:
您需要按照标准费率为 Vertex AI Online Prediction 支付费用。总费用取决于您使用的模型类型。某些模型类型按小时收取固定费用,具体取决于您使用的机器类型和节点数。某些模型类型具有按调用计算的费率。我们建议您将后者部署在您已设置明确预测配额的专用项目中。
您需要按照标准费率为 Spanner 和 Vertex AI 之间的数据传输支付费用。总费用取决于托管执行查询的服务器所在的区域,以及托管所调用端点的区域。如需最大限度地降低费用,请将 Vertex AI 端点部署在与 Spanner 实例相同的区域。使用多区域实例配置或多个 Vertex AI 端点时,请将端点部署在同一大洲。
[[["易于理解","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-05。"],[],[],null,["# Spanner Vertex AI integration overview\n\nThis page provides an overview of Spanner Vertex AI integration. Spanner Vertex AI integration works with both\nGoogleSQL and PostgreSQL databases.\n\nSpanner Vertex AI integration helps you to access classifier and regression ML models hosted on\n[Vertex AI](/vertex-ai) through the GoogleSQL and\nPostgreSQL interface. This\nhelps to seamlessly integrate ML predictions serving functionality with general\nSpanner data access operations performed using DQL/DML queries.\n\nBenefits of Spanner Vertex AI integration\n-----------------------------------------\n\nGenerating ML predictions using Spanner Vertex AI integration provides multiple benefits compared\nto the approach where Spanner data access and access to the Vertex AI\nprediction endpoint are performed separately:\n\n- Performance:\n - Better latency: Spanner Vertex AI integration talking to the Vertex AI service directly eliminates additional round-trips between a compute node running a Spanner's client and the Vertex AI service.\n - Better throughput/parallelism: Spanner Vertex AI integration runs on top of Spanner's distributed query processing infrastructure, which supports highly parallelizable query execution.\n- User experience:\n - Ability to use a single, simple, coherent, and familiar SQL interface to facilitate both data transformation and ML serving scenarios on Spanner level of scale lowers the ML entry barrier and allows for a much smoother user experience.\n- Costs:\n - Spanner Vertex AI integration uses Spanner [compute capacity](/spanner/docs/compute-capacity) to merge the results of ML computations and SQL query execution, which eliminates the need to provision an additional compute (for example, in Compute Engine or Google Kubernetes Engine) for that.\n\nHow does Spanner Vertex AI integration work?\n--------------------------------------------\n\nSpanner Vertex AI integration doesn't host ML models, but relies on the Vertex AI service\ninfrastructure instead. You don't need to train a model using Vertex AI\nto use it with Spanner Vertex AI integration, but you must deploy it to a Vertex AI endpoint.\n\nTo train models on data stored in Spanner, you can use the following:\n\n- [BigQuery Federated queries](/bigquery/docs/spanner-federated-queries) together\n with [BigQuery ML](/bigquery/docs/bqml-introduction).\n\n- [Dataflow](/dataflow) to export data from Spanner into CSV format\n and import the [CSV data source](/vertex-ai/docs/datasets/prepare-tabular#csv) into Vertex AI.\n\nSpanner Vertex AI integration extends the following functions for using ML models:\n\n- **Generate ML predictions** by calling a model using\n SQL on your Spanner data. You can use a model from the\n [Vertex AI Model Garden](/vertex-ai/docs/start/explore-models)\n or a model deployed to your [Vertex AI endpoint](/vertex-ai/docs/general/deployment).\n\n- **Generate text embeddings** to have an LLM translate\n text prompts into numbers. To\n learn more about embeddings, see [Get text embeddings](/vertex-ai/docs/generative-ai/embeddings/get-text-embeddings).\n\nUsing Spanner Vertex AI integration functions\n---------------------------------------------\n\nA model in Spanner Vertex AI integration can be used to generate predictions or text\nembeddings in your SQL code using the ML Predict functions. These functions\nare as follows: \n\n### GoogleSQL\n\n\nYou can use the following ML predict function for GoogleSQL:\n\n[`ML.PREDICT`](/spanner/docs/reference/standard-sql/ml-functions#mlpredict)\n\nYou need to register your model using the [`CREATE MODEL`](/spanner/docs/reference/standard-sql/data-definition-language#create_model)\nDDL statement before using it with the `ML.PREDICT` function.\n\nYou can also use `SAFE.ML.PREDICT` to return `null` instead of an error in\nyour predictions. This is helpful in cases when running large queries\nwhere some failed predictions are tolerable.\n\n### PostgreSQL\n\nYou can use the following ML predict function for PostgreSQL:\n\n[`spanner.ML_PREDICT_ROW`](/spanner/docs/reference/postgresql/functions-and-operators#ml)\n\nTo use the functions,\nyou can select a model from the\n[Vertex AI Model Garden](/vertex-ai/docs/start/explore-models)\nor use a model that you've deployed to Vertex AI.\n\nFor more information on how to deploy a model to an endpoint\nin Vertex AI, see\n[Deploy a model to an endpoint](/vertex-ai/docs/general/deployment).\n\nFor more information\non how to use these functions to generate an ML prediction,\nsee [Generate ML predictions using SQL](/spanner/docs/ml-tutorial).\n\nFor more information on how to use these functions to generate text embeddings,\nsee [Get text embeddings](/vertex-ai/docs/generative-ai/embeddings/get-text-embeddings).\n\nPricing\n-------\n\nThere are no additional charges from Spanner when you use it with Spanner Vertex AI integration.\nHowever, there are other potential charges associated with this feature:\n\n- You pay the [standard rates](/vertex-ai/pricing) for Vertex AI\n online prediction. The total charge depends on the model type you use. Some model\n types have a flat per hour rate, depending on the machine type and number of\n nodes that you use. Some model types have per call rates. We recommend you\n deploy the latter in a dedicated project where you have set explicit prediction\n quotas.\n\n- You pay the [standard rates](/spanner/pricing#network) for data transfer\n between Spanner and Vertex AI. The total charge depends on\n the region hosting the server that executes the query and the region hosting the\n called endpoint. To minimize charges, deploy your Vertex AI endpoints\n in the same region as your Spanner instance. When using multi-regional\n instance configurations or multiple Vertex AI endpoints, deploy your\n endpoints on the same continent.\n\nSLA\n---\n\nDue to [Vertex AI online prediction availability](/vertex-ai/sla) being\nlower, you must properly configure Spanner ML models to maintain\n[Spanner's high availability](/spanner/sla) while using Spanner Vertex AI integration:\n\n1. Spanner ML models must use multiple Vertex AI endpoints on the backend to enable failover.\n2. Vertex AI endpoints must conform to the [Vertex AI SLA](/vertex-ai/sla).\n3. Vertex AI endpoints must provision enough capacity to handle incoming traffic.\n4. Vertex AI endpoints must use separate regions close to the Spanner database to avoid regional outages.\n5. Vertex AI endpoints should use separate projects to avoid issues with per-project prediction quotas.\n\nThe number of redundant Vertex AI endpoints depends on their SLA, and\nthe number of rows in Spanner queries:\n\nVertex AI endpoints don't need to host exactly the same model. We\nrecommend that you configure the Spanner ML model to have a primary,\ncomplex and compute intensive model as its first endpoint. Subsequent failover\nendpoints can point to simplified models that are less compute intensive,\nscale better and can absorb traffic spikes.\n\nLimitations\n-----------\n\n- Model input and output must be a JSON object.\n\nCompliance\n----------\n\n[Assured Workloads](/assured-workloads/docs/overview) don't support the\nVertex AI Prediction API. Enabling a\n[restrict resource usage constraint](/assured-workloads/docs/restrict-resource-usage)\ndisables the Vertex AI API and effectively the Spanner Vertex AI integration feature.\n\nAdditionally, we recommend that you create a\n[VPC Service Controls perimeter](/assured-workloads/docs/configure-vpc-sc) to ensure your\nproduction databases cannot connect to Vertex AI endpoints in your\nnon-production projects that might not have the proper compliance configuration."]]