Download the PHP package rubyat/laravel-rag without Composer
On this page you can find all versions of the php package rubyat/laravel-rag. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download rubyat/laravel-rag
More information about rubyat/laravel-rag
Files in rubyat/laravel-rag
Package laravel-rag
Short Description Add semantic search and Retrieval-Augmented Generation (RAG) to any Laravel app with PostgreSQL + pgvector.
License MIT
Informations about the package laravel-rag
rubyat/laravel-rag
A production-ready Retrieval-Augmented Generation (RAG) toolkit for Laravel with PostgreSQL + pgvector. Ingest documents, store embeddings, and answer questions grounded only in your own content — with source citations.
Features
- 🧩 Document ingestion — text is chunked (configurable size/overlap), embedded, and stored.
- 🔎 pgvector vector search — cosine similarity over an HNSW index for high recall at any scale.
- 💬 RAG pipeline — retrieves the most relevant chunks and asks an LLM to answer from them.
- 📎 Source citations — every answer returns the chunks it used, with similarity scores.
- 🔌 Driver-based — swap embedding/chat providers; OpenAI built-in, plus deterministic
fakedrivers for offline dev and tests (no API key, no network). - ⚙️ Sync or queued ingestion — inline by default, or dispatch a job for large documents.
- 🌐 HTTP API — ready-to-use
POST /api/rag/ingestandPOST /api/rag/askendpoints. - ✅ Tested — ships with a Pest suite that runs against pgvector using the fake drivers.
Requirements
- PHP 8.3+
- Laravel 11, 12, or 13
- PostgreSQL with the
pgvectorextension (0.5+ for HNSW)
Installation
Publish the config and run the migration:
The migration runs
CREATE EXTENSION IF NOT EXISTS vector, which needs a database role allowed to create extensions. The pgvector Docker image (pgvector/pgvector:pg16) is the quickest way to get it locally.
Configure a provider (or keep the offline fake drivers — no network needed):
Quick Start
In code
HTTP API
Ingest:
Ask:
Configuration
Published to config/rag.php. Every option is environment-driven:
| Option | Env | Default | Description |
|---|---|---|---|
embedding_driver |
RAG_EMBEDDING_DRIVER |
openai |
openai or fake |
chat_driver |
RAG_CHAT_DRIVER |
openai |
openai or fake |
dimensions |
RAG_DIMENSIONS |
1536 |
Vector size; must match the embedding model |
chunk_size |
RAG_CHUNK_SIZE |
1000 |
Chunk length in characters |
chunk_overlap |
RAG_CHUNK_OVERLAP |
200 |
Overlap between chunks |
top_k |
RAG_TOP_K |
4 |
Chunks retrieved per question |
queue_ingestion |
RAG_QUEUE_INGESTION |
false |
Dispatch ingestion to the queue (needs a worker) |
register_routes |
RAG_REGISTER_ROUTES |
true |
Auto-register the HTTP routes |
route_prefix |
RAG_ROUTE_PREFIX |
api/rag |
Prefix for the package routes |
The fake drivers are deterministic and require no network access — they power the test suite and let you try the full flow without API keys.
Swappable drivers
Embedding and chat providers are resolved from config and implement small contracts, so you can plug in your own:
Built in: OpenAiEmbeddingDriver / OpenAiChatDriver (HTTP) and FakeEmbeddingDriver / FakeChatDriver (offline, deterministic).
How it works
Documents are stored one row per chunk in the documents table (source, chunk_index, content, metadata, embedding vector(n)), indexed with HNSW (vector_cosine_ops). Retrieval orders by cosine distance (embedding <=> :query) and returns a similarity score in [0, 1].
Testing
The suite runs against PostgreSQL + pgvector using the deterministic fake drivers, so no API keys or network are required:
License
The MIT License (MIT). See LICENSE.
All versions of laravel-rag with dependencies
illuminate/contracts Version ^11.0|^12.0|^13.0
illuminate/database Version ^11.0|^12.0|^13.0
illuminate/support Version ^11.0|^12.0|^13.0