Vercel and MongoDB Atlas AI chatbot template

Simple Next.js + MongoDB Atlas AI boilerplate that uses Next.js, OpenAI with Atlas Vector Store for context.


End-to-End Tests

Introduction

How It Works

The server is mapped into to Next.js app under /app/api/.

Demo

TBD

Deploy Your Own

You can clone & deploy it to Vercel with one click:

Deploy with Vercel

Input for deployment

NODE_ENV=development
MONGODB_ATLAS_URI=<Atlas With Vector Store>
OPENAI_API_KEY=<API Key from Open AI>
ADMIN_API_KEY=<Any String to be used as admin auth>
SITE_BASE_URL=<the_deployed_domain_url> ## eg. https://mychat-project.vercel.app

The Admin page for context upload will work only if you connect the "Vercel Storage" type blob to your project as it uses it to upload files for processing

Upload fake docs as test context

Clone the repo and run locally:

npm install
npm run embed

This will vectorize the "FancyWidget" under ./fake_docs docs as context for the chatbot.

Getting Started

Create your MongoDB Deployment and get your connection URI:

Create an atlas vector index named vector_index on database docs collection embeddings:

{
  "fields": [
    {
      "type": "vector",
      "path": "embedding",
      "numDimensions": 1536,
      "similarity": "cosine"
    }
  ]
}

Developing Locally

Set the needed environment variable on .env.local:

NODE_ENV=development
MONGODB_ATLAS_URI=<your_atlas_uri>
OPENAI_API_KEY=<your_openai_key>
ADMIN_API_KEY=<access_key_to_use_on_admin>
SITE_BASE_URL=<the_deployed_domain_url> ## eg. https://mychat-project.vercel.app
## Optional

First, install the dependencies:

npm install
# or
yarn
# or
pnpm install

Then, run the development server:

npm run dev
# or
yarn dev
# or
pnpm dev

Open http://localhost:3000 with your browser to see the result.

To load data go to http://localhost:3000/admin - Input the configured admin API key as well as upload the source file to be stored as context.

Learn More

To learn more about Next.js, take a look at the following resources:

You can check out the Next.js GitHub repository - your feedback and contributions are welcome!