Skip to content

Commit 9c82e07

Browse files
authored
Merge pull request hkulekci#43 from hkulekci/query-param-improvements
Some Improvements for Endpoints
2 parents 11500d6 + a3eea6e commit 9c82e07

19 files changed

Lines changed: 765 additions & 76 deletions

src/Endpoints/Collections/Points.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ public function payload(): Payload
3131
/**
3232
* @throws InvalidArgumentException
3333
*/
34-
public function search(SearchRequest $searchParams): Response
34+
public function search(SearchRequest $searchParams, array $queryParams = []): Response
3535
{
3636
return $this->client->execute(
3737
$this->createRequest(
3838
'POST',
39-
'collections/' . $this->collectionName . '/points/search',
39+
'collections/' . $this->collectionName . '/points/search' . $this->queryBuild($queryParams),
4040
$searchParams->toArray()
4141
)
4242
);

src/Endpoints/Collections/Points/Payload.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function clear(array $points): Response
4040
* @return Response
4141
* @throws InvalidArgumentException
4242
*/
43-
public function delete(array $points, array $keys, Filter $filter = null): Response
43+
public function delete(array $points, array $keys, Filter $filter = null, array $queryParams = []): Response
4444
{
4545
$data = [
4646
'points' => $points,
@@ -53,7 +53,7 @@ public function delete(array $points, array $keys, Filter $filter = null): Respo
5353
return $this->client->execute(
5454
$this->createRequest(
5555
'POST',
56-
'/collections/' . $this->getCollectionName() . '/points/payload/delete',
56+
'/collections/' . $this->getCollectionName() . '/points/payload/delete' . $this->queryBuild($queryParams),
5757
$data
5858
)
5959
);
@@ -62,12 +62,12 @@ public function delete(array $points, array $keys, Filter $filter = null): Respo
6262
/**
6363
* @throws InvalidArgumentException
6464
*/
65-
public function set(array $points, array $payload, array $params = []): Response
65+
public function set(array $points, array $payload, array $queryParams = []): Response
6666
{
6767
return $this->client->execute(
6868
$this->createRequest(
6969
'POST',
70-
'/collections/' . $this->getCollectionName() . '/points/payload' . $this->queryBuild($params),
70+
'/collections/' . $this->getCollectionName() . '/points/payload' . $this->queryBuild($queryParams),
7171
[
7272
'payload' => $payload,
7373
'points' => $points,
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
/**
3+
* CollectionParams
4+
*
5+
* @since Mar 2023
6+
* @author Haydar KULEKCI <haydarkulekci@gmail.com>
7+
*/
8+
9+
namespace Qdrant\Models\Request\CollectionConfig;
10+
11+
use Qdrant\Models\Request\RequestModel;
12+
13+
class CollectionParams implements RequestModel
14+
{
15+
protected ?int $replicationFactor;
16+
protected ?int $writeConsistencyFactor;
17+
protected ?int $readFanOutFactor;
18+
protected ?bool $onDiskPayload;
19+
20+
public function setReplicationFactor(?int $replicationFactor): CollectionParams
21+
{
22+
$this->replicationFactor = $replicationFactor;
23+
24+
return $this;
25+
}
26+
27+
public function setWriteConsistencyFactor(?int $writeConsistencyFactor): CollectionParams
28+
{
29+
$this->writeConsistencyFactor = $writeConsistencyFactor;
30+
31+
return $this;
32+
}
33+
34+
public function setReadFanOutFactor(?int $readFanOutFactor): CollectionParams
35+
{
36+
$this->readFanOutFactor = $readFanOutFactor;
37+
38+
return $this;
39+
}
40+
41+
public function setOnDiskPayload(?bool $onDiskPayload): CollectionParams
42+
{
43+
$this->onDiskPayload = $onDiskPayload;
44+
45+
return $this;
46+
}
47+
48+
public function toArray(): array
49+
{
50+
return array_filter([
51+
'replication_factor' => $this->replicationFactor ?? null,
52+
'write_consistency_factor' => $this->writeConsistencyFactor ?? null,
53+
'read_fan_out_factor' => $this->readFanOutFactor ?? null,
54+
'on_disk_payload' => $this->onDiskPayload ?? null,
55+
]);
56+
}
57+
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?php
2+
/**
3+
* HnswConfig
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 HnswConfig implements RequestModel
15+
{
16+
protected ?int $m = null;
17+
protected ?int $efConstruct = null;
18+
protected ?int $fullScanThreshold = null;
19+
protected ?int $maxIndexingThreads = null;
20+
protected ?bool $onDisk = null;
21+
protected ?int $payloadM = null;
22+
23+
public function setM(?int $m): HnswConfig
24+
{
25+
if ($m < 0) {
26+
throw new InvalidArgumentException('m should be bigger than 0');
27+
}
28+
$this->m = $m;
29+
30+
return $this;
31+
}
32+
33+
public function setEfConstruct(?int $efConstruct): HnswConfig
34+
{
35+
if ($efConstruct < 4) {
36+
throw new InvalidArgumentException('ef_construct should be bigger than 4');
37+
}
38+
$this->efConstruct = $efConstruct;
39+
40+
return $this;
41+
}
42+
43+
public function setFullScanThreshold(?int $fullScanThreshold): HnswConfig
44+
{
45+
if ($fullScanThreshold < 10) {
46+
throw new InvalidArgumentException('full_scan_threshold should be bigger than 10');
47+
}
48+
$this->fullScanThreshold = $fullScanThreshold;
49+
50+
return $this;
51+
}
52+
53+
public function setMaxIndexingThreads(?int $maxIndexingThreads): HnswConfig
54+
{
55+
if ($maxIndexingThreads < 0) {
56+
throw new InvalidArgumentException('max_indexing_threads should be bigger than 0');
57+
}
58+
$this->maxIndexingThreads = $maxIndexingThreads;
59+
60+
return $this;
61+
}
62+
63+
public function setOnDisk(?bool $onDisk): HnswConfig
64+
{
65+
$this->onDisk = $onDisk;
66+
67+
return $this;
68+
}
69+
70+
public function setPayloadM(?int $payloadM): HnswConfig
71+
{
72+
if ($payloadM < 0) {
73+
throw new InvalidArgumentException('payload_m should be bigger than 0');
74+
}
75+
$this->payloadM = $payloadM;
76+
77+
return $this;
78+
}
79+
80+
public function toArray(): array
81+
{
82+
$data = [];
83+
if ($this->m) {
84+
$data['m'] = $this->m;
85+
}
86+
if ($this->efConstruct) {
87+
$data['ef_construct'] = $this->efConstruct;
88+
}
89+
if ($this->fullScanThreshold) {
90+
$data['full_scan_threshold'] = $this->fullScanThreshold;
91+
}
92+
if ($this->maxIndexingThreads) {
93+
$data['max_indexing_threads'] = $this->maxIndexingThreads;
94+
}
95+
if ($this->onDisk) {
96+
$data['on_disk'] = $this->onDisk;
97+
}
98+
if ($this->payloadM) {
99+
$data['payload_m'] = $this->payloadM;
100+
}
101+
102+
return $data;
103+
}
104+
}

src/Models/Request/CollectionConfig/OptimizersConfigDiff.php renamed to src/Models/Request/CollectionConfig/OptimizersConfig.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* OptimizersConfigDiff
3+
* OptimizersConfig
44
*
55
* @since Mar 2023
66
* @author Haydar KULEKCI <haydarkulekci@gmail.com>
@@ -10,7 +10,7 @@
1010

1111
use Qdrant\Models\Request\RequestModel;
1212

13-
class OptimizersConfigDiff implements RequestModel
13+
class OptimizersConfig implements RequestModel
1414
{
1515
/** @var float|null The minimal fraction of deleted vectors in a segment, required to perform segment optimization */
1616
protected ?float $deletedThreshold = null;
@@ -51,56 +51,56 @@ class OptimizersConfigDiff implements RequestModel
5151
protected ?int $maxOptimizationThreads = null;
5252

5353

54-
public function setDeletedThreshold(?float $deletedThreshold): OptimizersConfigDiff
54+
public function setDeletedThreshold(?float $deletedThreshold): OptimizersConfig
5555
{
5656
$this->deletedThreshold = $deletedThreshold;
5757

5858
return $this;
5959
}
6060

61-
public function setIndexingThreshold(?int $indexingThreshold): OptimizersConfigDiff
61+
public function setIndexingThreshold(?int $indexingThreshold): OptimizersConfig
6262
{
6363
$this->indexingThreshold = $indexingThreshold;
6464

6565
return $this;
6666
}
6767

68-
public function setVacuumMinVectorNumber(?int $vacuumMinVectorNumber): OptimizersConfigDiff
68+
public function setVacuumMinVectorNumber(?int $vacuumMinVectorNumber): OptimizersConfig
6969
{
7070
$this->vacuumMinVectorNumber = $vacuumMinVectorNumber;
7171

7272
return $this;
7373
}
7474

75-
public function setDefaultSegmentNumber(?int $defaultSegmentNumber): OptimizersConfigDiff
75+
public function setDefaultSegmentNumber(?int $defaultSegmentNumber): OptimizersConfig
7676
{
7777
$this->defaultSegmentNumber = $defaultSegmentNumber;
7878

7979
return $this;
8080
}
8181

82-
public function setMaxSegmentSize(?int $maxSegmentSize): OptimizersConfigDiff
82+
public function setMaxSegmentSize(?int $maxSegmentSize): OptimizersConfig
8383
{
8484
$this->maxSegmentSize = $maxSegmentSize;
8585

8686
return $this;
8787
}
8888

89-
public function setMemmapThreshold(?int $memmapThreshold): OptimizersConfigDiff
89+
public function setMemmapThreshold(?int $memmapThreshold): OptimizersConfig
9090
{
9191
$this->memmapThreshold = $memmapThreshold;
9292

9393
return $this;
9494
}
9595

96-
public function setFlushIntervalSec(?int $flushIntervalSec): OptimizersConfigDiff
96+
public function setFlushIntervalSec(?int $flushIntervalSec): OptimizersConfig
9797
{
9898
$this->flushIntervalSec = $flushIntervalSec;
9999

100100
return $this;
101101
}
102102

103-
public function setMaxOptimizationThreads(?int $maxOptimizationThreads): OptimizersConfigDiff
103+
public function setMaxOptimizationThreads(?int $maxOptimizationThreads): OptimizersConfig
104104
{
105105
$this->maxOptimizationThreads = $maxOptimizationThreads;
106106

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+
}

src/Models/Request/CollectionParamsDiff.php

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)