Skip to content

Commit 497bcdd

Browse files
authored
Merge pull request hkulekci#59 from julien-jourde/fix-payload-vector-params
Fix `with_payload` and `with_vector` params.
2 parents 81e01e9 + bfc80e6 commit 497bcdd

4 files changed

Lines changed: 241 additions & 5 deletions

File tree

src/Models/Request/ScrollRequest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ public function toArray(): array
7777
if ($this->offset) {
7878
$body['offset'] = $this->offset;
7979
}
80-
if ($this->withVector) {
80+
if ($this->withVector !== null) {
8181
$body['with_vector'] = $this->withVector;
8282
}
83-
if ($this->withPayload) {
83+
if ($this->withPayload !== null) {
8484
$body['with_payload'] = $this->withPayload;
8585
}
8686
if ($this->orderBy) {

src/Models/Request/SearchRequest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,14 @@ public function toArray(): array
112112
if ($this->offset) {
113113
$body['offset'] = $this->offset;
114114
}
115-
if ($this->withVector) {
115+
if ($this->withVector !== null) {
116116
$body['with_vector'] = $this->withVector;
117117
}
118-
if ($this->withPayload) {
118+
if ($this->withPayload !== null) {
119119
$body['with_payload'] = $this->withPayload;
120120
}
121121

122122
return $body;
123123
}
124124

125-
}
125+
}
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
<?php
2+
/**
3+
* @since Mar 2023
4+
* @author Haydar KULEKCI <haydarkulekci@gmail.com>
5+
*/
6+
7+
namespace Qdrant\Tests\Integration\Endpoints\Collections;
8+
9+
use Qdrant\Endpoints\Collections;
10+
use Qdrant\Exception\InvalidArgumentException;
11+
use Qdrant\Models\PointsStruct;
12+
use Qdrant\Models\Request\CreateIndex;
13+
use Qdrant\Models\Request\ScrollRequest;
14+
use Qdrant\Models\VectorStruct;
15+
use Qdrant\Tests\Integration\AbstractIntegration;
16+
17+
class SearchPayloadTest extends AbstractIntegration
18+
{
19+
/**
20+
* @throws InvalidArgumentException
21+
*/
22+
public function setUp(): void
23+
{
24+
parent::setUp();
25+
26+
$this->createCollections('sample-collection');
27+
28+
$response = $this->getCollections('sample-collection')->index()->create(
29+
(new CreateIndex('payload', [
30+
'type' => 'integer',
31+
'range' => true,
32+
'lookup' => false,
33+
'is_principal' => true
34+
])),
35+
[
36+
'wait' => 'true'
37+
]
38+
);
39+
40+
$this->assertEquals('ok', $response['status']);
41+
$this->assertEquals('completed', $response['result']['status']);
42+
43+
$response = $this->getCollections('sample-collection')->points()
44+
->upsert(
45+
PointsStruct::createFromArray(self::basicPointDataProvider()[0][0]),
46+
[
47+
'wait' => 'true'
48+
]
49+
);
50+
51+
$this->assertEquals('ok', $response['status']);
52+
$this->assertEquals('completed', $response['result']['status']);
53+
}
54+
55+
public static function basicPointDataProvider(): array
56+
{
57+
return [
58+
[
59+
[
60+
[
61+
'id' => 1,
62+
'vector' => new VectorStruct([1, 3, 400], 'image'),
63+
'payload' => [
64+
'sort' => 1,
65+
'color' => 'red'
66+
]
67+
],
68+
[
69+
'id' => 2,
70+
'vector' => new VectorStruct([1, 3, 300], 'image'),
71+
'payload' => [
72+
'sort' => 2,
73+
'color' => 'red'
74+
]
75+
],
76+
[
77+
'id' => 3,
78+
'vector' => new VectorStruct([1, 3, 300], 'image'),
79+
'payload' => [
80+
'sort' => 3,
81+
'color' => 'green'
82+
]
83+
],
84+
]
85+
]
86+
];
87+
}
88+
89+
public function testScrollWithPayload(): void
90+
{
91+
$scroll = (new ScrollRequest())->setWithPayload(true);
92+
$response = $this->getCollections('sample-collection')->points()->scroll($scroll);
93+
94+
$this->assertEquals('ok', $response['status']);
95+
$this->assertCount(2, $response['result']);
96+
$this->assertCount(3, $response['result']['points']);
97+
$this->assertArrayHasKey('payload', $response['result']['points'][0]);
98+
}
99+
100+
public function testScrollWithoutPayload(): void
101+
{
102+
$scroll = (new ScrollRequest())->setWithPayload(false);
103+
$response = $this->getCollections('sample-collection')->points()->scroll($scroll);
104+
105+
$this->assertEquals('ok', $response['status']);
106+
$this->assertCount(2, $response['result']);
107+
$this->assertCount(3, $response['result']['points']);
108+
$this->assertArrayNotHasKey('payload', $response['result']['points'][0]);
109+
}
110+
111+
protected function tearDown(): void
112+
{
113+
parent::tearDown();
114+
$collections = new Collections($this->client);
115+
116+
$collections->setCollectionName('sample-collection')->delete();
117+
}
118+
}
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
<?php
2+
/**
3+
* @since Mar 2023
4+
* @author Haydar KULEKCI <haydarkulekci@gmail.com>
5+
*/
6+
7+
namespace Qdrant\Tests\Integration\Endpoints\Collections;
8+
9+
use Qdrant\Endpoints\Collections;
10+
use Qdrant\Exception\InvalidArgumentException;
11+
use Qdrant\Models\PointsStruct;
12+
use Qdrant\Models\Request\CreateIndex;
13+
use Qdrant\Models\Request\ScrollRequest;
14+
use Qdrant\Models\VectorStruct;
15+
use Qdrant\Tests\Integration\AbstractIntegration;
16+
17+
class SearchVectorTest extends AbstractIntegration
18+
{
19+
/**
20+
* @throws InvalidArgumentException
21+
*/
22+
public function setUp(): void
23+
{
24+
parent::setUp();
25+
26+
$this->createCollections('sample-collection');
27+
28+
$response = $this->getCollections('sample-collection')->index()->create(
29+
(new CreateIndex('payload', [
30+
'type' => 'integer',
31+
'range' => true,
32+
'lookup' => false,
33+
'is_principal' => true
34+
])),
35+
[
36+
'wait' => 'true'
37+
]
38+
);
39+
40+
$this->assertEquals('ok', $response['status']);
41+
$this->assertEquals('completed', $response['result']['status']);
42+
43+
$response = $this->getCollections('sample-collection')->points()
44+
->upsert(
45+
PointsStruct::createFromArray(self::basicPointDataProvider()[0][0]),
46+
[
47+
'wait' => 'true'
48+
]
49+
);
50+
51+
$this->assertEquals('ok', $response['status']);
52+
$this->assertEquals('completed', $response['result']['status']);
53+
}
54+
55+
public static function basicPointDataProvider(): array
56+
{
57+
return [
58+
[
59+
[
60+
[
61+
'id' => 1,
62+
'vector' => new VectorStruct([1, 3, 400], 'image'),
63+
'payload' => [
64+
'sort' => 1,
65+
'color' => 'red'
66+
]
67+
],
68+
[
69+
'id' => 2,
70+
'vector' => new VectorStruct([1, 3, 300], 'image'),
71+
'payload' => [
72+
'sort' => 2,
73+
'color' => 'red'
74+
]
75+
],
76+
[
77+
'id' => 3,
78+
'vector' => new VectorStruct([1, 3, 300], 'image'),
79+
'payload' => [
80+
'sort' => 3,
81+
'color' => 'green'
82+
]
83+
],
84+
]
85+
]
86+
];
87+
}
88+
89+
public function testScrollWithVector(): void
90+
{
91+
$scroll = (new ScrollRequest())->setWithVector(true);
92+
$response = $this->getCollections('sample-collection')->points()->scroll($scroll);
93+
94+
$this->assertEquals('ok', $response['status']);
95+
$this->assertCount(2, $response['result']);
96+
$this->assertCount(3, $response['result']['points']);
97+
$this->assertArrayHasKey('vector', $response['result']['points'][0]);
98+
}
99+
100+
public function testScrollWithoutVector(): void
101+
{
102+
$scroll = (new ScrollRequest())->setWithPayload(false);
103+
$response = $this->getCollections('sample-collection')->points()->scroll($scroll);
104+
105+
$this->assertEquals('ok', $response['status']);
106+
$this->assertCount(2, $response['result']);
107+
$this->assertCount(3, $response['result']['points']);
108+
$this->assertArrayNotHasKey('vector', $response['result']['points'][0]);
109+
}
110+
111+
protected function tearDown(): void
112+
{
113+
parent::tearDown();
114+
$collections = new Collections($this->client);
115+
116+
$collections->setCollectionName('sample-collection')->delete();
117+
}
118+
}

0 commit comments

Comments
 (0)