Skip to content

Commit 63c1f95

Browse files
committed
Updated readme [skip ci]
1 parent 9a887bf commit 63c1f95

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,17 @@ Type::addType('bit', 'Pgvector\Doctrine\BitType');
128128
Type::addType('sparsevec', 'Pgvector\Doctrine\SparseVectorType');
129129
```
130130

131+
And the distance functions
132+
133+
```php
134+
$config->addCustomNumericFunction('l2_distance', 'Pgvector\Doctrine\L2Distance');
135+
$config->addCustomNumericFunction('max_inner_product', 'Pgvector\Doctrine\MaxInnerProduct');
136+
$config->addCustomNumericFunction('cosine_distance', 'Pgvector\Doctrine\CosineDistance');
137+
$config->addCustomNumericFunction('l1_distance', 'Pgvector\Doctrine\L1Distance');
138+
$config->addCustomNumericFunction('hamming_distance', 'Pgvector\Doctrine\HammingDistance');
139+
$config->addCustomNumericFunction('jaccard_distance', 'Pgvector\Doctrine\JaccardDistance');
140+
```
141+
131142
Update your model
132143

133144
```php
@@ -155,6 +166,17 @@ $entityManager->persist($item);
155166
$entityManager->flush();
156167
```
157168

169+
Get the nearest neighbors to a vector
170+
171+
```php
172+
$neighbors = $entityManager->createQuery('SELECT i FROM Item i ORDER BY l2_distance(i.embedding, ?1)')
173+
->setParameter(1, new Vector([1, 2, 3]))
174+
->setMaxResults(5)
175+
->getResult();
176+
```
177+
178+
Also supports `max_inner_product`, `cosine_distance`, `l1_distance`, `hamming_distance`, and `jaccard_distance`
179+
158180
### PgSql
159181

160182
Enable the extension

0 commit comments

Comments
 (0)