1. Go to this page and download the library: Download ayaashraf/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/ */
use AyaAshraf\LaravelRag\Services\EmbeddingGenerator;
class CustomEmbeddingGenerator implements EmbeddingGenerator
{
public function embed(array $texts): array
{
// Your embedding logic
return $vectors;
}
public function dimensions(): int
{
return 768;
}
}
// Register in AppServiceProvider
$this->app->bind(EmbeddingGenerator::class, CustomEmbeddingGenerator::class);
use AyaAshraf\LaravelRag\Models\Document;
use AyaAshraf\LaravelRag\Services\DocumentTextExtractor;
use AyaAshraf\LaravelRag\Services\DocumentEmbeddingIndexer;
$extractor = app(DocumentTextExtractor::class);
$indexer = app(DocumentEmbeddingIndexer::class);
$text = $extractor->extract('/path/to/file.pdf');
$chunksCreated = $indexer->index($document, $text);