flutter_rag_chatbot 0.1.0 copy "flutter_rag_chatbot: ^0.1.0" to clipboard
flutter_rag_chatbot: ^0.1.0 copied to clipboard

A Flutter package for building RAG-based chatbots with local vector storage and xAI Grok API integration.

flutter_rag_chatbot #

A Flutter package designed to help developers easily build and integrate RAG-based chatbots into mobile apps. This package leverages Retrieval-Augmented Generation to retrieve relevant documents from a local vector store and then augment queries to a Language Model (LLM) like xAI's Grok API.

Features #

  • Retrieval-Augmented Generation (RAG): Combines information retrieval with text generation.
  • Local Vector Store: Basic in-memory vector store for document retrieval using cosine similarity.
  • LLM Integration: Designed to integrate with LLMs (e.g., xAI Grok API).
  • Chat UI Widget: A pre-built Flutter widget for displaying chat conversations.
  • Offline Fallback: (Planned) Cache responses for offline access.
  • Multi-turn History: Maintains conversation context.
  • Markdown Parsing: Displays LLM responses formatted with Markdown.
  • Extensibility: Hooks for custom retrievers and LLMs.
  • Future-Proofing: Includes placeholders for image inputs, query logging, and hybrid edge/cloud modes.

Installation #

Add the following to your pubspec.yaml file:

dependencies:
  flutter_rag_chatbot:
    git:
      url: https://github.com/your-username/flutter_rag_chatbot.git # Replace with your repository URL
      ref: main # Or the specific branch/tag
  # Or, if published to pub.flutter-io.cn:
  # flutter_rag_chatbot: ^0.1.0

Then run flutter pub get.

Usage #

1. Initialize the RagChatbot #

First, initialize the RagChatbot with your API key and a knowledge base (list of documents).

import 'package:flutter/material.dart';
import 'package:flutter_rag_chatbot/flutter_rag_chatbot.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  late final RagChatbot _chatbot;
  final List<String> _knowledgeBase = [
    "The capital of France is Paris.",
    "Mount Everest is the highest mountain in the world.",
    "The Earth revolves around the Sun.",
    "Flutter is a UI toolkit for building natively compiled applications for mobile, web, and desktop from a single codebase.",
  ];

  @override
  void initState() {
    super.initState();
    _chatbot = RagChatbot();
    _initializeChatbot();
  }

  Future<void> _initializeChatbot() async {
    await _chatbot.initialize(
      apiKey: 'YOUR_XAI_GROK_API_KEY', // Replace with your actual API key
      knowledgeBase: _knowledgeBase,
    );
    setState(() {}); // Rebuild to show the chat widget after initialization
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'RAG Chatbot Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: Scaffold(
        appBar: AppBar(
          title: const Text('RAG Chatbot Demo'),
        ),
        body: _chatbot == null
            ? const Center(child: CircularProgressIndicator())
            : RagChatWidget(chatbot: _chatbot),
      ),
    );
  }
}

2. Use the RagChatWidget #

Integrate the RagChatWidget into your Flutter application:

// See the example above for full integration.
// In your widget tree:
RagChatWidget(chatbot: _chatbot)

Contributing #

Contributions are welcome! Please feel free to open an issue or submit a pull request.

License #

This project is licensed under the MIT License - see the LICENSE file for details.

1
likes
0
points
47
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter package for building RAG-based chatbots with local vector storage and xAI Grok API integration.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, flutter_markdown, http, sqlite3, vector_math

More

Packages that depend on flutter_rag_chatbot