1. Go to this page and download the library: Download sellinnate/rag-engine 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/ */
sellinnate / rag-engine example snippets
use Sellinnate\RagEngine\Facades\Rag;
// 1. INGEST — register content as a Document (stored & encrypted, not yet searchable).
$document = Rag::ingest(
Rag::source()->text('Refunds are issued within 14 business days of an approved request.')
);
// 2. PROCESS — run the pipeline: parse → clean & redact PII → chunk → embed → store.
Rag::process($document); // or: ProcessDocumentJob::dispatch(...) on a queue
// 3. SEARCH — find the most relevant chunks by meaning.
$hits = Rag::search('how long until I get my money back?')->topK(3)->get();
$hits[0]->content; // "Refunds are issued within 14 business days..."
$hits[0]->score; // relevance score
$hits[0]->metadata['source_ref']; // provenance: where it came from
// 4. (OPTIONAL) ASK — let an LLM write a cited answer from the retrieved chunks.
$answer = Rag::ask('how long do refunds take?')->using('openai')->generate();
$answer->answer; // "Refunds take 14 business days. [1]"
$answer->citations; // [['index' => 1, 'document_id' => '…', 'chunk_id' => '…']]
use Sellinnate\RagEngine\Concerns\HasEmbeddings;
use Sellinnate\RagEngine\Contracts\Embeddable;
use Sellinnate\RagEngine\Eloquent\EmbeddableDefinition;
class Article extends Model implements Embeddable
{
use HasEmbeddings; // auto-indexes on save, removes on delete
public function toEmbeddable(): EmbeddableDefinition
{
return EmbeddableDefinition::make()
->add('Title', $this->title)
->add('Body', $this->body)
->
$result = Rag::ask('What is our refund policy?')
->topK(5)
->using('anthropic') // or omit to use the default RAG_LLM
->generate();
$result->answer; // "Refunds are issued within 14 business days. [1]"
$result->citations; // [['index' => 1, 'document_id' => '…', 'chunk_id' => '…']]
$result->sources; // the SearchHits the answer was built from
use Sellinnate\RagEngine\Facades\Rag;
// Run work scoped to a tenant (previous tenant restored afterwards):
Rag::forTenant('tenant-7', fn () => Rag::search('q')->get());
// Right to erasure — crypto-shred a tenant:
Rag::kms()->destroyKey('tenant-7');