1. Go to this page and download the library: Download moneo/laravel-rag library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
moneo / laravel-rag example snippets
use Moneo\LaravelRag\Concerns\HasVectorSearch;
use Moneo\LaravelRag\Concerns\AutoEmbeds;
class Document extends Model
{
use HasVectorSearch, AutoEmbeds;
protected string $embedSource = 'content';
protected string $vectorColumn = 'embedding';
}
use Moneo\LaravelRag\Memory\RagThread;
$thread = RagThread::create(['model' => Document::class]);
$result1 = $thread->ask('What is Laravel?');
$result2 = $thread->ask('Compare it with Symfony.'); // context-aware
use Moneo\LaravelRag\Facades\RagEval;
$report = RagEval::suite()
->using(Rag::from(Document::class))
->add(question: 'What is pgvector?', expected: 'A PostgreSQL extension for vector similarity search')
->add(question: 'How to install?', expected: 'Run composer
// In AppServiceProvider::boot()
use Moneo\LaravelRag\Mcp\RagMcpServer;
app(RagMcpServer::class)
->register(Document::class)
->as('company-docs')
->description('Search internal company documentation')
->expose();
// In your PanelProvider
->plugins([
\Moneo\LaravelRag\Filament\RagPlugin::make(),
])
use Moneo\LaravelRag\VectorStores\Contracts\VectorStoreContract;
class QdrantStore implements VectorStoreContract
{
public function upsert(string $id, array $vector, array $metadata): void { /* ... */ }
public function similaritySearch(array $vector, int $limit, float $threshold = 0.0): Collection { /* ... */ }
public function hybridSearch(string $query, array $vector, float $semanticWeight, float $fulltextWeight, int $limit): Collection { /* ... */ }
public function delete(string $id): void { /* ... */ }
public function flush(string $collection): void { /* ... */ }
public function table(string $table): static { /* ... */ }
public function supportsFullTextSearch(): bool { return false; }
}