Skip to content

Commit 72b2a4b

Browse files
authored
Merge pull request #52 from dmitrichev/hnsw-m-could-be-zero
The value of the HNSW configuration parameter M can be zero
2 parents 70f0a5a + e5f490d commit 72b2a4b

File tree

4 files changed

+51
-1
lines changed

4 files changed

+51
-1
lines changed

src/Models/Request/CollectionConfig/HnswConfig.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function setPayloadM(?int $payloadM): HnswConfig
8080
public function toArray(): array
8181
{
8282
$data = [];
83-
if ($this->m) {
83+
if ($this->m !== null) {
8484
$data['m'] = $this->m;
8585
}
8686
if ($this->efConstruct) {

tests/Unit/Models/Request/CollectionConfig/HnswConfigTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ public function testWithM(): void
2828
], $config->toArray());
2929
}
3030

31+
public function testWithZeroM(): void
32+
{
33+
$config = (new HnswConfig())->setM(0);
34+
35+
$this->assertEquals([
36+
'm' => 0
37+
], $config->toArray());
38+
}
39+
3140
public function testWithInvalidM(): void
3241
{
3342
$this->expectException(InvalidArgumentException::class);

tests/Unit/Models/Request/CreateCollectionTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,31 @@ public function testCreateCollectionWithHnswConfig(): void
193193
);
194194
}
195195

196+
public function testCreateCollectionWithHnswConfigAndZeroM(): void
197+
{
198+
$collection = new CreateCollection();
199+
$collection->addVector(new VectorParams(1024, VectorParams::DISTANCE_COSINE));
200+
$diff = (new HnswConfig())
201+
->setM(0)
202+
->setPayloadM(1);
203+
204+
$collection->setHnswConfig($diff);
205+
206+
$this->assertEquals(
207+
[
208+
'vectors' => [
209+
'size' => '1024',
210+
'distance' => 'Cosine'
211+
],
212+
'hnsw_config' => [
213+
'm' => 0,
214+
'payload_m' => 1,
215+
]
216+
],
217+
$collection->toArray()
218+
);
219+
}
220+
196221
public function testCreateCollectionWithWalConfig(): void
197222
{
198223
$collection = new CreateCollection();

tests/Unit/Models/Request/UpdateCollectionTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,22 @@ public function testUpdateCollectionWithHnswConfig(): void
5858
);
5959
}
6060

61+
public function testUpdateCollectionWithHnswConfigAndZeroM(): void
62+
{
63+
$collection = new UpdateCollection();
64+
$collection->setHnswConfig((new HnswConfig())->setM(0)->setEfConstruct(5));
65+
66+
$this->assertEquals(
67+
[
68+
'hnsw_config' => [
69+
'm' => 0,
70+
'ef_construct' => 5
71+
],
72+
],
73+
$collection->toArray()
74+
);
75+
}
76+
6177
public function testUpdateCollectionWithQuantizationConfig(): void
6278
{
6379
$collection = new UpdateCollection();

0 commit comments

Comments
 (0)