Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

stub out the page for plugins

Copplee07bde96589a
diff --git a/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts b/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts
index 0ae444aef33..70f1a3cb56f 100644
--- a/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts
+++ b/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts
@@ -893,6 +893,10 @@ export const ai: NavMenuConstant = {
name: 'OpenAI completions with Edge Functions',
url: '/guides/ai/examples/openai',
},
+ {
+ name: 'Building ChatGPT Plugins',
+ url: '/guides/ai/examples/building-chatgpt-plugins',
+ },
{
name: 'ChatGPT for your own knowledge base',
url: '/guides/ai/examples/nextjs-vector-search',
diff --git a/apps/docs/pages/guides/ai.mdx b/apps/docs/pages/guides/ai.mdx
index 9b375a434c4..0be1bc28783 100644
--- a/apps/docs/pages/guides/ai.mdx
+++ b/apps/docs/pages/guides/ai.mdx
@@ -13,6 +13,15 @@ Supabase provides a number of tools to get started with Vectors and Embeddings.
- An embedding store using the popular [pgvector](https://github.com/pgvector/pgvector/)
- A Python Library for managing unstructured collections called [Vecs](https://supabase.github.io/vecs/api)
+## Features
+
+Supabase provides a full toolkit for developing AI applications.
+
+- A vector store and embeddings support using pgvector.
+- A Python client for managing unstructured embeddings.
+- Database migrations for managing structured embeddings.
+- Integrations with all popular AI providers, such as OpenAI, Hugging Face, LangChain, and more.
+
## Examples
Check out all of the AI [templates and examples](https://github.com/supabase/supabase/tree/master/examples/ai) in our GitHub repository.
@@ -32,12 +41,6 @@ Check out all of the AI [templates and examples](https://github.com/supabase/sup
</div>
export const examples = [
- {
- name: 'ChatGPT for your own knowledge base',
- description:
- 'Learn how to build a ChatGPT-style doc search powered by Next.js, OpenAI, and Supabase.',
- href: '/guides/ai/examples/nextjs-vector-search',
- },
{
name: 'Headless Vector Search',
description: 'A toolkit to perform vector similarity search on your knowledge base embeddings.',
@@ -56,6 +59,35 @@ export const examples = [
},
]
+## Case studies
+
+<div className="grid md:grid-cols-12 gap-4 not-prose">
+ {customers.map((x) => (
+ <div className="col-span-4" key={x.href}>
+ <Link href={x.href} passHref>
+ <a>
+ <GlassPanel title={x.name}>{x.description}</GlassPanel>
+ </a>
+ </Link>
+ </div>
+ ))}
+</div>
+
+export const customers = [
+ {
+ name: 'Mendable switches from Pinecone to Supabase for PostgreSQL vector embeddings',
+ description:
+ 'How Mendable boosts efficiency and accuracy of chat powered search for documentation using Supabase with pgvector',
+ href: 'https://supabase.com/customers/mendableai',
+ },
+ {
+ name: 'Markprompt: GDPR-Compliant AI Chatbots for Docs and Websites',
+ description:
+ "AI-powered chatbot platform, Markprompt, empowers developers to deliver efficient and GDPR-compliant prompt experiences on top of their content, by leveraging Supabase's secure and privacy-focused database and authentication solutions",
+ href: 'https://supabase.com/customers/markprompt',
+ },
+]
+
export const Page = ({ children }) => <Layout meta={meta} children={children} hideToc={true} />
export default Page
diff --git a/apps/docs/pages/guides/ai/examples/building-chatgpt-plugins.mdx b/apps/docs/pages/guides/ai/examples/building-chatgpt-plugins.mdx
new file mode 100644
index 00000000000..239f2a8931e
--- /dev/null
+++ b/apps/docs/pages/guides/ai/examples/building-chatgpt-plugins.mdx
@@ -0,0 +1,161 @@
+import Layout from '~/layouts/DefaultGuideLayout'
+import StepHikeCompact from '~/components/StepHikeCompact'
+
+export const meta = {
+ title: 'Building ChatGPT plugins',
+ subtitle: 'Use Supabase as a Retrieval Store for your ChatGPT plugin.',
+ breadcrumb: 'AI Examples',
+}
+
+ChatGPT recently released [Plugins](https://openai.com/blog/chatgpt-plugins) which help ChatGPT access up-to-date information, run computations, or use third-party services.
+If you're building a plugin for ChatGPT, you'll probably want to answer questions from a specific source. We can solve this with “retrieval plugins”, which allow ChatGPT to access information from a database.
+
+## What is ChatGPT Retrieval Plugin?
+
+A [Retrieval Plugin](https://github.com/openai/chatgpt-retrieval-plugin) is a Python project designed to inject external data into a ChatGPT conversation. It does a few things:
+
+1. Turn documents into smaller chunks.
+2. Converts chunks into embeddings using OpenAI's `text-embedding-ada-002` model.
+3. Stores the embeddings into a vector database.
+4. Queries the vector database for relevant documents when a question is asked.
+
+It allows ChatGPT to dynamically pull relevant information into conversations from your data sources. This could be PDF documents, Confluence, or Notion knowledge bases.
+
+## Example: Chat with Postgres Docs
+
+Let’s build an example where we can “ask ChatGPT questions” about the Postgres documentation. ChatGPT already knows about the Postgres docs, because they are publicly available, but this is still a useful example which will show you how to work with PDF files.
+
+This will require several steps:
+
+1. Download all the [Postgres docs as a PDF](https://www.postgresql.org/files/documentation/pdf/15/postgresql-15-US.pdf)
+2. Convert the docs into chunks of embedded text and store them in Supabase
+3. Run our plugin locally so that we can ask questions about the Postgres docs.
+
+<img
+ className="dark:hidden !m-0"
+ alt="diagram reference"
+ src="https://supabase.com/images/blog/2023-05-25-chatgpt-plugins-support-postgres/chatgpt-plugin-scheme--light.png"
+/>
+
+<img
+ className="hidden dark:block !m-0"
+ alt="diagram reference"
+ src="https://supabase.com/images/blog/2023-05-25-chatgpt-plugins-support-postgres/chatgpt-plugin-scheme--dark.png"
+/>
+
+### Step 1: Fork the ChatGPT Retrieval Plugin repository
+
+Fork the ChatGPT Retrieval Plugin repository to your GitHub account and clone it to your local machine. Read through the `README.md` file to understand the project structure.
+
+### Step 2: Install dependencies
+
+Choose your desired datastore provider and remove unused dependencies from `pyproject.toml`. For this example, we'll use Supabase. And install dependencies with Poetry:
+
+```bash
+poetry install
+```
+
+### Step 3: Create a Supabase project
+
+Create a [Supabase project](https://supabase.com/dashboard) and database by following the instructions [here](https://supabase.com/docs/guides/platform). Export the environment variables required for the retrieval plugin to work:
+
+```bash
+export OPENAI_API_KEY=<open_ai_api_key>
+export DATASTORE=supabase
+export SUPABASE_URL=<supabase_url>
+export SUPABASE_SERVICE_ROLE_KEY=<supabase_key>
+```
+
+For Postgres datastore, you'll need to export these environment variables instead:
+
+```bash
+export OPENAI_API_KEY=<open_ai_api_key>
+export DATASTORE=postgres
+export PG_HOST=<postgres_host_url>
+export PG_PASSWORD=<postgres_password>
+```
+
+### Step 4: Run Postgres Locally
+
+To start quicker you may use Supabase CLI to spin everything up locally as it already includes pgvector from the start. Install `supabase-cli`, go to the `examples/providers` folder in the repo and run:
+
+```bash
+supabase start
+```
+
+This will pull all docker images and run supabase stack in docker on your local machine. It will also apply all the necessary migrations to set the whole thing up. You can then use your local setup the same way, just export the environment variables and follow to the next steps.
+
+Using `supabase-cli` is not required and you can use any other docker image or hosted version of PostgresDB that includes `pgvector`. Just make sure you run migrations from `examples/providers/supabase/migrations/20230414142107_init_pg_vector.sql`.
+
+### Step 5: Obtain OpenAI API key
+
+To create embeddings Plugin uses OpenAI API and `text-embedding-ada-002` model. Each time we add some data to our datastore, or try to query relevant information from it, embedding will be created either for inserted data chunk, or for the query itself. To make it work we need to export `OPENAI_API_KEY`. If you already have an account in OpenAI, you just need to go to [User Settings - API keys](https://platform.openai.com/account/api-keys) and Create new secret key.
+
+![OpenAI Secret Keys](/images/blog/2023-05-25-chatgpt-plugins-support-postgres/openai-secret-keys.png)
+
+### Step 6: Run the plugin
+
+Execute the following command to run the plugin:
+
+```bash
+poetry run dev
+# output
+INFO: Will watch for changes in these directories: ['./chatgpt-retrieval-plugin']
+INFO: Uvicorn running on http://localhost:3333 (Press CTRL+C to quit)
+INFO: Started reloader process [87843] using WatchFiles
+INFO: Started server process [87849]
+INFO: Waiting for application startup.
+INFO: Application startup complete.
+```
+
+The plugin will start on your localhost - port :3333 by default.
+
+### Step 6: Populating data in the datastore
+
+For this example, we'll upload Postgres documentation to the datastore. Download the [Postgres documentation](https://www.postgresql.org/files/documentation/pdf/15/postgresql-15-US.pdf) and use the `/upsert-file` endpoint to upload it:
+
+```bash
+curl -X POST -F \\"file=@./postgresql-15-US.pdf\\" <http://localhost:3333/upsert-file>
+```
+
+The plugin will split your data and documents into smaller chunks automatically. You can view the chunks using the Supabase dashboard or any other SQL client you prefer. For the whole Postgres Documentation I got 7,904 records in my documents table, which is not a lot, but we can try to add index for `embedding` column to speed things up by a little. To do so, you should run the following SQL command:
+
+```sql
+create index on documents
+using ivfflat (embedding vector_ip_ops)
+with (lists = 10);
+```
+
+This will create an index for the inner product distance function. Important to note that it is an approximate index. It will change the logic from performing the exact nearest neighbor search to the approximate nearest neighbor search.
+
+We are using `lists = 10`, because as a general guideline, you should start looking for optimal lists constant value with the formula: `rows / 1000` when you have less than 1 million records in your table.
+
+### Step 7: Using our plugin within ChatGPT
+
+To integrate our plugin with ChatGPT, register it in the ChatGPT dashboard. Assuming you have access to ChatGPT Plugins and plugin development, select the Plugins model in a new chat, then choose "Plugin store" and "Develop your own plugin." Enter `localhost:3333` into the domain input, and your plugin is now part of ChatGPT.
+
+![ChatGPT Change Model](/images/blog/2023-05-25-chatgpt-plugins-support-postgres/chatgpt-change-model.png)
+
+![ChatGPT Plugin Store](/images/blog/2023-05-25-chatgpt-plugins-support-postgres/chatgpt-plugin-store.png)
+
+![ChatGPT Local Plugin](/images/blog/2023-05-25-chatgpt-plugins-support-postgres/chatgpt-local-plugin.png)
+
+You can now ask questions about Postgres and receive answers derived from the documentation!
+
+Let's try it out: ask ChatGPT to find out when to use `check` and when to use `using`. You will be able to see what queries were sent to our plugin and what it responded to.
+
+![Ask ChatGPT](/images/blog/2023-05-25-chatgpt-plugins-support-postgres/ask-chatgpt.png)
+
+![ChatGPT Query](/images/blog/2023-05-25-chatgpt-plugins-support-postgres/chatgpt-query.png)
+
+And after ChatGPT receives a response from the plugin it will answer your question with the data from the documentation.
+
+![ChatGPT Reply](/images/blog/2023-05-25-chatgpt-plugins-support-postgres/chatgpt-reply.png)
+
+## Resources
+
+- ChatGPT Retrieval Plugin: [github.com/openai/chatgpt-retrieval-plugin](https://github.com/openai/chatgpt-retrieval-plugin)
+- ChatGTP Plugins: [official documentation](https://platform.openai.com/docs/plugins/introduction)
+
+export const Page = ({ children }) => <Layout meta={meta} children={children} />
+export default Page