
Template details
Internal Knowledge Base Preview
A Next.js RAG chatbot template using the AI SDK middleware for retrieval-augmented generation and guardrails.
About this template
Internal Knowledge Base Preview is a Next.js starter template from Vercel Labs that demonstrates retrieval-augmented generation (RAG) and guardrail enforcement through the AI SDK's language model middleware. It is a working example that turns internal documents into a question-answering chatbot, with a public GitHub repository that has collected 318 stars.
What is Internal Knowledge Base Preview?
Internal Knowledge Base Preview is a chatbot template built for internal knowledge management. It takes a user's natural-language question, retrieves relevant context from a document store, and returns a grounded answer generated by a language model from providers like OpenAI or Anthropic. The template runs on Next.js and relies on the AI SDK to connect to models, with middleware that intercepts requests to add retrieval and guardrail logic.
Key Features
- Language Model Middleware — Uses the AI SDK's middleware interface to wrap model calls, demonstrating how to inject retrieval and safety checks without modifying each call site.
- Retrieval-Augmented Generation — Combines document retrieval with generation so answers are based on your internal content rather than the model's general knowledge.
- Guardrail Enforcement — Shows how to validate inputs and outputs inside the middleware, blocking disallowed content before it reaches the model or the user.
- Next.js Framework — Bootstrapped with create-next-app, providing a standard React-based structure for the web interface.
- Provider Agnostic — Works with any AI provider supported by the AI SDK, with OpenAI and Anthropic named in the setup instructions.
- Vercel Deployment — Offers a one-click Deploy with Vercel button that provisions Vercel Blob for file storage and Postgres for the knowledge base, with environment variables like OPENAI_API_KEY and AUTH_SECRET.
- Environment-Based Configuration — All secrets and settings are managed through a .env file following the .env.example template.
Who is it for?
- Developer teams at companies — Build an internal Q&A bot that answers policy, product, and HR questions from company documents.
- AI engineers — Use the template as a reference implementation for RAG and guardrail patterns with the AI SDK.
- Next.js developers — Learn how to integrate AI features into a Next.js application with middleware.
What can you do with it?
- Employee self-service: Create a chatbot that lets staff ask questions about internal documentation and get answers grounded in that content.
- Advanced AI prototyping: Experiment with different providers, retrieval strategies, and guardrail rules by modifying the middleware code.
- Compliance demonstrations: Showcase how to enforce content policy on model inputs and outputs in production systems.
How does it work?
The template boots via create-next-app with the example repository URL. After signing up for AI provider accounts and setting API keys, you copy .env.example to .env, install dependencies with npm install, and start the development server with npm run dev. The middleware intercepts each language model call, retrieves relevant documents, and applies guardrails before returning the final response.
FAQ
What environment variables are required?
The example lists OPENAI_API_KEY and AUTH_SECRET as required, plus storage configuration for Vercel Blob and Postgres. You can find the exact keys in the .env.example file in the repository.
Which AI providers can I use?
The setup mentions signing up for providers such as OpenAI and Anthropic. Because the AI SDK supports many providers, you can switch by updating the environment variables and model configuration.
Is this an official template?
Yes, it's published by Vercel Labs, the experimental arm of Vercel, and is part of the AI SDK preview examples.
Can I deploy this to Vercel automatically?
Yes, the README includes a Deploy with Vercel button that clones the repository and sets up the required Blob and Postgres stores.














