Production-grade Retrieval-Augmented Generation for Laravel.
Dense vector search · Knowledge graph · Cohere reranking · Multi-tier semantic cache · LLM query classifier.
Extracted from a chatbot SaaS in production.
This package was extracted from production code 1 and ships a working but unpolished v0.1. Expect:
- ✅ All 12 services compile, namespaces clean, no leaked secrets
- ✅ Configuration via standard Laravel
config/rag-pipeline.php - ✅ Drop-in
RagPipelineServiceProviderauto-discovered by Laravel ⚠️ Tests partially migrated (CohereRerankService 12 scenarios shipped, others need adaptation)⚠️ Examples coming in v0.2⚠️ Vector store and graph DB hard-coded to ChromaDB + Neo4j (driver abstraction planned)
If you want polish before betting your project on it, watch the repo and wait for v1.0. If you want to use it now and shape the API, jump in — PRs and issues very welcome.
A single Laravel package that handles the full RAG pipeline end-to-end — not just vector search, but everything between "user types a question" and "LLM gets the best context".
┌──────────────────────────────────────┐
user query ─────▶│ QueryClassifierService │
│ STRUCTURED | SEMANTIC | COMPLEX │
└──────────────┬───────────────────────┘
│
┌─────────────────────┴─────────────────────┐
▼ ▼
┌─────────────────────┐ ┌──────────────────────┐
│ QueryCacheService │ L1 / L2 / L3 │ QueryRouterService │
│ exact / norm / │ cache miss │ routes to dense / │
│ semantic similarity│ ───────────────▶ │ graph / hybrid │
└─────────────────────┘ └─────────┬────────────┘
│
┌─────────────────────┬───────────────┴───────────────┐
▼ ▼ ▼
┌──────────────────┐ ┌────────────────────┐ ┌──────────────────┐
│ EmbeddingService │ │KnowledgeGraph │ │VectorMemoryService│
│ OpenAI embed-3 │ │Service (Neo4j) │ │ ChromaDB v2 API │
│ + 30d cache │ │ Cypher queries │ │ Guzzle direct │
└────────┬─────────┘ └────────┬───────────┘ └────────┬─────────┘
│ │ │
└──────────────────────┼──────────────────────────────┘
▼
┌─────────────────────────────┐
│ CohereRerankService │
│ rerank-multilingual-v3.0 │
│ (fallback: RerankingService│
│ heuristic + OpenAI score) │
└──────────────┬──────────────┘
│
▼
┌─────────────────────────────┐
│ WorkingMemoryService │
│ Redis LRU 7±2 items │
│ (Miller's law) │
└──────────────┬──────────────┘
│
▼
top-K chunks
ready for your LLM
12 services, ~3,500 lines of PHP, all wired through one RAGOrchestratorService.
The PHP / Laravel ecosystem has plenty of vector-search-and-stop-there tutorials. What you usually don't get bundled:
| Component | Status in most PHP RAG examples | In this package |
|---|---|---|
| Dense vector search (ChromaDB) | ✅ | ✅ |
| Embedding cache (30d) | ❌ | ✅ |
| Knowledge graph (Neo4j) | ❌ | ✅ |
| Multi-source query router | ❌ | ✅ |
| LLM-based query classifier | ❌ | ✅ |
| Cohere reranking | ❌ | ✅ |
| Fallback local reranker | ❌ | ✅ |
| L1/L2/L3 semantic cache | ❌ | ✅ |
| Pre-computed FAQ responses | ❌ | ✅ |
| Working memory (Miller's 7±2) | ❌ | ✅ |
If you've been gluing 4 different libraries to get this stack, that's the gap.
composer require grobinson3108/laravel-rag-pipeline:dev-mainPublish config:
php artisan vendor:publish --tag=rag-pipeline-configFill .env:
OPENAI_API_KEY=sk-...
COHERE_API_KEY=...
CHROMA_HOST=http://localhost:8000
NEO4J_URI=bolt://localhost:7687
NEO4J_USER=neo4j
NEO4J_PASSWORD=your-passwordUse the orchestrator:
use Grobinson3108\LaravelRagPipeline\RAG\RAGOrchestratorService;
$rag = app(RAGOrchestratorService::class);
$result = $rag->process(
query: 'How do I cancel my subscription?',
botId: 'my-bot-uuid',
sessionId: $request->session()->getId(),
options: ['top_k' => 5]
);
// $result['contexts'] => array of top-K chunks with scores
// $result['metadata'] => timing, cache hits, classifier verdict, etc.All bound as singletons in the container — inject anywhere.
| Service | Role |
|---|---|
RAGOrchestratorService |
Main entry — 7-step pipeline orchestration |
EmbeddingService |
OpenAI embeddings + 30d Redis cache |
CohereRerankService |
Cohere rerank-multilingual-v3.0 (production reranker) |
RerankingService |
Local fallback (heuristic + OpenAI score) |
QueryClassifierService |
LLM-based STRUCTURED/SEMANTIC/COMPLEX classifier with rules fallback |
QueryRouterService |
Routes classified queries to the right retrieval strategy |
KnowledgeGraphService |
Neo4j via laudis/neo4j-php-client |
VectorMemoryService |
ChromaDB v2 API (direct Guzzle, no SDK lock-in) |
WorkingMemoryService |
Redis LRU 7±2 items per bot (conversation context) |
QueryCacheService |
L1 exact / L2 normalized / L3 semantic similarity |
CacheStrategyService |
Adaptive TTL + cache decisions per query type |
PreComputedResponseService |
Pattern-matched FAQ responses (zero-LLM) |
v0.2 (Q3 2026) — Driver abstraction
- Vector store interface (ChromaDB / Qdrant / Pinecone / Weaviate)
- Graph DB interface (Neo4j / Memgraph / NebulaGraph)
- Reranker interface (Cohere / Voyage / BGE local / custom)
v0.3 — Examples + tests
- Working example app (
examples/chatbot/) - Migrated test suite (currently only CohereRerank shipped)
v1.0 — Production hardening
- Telemetry hooks (Langfuse, OTLP)
- Performance benchmarks
- Cost guards integration
This is alpha — the API will move. The fastest way to influence it is to open an issue with your use case before I lock decisions.
PRs especially welcome for:
- Pinecone / Qdrant driver
- Memgraph driver
- Voyage / BGE reranker
- Migrated tests for Memory/Cache services
MIT — see LICENSE.
Greg Robinson — AI Architect, RAG & agentic systems, Audelalia (🇫🇷 Montpellier).
Companion repos:
- laravel-mcp-server — Expose your Laravel app to Claude via MCP
- mcp-server-saas-gateway — One MCP server, N REST APIs (TypeScript)
- vibe-coding-arsenal — 38 Claude Code commands and skills
- claude-code-agents-laravel-vue — 9 stack-specific sub-agents
If this saves you days of plumbing, ⭐ goes a long way.
Footnotes
-
Specifically: a chatbot SaaS that handled real customer conversations with this exact pipeline for several months in 2025–2026. ↩