PHPackages                             x-laravel/embedding-mysql-driver - 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. [Database &amp; ORM](/categories/database)
4. /
5. x-laravel/embedding-mysql-driver

ActiveLibrary[Database &amp; ORM](/categories/database)

x-laravel/embedding-mysql-driver
================================

MySQL 9 native VECTOR similarity driver for x-laravel/embedding.

v1.1.0(1mo ago)00MITPHPPHP ^8.3CI failing

Since May 9Pushed 1mo agoCompare

[ Source](https://github.com/x-laravel/embedding-mysql-driver)[ Packagist](https://packagist.org/packages/x-laravel/embedding-mysql-driver)[ RSS](/packages/x-laravel-embedding-mysql-driver/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (4)Versions (3)Used By (0)

x-laravel/embedding — MySQL 9 Driver
====================================

[](#x-laravelembedding--mysql-9-driver)

[![Tests](https://github.com/x-laravel/embedding-mysql-driver/actions/workflows/tests.yml/badge.svg)](https://github.com/x-laravel/embedding-mysql-driver/actions/workflows/tests.yml)[![PHP](https://camo.githubusercontent.com/c8d8dad6beb757a2b8acba331d16140813699543b88a37af0a81f20bd35f61de/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e332532422d626c7565)](https://www.php.net)[![Laravel](https://camo.githubusercontent.com/42e62a9adb05b6cb16993782fd4b04b64a76be3ff5704d170001885eb70c8448/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d313225323025374325323031332d726564)](https://laravel.com)[![License](https://camo.githubusercontent.com/f8df3091bbe1149f398a5369b2c39e896766f9f6efba3477c63e9b4aa940ef14/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e)](LICENSE.md)

MySQL HeatWave native vector driver for [x-laravel/embedding](https://github.com/x-laravel/embedding).

How It Works
------------

[](#how-it-works)

- Implements `SimilarityDriver` — registers as the `mysql` driver, similarity search runs entirely in MySQL using `VEC_DISTANCE_COSINE`
- Implements `VectorStore` — writes embeddings via `INSERT ... ON DUPLICATE KEY UPDATE` with `STRING_TO_VECTOR()`, reads via a `VECTOR_TO_STRING` global scope

Requirements
------------

[](#requirements)

- PHP ^8.3
- Laravel ^12.0 | ^13.0
- `x-laravel/embedding ^1.0`
- **MySQL HeatWave** — `VEC_DISTANCE_COSINE` is not available in MySQL Community Edition; this driver requires [MySQL HeatWave](https://www.oracle.com/mysql/heatwave/)

Installation
------------

[](#installation)

```
composer require x-laravel/embedding-mysql-driver
```

The `MysqlEmbeddingServiceProvider` is auto-discovered and registers the `mysql` driver automatically.

Setup
-----

[](#setup)

### 1. Configure x-laravel/embedding

[](#1-configure-x-laravelembedding)

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', env('DB_CONNECTION', 'mysql')),
    'table'      => env('EMBEDDINGS_DB_TABLE', 'embeddings'),
],

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

### 2. Create the embeddings table

[](#2-create-the-embeddings-table)

This driver ships its own MySQL-native migration that **replaces** the default one from `x-laravel/embedding`. It creates a `VECTOR(1536)` column.

Run the migration:

```
php artisan migrate
```

If you need to customise the DDL, publish the migration first:

```
php artisan vendor:publish --tag=embedding-mysql-migrations
php artisan migrate
```

> **Note:** `VEC_DISTANCE_COSINE` is only available on **MySQL HeatWave**, not MySQL Community Edition. For production, add a `VECTOR INDEX` on the `vector` column after publishing the migration.

### 3. Model

[](#3-model)

Follow the standard `x-laravel/embedding` setup. No MySQL-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
-----

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

[](#testing)

Tests require a MySQL HeatWave instance. The `docker-compose.yml` uses `mysql:9.1.0` for CI convenience but `VEC_DISTANCE_COSINE` tests will fail against Community Edition — run them against a real HeatWave instance.

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

[](#license)

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

###  Health Score

39

—

LowBetter than 84% of packages

Maintenance94

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 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.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

31d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2bdb64c6c087c331b8bd5906bb1aa7eb06bc83af3654a48ba8ab9da365976651?d=identicon)[X-Adam](/maintainers/X-Adam)

---

Top Contributors

[![x-adam](https://avatars.githubusercontent.com/u/60411758?v=4)](https://github.com/x-adam "x-adam (3 commits)")

---

Tags

laravelaimysqlvectorembedding

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/x-laravel-embedding-mysql-driver/health.svg)

```
[![Health](https://phpackages.com/badges/x-laravel-embedding-mysql-driver/health.svg)](https://phpackages.com/packages/x-laravel-embedding-mysql-driver)
```

###  Alternatives

[kirschbaum-development/eloquent-power-joins

The Laravel magic applied to joins.

1.6k29.9M42](/packages/kirschbaum-development-eloquent-power-joins)[illuminate/database

The Illuminate Database package.

3.0k54.1M11.0k](/packages/illuminate-database)[lemaur/eloquent-publishing

207.8k1](/packages/lemaur-eloquent-publishing)

PHPackages © 2026

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