Zense LogoZenseAI

Docs
Tutorial
RAG Chatbot
implement rag in your chatbot

Implement RAG in Your Chatbot

Learn how to enhance your chatbot with knowledge from documents

Adding Knowledge to Your Chatbot

Let's enhance our Virtual Fan Zhongyan by adding specific knowledge from Chinese literature!

Step 1: Access the Control Panel

Click the blue toggle button on the right side of the chat interface to open the control panel. Open Control Panel

Step 2: Configure Bot Settings

The control panel allows you to customize various aspects of your chatbot:

Basic Settings

  • Upload or change bot icon
  • Modify bot name
  • Switch language models Basic Settings

Advanced Parameters

You can fine-tune your bot's behavior using these parameters:

Parameter Range Description Recommended Value
Temperature 0.0 - 1.0 Controls randomness. Higher values make output more creative but less focused 0.7
Top P 0.0 - 1.0 Nucleus sampling parameter. Controls diversity of responses 0.9
Frequency Penalty 0.0 - 2.0 Reduces repetition by penalizing frequently used words 0.0
Presence Penalty 0.0 - 2.0 Encourages discussing new topics by penalizing used topics 0.0
Max Tokens 100 - 4000 Maximum length of response 2000

Model Parameters

Step 3: Add Knowledge Base Files

Scroll down to the "Knowledge Base Files" section where you can upload documents to enhance your bot's knowledge:

  1. Supported Formats

    • PDF files
    • Word documents (.doc, .docx)
    • Text files (.txt)
  2. Upload Process

    • Click the upload area
    • Select your document (in this example, we'll use "岳陽樓記.pdf")
    • Wait for processing and embedding Upload Knowledge Base

Step 4: Review Document Chunks

After uploading, you can review how the document has been processed:

  1. Click the "eye" icon next to your uploaded document
  2. Review the chunks created from your document
  3. Each chunk represents a segment that can be retrieved by the RAG system

View Chunks

Step 5: Test Your Enhanced Bot

Now you can test your bot's new knowledge:

  1. Ask about the uploaded content Example: "What do you know about 岳陽樓記?"
  2. The bot will combine its base knowledge with the uploaded content
  3. Responses will include specific references and quotes from the document

Test Knowledge

How It Works

When you ask a question:

  1. The system searches through the embedded chunks of your uploaded documents
  2. Relevant chunks are retrieved based on semantic similarity
  3. The bot combines these chunks with its base knowledge to create comprehensive answers
  4. The response maintains the bot's character while incorporating specific knowledge from your documents

Tips for Better Results

  1. Document Quality

    • Use clear, well-formatted documents
    • Ensure text is properly recognized (especially for scanned PDFs)
  2. Chunking Strategy

    • Review the chunks to ensure they make sense
    • Upload multiple related documents for broader context
  3. Query Formulation

    • Ask specific questions
    • Reference key terms from the documents

What's Next?

Now that you've implemented RAG, you can:

  • Add more Chinese literature documents
  • Fine-tune the model parameters
  • Create specialized knowledge bases for different topics