Skip to content

Commit 5627d6e

Browse files
authored
Merge pull request #33 from yunwuxin/patch-1
2 parents f33b689 + a8d7c11 commit 5627d6e

File tree

3 files changed

+104
-7
lines changed

3 files changed

+104
-7
lines changed

src/Endpoints/Collections/Points.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* @since Mar 2023
88
* @author Haydar KULEKCI <haydarkulekci@gmail.com>
99
*/
10+
1011
namespace Qdrant\Endpoints\Collections;
1112

1213
use Qdrant\Endpoints\AbstractEndpoint;
@@ -16,6 +17,7 @@
1617
use Qdrant\Models\PointsStruct;
1718
use Qdrant\Models\Request\PointsBatch;
1819
use Qdrant\Models\Request\RecommendRequest;
20+
use Qdrant\Models\Request\ScrollRequest;
1921
use Qdrant\Models\Request\SearchRequest;
2022
use Qdrant\Response;
2123

@@ -43,16 +45,18 @@ public function search(SearchRequest $searchParams): Response
4345
/**
4446
* @throws InvalidArgumentException
4547
*/
46-
public function scroll(Filter $filter = null): Response
48+
public function scroll(Filter|ScrollRequest $scrollParams = null, array $queryParams = []): Response
4749
{
4850
$body = [];
49-
if ($filter) {
50-
$body['filter'] = $filter->toArray();
51+
if ($scrollParams instanceof Filter) {
52+
$body['filter'] = $scrollParams->toArray();
53+
} elseif ($scrollParams instanceof ScrollRequest) {
54+
$body = $scrollParams->toArray();
5155
}
5256
return $this->client->execute(
5357
$this->createRequest(
5458
'POST',
55-
'/collections/' . $this->getCollectionName() . '/points/scroll',
59+
'/collections/' . $this->getCollectionName() . '/points/scroll' . $this->queryBuild($queryParams),
5660
$body
5761
)
5862
);
@@ -100,9 +104,9 @@ public function ids(array $ids, $withPayload = false, $withVector = true, array
100104
'POST',
101105
'/collections/' . $this->getCollectionName() . '/points' . $this->queryBuild($queryParams),
102106
[
103-
'ids' => $ids,
107+
'ids' => $ids,
104108
'with_payload' => $withPayload,
105-
'with_vector' => $withVector,
109+
'with_vector' => $withVector,
106110
]
107111
)
108112
);
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
3+
namespace Qdrant\Models\Request;
4+
5+
use Qdrant\Models\Filter\Filter;
6+
use Qdrant\Models\Traits\ProtectedPropertyAccessor;
7+
8+
class ScrollRequest implements RequestModel
9+
{
10+
11+
use ProtectedPropertyAccessor;
12+
13+
protected ?Filter $filter = null;
14+
15+
protected ?int $limit = null;
16+
17+
protected int|string|null $offset = null;
18+
19+
protected bool|array|null $withVector = null;
20+
21+
protected bool|array|null $withPayload = null;
22+
23+
public function setFilter(Filter $filter): static
24+
{
25+
$this->filter = $filter;
26+
27+
return $this;
28+
}
29+
30+
public function setLimit(int $limit): static
31+
{
32+
$this->limit = $limit;
33+
34+
return $this;
35+
}
36+
37+
public function setOffset(int|string $offset): static
38+
{
39+
$this->offset = $offset;
40+
41+
return $this;
42+
}
43+
44+
public function setWithPayload($withPayload): static
45+
{
46+
$this->withPayload = $withPayload;
47+
48+
return $this;
49+
}
50+
51+
public function setWithVector($withVector): static
52+
{
53+
$this->withVector = $withVector;
54+
55+
return $this;
56+
}
57+
58+
public function toArray(): array
59+
{
60+
$body = [];
61+
62+
if ($this->filter !== null && $this->filter->toArray()) {
63+
$body['filter'] = $this->filter->toArray();
64+
}
65+
if ($this->limit) {
66+
$body['limit'] = $this->limit;
67+
}
68+
if ($this->offset) {
69+
$body['offset'] = $this->offset;
70+
}
71+
if ($this->withVector) {
72+
$body['with_vector'] = $this->withVector;
73+
}
74+
if ($this->withPayload) {
75+
$body['with_payload'] = $this->withPayload;
76+
}
77+
78+
return $body;
79+
}
80+
}

tests/Integration/Endpoints/Collections/PointsTest.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Qdrant\Models\PointStruct;
1414
use Qdrant\Models\Request\CreateCollection;
1515
use Qdrant\Models\Request\PointsBatch;
16+
use Qdrant\Models\Request\ScrollRequest;
1617
use Qdrant\Models\Request\VectorParams;
1718
use Qdrant\Models\VectorStruct;
1819
use Qdrant\Tests\Integration\AbstractIntegration;
@@ -137,6 +138,18 @@ public function testScrollPoint(array $points): void
137138
$response = $this->getCollections('sample-collection')->points()->scroll($filter);
138139
$this->assertCount(1, $response['result']['points']);
139140
$this->assertEquals(2, $response['result']['points'][0]['id']);
141+
142+
$request = (new ScrollRequest())
143+
->setLimit(1)
144+
->setFilter($filter)
145+
->setWithPayload(true)
146+
->setWithVector(true)
147+
->setOffset(2);
148+
149+
$response = $this->getCollections('sample-collection')->points()->scroll($request);
150+
151+
$this->assertCount(1, $response['result']['points']);
152+
$this->assertEquals(2, $response['result']['points'][0]['id']);
140153
}
141154

142155
/**
@@ -232,4 +245,4 @@ protected function tearDown(): void
232245

233246
$this->getCollections('sample-collection')->delete();
234247
}
235-
}
248+
}

0 commit comments

Comments
 (0)