{"data":{"slug":"supabase-community-nextjs-openai-doc-search","name":"nextjs-openai-doc-search","tagline":"Template for building your own custom ChatGPT style doc search","github_url":"https://github.com/supabase-community/nextjs-openai-doc-search","owner":"supabase-community","repo":"nextjs-openai-doc-search","owner_avatar_url":"https://avatars.githubusercontent.com/u/87650496?v=4","primary_language":"TypeScript","stars":1732,"forks":315,"topics":["ai","chatgpt","nextjs","openai","postgres","supabase","template","vector-search"],"archived":false,"github_pushed_at":"2026-05-12T19:58:11+00:00","maintenance_label":"Slowing","stars_delta_30d":3,"url":"https://www.graphcanon.com/tools/supabase-community-nextjs-openai-doc-search","markdown_url":"https://www.graphcanon.com/tools/supabase-community-nextjs-openai-doc-search.md","api_url":"https://www.graphcanon.com/api/graphcanon/tools/supabase-community-nextjs-openai-doc-search","graph_url":"https://www.graphcanon.com/api/graphcanon/graph?tool=supabase-community-nextjs-openai-doc-search","description":"Template for building your own custom ChatGPT style doc search powered by Next.js, OpenAI, and Supabase.","homepage_url":"https://supabase.com/blog/chatgpt-supabase-docs","license":"Apache-2.0","open_issues":12,"watchers":17,"ai_summary":"This repository offers a templated solution using Next.js, OpenAI API, and Supabase to create a document search tool similar in functionality to ChatGPT.","readme_excerpt":"# Next.js OpenAI Doc Search Starter\n\nThis starter takes all the `.mdx` files in the `pages` directory and processes them to use as custom context within [OpenAI Text Completion](https://platform.openai.com/docs/guides/completion) prompts.\n\n## Deploy\n\nDeploy this starter to Vercel. The Supabase integration will automatically set the required environment variables and configure your [Database Schema](./supabase/migrations/20230406025118_init.sql). All you have to do is set your `OPENAI_KEY` and you're ready to go!\n\n[\n\n## Technical Details\n\nBuilding your own custom ChatGPT involves four steps:\n\n1. [👷 Build time] Pre-process the knowledge base (your `.mdx` files in your `pages` folder).\n2. [👷 Build time] Store embeddings in Postgres with [pgvector](https://supabase.com/docs/guides/database/extensions/pgvector).\n3. [🏃 Runtime] Perform vector similarity search to find the content that's relevant to the question.\n4. [🏃 Runtime] Inject content into OpenAI GPT-3 text completion prompt and stream response to the client.\n\n## 👷 Build time\n\nStep 1. and 2. happen at build time, e.g. when Vercel builds your Next.js app. During this time the [`generate-embeddings`](./lib/generate-embeddings.ts) script is being executed which performs the following tasks:\n\n```mermaid\nsequenceDiagram\n    participant Vercel\n    participant DB (pgvector)\n    participant OpenAI (API)\n    loop 1. Pre-process the knowledge base\n        Vercel->>Vercel: Chunk .mdx pages into sections\n        loop 2. Create & store embeddings\n            Vercel->>OpenAI (API): create embedding for page section\n            OpenAI (API)->>Vercel: embedding vector(1536)\n            Vercel->>DB (pgvector): store embedding for page section\n        end\n    end\n```\n\nIn addition to storing the embeddings, this script generates a checksum for each of your `.mdx` files and stores this in another database table to make sure the embeddings are only regenerated when the file has changed.\n\n## 🏃 Runtime\n\nStep 3. and 4. happen at runtime, anytime the user submits a question. When this happens, the following sequence of tasks is performed:\n\n```mermaid\nsequenceDiagram\n    participant Client\n    participant Edge Function\n    participant DB (pgvector)\n    participant OpenAI (API)\n    Client->>Edge Function: { query: lorem ispum }\n    critical 3. Perform vector similarity search\n        Edge Function->>OpenAI (API): create embedding for query\n        OpenAI (API)->>Edge Function: embedding vector(1536)\n        Edge Function->>DB (pgvector): vector similarity search\n        DB (pgvector)->>Edge Function: relevant docs content\n    end\n    critical 4. Inject content into prompt\n        Edge Function->>OpenAI (API): completion request prompt: query + relevant docs content\n        OpenAI (API)-->>Client: text/event-stream: completions response\n    end\n```\n\nThe relevant files for this are the [`SearchDialog` (Client)](./components/SearchDialog.tsx) component and the [`vector-search` (Edge Function)](./pages/api/vector-search.ts).\n\nThe initialization of the database, including the setup of the `pgvector` extension is stored in the [`supabase/migrations` folder](./supabase/migrations/) which is automatically applied to your local Postgres instance when running `supabase start`.\n\n## Local Development\n\n### Configuration\n\n- `cp .env.example .env`\n- Set your `OPENAI_KEY` in the newly created `.env` file.\n- Set `NEXT_PUBLIC_SUPABASE_ANON_KEY` and `SUPABASE_SERVICE_ROLE_KEY` run:\n  > Note: You have to run supabase to retrieve the keys.\n\n### Start Supabase\n\nMake sure you have Docker installed and running locally. Then run\n\n```bash\nsupabase start\n```\n\nTo retrieve `NEXT_PUBLIC_SUPABASE_ANON_KEY` and `SUPABASE_SERVICE_ROLE_KEY` run:\n\n```bash\nsupabase status\n```\n\n### Start the Next.js App\n\nIn a new terminal window, run\n\n```bash\npnpm dev\n```\n\n### Using your custom .mdx docs\n\n1. By default your documentation will need to be in `.mdx` format. This can be done by renaming existing (or compatible) markdown `.md` file.\n2. R","github_created_at":"2023-04-01T04:12:56+00:00","created_at":"2026-07-11T11:34:01.469896+00:00","updated_at":"2026-08-23T06:01:49.906369+00:00","categories":[{"slug":"data-retrieval","name":"Data & Retrieval","url":"https://www.graphcanon.com/categories/data-retrieval","markdown_url":"https://www.graphcanon.com/categories/data-retrieval.md","api_url":"https://www.graphcanon.com/api/graphcanon/categories/data-retrieval"},{"slug":"inference-serving","name":"Inference & Serving","url":"https://www.graphcanon.com/categories/inference-serving","markdown_url":"https://www.graphcanon.com/categories/inference-serving.md","api_url":"https://www.graphcanon.com/api/graphcanon/categories/inference-serving"}],"tags":[{"slug":"ai","name":"ai"},{"slug":"chatgpt","name":"chatgpt"},{"slug":"nextjs","name":"nextjs"},{"slug":"openai","name":"openai"},{"slug":"postgres","name":"postgres"},{"slug":"supabase","name":"supabase"},{"slug":"vector-search","name":"vector-search"}],"trust":{"provenance":{"is_fork":false,"github_id":622081419,"owner_type":"Organization","methodology":"github_public_v1","parent_repo":null,"near_duplicate_slugs":[]},"computed_at":"2026-08-23T06:01:49.084Z","maintenance":{"label":"Slowing","score":36,"methodology":"github_public_v1","releases_90d":0,"days_since_push":102,"last_release_at":null,"stars_delta_30d":3,"open_issues_delta_30d":0},"security_summary":{"status":"no_lockfile","scanner":null,"low_count":0,"high_count":0,"last_scan_at":"2026-07-11T11:34:02.785Z","medium_count":0,"scan_profile":"none","critical_count":0}},"capability_facts":{"mcp":{"source":"repo_scan","observed_at":"2026-08-23T06:01:49.526Z","server_manifest":false},"scan":{"source":"repo_scan","observed_at":"2026-08-23T06:01:49.526Z"},"has_cli":{"value":true,"source":"package.json:bin|scripts","observed_at":"2026-08-23T06:01:49.526Z"},"languages":{"value":["typescript","javascript"],"source":"github.language+package.json","observed_at":"2026-08-23T06:01:49.526Z"},"license_spdx":{"value":"Apache-2.0","source":"github.license","observed_at":"2026-08-23T06:01:49.526Z"}},"decision_facts":{"hosting":null,"pricing":null,"requirements":{"notes":["An active subscription to the OpenAI API might be necessary depending on usage volume.","Supabase account for database needs if you're using their service directly."],"min_ram_gb":2,"requires_docker":false},"constraints":{"min_ram_gb":2,"requires_docker":false},"when_to_use":["- When you want a template solution that integrates with Next.js for building modern web applications.","- If your project already uses the OpenAI and Supabase ecosystems as it leverages these services directly, reducing setup overhead."],"when_not_to_use":["- Avoid if you are not utilizing or wish to avoid integrating Next.js as part of your application stack since this tool relies heavily on it.","- Not suitable for projects where alternative AI or database solutions (not from OpenAI and Supabase) are preferred or required."],"source":"enrich:decision_facts","observed_at":"2026-07-12T12:43:54.866Z"},"constraint_facets":{"min_ram_gb":2,"requires_docker":false},"decision_summary":[{"label":"Requirements","value":"Min 2 GB RAM; An active subscription to the OpenAI API might be necessary depending on usage volume.; Supabase account for database needs if you're using their service directly."},{"label":"Adopt for","value":"nextjs-openai-doc-search utilizes a stack consisting of Next.js, OpenAI API, and Supabase to build customized document search solutions similar to ChatGPT."}]}}