flutter_rag

GitHub Repository pub package Flutter RAG Logo A pure Dart Retrieval‑Augmented Generation (RAG) engine for Flutter applications. It provides document ingestion, chunking, vector search, and seamless integration with OpenAI LLMs to build powerful AI‑assisted chatbots and knowledge bases.


Features

Flutter RAG Demo

  • Document loaders for PDF, CSV, Excel, and plain text.
  • Recursive chunk splitter with configurable size and overlap.
  • In‑memory vector store (with optional persistence adapters).
  • OpenAI embeddings & LLM integration out of the box.
  • Typed API for adding documents, querying, and retrieving answers.
  • Zero external native dependencies – works on Android, iOS, Web, and Desktop.

Installation

Add the package to your pubspec.yaml:

dependencies:
  flutter_rag: ^0.1.0

Then run:

flutter pub get

Quick Start

import 'package:flutter_rag/flutter_rag.dart';

void main() async {
  const apiKey = String.fromEnvironment('OPENAI_API_KEY');
  final rag = FlutterRag(
    apiKey: apiKey,
    chunkSize: 500,
    chunkOverlap: 50,
  );

  await rag.addDocument(PdfLoader('assets/knowledge.pdf'));

  final answer = await rag.ask('What are the main benefits of RAG?');
  print('Answer: $answer');
}

The example in example/lib/main.dart demonstrates a full UI that lets users upload PDFs/CSVs, view status, and chat with the engine.


API Overview

Class / Function Description
FlutterRag Core engine – configure embeddings, LLM, chunking, and vector store.
PdfLoader, CsvLoader, ExcelLoader Helpers to read common document formats and return a list of Document objects.
RecursiveCharacterTextSplitter Splits large texts into overlapping chunks for better retrieval.
VectorStoreRetriever Retrieves the top‑k most similar chunks from the vector store.
RagEngine.invoke(String query) Executes the full RAG pipeline (retrieval → LLM) and returns an Answer object.

Contributing

Contributions are welcome! Please:

  1. Fork the repository.
  2. Create a feature branch (git checkout -b feature/awesome‑feature).
  3. Write tests and run flutter test.
  4. Submit a pull request.

Make sure to follow the existing code style and run dart format . before committing.

Maintainer

👨💻 Project Maintainer

Hamid Hosen

Md. Hamid Hosen

Associate Software Engineer @P2M Soft

GitHub Profile | Contributions


License

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


Publishing to pub.dev

When you are ready to release a new version:

  1. Update the version in pubspec.yaml (e.g., version: 0.2.0).
  2. Run dart pub publish --dry-run to verify the package.
  3. Fix any warnings or missing assets.
  4. Execute dart pub publish and follow the prompts.

Make sure your README.md and CHANGELOG.md are up‑to‑date before publishing.

Libraries

flutter_rag