partitech / doctrine-pgvector
Postgresql vector type with doctrine
Installs: 28 849
Dependents: 0
Suggesters: 0
Security: 0
Stars: 15
Watchers: 2
Forks: 5
Open Issues: 0
Requires
- php: ^8.0
- doctrine/dbal: ^3.6|^4
- doctrine/orm: ^2.19|^3.0
Requires (Dev)
- phpunit/phpunit: ^5.2
README
Tip
For more detailed information and comprehensive guides, please visit our official documentation
Partitech Doctrine PgVector is a Doctrine extension for integrating PostgreSQL vector types into your PHP projects using Doctrine ORM. This module simplifies using vectors in your database by providing calculation functions such as distance, inner product, and cosine similarity.
📦 Installation
You can install Partitech Doctrine PgVector via Composer:
composer require partitech/doctrine-pgvector
⚙️ Configuration
Add the types and functions to your Doctrine configuration:
doctrine: dbal: types: vector: Partitech\DoctrinePgVector\Type\VectorType orm: dql: string_functions: distance: Partitech\DoctrinePgVector\Query\Distance inner_product: Partitech\DoctrinePgVector\Query\InnerProduct cosine_similarity: Partitech\DoctrinePgVector\Query\CosineSimilarity
🛠️ Usage
Vector Types
Use vector types directly in your Doctrine entities:
/** @Column(type="vector") */ private $vector;
Available DQL Functions
distance(vector, vector)
inner_product(vector, vector)
cosine_similarity(vector, vector)
These functions can be directly used in your Doctrine queries.
📌 Examples
Example query using distance:
$query = $entityManager->createQuery( 'SELECT e FROM Entity e ORDER BY distance(e.vector, :inputVector) ASC' ); $query->setParameter('inputVector', [0.1, 0.2, 0.3]); $result = $query->getResult();
✅ Testing and Development
To run unit tests:
composer test
🤝 Contribution
Contributions are welcome! Check the issues page to start contributing or submit a Pull Request.
📄 License
This project is licensed under the MIT License. See LICENSE for more details.