jati/rafurivel

Zero-configuration VectorRAG & Semantic Search for Laravel Eloquent Models.

Maintainers

Package info

github.com/ginganomercy/rafurivel

pkg:composer/jati/rafurivel

Transparency log

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

dev-main 2026-07-27 12:45 UTC

This package is auto-updated.

Last update: 2026-07-27 12:46:14 UTC


README

๐Ÿค– Rafurivel (Laravel VectorRAG)

Zero-Configuration Vector Database Synchronization & Semantic Search for Laravel Eloquent

Turn your Eloquent Models into an AI-powered Semantic Search engine in one line of code.

๐Ÿ“– What is Rafurivel?

Rafurivel is an Enterprise-Grade Laravel package that seamlessly bridges your relational database (MySQL/PostgreSQL) with a Vector Database (Pinecone, pgvector) and an AI Embedding Engine (OpenAI, Ollama, Anthropic).

By simply adding a single PHP Trait to your model, Rafurivel automatically hooks into Laravel's native lifecycle events (saved and deleted) and synchronizes your model's data into vectors asynchronously using Laravel Queue/Horizon.

It enables Semantic Search: Searching your database by context and meaning, rather than exact keyword matching.

๐ŸŒŸ Core Features & Enterprise Robustness (v1.0.1+)

  • Zero-Config Integration: Add use VectorSearchable; and you're done.
  • Rust Native SIMD Engine (ffi driver): Powered by an embedded C-ABI Rust kernel (rafurivel-core) utilizing SIMD vector instructions (AVX2/NEON) to calculate Cosine Similarity and L2 Norms 20xโ€“40x faster than interpreted PHP.
  • Fail-Safe Automatic Fallback: If PHP FFI is disabled or the native library is unavailable, VectorStoreManager automatically falls back to an optimized PHP memory store (MemoryVectorStore) without crashing your application.
  • Asynchronous (Non-blocking): All vectorization processes happen entirely in the background. Your web requests remain at 0ms overhead.
  • Event Recursion Protection: Smartly detects $model->wasChanged() to prevent infinite CPU loops if other background jobs trigger the save() method.
  • API Resilience & Auto-Retry: Wraps external API calls (OpenAI) in robust try-catch blocks. If an API hits a Rate Limit (HTTP 429), the job intelligently releases itself back into the queue with exponential backoff (10s, 30s, 60s) preventing any data loss.
  • Flat-Memory Bulk Sync CLI: Includes an artisan command that safely chunks your database, destroys object references, and triggers PHP's Garbage Collector (gc_collect_cycles) to keep RAM usage flat, even when syncing millions of rows.

โšก Performance Benchmarks

Driver Engine 1,000 Vectors (1,536-dim) Requirements Fail-Safe Fallback
ffi (Rust SIMD Kernel) ~0.05 ms โ€” 0.1 ms ffi.enable=true in php.ini Auto-fallback to memory driver if FFI disabled
memory (PHP Optimized) ~0.7 ms โ€” 1.2 ms Pure PHP 8.1+ 100% portable zero-dependency fallback

๐Ÿ“ฆ Installation

composer require jati/rafurivel:"^1.0"

Publish the configuration file:

php artisan vendor:publish --tag="rafurivel-config"

โš™๏ธ Configuration (config/rafurivel.php)

After publishing, you can configure the AI engines and stores in .env:

# Supported Engines: mock, openai, ollama
RAFURIVEL_ENGINE=openai
OPENAI_API_KEY=sk-your-secret-key
OPENAI_EMBEDDING_MODEL=text-embedding-3-small

# Supported Stores: ffi (Rust SIMD Kernel), memory (PHP), pinecone, pgvector
RAFURIVEL_STORE=ffi

# Async Queue Configuration
QUEUE_CONNECTION=redis
RAFURIVEL_QUEUE=vector-sync

๐Ÿš€ Usage Guide

1. Preparing the Eloquent Model

Add the VectorSearchable trait to any Eloquent model you wish to vectorize.

Warning

DATA PRIVACY SECURITY WARNING: By default, Rafurivel will serialize your entire model to JSON and send it to the AI provider. If your model contains sensitive fields (PII, Passwords, SSN), you MUST override the toVectorString() method to define exactly what text gets vectorized!

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Rafurivel\Traits\VectorSearchable;

class Article extends Model
{
    use VectorSearchable;
    
    // ๐Ÿ›ก๏ธ SECURITY: Define EXACTLY what text gets vectorized!
    public function toVectorString(): string
    {
        return "Title: {$this->title}. Content: {$this->content}";
    }
}

2. The Auto-Sync Magic

Whenever you create, update, or delete a model, Rafurivel pushes a job to your Laravel Queue. You don't need to write any extra code.

// Behind the scenes, the SyncVectorEmbedding Job is dispatched to Redis!
$article = Article::create([
    'title' => 'Building AI Apps in Laravel', 
    'content' => 'Vector databases are the future...'
]);

// Automatically dispatches RemoveVectorEmbedding Job!
$article->delete();

3. Bulk Sync Command (For Existing Data)

If you are installing Rafurivel on an existing database, or if you use bulk Eloquent updates (which do not fire Eloquent events), you must manually sync the data.

Run this command to safely chunk and queue thousands of models without running out of memory:

php artisan rafurivel:sync "App\Models\Article"

Note: Ensure your Queue Worker (php artisan queue:work) is running to process the jobs.

4. Semantic Search

Search your database not by exact keywords, but by meaning. Rafurivel embeds your search query, searches the vector database, and automatically hydrates the results back into standard Eloquent Models, perfectly preserving the vector score ordering!

// Search for "How do I build AI apps in PHP?" and return Top 5 matches
$results = Article::semanticSearch("How do I build AI apps in PHP?", 5);

foreach ($results as $article) {
    echo $article->title; // Outputs Eloquent Model properties natively
}

๐Ÿงช Testing

Rafurivel is heavily tested using Orchestra Testbench. To run the test suite:

composer exec phpunit

๐Ÿ‘จโ€๐Ÿ’ป Author

Rafly A.R ๐Ÿ“ง Email: raflypriyantoro@gmail.com ๐Ÿ“ธ Instagram: @galaxy_scream

๐Ÿ“œ License

This package is open-sourced software licensed under the MIT license.