About Next.js OpenAI Doc Search
The Next.js OpenAI Doc Search Starter is a template designed for creating a custom ChatGPT style documentation search. This is powered by Next.js, OpenAI, and Supabase. The starter processes all the .mdx files in the pages directory to use as custom context within OpenAI Text Completion prompts. By deploying this starter on Vercel, the Supabase integration will automatically set up the required environment variables and configure your Database Schema. The only thing left for the user is to set the OPENAI_KEY, and it’s ready to go.
Features of Next.js OpenAI Doc Search
- Custom Context Processing: The starter takes all the .mdx files in the pages directory and processes them to be used as custom context within OpenAI Text Completion prompts.
- Technical Details: Building a custom ChatGPT involves four main steps:
- Build Time: Pre-process the knowledge base (your .mdx files in your pages folder) and store embeddings in Postgres with pgvector.
- Runtime: Perform vector similarity search to find content relevant to the question and inject this content into the OpenAI GPT-3 text completion prompt, streaming the response to the client.
- Embeddings Generation: A script is executed during build time that generates embeddings for each .mdx file. It also creates a checksum for each file to ensure embeddings are regenerated only when the file changes.
- Runtime Sequence: At runtime, when a user submits a question, a series of tasks are performed. This includes creating an embedding for the query, performing a vector similarity search, and injecting the relevant content into the OpenAI GPT-3 prompt.
- Local Development: The starter provides detailed instructions for local development. This includes setting up environment variables, starting Supabase, and running the Next.js app.
- Database Initialization: The initialization of the database, including the setup of the pgvector extension, is stored in the supabase/migrations folder. This is automatically applied to the local Postgres instance when running supabase start.
- Custom .mdx Docs: By default, the documentation needs to be in .mdx format. Users can rename existing markdown files to .mdx format. There are also instructions provided for regenerating embeddings and refreshing the NextJS rendered page.
- Learning Resources: The starter provides additional resources such as a blog post on building ChatGPT for Supabase Docs and a video tutorial on the Rabbit Hole Syndrome YouTube Channel.