Skip to content

✨ Simple AI powered (Gemini LLM) chat bot that uses Retrieval-Augmented Generation (RAG)!

License

Notifications You must be signed in to change notification settings

h1dd3nsn1p3r/chatbot-sample-app

Repository files navigation

Chatbot + RAG (Gemini & Pinecone)

This project is an open-source sample chatbot application built with HonoJS, utilizing Retrieval-Augmented Generation (RAG) powered by Google Gemini and Pinecone. It features real-time streaming responses and persists chat history in MongoDB.

Features

  • Framework: Built on HonoJS for a lightweight and fast web standard-based server.
  • LLM: Uses Google's Gemini 2.5 Flash for fast and efficient text generation.
  • Embeddings: Uses Gemini Text Embedding 004 for high-quality vector embeddings.
  • Vector Database: Integrates with Pinecone for efficient similarity search and context retrieval.
  • Database: Stores chat sessions and history in MongoDB.
  • Streaming: Supports streaming responses for a better user experience.
  • RAG: Implements a complete RAG pipeline:
    • Document ingestion from text files.
    • Chunking and embedding.
    • Context-aware response generation.

Prerequisites

Before you begin, ensure you have the following:

  • Node.js (v18 or higher)
  • MongoDB: A running MongoDB instance (local or Atlas).
  • Pinecone Account: An API key and an Index created in Pinecone.
  • Google Gemini API Key: Access to Google's Generative AI models.

Installation

  1. Clone the repository:

    git clone <repository-url>
    cd hono-chatbot-rag
  2. Install dependencies:

    npm install

Configuration

  1. Create a .env file in the root directory
    touch .env

Refer to the .env.example for the required env variables.

Data Ingestion

To use the RAG capabilities, you need to ingest documents into your Pinecone vector store.

  1. Place your text documents (.txt files) in the .bin/docs directory.

    • The script looks for files in .bin/docs relative to the project root.
    • Create the directory if it doesn't exist: mkdir -p .bin/docs
  2. Run the ingestion script:

    npm run ingest:embeddings

    This script will:

    • Load text files from .bin/docs.
    • Split them into chunks (1000 chars, 200 overlap).
    • Generate embeddings using Gemini.
    • Upload the vectors to your Pinecone index.

Running the Application

Development Mode

Run the server with hot-reloading:

npm run dev

Production Build

Build and start the production server:

npm run build
npm start

The server will start on http://localhost:3000 (or your configured PORT).

API Usage

1. Create a New Chat

Initialize a new chat session.

  • Endpoint: POST /chats
  • Response:
    {
      "id": "65f..." // The Chat ID
    }

2. Send a Message

Send a user message and receive a streaming response.

  • Endpoint: PUT /chats/:id
  • Body:
    {
      "content": "What is name of the chapter one?"
    }
  • Response: A text stream of the assistant's response.

Project Structure

  • src/app.ts: Main application entry point and server setup.
  • src/api/: Route handlers (Chat creation, message handling).
  • src/services/: External services integration (Gemini, Pinecone).
  • src/models/: Mongoose data models.
  • .bin/ingest.ts: Script for processing and ingesting documents.
  • .bin/docs: Directory for source documents for RAG.

License

MIT

About

✨ Simple AI powered (Gemini LLM) chat bot that uses Retrieval-Augmented Generation (RAG)!

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published