1. Go to this page and download the library: Download omniglies/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 Omniglies\LaravelRag\Facades\Rag;
// Ingest a document
$document = Rag::ingestDocument('Document Title', $uploadedFile, [
'author' => 'John Doe',
'category' => 'Research'
]);
// Ask a question
$response = Rag::askWithContext('What is machine learning?');
echo $response['answer'];
// Search for similar content
$chunks = Rag::searchRelevantChunks('artificial intelligence', 5);
use Omniglies\LaravelRag\Services\RagService;
class MyController extends Controller
{
public function __construct(private RagService $ragService) {}
public function search(Request $request)
{
$results = $this->ragService->searchRelevantChunks(
$request->query,
$request->limit ?? 10
);
return response()->json($results);
}
}