Skip to content

Commit 5beeabc

Browse files
authored
Explicitly do not support base vector search methods (#3535)
As the existing `vectorSearch` method already supports all their usage and the arguments for the base methods don't correspond with MongoDB vector search usage
1 parent ab3044f commit 5beeabc

2 files changed

Lines changed: 62 additions & 2 deletions

File tree

src/Query/Builder.php

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -703,8 +703,7 @@ protected function removeExistingOrdersFor($column): array
703703
function ($orderColumn) use ($column) {
704704
return $orderColumn === $column
705705
|| ($orderColumn === 'id' && $column === '_id')
706-
|| ($orderColumn === '_id' && $column === 'id'
707-
);
706+
|| ($orderColumn === '_id' && $column === 'id');
708707
},
709708
);
710709

@@ -1871,4 +1870,59 @@ public function orWhereIntegerNotInRaw($column, $values, $boolean = 'and')
18711870
{
18721871
throw new BadMethodCallException('This method is not supported by MongoDB');
18731872
}
1873+
1874+
/**
1875+
* Base method from Laravel >= 13.0
1876+
* ToDo: mark as `#[Override]` when we drop support for Laravel < 13.0
1877+
*
1878+
* @internal This method is not supported by MongoDB. Use vectorSearch() instead.
1879+
*/
1880+
public function whereVectorSimilarTo($column, $vector, $minSimilarity = 0.6, $order = true)
1881+
{
1882+
throw new BadMethodCallException('This method is not supported by MongoDB. Use vectorSearch() instead.');
1883+
}
1884+
1885+
/**
1886+
* Base method from Laravel >= 13.0
1887+
* ToDo: mark as `#[Override]` when we drop support for Laravel < 13.0
1888+
*
1889+
* @internal This method is not supported by MongoDB. Use vectorSearch() with the $filter parameter instead.
1890+
*/
1891+
public function whereVectorDistanceLessThan($column, $vector, $maxDistance, $boolean = 'and')
1892+
{
1893+
throw new BadMethodCallException('This method is not supported by MongoDB. Use vectorSearch() with the $filter parameter instead.');
1894+
}
1895+
1896+
/**
1897+
* Base method from Laravel >= 13.0
1898+
* ToDo: mark as `#[Override]` when we drop support for Laravel < 13.0
1899+
*
1900+
* @internal This method is not supported by MongoDB. Use vectorSearch() with the $filter parameter instead.
1901+
*/
1902+
public function orWhereVectorDistanceLessThan($column, $vector, $maxDistance)
1903+
{
1904+
throw new BadMethodCallException('This method is not supported by MongoDB. Use vectorSearch() with the $filter parameter instead.');
1905+
}
1906+
1907+
/**
1908+
* Base method from Laravel >= 13.0
1909+
* ToDo: mark as `#[Override]` when we drop support for Laravel < 13.0
1910+
*
1911+
* @internal This method is not supported by MongoDB. Use vectorSearch() instead, which returns vectorSearchScore in the result.
1912+
*/
1913+
public function selectVectorDistance($column, $vector, $as = null)
1914+
{
1915+
throw new BadMethodCallException('This method is not supported by MongoDB. Use vectorSearch() instead, which returns vectorSearchScore in the result.');
1916+
}
1917+
1918+
/**
1919+
* Base method from Laravel >= 13.0
1920+
* ToDo: mark as `#[Override]` when we drop support for Laravel < 13.0
1921+
*
1922+
* @internal This method is not supported by MongoDB. Use vectorSearch() instead, which returns results ordered by vector score.
1923+
*/
1924+
public function orderByVectorDistance($column, $vector = [])
1925+
{
1926+
throw new BadMethodCallException('This method is not supported by MongoDB. Use vectorSearch() instead, which returns results ordered by vector score.');
1927+
}
18741928
}

tests/Query/BuilderTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,6 +1646,12 @@ public static function getEloquentMethodsNotSupported()
16461646

16471647
/** @see DatabaseQueryBuilderTest::testOrWhereIntegerNotInRaw */
16481648
yield 'orWhereIntegerNotInRaw' => [fn (Builder $builder) => $builder->orWhereIntegerNotInRaw('id', ['1a', 2])];
1649+
1650+
yield 'whereVectorSimilarTo' => [fn (Builder $builder) => $builder->whereVectorSimilarTo('embedding', [0.1, 0.2])];
1651+
yield 'whereVectorDistanceLessThan' => [fn (Builder $builder) => $builder->whereVectorDistanceLessThan('embedding', [0.1, 0.2], 0.5)];
1652+
yield 'orWhereVectorDistanceLessThan' => [fn (Builder $builder) => $builder->orWhereVectorDistanceLessThan('embedding', [0.1, 0.2], 0.5)];
1653+
yield 'selectVectorDistance' => [fn (Builder $builder) => $builder->selectVectorDistance('embedding', [0.1, 0.2])];
1654+
yield 'orderByVectorDistance' => [fn (Builder $builder) => $builder->orderByVectorDistance('embedding', [0.1, 0.2])];
16491655
}
16501656

16511657
#[DataProvider('provideDisableRenameEmbeddedIdField')]

0 commit comments

Comments
 (0)