Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The value of the HNSW configuration parameter M can be zero #52

Merged
merged 1 commit into from
May 31, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/Models/Request/CollectionConfig/HnswConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function setPayloadM(?int $payloadM): HnswConfig
public function toArray(): array
{
$data = [];
if ($this->m) {
if ($this->m !== null) {
$data['m'] = $this->m;
}
if ($this->efConstruct) {
Expand Down
9 changes: 9 additions & 0 deletions tests/Unit/Models/Request/CollectionConfig/HnswConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ public function testWithM(): void
], $config->toArray());
}

public function testWithZeroM(): void
{
$config = (new HnswConfig())->setM(0);

$this->assertEquals([
'm' => 0
], $config->toArray());
}

public function testWithInvalidM(): void
{
$this->expectException(InvalidArgumentException::class);
Expand Down
25 changes: 25 additions & 0 deletions tests/Unit/Models/Request/CreateCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,31 @@ public function testCreateCollectionWithHnswConfig(): void
);
}

public function testCreateCollectionWithHnswConfigAndZeroM(): void
{
$collection = new CreateCollection();
$collection->addVector(new VectorParams(1024, VectorParams::DISTANCE_COSINE));
$diff = (new HnswConfig())
->setM(0)
->setPayloadM(1);

$collection->setHnswConfig($diff);

$this->assertEquals(
[
'vectors' => [
'size' => '1024',
'distance' => 'Cosine'
],
'hnsw_config' => [
'm' => 0,
'payload_m' => 1,
]
],
$collection->toArray()
);
}

public function testCreateCollectionWithWalConfig(): void
{
$collection = new CreateCollection();
Expand Down
16 changes: 16 additions & 0 deletions tests/Unit/Models/Request/UpdateCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,22 @@ public function testUpdateCollectionWithHnswConfig(): void
);
}

public function testUpdateCollectionWithHnswConfigAndZeroM(): void
{
$collection = new UpdateCollection();
$collection->setHnswConfig((new HnswConfig())->setM(0)->setEfConstruct(5));

$this->assertEquals(
[
'hnsw_config' => [
'm' => 0,
'ef_construct' => 5
],
],
$collection->toArray()
);
}

public function testUpdateCollectionWithQuantizationConfig(): void
{
$collection = new UpdateCollection();
Expand Down
Loading