1. Go to this page and download the library: Download ikramulmustafa/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/ */
ikramulmustafa / laravel-rag example snippets
use Ikram\Rag\Facades\Rag;
Rag::ingest(
source: 'policies/refunds.md',
content: file_get_contents(storage_path('policies/refunds.md')),
collection: 'policies',
);
$result = Rag::retrieve('How long do customers have to request a refund?');
$result->toPrompt(); // numbered context block, ready for a prompt
$result->sources(); // ['policies/refunds.md']
$result->topScore(); // similarity of the best match
$result = Rag::retrieve($question, limit: 5);
if ($result->isEmpty()) {
return 'I do not have information on that.'; // a valid answer
}
$answer = $llm->complete(<<<PROMPT
Answer using only the context below. If the context does not contain the
answer, say so. Cite sources by their bracket number.
{$result->toPrompt()}
Question: {$question}
PROMPT);
return ['answer' => $answer, 'citations' => $result->citations];