PHPackages                             jati/rafurivel - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. jati/rafurivel

ActiveLibrary

jati/rafurivel
==============

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

00PHP

Since Jul 27Pushed todayCompare

[ Source](https://github.com/ginganomercy/rafurivel)[ Packagist](https://packagist.org/packages/jati/rafurivel)[ RSS](/packages/jati-rafurivel/feed)WikiDiscussions main Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

🤖 Rafurivel (Laravel VectorRAG)
===============================

[](#-rafurivel-laravel-vectorrag)

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

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

---

📖 What is Rafurivel?
--------------------

[](#-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 &amp; Enterprise Robustness (v1.0.1+)
-----------------------------------------------------

[](#-core-features--enterprise-robustness-v101)

- **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 &amp; 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
------------------------

[](#-performance-benchmarks)

Driver Engine1,000 Vectors (1,536-dim)RequirementsFail-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
--------------

[](#-installation)

```
composer require jati/rafurivel:"^1.0"
```

Publish the configuration file:

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

---

⚙️ Configuration (`config/rafurivel.php`)
-----------------------------------------

[](#️-configuration-configrafurivelphp)

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
-------------

[](#-usage-guide)

### 1. Preparing the Eloquent Model

[](#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

[](#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)

[](#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

[](#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
---------

[](#-testing)

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

```
composer exec phpunit
```

---

👨‍💻 Author
----------

[](#‍-author)

**Rafly A.R**📧 Email: 📸 Instagram: [@galaxy\_scream](https://instagram.com/galaxy_scream)

📜 License
---------

[](#-license)

This package is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).

###  Health Score

20

—

LowBetter than 12% of packages

Maintenance65

Regular maintenance activity

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity11

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/a8c8add9718b841e43b15c555815dd6180eb37052bb3af1c88d5d9057ff7ce2c?d=identicon)[ginganomercy](/maintainers/ginganomercy)

---

Top Contributors

[![ginganomercy](https://avatars.githubusercontent.com/u/155315911?v=4)](https://github.com/ginganomercy "ginganomercy (6 commits)")

### Embed Badge

![Health badge](/badges/jati-rafurivel/health.svg)

```
[![Health](https://phpackages.com/badges/jati-rafurivel/health.svg)](https://phpackages.com/packages/jati-rafurivel)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
