Download the PHP package moneo/laravel-rag without Composer
On this page you can find all versions of the php package moneo/laravel-rag. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download moneo/laravel-rag
More information about moneo/laravel-rag
Files in moneo/laravel-rag
Package laravel-rag
Short Description A complete, driver-based RAG pipeline for Laravel
License MIT
Informations about the package laravel-rag
Laravel RAG
A complete, driver-based RAG (Retrieval-Augmented Generation) pipeline for Laravel. Built on Prism PHP for provider-agnostic LLM and embedding support.
Features
- Driver-based vector stores — pgvector (production) and sqlite-vec (local dev), swappable via
.env - Blueprint macros —
$table->vector(),$table->vectorIndex()feel native to Laravel - Model traits —
HasVectorSearchandAutoEmbedsfor zero-boilerplate integration - Embedding cache — SHA-256 deduplication reduces API costs by 60-80%
- Chunking strategies — Character, Sentence, Markdown, and Semantic chunkers
- Fluent RAG pipeline —
Rag::from(Document::class)->ask('question') - Streaming SSE — Real-time response streaming via Server-Sent Events
- Agentic RAG — Iterative retrieval with sufficiency evaluation
- Hybrid search — Reciprocal Rank Fusion (RRF) combining semantic + full-text
- LLM re-ranking — Score and re-order chunks by relevance
- Conversation memory — Threaded conversations with automatic context summarization
- RAG Evals — First Laravel-native evaluation framework (Faithfulness, Relevancy, Context Recall)
- MCP Server — Expose your RAG as MCP tools for Claude Desktop, Cursor, etc.
- Artisan commands —
rag:index,rag:test,rag:estimate,rag:eval,rag:mcp-serve - DevTools — Debugbar collector and Telescope watcher
- Livewire component — Drop-in
<livewire:rag-chat>with streaming and sources - Filament plugin — Admin panel for documents, embeddings, and interactive testing
Requirements
- PHP 8.2+
- Laravel 11+
- Prism PHP ^0.100
Vector store (choose one):
- pgvector (recommended for production) — PostgreSQL + pgvector extension
- sqlite-vec (local dev, Docker/Linux only) — sqlite-vec
Note: sqlite-vec requires PHP compiled with SQLite extension loading support. macOS PHP (Herd, Homebrew) does not support this. Use Docker, Laravel Sail, or switch to pgvector on macOS.
Installation
Publish the config:
Run migrations:
Configuration
Vector Store Setup
Option A: pgvector (recommended)
Works everywhere. Requires PostgreSQL with pgvector extension.
Option B: sqlite-vec (Docker/Linux only)
Zero-infrastructure local dev. Does NOT work on macOS Herd/Homebrew PHP.
Linux (Ubuntu/Debian):
Docker / Laravel Sail:
macOS: sqlite-vec is not supported with Herd or Homebrew PHP. Use pgvector instead:
Quick Start
1. Prepare Your Model
2. Create a Migration
3. Ingest Content
4. Query
Streaming
Hybrid Search
Re-ranking
Agentic RAG
Conversation Memory
Chunking Strategies
RAG Evals
CLI:
MCP Server
Artisan Commands
Livewire Component
Filament Plugin
DevTools
Debugbar
Auto-registers when barryvdh/laravel-debugbar is installed. Shows:
- RAG call count, chunks retrieved
- Cache hit/miss rate
- Retrieval vs generation timing
Telescope
Auto-registers when laravel/telescope is installed. Records:
- Embedding generation events
- Cache hit events
Error Handling & Retry
All Prism API calls are wrapped in PrismRetryHandler with exponential backoff:
- Rate limits (429): retried with backoff + jitter, throws
EmbeddingRateLimitExceptionafter 3 attempts - Server errors (5xx): retried once, throws
EmbeddingServiceException - Timeouts: throws
EmbeddingTimeoutException - Malformed responses: throws
EmbeddingResponseException - Dimension mismatch: throws
DimensionMismatchExceptionbefore storage
Exception hierarchy:
Structured Logging
All operations emit structured logs via RagLogger (channel: rag.*):
rag.embedding.*— API calls, cache hits/missesrag.retrieval.*— search operationsrag.generation.*— LLM generationrag.cache.*— cache operationsrag.error.*— all caught exceptions with context
Text fields are SHA-256 hashed for privacy — raw user input never appears in logs.
Custom Vector Store Driver
Implement VectorStoreContract:
Register in a service provider:
Benchmarks
| Operation | 1K docs | 10K docs | 100K docs |
|---|---|---|---|
| Character chunking (500 chars) | 0.3ms | 2.8ms | 28ms |
| Sentence chunking | 0.5ms | 4.5ms | 45ms |
| Markdown chunking | 0.4ms | 3.8ms | 38ms |
| RRF merge (100+100 results) | 0.1ms | 0.1ms | 0.1ms |
| Similarity search (pgvector HNSW) | 2ms | 5ms | 12ms |
| Hybrid search (pgvector) | 8ms | 15ms | 35ms |
| Embedding cache hit | 0.5ms | 0.5ms | 0.5ms |
Benchmarks run on Apple M2 Pro, PostgreSQL 16 with pgvector 0.7. Results may vary.
Security
This package ships with built-in security hardening:
- Input Sanitisation —
InputSanitiser::clean()strips 40+ known prompt injection patterns before text reaches the LLM - Vector Validation —
VectorValidator::validate()checks dimensions, NaN, and infinity before every upsert - Cache Integrity — HMAC-signed cache keys prevent tampered cache entries; corrupted entries are auto-evicted
- SQL Injection Protection — Table names are validated against a strict regex before SQL interpolation
- MCP Input Validation — Malformed JSON-RPC requests return errors without executing retrieval
Testing
Quality Gates
All of these must pass before merge:
| Gate | Requirement |
|---|---|
| PHPStan | Level 9, zero errors |
| Test Coverage | >= 99% line, >= 95% branch |
| Mutation Score (MSI) | >= 85% |
| Rector | Zero suggestions |
| Architecture Tests | All Pest arch() rules green |
| Security Audit | composer audit — zero vulnerabilities |
| CI Matrix | PHP 8.2/8.3/8.4 x Laravel 11/12 |
Contributing
- Fork the repo and create a feature branch
- Write tests first — every new feature needs unit + feature tests
-
Run the full quality gate suite locally:
- Ensure all architecture tests pass:
vendor/bin/pest --testsuite=Architecture - Submit a PR — CI will run the full matrix automatically
Adding a Custom Vector Store Driver
Community drivers should:
- Follow naming:
moneo/laravel-rag-{driver}(e.g.,moneo/laravel-rag-qdrant) - Implement
VectorStoreContract - Extend
VectorStoreContractTestfrom this package to prove compliance - Target MSI >= 90% for the driver code
Security
See SECURITY.md for vulnerability disclosure policy and security measures.
License
MIT License. See LICENSE for details.
All versions of laravel-rag with dependencies
illuminate/support Version ^11.0|^12.0
illuminate/database Version ^11.0|^12.0
illuminate/console Version ^11.0|^12.0
illuminate/events Version ^11.0|^12.0
prism-php/prism Version ^1.0