Google AlloyDB for PostgreSQL
AlloyDB 是一种完全托管的关系型数据库服务,提供高吞吐量、无缝集成和出色的可扩展性。AlloyDB 与 PostgreSQL 100% 兼容。利用 AlloyDB 的 Langchain 集成,扩展您的数据库应用程序以构建由 AI 驱动的体验。
本笔记本将介绍如何使用 AlloyDB for PostgreSQL 通过 AlloyDBVectorStore 类存储向量嵌入。
在 GitHub 上了解有关该软件包的更多信息。
开始之前
要运行此笔记本,您需要执行以下操作:
🦜🔗 库安装
安装集成库 langchain-google-alloydb-pg 以及嵌入服务库 langchain-google-vertexai。
%pip install --upgrade --quiet langchain-google-alloydb-pg langchain-google-vertexai
仅限 Colab: 取消注释下面的单元格以重启内核,或使用按钮重启内核。对于 Vertex AI Workbench,您可以使用顶部的按钮重启终 端。
# # Automatically restart kernel after installs so that your environment can access the new packages
# import IPython
# app = IPython.Application.instance()
# app.kernel.do_shutdown(True)
🔐 身份验证
通过笔记本中登录的 IAM 用户身份验证到 Google Cloud,以便访问您的 Google Cloud 项目。
- 如果您正在使用 Colab 运行此笔记本,请使用下面的单元格并继续。
- 如果您正在使用 Vertex AI Workbench,请查看此处的设置说明:https://github.com/GoogleCloudPlatform/generative-ai/tree/main/setup-env。
from google.colab import auth
auth.authenticate_user()
☁ 设置您的 Google Cloud 项目
设置您的 Google Cloud 项目,以便您在此 notebook 中利用 Google Cloud 资源。
如果您不知道您的项目 ID,可以尝试以下方法:
- 运行
gcloud config list。 - 运行
gcloud projects list。 - 请参阅支持页面:查找项目 ID。
# @markdown Please fill in the value below with your Google Cloud project ID and then run the cell.
PROJECT_ID = "my-project-id" # @param {type:"string"}
# Set the project id
!gcloud config set project {PROJECT_ID}