Skip to content

Commit bc78262

Browse files
committed
WalConfig initialized and HnswTests improved
1 parent cb53ffe commit bc78262

4 files changed

Lines changed: 158 additions & 4 deletions

File tree

src/Models/Request/CollectionConfig/HnswConfig.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class HnswConfig implements RequestModel
2222

2323
public function setM(?int $m): HnswConfig
2424
{
25-
if ($this->efConstruct < 0) {
25+
if ($m < 0) {
2626
throw new InvalidArgumentException('m should be bigger than 0');
2727
}
2828
$this->m = $m;
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/**
3+
* WalConfig
4+
*
5+
* @since Dec 2023
6+
* @author Haydar KULEKCI <haydarkulekci@gmail.com>
7+
*/
8+
9+
namespace Qdrant\Models\Request\CollectionConfig;
10+
11+
use Qdrant\Exception\InvalidArgumentException;
12+
use Qdrant\Models\Request\RequestModel;
13+
14+
class WalConfig implements RequestModel
15+
{
16+
protected ?int $walCapacityMb = null;
17+
protected ?int $walSegmentsAhead = null;
18+
19+
public function setWalCapacityMb(?int $walCapacityMb): WalConfig
20+
{
21+
if ($walCapacityMb < 1) {
22+
throw new InvalidArgumentException('wal_capacity_mb should be bigger than 1');
23+
}
24+
$this->walCapacityMb = $walCapacityMb;
25+
26+
return $this;
27+
}
28+
29+
public function setWalSegmentsAhead(?int $walSegmentsAhead): WalConfig
30+
{
31+
if ($walSegmentsAhead < 0) {
32+
throw new InvalidArgumentException('wal_segments_ahead should be bigger than 0');
33+
}
34+
$this->walSegmentsAhead = $walSegmentsAhead;
35+
36+
return $this;
37+
}
38+
39+
public function toArray(): array
40+
{
41+
$data = [];
42+
if ($this->walCapacityMb) {
43+
$data['wal_capacity_mb'] = $this->walCapacityMb;
44+
}
45+
if ($this->walSegmentsAhead) {
46+
$data['wal_segments_ahead'] = $this->walSegmentsAhead;
47+
}
48+
49+
return $data;
50+
}
51+
}

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

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
namespace Qdrant\Tests\Unit\Models\Request\CollectionConfig;
88

99
use PHPUnit\Framework\TestCase;
10+
use Qdrant\Exception\InvalidArgumentException;
1011
use Qdrant\Models\Request\CollectionConfig\HnswConfig;
1112

1213
class HnswConfigTest extends TestCase
@@ -27,6 +28,15 @@ public function testWithM(): void
2728
], $config->toArray());
2829
}
2930

31+
public function testWithInvalidM(): void
32+
{
33+
$this->expectException(InvalidArgumentException::class);
34+
$this->expectExceptionMessage('m should be bigger than 0');
35+
$config = (new HnswConfig())->setM(-1);
36+
37+
$this->assertEquals([], $config->toArray());
38+
}
39+
3040
public function testWithEfConstruct(): void
3141
{
3242
$config = (new HnswConfig())->setEfConstruct(10);
@@ -36,6 +46,15 @@ public function testWithEfConstruct(): void
3646
], $config->toArray());
3747
}
3848

49+
public function testWithInvalidEfConstruct(): void
50+
{
51+
$this->expectException(InvalidArgumentException::class);
52+
$this->expectExceptionMessage('ef_construct should be bigger than 4');
53+
$config = (new HnswConfig())->setEfConstruct(-1);
54+
55+
$this->assertEquals([], $config->toArray());
56+
}
57+
3958
public function testWithFullScanThreshold(): void
4059
{
4160
$config = (new HnswConfig())->setFullScanThreshold(10);
@@ -45,7 +64,16 @@ public function testWithFullScanThreshold(): void
4564
], $config->toArray());
4665
}
4766

48-
public function testWithDeletedThreshold(): void
67+
public function testWithInvalidFullScanThreshold(): void
68+
{
69+
$this->expectException(InvalidArgumentException::class);
70+
$this->expectExceptionMessage('full_scan_threshold should be bigger than 10');
71+
$config = (new HnswConfig())->setFullScanThreshold(1);
72+
73+
$this->assertEquals([], $config->toArray());
74+
}
75+
76+
public function testWithMaxIndexingThreads(): void
4977
{
5078
$config = (new HnswConfig())->setMaxIndexingThreads(9);
5179

@@ -54,6 +82,15 @@ public function testWithDeletedThreshold(): void
5482
], $config->toArray());
5583
}
5684

85+
public function testWithInvalidMaxIndexingThreads(): void
86+
{
87+
$this->expectException(InvalidArgumentException::class);
88+
$this->expectExceptionMessage('max_indexing_threads should be bigger than 0');
89+
$config = (new HnswConfig())->setMaxIndexingThreads(-1);
90+
91+
$this->assertEquals([], $config->toArray());
92+
}
93+
5794
public function testWithOnDisk(): void
5895
{
5996
$config = (new HnswConfig())->setOnDisk(true);
@@ -63,7 +100,7 @@ public function testWithOnDisk(): void
63100
], $config->toArray());
64101
}
65102

66-
public function testWithDefaultSegmentNumber(): void
103+
public function testWithPayloadM(): void
67104
{
68105
$config = (new HnswConfig())->setPayloadM(10);
69106

@@ -72,7 +109,16 @@ public function testWithDefaultSegmentNumber(): void
72109
], $config->toArray());
73110
}
74111

75-
public function testWithFlushIntervalSec(): void
112+
public function testWithInvalidPayloadM(): void
113+
{
114+
$this->expectException(InvalidArgumentException::class);
115+
$this->expectExceptionMessage('payload_m should be bigger than 0');
116+
$config = (new HnswConfig())->setPayloadM(-1);
117+
118+
$this->assertEquals([], $config->toArray());
119+
}
120+
121+
public function testWithMultipleParameters(): void
76122
{
77123
$config = (new HnswConfig())->setMaxIndexingThreads(10)->setPayloadM(10);
78124

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
/**
3+
* @since Oct 2023
4+
* @author Haydar KULEKCI <haydarkulekci@gmail.com>
5+
*/
6+
7+
namespace Qdrant\Tests\Unit\Models\Request\CollectionConfig;
8+
9+
use PHPUnit\Framework\TestCase;
10+
use Qdrant\Exception\InvalidArgumentException;
11+
use Qdrant\Models\Request\CollectionConfig\WalConfig;
12+
13+
class WalConfigTest extends TestCase
14+
{
15+
public function testBasic(): void
16+
{
17+
$config = new WalConfig();
18+
19+
$this->assertEquals([], $config->toArray());
20+
}
21+
22+
public function testWithWalCapacityMb(): void
23+
{
24+
$config = (new WalConfig())->setWalCapacityMb(10);
25+
26+
$this->assertEquals([
27+
'wal_capacity_mb' => 10
28+
], $config->toArray());
29+
}
30+
31+
public function testWithInvalidM(): void
32+
{
33+
$this->expectException(InvalidArgumentException::class);
34+
$this->expectExceptionMessage('wal_capacity_mb should be bigger than 1');
35+
$config = (new WalConfig())->setWalCapacityMb(0);
36+
37+
$this->assertEquals([], $config->toArray());
38+
}
39+
40+
public function testWithEfConstruct(): void
41+
{
42+
$config = (new WalConfig())->setWalSegmentsAhead(1);
43+
44+
$this->assertEquals([
45+
'wal_segments_ahead' => 1
46+
], $config->toArray());
47+
}
48+
49+
public function testWithInvalidEfConstruct(): void
50+
{
51+
$this->expectException(InvalidArgumentException::class);
52+
$this->expectExceptionMessage('wal_segments_ahead should be bigger than 0');
53+
$config = (new WalConfig())->setWalSegmentsAhead(-1);
54+
55+
$this->assertEquals([], $config->toArray());
56+
}
57+
}

0 commit comments

Comments
 (0)