Simple Next.js + MongoDB Atlas AI boilerplate that uses Next.js, OpenAI with Atlas Vector Store for context.
The server is mapped into to Next.js app under /app/api/
.
TBD
You can clone & deploy it to Vercel with one click:
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
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.
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"
}
]
}
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.
To learn more about Next.js, take a look at the following resources:
- Next.js Documentation - learn about Next.js features and API.
- Learn Next.js - an interactive Next.js tutorial.
- MongoDB NodeJS
- MongoDB for Artificial Intelligence - set of guides and resources to get started with GenAI and MongoDB.
You can check out the Next.js GitHub repository - your feedback and contributions are welcome!