$ show pgvector/pgvector-php
This repository provides a PHP library for integrating with the pgvector extension in PostgreSQL, offering support for vector, halfvec, bit, and sparsevec data types. It includes core vector classes (Vector, HalfVector, SparseVector) and integrations for Laravel (Eloquent models, migrations, and a service provider) and Doctrine (DBAL types and DQL functions). The library enables developers to store and query vector embeddings using various distance metrics (L2, inner product, cosine, etc.) in their PHP applications. The architecture is modular, with separate namespaces for core functionality, Laravel, and Doctrine integrations, allowing users to adopt only the parts they need.
The LLM identified 2 files worth highlighting for reuse:
Provides a reusable scope and method for Eloquent models to find nearest neighbors using various distance metrics (L2, inner product, cosine, etc.) by leveraging raw SQL expressions and annotating the query with the distance. It is self-contained within the Laravel namespace and only requires the vector classes and the Distance enum.
Encapsulates the registration of custom DBAL types and DQL functions for Doctrine ORM, allowing seamless use of pgvector vector types in Doctrine entities. It is self-contained and can be dropped into any Doctrine project that uses the pgvector extension, relying on the accompanying type and function classes in the same directory.