nomanur / laravel-markdown-rag
Transform Markdown files into AI-ready context with smart chunking and RAG capabilities for Laravel
Requires
- php: ^8.2
- illuminate/support: ^10.0|^11.0|^12.0
- laravel/ai: ^0.2.5
- livewire/livewire: ^3.0|^4.0
Requires (Dev)
- orchestra/testbench: ^9.16
- phpunit/phpunit: ^10.0|^11.0
README
Laravel Markdown RAG is a package that allows you to build a Retrieval-Augmented Generation (RAG) system using Markdown files as your knowledge base, powered by Gemini AI.
Installation
You can install the package via composer:
composer require nomanur/laravel-markdown-rag
Publish the package assets and configuration:
php artisan vendor:publish --provider="Nomanur\LaravelMarkdownRAGServiceProvider" php artisan vendor:publish --provider="Laravel\Ai\AiServiceProvider"
Run the migrations:
php artisan migrate
Configuration
Add the following environment variables to your .env file:
GEMINI_API_KEY= GEMINI_MODEL=gemini-2.5-flash AI_EMBEDDING_PROVIDER=gemini AI_DEFAULT_PROVIDER=gemini MARKDOWN_INFO_PATH=knowledge-base MARKDOWN_EMBEDDING_BATCH_SIZE=50 MARKDOWN_AI_RETRY_MAX_ATTEMPTS=3 MARKDOWN_QUERY_REWRITE=false MARKDOWN_RERANKING=false
MARKDOWN_CHAT_RATE_LIMIT: 5 (optional) if you want to rate the limit for the chat.MARKDOWN_INFO_PATH: (optional) the path to the markdown files in the public directory.MARKDOWN_EMBEDDING_BATCH_SIZE: (optional) the number of chunks to process in a single embedding request (default: 50).MARKDOWN_AI_RETRY_MAX_ATTEMPTS: (optional) the maximum number of retry attempts for AI requests (default: 3).MARKDOWN_QUERY_REWRITE: (optional) whether to enable query rewriting for better retrieval (default: false).MARKDOWN_RERANKING: (optional) whether to enable reranking of search results (default: false).
To use the configuration, update the code in config/ai.php with:
'default' => env('AI_DEFAULT_PROVIDER', 'ollama'), 'default_for_images' => env('AI_IMAGE_PROVIDER', 'gemini'), 'default_for_audio' => env('AI_AUDIO_PROVIDER', 'openai'), 'default_for_transcription' => env('AI_TRANSCRIPTION_PROVIDER', 'openai'), 'default_for_embeddings' => env('AI_EMBEDDING_PROVIDER', 'openai'), 'default_for_reranking' => env('AI_RERANKING_PROVIDER', 'cohere'), 'providers' => [ 'gemini' => [ 'driver' => 'gemini', 'key' => env('GEMINI_API_KEY'), 'models' => [ 'text' => [ 'default' => env('GEMINI_MODEL', 'gemini-1.5-flash'), 'cheapest' => env('GEMINI_MODEL_CHEAPEST', 'gemini-1.5-flash'), 'smartest' => env('GEMINI_MODEL_SMARTEST', 'gemini-2.0-pro-exp-02-05'), ], ], ], ],
Usage
1. Register Routes
Run the following command to register the necessary routes:
php artisan markdownrag:route
2. Setup Knowledge Base
Create a folder for your markdown files within the public directory. By default, this is public/knowledge-base, but you can change it using the MARKDOWN_INFO_PATH environment variable. Add your .md files there.
Example:
public/
└── knowledge-base/
├── company/
│ ├── file1.md
│ ├── file2.md
│ └── file3.md
└── product/
├── file1.md
├── file2.md
└── file3.md
3. Indexing
Index your markdown files to make them searchable:
php artisan markdownrag:index
4. Accessing the Interface
You can access the chat interface at the following URL:
your-domain.com/markdownrag
Testing
composer test
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email nomanurrahman@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.