Skip to content

Commit 0a92196

Browse files
authored
Merge pull request hkulekci#60 from julien-jourde/fix-recommended-request-missing-properties
Add `withPayload` and `withVector` properties on `RecommendRequest` class
2 parents 497bcdd + 70ed69d commit 0a92196

2 files changed

Lines changed: 68 additions & 1 deletion

File tree

src/Models/Request/Points/RecommendRequest.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ class RecommendRequest
3535
protected ?int $limit = null;
3636
protected ?int $offset = null;
3737
protected ?float $scoreThreshold = null;
38+
protected bool|array|null $withVector = null;
39+
protected bool|array|null $withPayload = null;
3840

3941
public function __construct(protected array $positive, protected array $negative = [])
4042
{
@@ -96,6 +98,20 @@ public function setOffset(int $offset): static
9698
return $this;
9799
}
98100

101+
public function setWithPayload($withPayload): static
102+
{
103+
$this->withPayload = $withPayload;
104+
105+
return $this;
106+
}
107+
108+
public function setWithVector($withVector): static
109+
{
110+
$this->withVector = $withVector;
111+
112+
return $this;
113+
}
114+
99115
public function toArray(): array
100116
{
101117
$body = [
@@ -124,7 +140,13 @@ public function toArray(): array
124140
if ($this->offset !== null) {
125141
$body['offset'] = $this->offset;
126142
}
143+
if ($this->withVector !== null) {
144+
$body['with_vector'] = $this->withVector;
145+
}
146+
if ($this->withPayload !== null) {
147+
$body['with_payload'] = $this->withPayload;
148+
}
127149

128150
return $body;
129151
}
130-
}
152+
}

tests/Integration/Endpoints/Collections/Points/RecommendTest.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Qdrant\Models\Request\Points\RecommendRequest;
1616
use Qdrant\Models\VectorStruct;
1717
use Qdrant\Tests\Integration\AbstractIntegration;
18+
use function var_dump;
1819

1920
class RecommendTest extends AbstractIntegration
2021
{
@@ -94,6 +95,50 @@ public function testRecommendPoint(array $positive, array $negative): void
9495
$this->assertEquals('ok', $response['status']);
9596
}
9697

98+
/**
99+
* @dataProvider recommendQueryProvider
100+
*/
101+
public function testRecommendPointWithPayload(array $positive, array $negative): void
102+
{
103+
$recommendRequest = (new RecommendRequest($positive, $negative))
104+
->setLimit(3)
105+
->setUsing('image')
106+
->setFilter(
107+
(new Filter())->addMust(
108+
new MatchString('image', 'sample image')
109+
)
110+
)
111+
->setWithPayload(true);
112+
113+
$response = $this->getCollections('sample-collection')->points()->recommend()->recommend($recommendRequest);
114+
115+
$this->assertEquals('ok', $response['status']);
116+
$this->assertCount(2, $response['result']);
117+
$this->assertArrayHasKey('payload', $response['result'][0]);
118+
}
119+
120+
/**
121+
* @dataProvider recommendQueryProvider
122+
*/
123+
public function testRecommendPointWithVector(array $positive, array $negative): void
124+
{
125+
$recommendRequest = (new RecommendRequest($positive, $negative))
126+
->setLimit(3)
127+
->setUsing('image')
128+
->setFilter(
129+
(new Filter())->addMust(
130+
new MatchString('image', 'sample image')
131+
)
132+
)
133+
->setWithVector(true);
134+
135+
$response = $this->getCollections('sample-collection')->points()->recommend()->recommend($recommendRequest);
136+
137+
$this->assertEquals('ok', $response['status']);
138+
$this->assertCount(2, $response['result']);
139+
$this->assertArrayHasKey('vector', $response['result'][0]);
140+
}
141+
97142
public function testRecommendWithThreshold(): void
98143
{
99144
// Upsert points

0 commit comments

Comments
 (0)