Skip to content
AI & Vectors

学习如何将 Supabase 与 LlamaIndex 集成,这是一个用于你的大语言模型应用的数据框架。

Learn how to integrate Supabase with LlamaIndex, a data framework for your LLM applications.

本指南将带你通过一个使用 LlamaIndex SupabaseVectorStore 的基本示例。

🌐 This guide will walk you through a basic example using the LlamaIndex SupabaseVectorStore.

项目设置 #

🌐 Project setup

要创建一个新的 Postgres 数据库,在 Supabase 里新建一个项目:

🌐 To create a new Postgres database, start a new Project in Supabase:

  1. 在 Supabase 仪表板中创建一个新项目
  2. 输入你的项目详情。记得把密码安全地保存起来。

你的数据库将在不到一分钟内可用。

🌐 Your database will be available in less than a minute.

查找你的凭证:

你可以在仪表板上找到你的项目凭证:

🌐 You can find your project credentials on the dashboard:

启动注意本 #

🌐 Launching a notebook

在 Colab 中启动我们的 LlamaIndex 注意本:

🌐 Launch our LlamaIndex notebook in Colab:

在注意本的顶部,你会看到一个按钮 Copy to Drive。点击这个按钮就可以把注意本复制到你的谷歌云端硬盘。

🌐 At the top of the notebook, you'll see a button Copy to Drive. Click this button to copy the notebook to your Google Drive.

填写你的 OpenAI 凭证 #

🌐 Fill in your OpenAI credentials

在注意本里,添加你的 OPENAI_API_KEY 密钥。找到包含这段代码的单元格:

🌐 Inside the Notebook, add your OPENAI_API_KEY key. Find the cell which contains this code:

1
import os
2
os.environ['OPENAI_API_KEY'] = "[your_openai_api_key]"

正在连接到你的数据库 #

🌐 Connecting to your database

在注意本里,找到指定 DB_CONNECTION 的单元格。它会包含像这样的代码:

🌐 Inside the Notebook, find the cell which specifies the DB_CONNECTION. It will contain some code like this:

1
DB_CONNECTION = "postgresql://<user>:<password>@<host>:<port>/<db_name>"
2
3
# create vector store client
4
vx = vecs.create_client(DB_CONNECTION)

DB_CONNECTION 替换为你自己的连接字符串。你可以在项目仪表板上点击 连接 找到连接字符串。

🌐 Replace the DB_CONNECTION with your own connection string. You can find the connection string on your project dashboard by clicking Connect.

浏览注意本 #

🌐 Stepping through the notebook

现在剩下的就是逐步运行注意本了。你可以通过点击每个代码单元左上角的“执行”按钮(ctrl+enter)来完成。注意本会引导你完成创建集合、向其中添加数据以及查询的过程。

🌐 Now all that's left is to step through the notebook. You can do this by clicking the "execute" button (ctrl+enter) at the top left of each code cell. The notebook guides you through the process of creating a collection, adding data to it, and querying it.

你可以在 表格编辑器 中查看已插入的项目,只需从模式下拉菜单中选择 vecs 模式即可。

🌐 You can view the inserted items in the Table Editor, by selecting the vecs schema from the schema dropdown.

Colab documents

资源 #

🌐 Resources

  • 访问 LlamaIndex + SupabaseVectorStore 文档
  • 访问官方 LlamaIndex 仓库