x-laravel/embedding-oracle-plugin

Oracle 26ai vector similarity driver for x-laravel/embedding.

Maintainers

Package info

github.com/x-laravel/embedding-oracle-plugin

pkg:composer/x-laravel/embedding-oracle-plugin

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-05-08 01:27 UTC

This package is auto-updated.

Last update: 2026-05-08 01:29:53 UTC


README

Tests PHP Laravel License

Oracle 26ai native vector similarity driver for x-laravel/embedding.

How It Works

  • Implements SimilarityDriver — registers as the oracle driver, similarity search runs entirely in Oracle using VECTOR_DISTANCE
  • Implements VectorStore — writes embeddings via MERGE INTO ... USING DUAL with TO_VECTOR(), no PHP-side JSON workaround needed

Requirements

  • PHP ^8.3
  • Laravel ^12.0 | ^13.0
  • x-laravel/embedding ^1.0
  • Oracle Database 26ai (Free or Enterprise)

Installation

composer require x-laravel/embedding-oracle-plugin

The OracleEmbeddingServiceProvider is auto-discovered and registers the oracle driver automatically.

Setup

1. Configure x-laravel/embedding

Publish the config if you haven't already:

php artisan vendor:publish --tag=embedding-config

Set the similarity driver and database connection in config/embedding.php:

'database' => [
    'connection' => env('EMBEDDINGS_DATABASE_CONNECTION', 'oracle'),
    'table'      => env('EMBEDDINGS_DB_TABLE', 'embeddings'),
],

'similarity' => [
    'driver' => env('EMBEDDING_SIMILARITY_DRIVER', 'oracle'),
],

2. Create the embeddings table

This plugin ships its own Oracle-native migration that replaces the default one from x-laravel/embedding. It creates a VECTOR(1536, FLOAT32) column.

Run the migration:

php artisan migrate

If you need to customise the DDL (e.g. tablespace, index parameters), publish the migration first:

php artisan vendor:publish --tag=embedding-oracle-migrations
php artisan migrate

Note: VECTOR_DISTANCE works without an index (sequential scan). If you have the Oracle In-Memory option, add a CREATE VECTOR INDEX ... ORGANIZATION INMEMORY NEIGHBOR GRAPH statement after publishing the migration.

3. Model

Follow the standard x-laravel/embedding setup. No Oracle-specific changes are needed on your models.

use XLaravel\Embedding\Attributes\EmbedOn;
use XLaravel\Embedding\Concerns\Embeddable;
use XLaravel\Embedding\Contracts\HasEmbeddings;

#[EmbedOn('title', 'body')]
class Post extends Model implements HasEmbeddings
{
    use Embeddable;

    public function toEmbeddingText(): string
    {
        return $this->title.' '.$this->body;
    }
}

Usage

The driver is transparent — use the standard x-laravel/embedding API:

Post::similarToText('web framework', limit: 10);
Post::similarTo($vector, limit: 10, threshold: 0.8);
Post::rankByRelevance($posts, 'web framework');

$post->mostSimilar(limit: 5);
$post->similarityTo($otherPost);

All methods set a similarity_score float attribute on each returned model.

Testing

# Build first (once per PHP version)
DOCKER_BUILDKIT=0 docker compose --profile php83 build

# Run tests
docker compose --profile php83 up
docker compose --profile php84 up
docker compose --profile php85 up

License

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