PHPackages                             x-laravel/embedding-sqlsrv-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-sqlsrv-driver

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

x-laravel/embedding-sqlsrv-driver
=================================

SQL Server 2025 native vector similarity driver for x-laravel/embedding.

v1.1.0(2mo ago)01MITPHP ^8.3

Since May 9Compare

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

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

x-laravel/embedding — SQL Server Driver
=======================================

[](#x-laravelembedding--sql-server-driver)

[![Tests](https://github.com/x-laravel/embedding-sqlsrv-driver/actions/workflows/tests.yml/badge.svg)](https://github.com/x-laravel/embedding-sqlsrv-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)

SQL Server 2025 / Azure SQL native vector driver for [x-laravel/embedding](https://github.com/x-laravel/embedding).

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

[](#how-it-works)

- Implements `SimilarityDriver` — registers as the `sqlsrv` driver, similarity search runs entirely in SQL Server using `VECTOR_DISTANCE('cosine', ...)`
- Implements `VectorStore` — writes embeddings via `MERGE INTO` with `CAST(? AS VECTOR(n))`, reads via a `CAST(vector AS NVARCHAR(MAX))` global scope

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

[](#requirements)

- PHP ^8.3 + `ext-sqlsrv` + `ext-pdo_sqlsrv` + Microsoft ODBC Driver 18
- Laravel ^12.0 | ^13.0
- `x-laravel/embedding ^1.0`
- SQL Server 2025 or Azure SQL Database (native `VECTOR` type required)

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

[](#installation)

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

The `SqlServerEmbeddingServiceProvider` is auto-discovered and registers the `sqlsrv` 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', 'sqlsrv')),
    '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 SQL Server-native migration that **replaces** the default one from `x-laravel/embedding`. It creates a `VECTOR(n)` column.

Run the migration:

```
php artisan migrate
```

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

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

> **Note:** `VECTOR_DISTANCE` requires SQL Server 2025 or Azure SQL Database. This is not available in SQL Server 2019/2022.

### 3. Model

[](#3-model)

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

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

37

—

LowBetter than 81% of packages

Maintenance85

Actively maintained with recent releases

Popularity1

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

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

76d ago

### Community

Maintainers

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

---

Tags

laravelaisqlservermssqlvectorembedding

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[illuminate/database

The Illuminate Database package.

2.8k54.9M12.2k](/packages/illuminate-database)[laravel/ai

The official AI SDK for Laravel.

1.0k3.2M246](/packages/laravel-ai)[yajra/laravel-oci8

Oracle DB driver for Laravel via OCI8

8793.2M25](/packages/yajra-laravel-oci8)[ramadan/custom-fresh

A Laravel package to specify the tables that you do not want to drop while refreshing the database.

611.6k](/packages/ramadan-custom-fresh)[lemaur/eloquent-publishing

218.1k1](/packages/lemaur-eloquent-publishing)[ramadan/easy-model

A Laravel package for enjoyably managing database queries.

111.6k](/packages/ramadan-easy-model)

PHPackages © 2026

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