Bruno API Client | Blog & News

Ask Your Docs: Building a Chatbot for Documentation

Written by Ganesh Patil | Jun 19, 2025

Tired of sifting through endless documentation to find answers? What if you could just ask your docs a question and get an instant, accurate response? That's exactly what a "Doc Chatbot" can do! In the age of AI, we can build smart assistants that understand your questions and pull answers directly from your product's documentation.

This guide will walk you through building your own Doc Chatbot using powerful yet accessible tools like OpenAI and Next.js.

What We're Building

We'll create a chatbot that can answer questions based on your specific documentation files (like Markdown or plain text). Here’s a quick look at the core technologies we'll use:

  • Your documentation (Markdown/text files) acts as the source of truth.
  • OpenAI Embeddings: To turn text into "smart" numbers for searching.
  • Neon (PostgreSQL + pgvector) & Drizzle ORM: To store and quickly find your "smart" documentation numbers.
  • Next.js 14 (App Router): For building a fast and modern website.
  • Tailwind CSS: For a clean and responsive look.

Let's break down how this smart assistant works!

The Big Idea: RAG Chatbot

Our chatbot uses a clever technique called Retrieval Augmented Generation (RAG). Imagine this: instead of the AI making up answers, it first looks up relevant information from your docs, and then uses only that information to give you a precise answer. This helps prevent the AI from "hallucinating" (making things up!).

 

 

Key Components Explained (with simple code)

1. Your Documentation: The Knowledge Base

Your documents (like Markdown files in a `docs` folder) are the heart of our chatbot's knowledge. We'll break these files into smaller pieces, called "chunks."

2. OpenAI Embeddings: Making Text Smart

OpenAI's "embedding" models (like `text-embedding-ada-002`) are like magicians! They take a piece of text and turn it into a list of numbers (called a "vector"). Texts with similar meanings will have vectors that are "close" to each other in this number space. This is how we find relevant information!

import { OpenAI } from 'openai';

const openai = new OpenAI();

async function getEmbedding(text) {
  const response = await openai.embeddings.create({
    model: "text-embedding-ada-002",
    input: text,
  });
  return response.data[0].embedding; // This is our 'smart' number list!
}

3. Storing Smart Text: Neon (PostgreSQL + pgvector) & Drizzle ORM

We need a special database to store these "smart" text numbers (vectors) and find them quickly.

  • Neon: A super easy-to-use cloud database (PostgreSQL) that supports a special extension called `pgvector`.
  • pgvector: This extension lets PostgreSQL understand and search through our vector embeddings very fast.
  • Drizzle ORM: A tool that helps our Next.js application talk to the PostgreSQL database easily and safely.

Our database table for document chunks will look something like this:

import { pgTable, text, vector } from 'drizzle-orm/pg-core';

export const documentChunks = pgTable('document_chunks', {
  id: text('id').primaryKey(),
  content: text('content'), // The actual text chunk
  embedding: vector('embedding', { dimensions: 1536 }), // Our 'smart' numbers!
  sourcePath: text('source_path'), // Where did this text come from?
});

4. The Website: Next.js 14 & Tailwind CSS

We use Next.js 14 for the entire website. It's great for building both the user interface (what you see) and the API (how the website talks to our AI logic). Tailwind CSS makes designing a modern, clean chat interface a breeze.

How the Chatbot Works: Step-by-Step

Step 1: Indexing Your Docs (One-time Setup)

Before your chatbot can answer questions, it needs to "read" and understand your documentation.

  • We read all your Markdown/text files.
  • Break them into small chunks.
  • Use OpenAI to get a "smart number" (embedding) for each chunk.
  • Store these chunks and their "smart numbers" in our Neon database.
// Simplified ingestion logic
import { OpenAI } from 'openai';
import { db } from '@/db'; // Our database connection
import { documentChunks } from '@/db/schema'; // Our schema defined above

const openai = new OpenAI();

async function ingestChunk(chunkText, chunkPath) {
  const embedding = await getEmbedding(chunkText); // Get smart numbers
  await db.insert(documentChunks).values({
    id: crypto.randomUUID(), // Unique ID for each chunk
    content: chunkText,
    embedding: embedding,
    sourcePath: chunkPath,
  });
  console.log(`Ingested: ${chunkPath}`);
}

// Imagine a loop here that reads your docs and calls ingestChunk for each piece.

Step 2: Chatting with Your Docs

When a user asks a question:

  1. The user's question is sent to our Next.js API.
  2. We get a "smart number" (embedding) for the user's question using OpenAI.
  3. We ask our Neon database to find the "smartest" (most similar) document chunks based on the user's question's "smart number."
  4. We send these relevant document chunks (as "context") along with the original question to a powerful OpenAI model (like GPT-3.5).
  5. OpenAI uses the provided context to generate an accurate answer, which is then streamed back to the user's chat screen.
This process ensures your chatbot answers are always based on your actual documentation, making it very reliable!

Ready to Build?

This project is open-source and ready for you to try! You can find all the code and detailed setup instructions on GitHub.

Explore the `bruno-chatbot` GitHub repository

Getting Started is Simple:

  1. Clone the repository: Get the code onto your computer.
  2. Set up Neon: Create a free database on Neon and enable the `pgvector` extension.
  3. Configure: Add your OpenAI API key and Neon database details to your environment variables.
  4. Ingest your docs: Run a script to turn your `docs` folder content into "smart numbers" in the database.
  5. Launch: Start the Next.js application!

Conclusion: Your Docs, Smarter and Easier!

Imagine a world where finding information in your documentation is as simple as asking a question. By combining OpenAI's intelligence, Neon's powerful database, and Next.js's modern web capabilities, you can transform your static documents into a dynamic, smart resource.

Give it a try, explore the code, and make your documentation work harder for you!

Happy chatting!