Newsletter
Join the Community
Subscribe to our newsletter for the latest news and updates
A Next.js RAG chatbot template using the Vercel AI SDK, Drizzle ORM, and PostgreSQL for retrieval-augmented generation.
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.
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.
streamText tool calls — the AI SDK's streamText function is used both to retrieve information from the database and to add new information into it through custom tools.useChat hook pipes model responses to the frontend token by token for a chat-like experience.OPENAI_API_KEY environment variable, and provisions a PostgreSQL store automatically..env.example, add API keys, run npm run db:migrate, and npm run dev on port 3000.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.
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.
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.
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.
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.
