Skip to content

Commit 08d325c

Browse files
Validate efConstruction >= M0 in HNSW Config
1 parent 1900745 commit 08d325c

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/HNSW/Config.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,14 @@ public function __construct(
8282
if ($M < 2) {
8383
throw new \InvalidArgumentException('M must be at least 2.');
8484
}
85-
if ($efConstruction < $M) {
86-
throw new \InvalidArgumentException('efConstruction must be ≥ M.');
85+
$resolvedM0 = $M0 ?? ($M * 2);
86+
87+
if ($efConstruction < $resolvedM0) {
88+
throw new \InvalidArgumentException("efConstruction must be ≥ M0 ({$resolvedM0}).");
8789
}
8890

8991
$this->M = $M;
90-
$this->M0 = $M0 ?? ($M * 2);
92+
$this->M0 = $resolvedM0;
9193
$this->mL = $mL ?? (1.0 / log($M));
9294
$this->efConstruction = $efConstruction;
9395
$this->efSearch = $efSearch;

0 commit comments

Comments
 (0)