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.
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
Example: say you want to find AI matching jobs for the customer
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
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
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
$customer = Customer::find(1);
$customer->matchingResults(Job::class);
composer test