Download the PHP package x-laravel/embedding without Composer

On this page you can find all versions of the php package x-laravel/embedding. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package embedding

Embedding

Tests PHP Laravel

A Laravel package that automatically generates and stores vector embeddings for Eloquent models using laravel/ai.

How It Works

Requirements

Installation

Run the migration:

Optionally publish the config file:

Setup

1. Single-slot model

For most use cases, return a string from toEmbeddingText() and list trigger fields in $embeddable:

2. Multi-slot model

Return an array from toEmbeddingText() and use a nested $embeddable map to define which fields trigger each slot:

When title changes, only the title and full slots are re-embedded — body is left untouched.

3. Defining trigger fields with #[EmbedOn]

As an alternative to $embeddable, use the #[EmbedOn] attribute. The attribute is repeatable for multi-slot models:

$embeddable and #[EmbedOn] merge — you can use both.

Usage

Generating embeddings

Suppressing embedding generation

Similarity search

All similarity methods accept an optional slot parameter (defaults to 'default'):

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

threshold defaults to 0.0 — pass a value between 0.0 and 1.0 to filter low-scoring results.

Reranking

Cosine similarity is good at narrowing a large corpus down to candidates, but mixing in a rerank model on top — Cohere, Voyage, Jina — usually produces noticeably better top-K ordering for RAG pipelines. The package exposes this as a Collection macro that delegates to laravel/ai's reranking gateway:

Each returned model carries a rerank_score attribute alongside the existing similarity_score, sorted by rerank score descending. JSON responses include both attributes automatically — formatting and visibility are left to your application layer.

Full signature:

Empty collections and single-item collections short-circuit — no API call is made.

The active provider follows laravel/ai's ai.default_for_reranking config; the package does not add a second layer of provider/model configuration. If you need direct access (e.g. to rerank a manually fetched collection) resolve the service from the container:

Similarity Drivers

The php driver is built-in and works with any database — it loads vectors into PHP and computes cosine similarity in memory. For DB-level vector search, install the appropriate driver:

Driver Database Operation
(built-in) Any (SQLite, MySQL 8, …) php — PHP-side cosine similarity
embedding-mysql-driver MySQL HeatWave VEC_DISTANCE_COSINE
embedding-mariadb-driver MariaDB 11.7+ VEC_Distance_Cosine
embedding-pgsql-driver PostgreSQL + pgvector <=> operator
embedding-oracle-driver Oracle 26ai VECTOR_DISTANCE
embedding-sqlsrv-driver SQL Server 2025 / Azure SQL VECTOR_DISTANCE
embedding-qdrant-driver Qdrant $vectorSearch REST API

When a driver is installed, the auto selector detects the DB connection and switches automatically. Override via config or register a custom driver:

Plugins

Optional add-on packages that extend the core with non-storage concerns. Install only the ones you need.

Plugin Purpose
embedding-pulse-plugin Laravel Pulse cards and recorders — per-slot throughput, generation latency (p50/p95/max + slow-call threshold), failed-job tracking, and a live "embeddings by slot" counter for the Pulse dashboard.

embedding-pulse-plugin

Auto-discovered. Adds four Livewire cards (embedding.throughput, embedding.latency, embedding.failures, embedding.slots) that you drop into your Pulse dashboard:

Recorders listen to ModelEmbedded / ModelEmbedding / JobFailed and write into Pulse's own storage — no extra tables. See the plugin README for configuration details.

Model Events

Callbacks receive $model and $slot as arguments:

Laravel events ModelEmbedding and ModelEmbedded are also fired and each carry $model, $slot, and (for ModelEmbedded) $embedding.

Soft Delete

By default, deleting a model deletes all its slot embeddings. Set embedding.soft_delete to true to preserve them on soft delete.

Per-model override:

Event false (default) true
soft delete all slot embeddings deleted embeddings kept
restore all slots regenerated unchanged
force delete all slot embeddings deleted all slot embeddings deleted

Artisan Commands

embedding:generate

When the model argument is omitted, the command scans app/Models (or app/) for classes implementing HasEmbeddings, asks for confirmation if more than one is found, and processes them sequentially. Failures are isolated per model and a summary is printed at the end.

embedding:clear

Bulk-delete stored embeddings. Requires either a model class or --all.

embedding:clean

Tidy up stale rows. By default deletes both orphan records (model class missing or model row no longer exists) and records whose slot is no longer defined in the model's embeddingSlotMap().

embedding:status

Read-only health report — configuration, per-slot coverage, orphan / invalid-slot counts, and storage size. Useful after deployments or as a periodic monitoring check.

Sample output:

Storage metrics are read through the VectorStoreMetrics contract. The core package ships a default implementation (JsonVectorStoreMetrics) that returns the row count via Eloquent and null for every byte field — DB-specific driver packages override the binding in their service provider to provide native byte figures.

You can read the same metrics from your own code:

rows is always an int. The byte fields are int|nullnull means the driver cannot or will not supply that metric (insufficient privileges, unsupported backend, etc.) and is rendered as n/a by embedding:status. rows may be approximate when a driver reports it via fast metadata tables (e.g. MySQL information_schema.tables.table_rows); for an exact count, use XLaravel\Embedding\Models\Embedding::count() instead.

Configuration

Environment Variable Default Description
EMBEDDING_DIMENSIONS 1536 Vector size — must match your AI model's output
EMBEDDINGS_DATABASE_CONNECTION DB_CONNECTION Dedicated DB connection for embeddings
EMBEDDINGS_DB_TABLE embeddings Table name
QUEUE_CONNECTION sync Queue connection for the generation job
EMBEDDING_QUEUE embedding Queue name
EMBEDDING_SIMILARITY_DRIVER auto Force a specific similarity driver (php, or an installed DB driver)

Database

The core migration creates the vector column as json. DB-specific drivers ship their own migration with a native vector column type (VECTOR, vector). Publish the driver migration instead of the core one when using a driver:

Testing

License

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


All versions of embedding with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
illuminate/database Version ^12.0|^13.0
illuminate/support Version ^12.0|^13.0
illuminate/queue Version ^12.0|^13.0
laravel/ai Version ^0.6
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package x-laravel/embedding contains the following files

Loading the files please wait ...