Table of Contents

🤖 Building a Custom AI Chatbot with RAG using C#


🎯 Purpose of the Sample

The Building a Custom Chatbot with RAG (Retrieval-Augmented Generation) Demo showcases how to use the LM-Kit.NET SDK to create a chatbot that integrates Retrieval-Augmented Generation techniques. This sample demonstrates the integration of large language models (LLMs) into a .NET application to facilitate a chatbot that can retrieve relevant information from loaded data sources and generate coherent responses based on that information.


👥 Industry Target Audience

This sample is particularly beneficial for developers and organizations in the following sectors:

  • 🛎️ Customer Support: Enhance customer service by retrieving and providing relevant information from knowledge bases.
  • 📚 Education: Develop interactive tutoring systems that can answer questions based on textbooks or other educational materials.
  • 🏥 Healthcare: Create virtual assistants that can provide information based on medical literature and guidelines.
  • 🛍️ E-commerce: Improve customer engagement by creating chatbots that can provide detailed product information and recommendations from extensive catalogs.

🚀 Problem Solved

Generating accurate and contextually relevant responses can be challenging, especially when dealing with extensive knowledge bases. The Building a Custom Chatbot with RAG Demo addresses this problem by leveraging RAG techniques to retrieve relevant information from data sources before generating responses, ensuring the chatbot provides precise and informative answers.


💻 Sample Application Description

The Building a Custom Chatbot with RAG Demo is a console application that allows users to interact with a chatbot designed to answer questions based on the content of loaded eBooks.

✨ Key Features

  • 📦 Model Selection: Users can load predefined models for chat and embeddings or provide custom model URIs.
  • 📊 Progress Tracking: The application displays download and loading progress for the selected models.
  • 📚 Data Source Loading: Loads eBooks as data sources that the chatbot can query.
  • 🔍 RAG Integration: Uses Retrieval-Augmented Generation to retrieve relevant information from data sources and generate responses.
  • 📈 Performance Metrics: Displays time taken to load data sources and other relevant metrics.
  • 🔧 Special Commands: Users can reset the conversation or regenerate responses using special commands.

🧠 Supported Models

The sample supports the following state-of-the-art models:

  • Chat Model: Llama 3.1 8B
  • Embeddings Model: BGE 1.5

📘 Data Sources

The sample loads the following eBooks as data sources:

  • Romeo and Juliet by William Shakespeare
  • Moby Dick by Herman Melville
  • Pride and Prejudice by Jane Austen

🛠️ Getting Started

📋 Prerequisites

  • .NET Framework 4.6.2 or .NET 6.0

📥 Download the Project

▶️ Running the Application

  1. 📂 Clone the repository:

    git clone https://github.com/LM-Kit/lm-kit-net-samples.git
    
  2. 📁 Navigate to the project directory:

    cd lm-kit-net-samples/console_framework_4.62/custom_chatbot_with_rag
    

    or

    cd lm-kit-net-samples/console_net6/custom_chatbot_with_rag
    
  3. 🔨 Build and run the application:

    dotnet build
    dotnet run
    
  4. 📜 Follow the on-screen prompts to load models and data sources and start querying the chatbot.

💡 Example Usage

  1. 📦 Load Models: The application will prompt to load predefined models or provide custom model URIs.
  2. 📚 Load Data Sources: The application will load eBooks as data sources for querying.
  3. ❓ Enter Query: Start by entering a query, such as "What are the causes and effects of the feud between the two prominent families" or "What are the names of the two rival families?".
  4. 💬 Receive Response: The chatbot will retrieve relevant information from the loaded data sources and generate a response.
  5. 🔄 Continue Interaction: Enter another query or end the program by submitting an empty input.

🛠️ Special Commands

  • 🔄 /reset: Start a new session and clear the conversation history.
  • ♻️ /regenerate: Get a new completion from the last input.

By following these steps, developers can explore the functionalities of LM-Kit.NET and integrate advanced RAG techniques into their chatbot applications, enhancing the accuracy and relevance of automated responses through retrieval-augmented generation.