thesubhendu / embedvector-laravel
Recommendation engine using Open AI embedding and PostgresSQL pgvector
Fund package maintenance!
thesubhendu
Requires
- php: ^8.2
- illuminate/contracts: ^10.0||^11.0
- openai-php/client: ^0.10.2
- pgvector/pgvector: ^0.2.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- larastan/larastan: ^2.9
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.1.1||^7.10.0
- orchestra/testbench: ^9.0.0||^8.22.0
- pestphp/pest: ^2.34
- pestphp/pest-plugin-arch: ^2.7
- pestphp/pest-plugin-laravel: ^2.3
- phpstan/extension-installer: ^1.3
- phpstan/phpstan-deprecation-rules: ^1.1
- phpstan/phpstan-phpunit: ^1.3
This package is auto-updated.
Last update: 2025-06-30 02:37:20 UTC
README
This package provides a recommendation engine using Open AI embedding and PostgresSQL pgvector. It uses the openai api to generate embeddings and stores them in the database. It then uses pgvector to search for similar embeddings.
⚠️ Notice: This package is currently in development and not yet ready for production use. Please use at your own risk.
Installation
composer require thesubhendu/embedvector-laravel
You can publish and run the migrations with:
php artisan vendor:publish --tag="recommender-migrations"
php artisan migrate
You can publish the config file with:
php artisan vendor:publish --tag="embed-vector-config"
This is the contents of the published config file:
return [ 'openai_api_key' => env('OPENAI_API_KEY', ''), ];
Add your openai api key to the .env file as OPENAI_API_KEY
To get api key login or signup at https://platform.openai.com/api-keys and create a new api key
Usage
Example: say you want to find AI matching jobs for the customer
Step 0: Prepare your model
Implement EmbeddableContract to Eloquent model use EmbeddableTrait
<?php namespace App\Models; use Subhendu\EmbedVector\Contracts\EmbeddableContract; use Subhendu\EmbedVector\Traits\EmbeddableTrait; class Customer extends Model implements EmbeddableContract { use EmbeddableTrait; }
Once model is ready run
Step 1:
php artisan embedding:batch {modelName} {--type=sync|init} {--force}
Example: php artisan embedding:batch App\\Models\\Customer --type=init
This will generate a jsonl file in storage/app/embeddings/
which is uploaded to openai api
Step 2:
php artisan process-completed-batch
This will process the embeddings (generated in step 1) and store them in the database
- Repeat step 1 and 2 with other models if needed
Step 3 :You can now search using the matchingResults
method:
$customer = Customer::find(1); $customer->matchingResults(Job::class);
Testing
composer test