Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
use Documents\User;
use Documents\VectorEmbedding;
use MongoDB\BSON\Binary;
use MongoDB\BSON\VectorType;

use function enum_exists;

class VectorSearchTest extends BaseTestCase
{
Expand Down Expand Up @@ -80,8 +83,16 @@ public function testQueryVector(): void

public function testQueryVectorAcceptsBinary(): void
{
[$stage] = $this->createVectorSearchStage();
$binaryVector = new Binary("\x01\x02\x03", 9);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was an invalid value for a binary vector.

MongoDB\Driver\Exception\InvalidArgumentException: Binary vector data is invalid

[$stage] = $this->createVectorSearchStage();
// @phpstan-ignore class.notFound (requires ext-mongodb 2.2+)
if (enum_exists(VectorType::class)) {
// @phpstan-ignore staticMethod.notFound (requires ext-mongodb 2.2+)
$binaryVector = Binary::fromVector([1, 2, 3], VectorType::Int8);
self::assertInstanceOf(Binary::class, $binaryVector);
} else {
$binaryVector = new Binary("\x03\x00\x01\x02\x03", 9);
}

$stage->queryVector($binaryVector);
self::assertSame(['$vectorSearch' => ['queryVector' => $binaryVector]], $stage->getExpression());
}
Expand Down