Building a Laravel Scout Driver for Cloudflare Vectorize
December 5, 2026
projects developmentI've been working on Laravel Scout Vectorize, a package that connects Laravel Scout to Cloudflare Vectorize using OpenAI embeddings. The goal is to use Scout's familiar Model::search() interface while the package takes care of turning model data and search queries into vectors.
I've written about using Laravel with Vectorize before. That post sketched out an architecture using Workers AI and a Worker. This project is a different implementation: a Scout driver calls OpenAI for embeddings and uses the Vectorize REST API directly.
Keeping the Scout interface
Scout gives a Laravel model a way to describe the data that should be searchable. With this driver, toSearchableArray() supplies the fields to embed. The package sends them to OpenAI, then stores the resulting vector and the model's ID in Vectorize. Each model uses a separate index derived from its searchableAs() value.
Search goes the other direction. The package embeds the query, asks Vectorize for similar vectors, and uses the matching IDs to load Eloquent models. It fetches those models in one database query and returns them in similarity order.
$posts = Post::search('cloudflare vector databases')
->take(5)
->get();
That looks like a normal Scout query, but the matching is based on the embeddings. The application still owns the records in its database; the vector index helps find them.
The picture is a simplification: real embeddings have many dimensions. Vectorize compares the query vector with indexed vectors and returns nearby matches; the application then loads the corresponding records.
The details behind the interface
The index dimensions have to match the embedding model. The package defaults to OpenAI's text-embedding-3-small; with its default 1536 dimensions, an index can be created with the included Artisan command:
php artisan vectorize:index:create posts --dimensions=1536 --metric=cosine
There are also commands to list and delete indexes and to add, search, or delete individual documents. That's useful when working directly with the index instead of going through a model.
Scout filters can be translated to Vectorize metadata filters. The model supplies metadata through scoutMetadata(), and each property used for filtering needs a Vectorize metadata index. Create that metadata index before inserting vectors, or reinsert existing vectors afterward so they can be filtered.
There are some limits the Scout interface can't make disappear. Vectorize writes are asynchronous, so a saved record may not show up in search immediately. Results are ordered by similarity, and Vectorize doesn't offer offset pagination: the driver fetches a bounded set and slices it locally, making the total approximate. For a predictable result set, take() is the better fit.
The package is on GitHub, with setup, configuration, and the current limitations in the README. Its tests use mocked HTTP responses, so they exercise the integration code without calling OpenAI or Cloudflare.