The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
cleans up the structure of the docs a bit
Copple666ad8dac680
diff --git a/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts b/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.tsindex fb0badfe875..665897064c0 100644--- a/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts+++ b/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts@@ -861,7 +861,10 @@ export const ai: NavMenuConstant = {items: [{ name: 'Overview', url: '/guides/ai' },{ name: 'Concepts', url: '/guides/ai/concepts' },- { name: 'Structured & Unstructured', url: '/guides/ai/structured-unstructured-embeddings' },+ {+ name: 'Structured & unstructured embeddings',+ url: '/guides/ai/structured-unstructured-embeddings',+ },{name: 'Quickstarts',url: undefined,@@ -882,27 +885,27 @@ export const ai: NavMenuConstant = {url: undefined,items: [{- name: 'Headless Vector Search',- url: '/guides/ai/examples/headless-vector-search',+ name: 'OpenAI completions using Edge Functions',+ url: '/guides/ai/examples/openai',},{- name: 'Image Search with OpenAI CLIP',+ name: 'Image search with OpenAI CLIP',url: '/guides/ai/examples/image-search-openai-clip',},{name: 'Generate image captions using Hugging Face',url: '/guides/ai/examples/huggingface-image-captioning',},- {- name: 'OpenAI completions using Edge Functions',- url: '/guides/ai/examples/openai',- },{name: 'Building ChatGPT Plugins',url: '/guides/ai/examples/building-chatgpt-plugins',},{- name: 'Vector search with Next.js and OpenAI',+ name: 'Adding generative Q&A to your documentation',+ url: '/guides/ai/examples/headless-vector-search',+ },+ {+ name: 'Adding generative Q&A to your Next.js site',url: '/guides/ai/examples/nextjs-vector-search',},],diff --git a/apps/docs/pages/guides/ai/examples/headless-vector-search.mdx b/apps/docs/pages/guides/ai/examples/headless-vector-search.mdxindex ca98d09eaa2..467d3788a38 100644--- a/apps/docs/pages/guides/ai/examples/headless-vector-search.mdx+++ b/apps/docs/pages/guides/ai/examples/headless-vector-search.mdx@@ -2,17 +2,17 @@ import Layout from '~/layouts/DefaultGuideLayout'import StepHikeCompact from '~/components/StepHikeCompact'export const meta = {- title: 'Headless Vector Search',- subtitle: 'A toolkit to perform vector similarity search on your knowledge base embeddings.',+ title: 'Adding generative Q&A for your documentation',+ subtitle:+ 'Learn how to build a ChatGPT-style doc search powered using our headless search toolkit.',breadcrumb: 'AI Examples',}-Provides a vector/similarity search for any documentation site or knowledge base. It's headless, so that you can integrate it into your existing website.+Supabase provides a [Headless Search Toolkit](https://github.com/supabase/headless-vector-search) for adding "Generative Q&A" to your documentation. The toolkit is "headless", so that you can integrate it into your existing website and style it to match your website theme.-This toolkit consists of 2 parts:+You can see how this works with the Supabase docs. Just him `cmd+k` and "ask" for something like "what are the features of supabase?". You will see that the response is streamed back, using the information provided in the docs:-- The [Headless Vector Search](https://github.com/supabase/headless-vector-search) template which you can deploy in your own organization.-- A [GitHub Action](https://github.com/supabase/embeddings-generator) which will ingest your markdown files, convert them to embeddings, and store them in your database.+## Tech stack@@ -20,5 +20,105 @@ This toolkit consists of 2 parts:- OpenAI: Embeddings and completions.- GitHub Actions: for ingesting your markdown docs.+## Toolkit++This toolkit consists of 2 parts:++- The [Headless Vector Search](https://github.com/supabase/headless-vector-search) template which you can deploy in your own organization.+- A [GitHub Action](https://github.com/supabase/embeddings-generator) which will ingest your markdown files, convert them to embeddings, and store them in your database.++## Usage++There are 3 steps to build similarity search inside your documentation:++1. Prepare your database.+2. Ingest your documentation.+3. Add a search interface.++### Prepare your database++To prepare, create a [new Supabase project](https://database.new) and store the database and API credentials, which you can find in the project [settings](https://app.supabase.com/_/settings).++Now we can use the [Headless Vector Search](https://github.com/supabase/headless-vector-search#set-up) instructions to set up the database:++1. Clone the repo to your local machine: `git clone [email protected]:supabase/headless-vector-search.git`+2. Link the repo to your remote project: `supabase link --project-ref XXX`+3. Apply the database migrations: `supabase db push`+4. Set your OpenAI key as a secret: `supabase secrets set OPENAI_KEY=sk-xxx`+5. Deploy the Edge Functions: `supabase functions deploy --no-verify-jwt`+6. Expose `docs` schema via API in Supabase Dashboard [settings](https://app.supabase.com/project/_/settings/api) > `API Settings` > `Exposed schemas`++### Ingest your documentation++Now we need to push your documentation into the database as embeddings. You can do this manually, but to make it easier we've created a [GitHub Action](https://github.com/marketplace/actions/supabase-embeddings-generator) which can update your database every time there is a Pull Request.++In your knowledge base repository, create a new action called `.github/workflows/generate_embeddings.yml` with the following content:++```yml+name: 'generate_embeddings'+on: # run on main branch changes+ push:+ branches:+ - main++jobs:+ generate:+ runs-on: ubuntu-latest+ steps:+ - uses: actions/checkout@v3+ - uses: supabase/[email protected] # Update this to the latest version.+ with:+ supabase-url: 'https://your-project-ref.supabase.co' # Update this to your project URL.+ supabase-service-role-key: ${{ secrets.SUPABASE_SERVICE_ROLE_KEY }}+ openai-key: ${{ secrets.OPENAI_KEY }}+ docs-root-path: 'docs' # the path to the root of your md(x) files+```++Make sure to choose the latest version, and set your `SUPABASE_SERVICE_ROLE_KEY` and `OPENAI_KEY` as repository secrets in your repo settings (settings > secrets > actions).++### Add a search interface++Now inside your docs, you need to create a search interface. Because this is a headless interface, you can use it with any language. The only requirement is that you send the user query to the `query` Edge Function, which will stream an answer back from OpenAI. It might look something like this:++```js+const onSubmit = (e: Event) => {+ e.preventDefault()+ answer.value = ""+ isLoading.value = true++ const query = new URLSearchParams({ query: inputRef.current!.value })+ const projectUrl = `https://your-project-ref.functions.supabase.co`+ const queryURL = `${projectURL}/${query}`+ const eventSource = new EventSource(queryURL)++ eventSource.addEventListener("error", (err) => {+ isLoading.value = false+ console.error(err)+ })++ eventSource.addEventListener("message", (e: MessageEvent) => {+ isLoading.value = false++ if (e.data === "[DONE]") {+ eventSource.close()+ return+ }++ const completionResponse: CreateCompletionResponse = JSON.parse(e.data)+ const text = completionResponse.choices[0].text++ answer.value += text+ });++ isLoading.value = true+}+```++## Resources++- Read about how we built [ChatGPT for the Supabase Docs](https://supabase.com/blog/chatgpt-supabase-docs).+- Read the pgvector Docs for [Embeddings and vector similarity](/docs/guides/database/extensions/pgvector)+- See how to build something like this from scratch [using Next.js](/docs/guides/ai/examples/nextjs-vector-search).+export const Page = ({ children }) => <Layout meta={meta} children={children} />export default Pagediff --git a/apps/docs/pages/guides/ai/examples/nextjs-vector-search.mdx b/apps/docs/pages/guides/ai/examples/nextjs-vector-search.mdxindex b90662d011c..01bef30379e 100644--- a/apps/docs/pages/guides/ai/examples/nextjs-vector-search.mdx+++ b/apps/docs/pages/guides/ai/examples/nextjs-vector-search.mdx@@ -10,7 +10,7 @@ export const meta = {tocVideo: 'xmfNUCjszh4',}-In this tutorial we'll build a custom ChatGPT-like search experience for your own knowledge base using Next.js. You will:+While our [Headless Vector search](/docs/guides/ai/examples/headless-vector-search) provides a toolkit for generative Q&A, in this tutorial we'll go more in-depth, build a custom ChatGPT-like search experience from the ground-up using Next.js. You will:1. Convert your markdown into embeddings using OpenAI.2. Store you embeddings in Postgres using pgvector.@@ -18,13 +18,7 @@ In this tutorial we'll build a custom ChatGPT-like search experience for your owYou can read our [Supabase Clippy](https://supabase.com/blog/chatgpt-supabase-docs) blog post for a full example.-We assume that you have a Next.js project with a collection of `.mdx` files nested inside your `pages` directory. We will start developing locally with the Supabase CLI and then push our local database changes to our hosted Supabase project.--<Admonition type="note">--You can find the [full Next.js example on GitHub](https://github.com/supabase-community/nextjs-openai-doc-search).--</Admonition>+We assume that you have a Next.js project with a collection of `.mdx` files nested inside your `pages` directory. We will start developing locally with the Supabase CLI and then push our local database changes to our hosted Supabase project. You can find the [full Next.js example on GitHub](https://github.com/supabase-community/nextjs-openai-doc-search).## Create a projectdiff --git a/apps/docs/pages/guides/ai/structured-unstructured-embeddings.mdx b/apps/docs/pages/guides/ai/structured-unstructured-embeddings.mdxindex 90c69fb4f90..05a3bf896c0 100644--- a/apps/docs/pages/guides/ai/structured-unstructured-embeddings.mdx+++ b/apps/docs/pages/guides/ai/structured-unstructured-embeddings.mdx@@ -7,9 +7,11 @@ export const meta = {sidebar_label: 'Structured and Unstructured embeddings',}-Most vector stores treat embeddings like NoSQL, unstructured data. Supabase is flexible enough to fit either a structured or an unstructured approach. Compare these code snippets:+Most vector stores treat embeddings like NoSQL, unstructured data. Supabase is flexible enough to fit either a structured or an unstructured approach.-**Structured (SQL)**+Compare these code snippets:++## Structured```sqlcreate table (@@ -20,7 +22,9 @@ create table ();```-**Unstructured (Python)**+A structured approach is usually defined in SQL, and managed via Database Migrations.++## Unstructured```pyimport vecs@@ -28,6 +32,8 @@ import vecsdocs = vx.create_collection(name="docs", dimension=1536)```+An unstructured approach is usually defined in Python, and has a much looser table definition.+## Choosing the right modelBoth approaches create a table where you can store your embeddings and some metadata. You should choose the best approach for your use-case.@@ -37,10 +43,6 @@ Both approaches create a table where you can store your embeddings and some metaBoth approaches are fine, and the one you should choose depends on your use-case.-## Engineering for scale--Data sources for vectors are typically large. As you grow you will want to run your Vector workload in unstructured collection across several databases (sometimes called "pods"). This allows each collection to scale independently. You can learn more tips in the [Engineering for Scale](/docs/guides/ai/engineering-for-scale) doc.-export const Page = ({ children }) => <Layout meta={meta} children={children} />export default Pagediff --git a/apps/docs/public/img/ai/headless-search/headless.png b/apps/docs/public/img/ai/headless-search/headless.pngnew file mode 100644index 00000000000..f9cbdc0457dBinary files /dev/null and b/apps/docs/public/img/ai/headless-search/headless.png differ