AlloyDB Omni集成本地模型实现数据不出域
Data + AI Anywhere: AlloyDB Omni integration with local models
提供了一套完整的本地数据库与LLM集成方案,包含具体SQL示例与K8s部署代码,对关注数据隐私与私有化部署的工程团队极具参考价值。
Open models like Gemma 4 from Google DeepMind are a great option to keep your data local. But how can a local AI model integrate with on-premises data?
来自 Google DeepMind 的 Gemma 4 等开放模型是保持数据本地化的绝佳选择。但本地 AI 模型如何与内部部署的数据集成呢?
AlloyDB Omni, Google’s 100% PostgreSQL-compatible database that runs anywhere, now integrates with locally hosted large language models (LLMs). With AlloyDB Omni, you can build agentic experiences on your own infrastructure and on your own terms. Whether it’s in the cloud, in your datacenter, or even on your laptop, you can have data plus AI anywhere.
AlloyDB Omni 是 Google 推出的完全兼容 PostgreSQL 的数据库,可在任何地方运行,现已支持与本地托管的大型语言模型(LLM)集成。借助 AlloyDB Omni,您可以在自己的基础设施上、按照自己的条件构建智能体体验。无论是在云端、数据中心,甚至是在您的笔记本电脑上,您都可以随时随地实现数据加 AI。
Built-in AI for your local environment
为您的本地环境内置 AI
AlloyDB Omni is a downloadable, run-anywhere edition of AlloyDB that easily deploys to your own infrastructure, including on-premises. AlloyDB Omni packs powerful, built-in AI, including the same ScaNN indexing technology powering Google Search. When you pair AlloyDB Omni with a model, you can store vector embeddings at scale; search them semantically; and even query the database using natural language. You can use virtually any model you like, whether that’s a frontier Cloud-hosted model like Gemini or a local model. And with locally hosted models you maintain complete control over your data environment.
AlloyDB Omni 是 AlloyDB 的可下载、随处运行的版本,可轻松部署到您自己的基础设施中,包括内部部署环境。AlloyDB Omni 集成了强大的内置 AI 功能,包括为 Google 搜索提供支持的相同 ScaNN 索引技术。当您将 AlloyDB Omni 与模型配对使用时,您可以大规模存储向量嵌入;进行语义搜索;甚至使用自然语言查询数据库。您可以使用几乎任何您喜欢的模型,无论是像 Gemini 这样的前沿云托管模型,还是本地模型。而使用本地托管模型时,您可以完全掌控您的数据环境。
Connecting to Gemma 4, Qwen3.8, and other local models
连接 Gemma 4、Qwen3.8 和其他本地模型
You can now connect AlloyDB Omni to local models like Gemma 4 and Qwen3.8. No matter which model you choose, the architecture remains the same.
您现在可以将 AlloyDB Omni 连接到 Gemma 4 和 Qwen3.8 等本地模型。无论您选择哪种模型,架构都保持不变。
AlloyDB Omni calls a local model server directly from SQL — keeping prompts, data, and responses inside your environment.
AlloyDB Omni 直接从 SQL 调用本地模型服务器——将提示词、数据和响应保留在您的环境中。
This setup enables entirely new use cases for environments that were previously blocked from adopting agentic capabilities. If you operate an air-gapped network or have data locality requirements, you can still build intelligent applications. You can analyze local logs, generate summaries of proprietary internal documents, and power localized chatbots—all while maintaining strict data governance.
这种设置使得以前无法采用智能体能力的环境能够开启全新的用例。如果您运营的是气隙隔离网络或具有数据本地性要求,您仍然可以构建智能应用程序。您可以分析本地日志、生成专有内部文档的摘要,并驱动本地化聊天机器人——同时保持严格的数据治理。
- Keep data on-premises: Because the database and the model sit in the same local environment, your data never crosses the public internet.
- Reduce latency: Processing inference requests locally minimizes network transit time.
- Query directly via SQL: Your standard database queries can invoke machine learning functions that process data locally. Like this:
- 将数据保留在内部:由于数据库和模型位于同一本地环境中,您的数据永远不会跨越公共互联网。
- 降低延迟:在本地处理推理请求可最大限度地减少网络传输时间。
- 通过 SQL 直接查询:您的标准数据库查询可以调用在本地处理数据的机器学习函数。如下所示:
code_block
代码块
<ListValue: [StructValue([('code', "SELECT customer_name,\r\n ai.generate('Summarize in 1 short sentence: ' || comment,\r\n model_id => 'gemma4_llm') AS summary\r\nFROM customer_feedback;\r\n\r\n customer_name | summary \r\n---------------+-----------------------------------------------------------------------\r\n Alice | The customer demands a refund for a double charge or they will cancel\r\n Bob | The user likes the product but requests dark mode support."), ('language', ''), ('caption', <wagtail.rich_text.RichText object at 0x7fae7e128250>)])]>
<ListValue: [StructValue([('code', "SELECT customer_name,\r\n ai.generate('用一句话总结:' || comment,\r\n model_id => 'gemma4_llm') AS summary\r\nFROM customer_feedback;\r\n\r\n customer_name | summary \r\n---------------+-----------------------------------------------------------------------\r\n Alice | 客户要求退还重复扣款,否则将取消订单\r\n Bob | 用户喜欢该产品,但请求支持深色模式。"), ('language', ''), ('caption', <wagtail.rich_text.RichText object at 0x7fae7e128250>)])]>
Next, you’ll see how to run queries like this yourself, step by step.
接下来,您将逐步了解如何自行运行此类查询。
Get started
开始使用
You can test this integration on your own machines today. Using a Kubernetes environment we will show you how to deploy and integrate AlloyDB Omni and a local open model.
您今天即可在自己的机器上测试此集成。我们将使用 Kubernetes 环境向您展示如何部署和集成 AlloyDB Omni 与本地开源模型。
Step 0: Before you begin
步骤 0:开始之前
In this example, we will use Google Kubernetes Engine (GKE) to host the AlloyDB Omni database and local model. GKE gives us a standardized, reproducible environment but you can use the same setup on-prem or almost anywhere.
在本示例中,我们将使用 Google Kubernetes Engine (GKE) 来托管 AlloyDB Omni 数据库和本地模型。GKE 为我们提供了一个标准化、可复现的环境,但您也可以在本地数据中心或几乎任何地方使用相同的设置。
We will assume you have already setup:
我们假设您已经完成了以下设置:
- A GKE cluster, and
- Kubernetes tools kubectl and Helm
- 一个 GKE 集群,以及
- Kubernetes 工具 kubectl 和 Helm
Step 1: Deploy the AlloyDB Omni Kubernetes Operator
步骤 1:部署 AlloyDB Omni Kubernetes Operator
We will use the AlloyDB Omni Kubernetes operator to set up our AlloyDB Omni database. The Operator makes deploying and maintaining AlloyDB Omni a breeze.
我们将使用 AlloyDB Omni Kubernetes Operator 来设置我们的 AlloyDB Omni 数据库。该 Operator 使部署和维护 AlloyDB Omni 变得轻而易举。
code_block
代码块
<ListValue: [StructValue([('code', "helm install \\\r\n cert-manager oci://quay.io/jetstack/charts/cert-manager \\\r\n --version v1.21.3 \\\r\n --namespace cert-manager \\\r\n --create-namespace \\\r\n --set crds.enabled=true \\\r\n --set global.leaderElection.namespace=cert-manager\r\n\r\nhelm install alloydbomni-operator oci://gcr.io/alloydb-omni/alloydbomni-operator \\\r\n--version 1.9.0 \\\r\n--create-namespace \\\r\n--namespace alloydb-omni-system \\\r\n$(helm install --help | grep -q -- '--rollback-on-failure' && echo '--rollback-on-failure' || echo '--atomic') \\\r\n--timeout 5m"), ('language', ''), ('caption', <wagtail.rich_text.RichText object at 0x7fae7e12ba50>)])]>
Step 2: Create your AlloyDB Omni database
步骤 2:创建您的 AlloyDB Omni 数据库
Don’t forget to enable the googleMLExtension.
别忘了启用 googleMLExtension。
code_block
代码块
<ListValue: [StructValue([('code', 'kubectl create namespace ai-demo\r\n\r\ncat << \'EOF\' | kubectl apply -f -\r\napiVersion: v1\r\nkind: Secret\r\nmetadata:\r\n name: db-pw-my-omni\r\n namespace: ai-demo\r\ntype: Opaque\r\ndata:\r\n my-omni: "VmVyeVN0cm9uZ1Bhc3N3b3Jk" # password "VeryStrongPassword"\r\n---\r\napiVersion: alloydbomni.dbadmin.goog/v1\r\nkind: DBCluster\r\nmetadata:\r\n name: my-omni\r\n namespace: ai-demo\r\nspec:\r\n databaseVersion: "18.4.0"\r\n primarySpec:\r\n adminUser:\r\n passwordRef:\r\n name: db-pw-my-omni\r\n features:\r\n googleMLExtension:\r\n enabled: true\r\n resources:\r\n cpu: 2\r\n memory: 4Gi\r\n disks:\r\n - name: DataDisk\r\n size: 20Gi\r\n storageClass: standard\r\n dbLoadBalancerOptions:\r\n annotations:\r\n networking.gke.io/load-balancer-type: "internal"\r\n allowExternalIncomingTraffic: true\r\nEOF'), ('language', ''), ('caption', <wagtail.rich_text.RichText object at 0x7fae7e129b50>)])]>
<ListValue: [StructValue([('code', 'kubectl create namespace ai-demo\r\n\r\ncat << \'EOF\' | kubectl apply -f -\r\napiVersion: v1\r\nkind: Secret\r\nmetadata:\r\n name: db-pw-my-omni\r\n namespace: ai-demo\r\ntype: Opaque\r\ndata:\r\n my-omni: "VmVyeVN0cm9uZ1Bhc3N3b3Jk" # password "VeryStrongPassword"\r\n---\r\napiVersion: alloydbomni.dbadmin.goog/v1\r\nkind: DBCluster\r\nmetadata:\r\n name: my-omni\r\n namespace: ai-demo\r\nspec:\r\n databaseVersion: "18.4.0"\r\n primarySpec:\r\n adminUser:\r\n passwordRef:\r\n name: db-pw-my-omni\r\n features:\r\n googleMLExtension:\r\n enabled: true\r\n resources:\r\n cpu: 2\r\n memory: 4Gi\r\n disks:\r\n - name: DataDisk\r\n size: 20Gi\r\n storageClass: standard\r\n dbLoadBalancerOptions:\r\n annotations:\r\n networking.gke.io/load-balancer-type: "internal"\r\n allowExternalIncomingTraffic: true\r\nEOF'), ('language', ''), ('caption', <wagtail.rich_text.RichText object at 0x7fae7e129b50>)])]
Step 3: Deploy your AI model
步骤 3:部署您的 AI 模型
We will use Ollama to help us deploy our model.
我们将使用 Ollama 来帮助我们部署模型。
In this example we deploy Gemma 4 from Google DeepMind. Or, you can modify this command to deploy Qwen3.8 – just change a few lines as noted in the comments.
在本示例中,我们部署来自 Google DeepMind 的 Gemma 4。或者,您可以修改此命令以部署 Qwen3.8 – 只需按照注释中的说明更改几行即可。
code_block
代码块
<ListValue: [StructValue([('code', 'cat << \'EOF\' | kubectl apply -f -\r\napiVersion: apps/v1\r\nkind: Deployment\r\nmetadata:\r\n name: ollama\r\n namespace: ai-demo\r\nspec:\r\n replicas: 1\r\n selector:\r\n matchLabels:\r\n app: ollama\r\n template:\r\n metadata:\r\n labels:\r\n app: ollama\r\n spec:\r\n containers:\r\n - name: ollama\r\n image: ollama/ollama:latest\r\n ports:\r\n - containerPort: 11434\r\n env:\r\n - name: OLLAMA_KEEP_ALIVE\r\n value: "-1" # keep the model in RAM\r\n - name: OLLAMA_LOAD_TIMEOUT\r\n value: "20m"\r\n resources:\r\n requests:\r\n cpu: "4"\r\n memory: "16Gi" # for Qwen 3.8: 24Gi\r\n volumeMounts:\r\n - name: models\r\n mountPath: /root/.ollama\r\n lifecycle:\r\n postStart:\r\n exec:\r\n command: ["/bin/sh", "-c", "(sleep 5 && ollama pull gemma4:12b) >/dev/null 2>&1 &"]\r\n # For Qwen 3.8, comment out the line above and use this one:\r\n # command: ["/bin/sh", "-c", "(sleep 5 && ollama pull qwen3.8) >/dev/null 2>&1 &"]\r\n volumes:\r\n - name: models\r\n ephemeral:\r\n volumeClaimTemplate:\r\n spec:\r\n accessModes: ["ReadWriteOnce"]\r\n resources:\r\n requests:\r\n storage: 30Gi\r\n---\r\napiVersion: v1\r\nkind: Service\r\nmetadata:\r\n name: ollama-service\r\n namespace: ai-demo\r\nspec:\r\n type: ClusterIP\r\n ports:\r\n - port: 11434\r\n targetPort: 11434\r\n selector:\r\n app: ollama\r\nEOF'), ('language', ''), ('caption', <wagtail.rich_text.RichText object at 0x7fae7d6fac90>)])]>
<ListValue: [StructValue([('code', 'cat << EOF | kubectl apply -f -\r\napiVersion: apps/v1\r\nkind: Deployment\r\nmetadata:\r\n name: ollama\r\n namespace: ai-demo\r\nspec:\r\n replicas: 1\r\n selector:\r\n matchLabels:\r\n app: ollama\r\n template:\r\n metadata:\r\n labels:\r\n app: ollama\r\n spec:\r\n containers:\r\n - name: ollama\r\n image: ollama/ollama:latest\r\n ports:\r\n - containerPort: 11434\r\n env:\r\n - name: OLLAMA_KEEP_ALIVE\r\n value: "-1" # keep the model in RAM\r\n - name: OLLAMA_LOAD_TIMEOUT\r\n value: "20m"\r\n resources:\r\n requests:\r\n cpu: "4"\r\n memory: "16Gi" # for Qwen 3.8: 24Gi\r\n volumeMounts:\r\n - name: models\r\n mountPath: /root/.ollama\r\n lifecycle:\r\n postStart:\r\n exec:\r\n command: ["/bin/sh", "-c", "(sleep 5 && ollama pull gemma4:12b) >/dev/null 2>&1 &"]\r\n # For Qwen 3.8, comment out the line above and use this one:\r\n # command: ["/bin/sh", "-c", "(sleep 5 && ollama pull qwen3.8) >/dev/null 2>&1 &"]\r\n volumes:\r\n - name: models\r\n ephemeral:\r\n volumeClaimTemplate:\r\n spec:\r\n accessModes: ["ReadWriteOnce"]\r\n resources:\r\n requests:\r\n storage: 30Gi\r\n---\r\napiVersion: v1\r\nkind: Service\r\nmetadata:\r\n name: ollama-service\r\n namespace: ai-demo\r\nspec:\r\n type: ClusterIP\r\n ports:\r\n - port: 11434\r\n targetPort: 11434\r\n selector:\r\n app: ollama\r\nEOF'), ('language', ''), ('caption', <wagtail.rich_text.RichText object at 0x7fae7d6fac90>)])]
Step 4: Register the model with AlloyDB Omni
步骤 4:向 AlloyDB Omni 注册模型
Connect to your database.
连接到您的数据库。
code_block
代码块
<ListValue: [StructValue([('code', 'kubectl exec -it -n ai-demo $(kubectl get pod -n ai-demo -l alloydbomni.internal.dbadmin.goog/task-type=database -o jsonpath=\'{.items[0].metadata.name}\') -c database -- env PGPASSWORD="VeryStrongPassword" psql -h 127.0.0.1 -U postgres'), ('language', ''), ('caption', <wagtail.rich_text.RichText object at 0x7fae7f4f6090>)])]>
<ListValue: [StructValue([('code', 'kubectl exec -it -n ai-demo $(kubectl get pod -n ai-demo -l alloydbomni.internal.dbadmin.goog/task-type=database -o jsonpath=\'{.items[0].metadata.name}\') -c database -- env PGPASSWORD="VeryStrongPassword" psql -h 127.0.0.1 -U postgres'), ('language', ''), ('caption', <wagtail.rich_text.RichText object at 0x7fae7f4f6090>)])]
Note: If you receive a connection error, you might need to wait a moment for your database to provision.
注意:如果出现连接错误,您可能需要等待片刻,以便数据库完成配置。
Now you should be connected to your AlloyDB Omni database with the psql client. Next, run the following SQL script to register your local model.
现在您应该已经通过 psql 客户端连接到您的 AlloyDB Omni 数据库。接下来,运行以下 SQL 脚本以注册您的本地模型。
code_block
代码块
更进一步:量化金融体系
看懂新闻只是起点——沿量化金融路径,把它变成能交付的工程能力