The AI SDK RAG Template is an open-source Next.js boilerplate that uses retrieval-augmented generation (RAG) to answer questions with information that is not part of the model's training data. It is powered by the Vercel AI SDK and stores vector embeddings in PostgreSQL via Drizzle ORM, streaming responses to the frontend in real time.
What is the AI SDK RAG Template?
The template is a full-stack Next.js application that demonstrates how to build a RAG chatbot with tool calling. It takes a user's question as input, retrieves relevant context from a PostgreSQL database, and produces a streamed natural-language answer. It is authored by nicoalbanese on GitHub and can be deployed to Vercel with one click.
What makes this template stand out?
streamTexttool calls — the AI SDK'sstreamTextfunction is used both to retrieve information from the database and to add new information into it through custom tools.- Real-time UI streaming — the
useChathook pipes model responses to the frontend token by token for a chat-like experience. - Drizzle ORM + PostgreSQL — vector embeddings are stored and queried through Drizzle, so the database layer keeps the same stack as the rest of the application.
- Framer Motion animations — the interface includes animated transitions built with Framer Motion.
- One-click Vercel deployment — a deploy button in the README creates the project, sets the
OPENAI_API_KEYenvironment variable, and provisions a PostgreSQL store automatically. - Simple setup workflow — five commands get the project running locally: npm install, copy
.env.example, add API keys, runnpm run db:migrate, andnpm run devon port 3000.
Who should use this template?
- Next.js developers who want a reference implementation of RAG without building the plumbing themselves.
- AI engineers who need a production-ready starting point for a question-answering bot over a custom corpus.
- Independent builders who want to ship a chat UI quickly and iterate on retrieval logic afterwards.
Use cases
- Document-based Q&A — ask questions over company wikis, product manuals, or research papers stored as embeddings.
- Internal knowledge assistants — give team members a bot that answers from internal documentation.
- Learning RAG patterns — study how tool calls, streaming, and PostgreSQL vector search fit together in one codebase.
How does the template work?
The frontend sends a message through the useChat hook to a Next.js API route. That route calls streamText, which decides which retrieval or ingestion tool to run, queries the PostgreSQL database for relevant vectors, and streams the generated answer back. Setup requires an OpenAI-compatible API key and a PostgreSQL connection string; a database migration script creates the schema.
FAQ
Is the AI SDK RAG Template free?
Yes, the template is open source and hosted on GitHub, so you can clone it without cost. You will need to pay for your own Vercel deployment and API usage.
What do I need to run it?
You need Node.js, npm, an API key for the Vercel AI Gateway (or OpenAI), and a PostgreSQL connection string. The .env.example file lists the required variables.
Does the template include a database?
It assumes you have PostgreSQL, and it includes a migration script to create the tables. The one-click Vercel deployment can provision a Postgres store for you.
Can I use it with other model providers?
The template uses the Vercel AI SDK, which supports many providers, but the README specifically shows an AI Gateway API key setup. You may need to adjust the model configuration.








