-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
201 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
/** | ||
* RecommendRequest | ||
* | ||
* @since Jun 2023 | ||
* @author Greg Priday <[email protected]> | ||
*/ | ||
namespace Qdrant\Models\Request\Points; | ||
|
||
use Qdrant\Exception\InvalidArgumentException; | ||
use Qdrant\Models\Filter\Filter; | ||
use Qdrant\Models\Traits\ProtectedPropertyAccessor; | ||
|
||
class BatchRecommendRequest | ||
{ | ||
use ProtectedPropertyAccessor; | ||
|
||
/** @var RecommendRequest[] $searches */ | ||
protected array $searches = []; | ||
|
||
/** | ||
* @param RecommendRequest[] $searches | ||
*/ | ||
public function __construct(array $searches) | ||
{ | ||
foreach ($searches as $search) { | ||
$this->addSearch($search); | ||
} | ||
} | ||
|
||
public function addSearch(RecommendRequest $request): static | ||
{ | ||
$this->searches[] = $request; | ||
|
||
return $this; | ||
} | ||
|
||
public function toArray(): array | ||
{ | ||
$searches = []; | ||
|
||
foreach ($this->searches as $search) { | ||
$searches[] = $search->toArray(); | ||
} | ||
|
||
return [ | ||
'searches' => $searches | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
/** | ||
* GroupRecommendRequest | ||
* | ||
* @since Jun 2024 | ||
* @author Greg Priday <[email protected]> | ||
* @author Haydar KULEKCI <[email protected]> | ||
*/ | ||
namespace Qdrant\Models\Request\Points; | ||
|
||
|
||
class GroupRecommendRequest | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
* @since Jun 2023 | ||
* @author Greg Priday <[email protected]> | ||
*/ | ||
namespace Qdrant\Models\Request; | ||
namespace Qdrant\Models\Request\Points; | ||
|
||
use Qdrant\Exception\InvalidArgumentException; | ||
use Qdrant\Models\Filter\Filter; | ||
|
@@ -29,7 +29,7 @@ class RecommendRequest | |
const STRATEGY_BEST_SCORE = 'best_score'; | ||
|
||
protected ?string $shardKey = null; | ||
protected string $strategy = ''; | ||
protected ?string $strategy = null; | ||
protected ?Filter $filter = null; | ||
protected ?string $using = null; | ||
protected ?int $limit = null; | ||
|
@@ -109,16 +109,19 @@ public function toArray(): array | |
if ($this->filter !== null && $this->filter->toArray()) { | ||
$body['filter'] = $this->filter->toArray(); | ||
} | ||
if($this->scoreThreshold) { | ||
if($this->scoreThreshold !== null) { | ||
$body['score_threshold'] = $this->scoreThreshold; | ||
} | ||
if ($this->using) { | ||
if ($this->using !== null) { | ||
$body['using'] = $this->using; | ||
} | ||
if ($this->limit) { | ||
if ($this->limit !== null) { | ||
$body['limit'] = $this->limit; | ||
} | ||
if ($this->offset) { | ||
if ($this->strategy !== null) { | ||
$body['strategy'] = $this->strategy; | ||
} | ||
if ($this->offset !== null) { | ||
$body['offset'] = $this->offset; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,14 +4,15 @@ | |
* @author Greg Priday <[email protected]> | ||
*/ | ||
|
||
namespace Qdrant\Tests\Integration\Endpoints\Collections; | ||
namespace Integration\Endpoints\Collections\Points; | ||
|
||
use Qdrant\Endpoints\Collections; | ||
use Qdrant\Exception\InvalidArgumentException; | ||
use Qdrant\Models\Filter\Condition\MatchString; | ||
use Qdrant\Models\Filter\Filter; | ||
use Qdrant\Models\PointsStruct; | ||
use Qdrant\Models\Request\RecommendRequest; | ||
use Qdrant\Models\Request\Points\BatchRecommendRequest; | ||
use Qdrant\Models\Request\Points\RecommendRequest; | ||
use Qdrant\Models\VectorStruct; | ||
use Qdrant\Tests\Integration\AbstractIntegration; | ||
|
||
|
@@ -47,6 +48,20 @@ public static function basicPointDataProvider(): array | |
'image' => 'sample image' | ||
] | ||
], | ||
[ | ||
'id' => 3, | ||
'vector' => new VectorStruct([1, 3, 200], 'image'), | ||
'payload' => [ | ||
'image' => 'sample image' | ||
] | ||
], | ||
[ | ||
'id' => 4, | ||
'vector' => new VectorStruct([1, 3, 100], 'image'), | ||
'payload' => [ | ||
'image' => 'sample image' | ||
] | ||
], | ||
] | ||
] | ||
]; | ||
|
@@ -74,7 +89,7 @@ public function testRecommendPoint(array $positive, array $negative): void | |
) | ||
); | ||
|
||
$response = $this->getCollections('sample-collection')->points()->recommend($recommendRequest); | ||
$response = $this->getCollections('sample-collection')->points()->recommend()->recommend($recommendRequest); | ||
|
||
$this->assertEquals('ok', $response['status']); | ||
} | ||
|
@@ -104,11 +119,13 @@ public function testRecommendWithThreshold(): void | |
// Perform recommend without score threshold | ||
$responseWithoutThreshold = $this->getCollections('sample-collection') | ||
->points() | ||
->recommend() | ||
->recommend($recommendRequestWithoutThreshold); | ||
|
||
// Perform recommend with score threshold | ||
$responseWithThreshold = $this->getCollections('sample-collection') | ||
->points() | ||
->recommend() | ||
->recommend($recommendRequestWithThreshold); | ||
|
||
// Check that we got a response in both cases | ||
|
@@ -123,6 +140,35 @@ public function testRecommendWithThreshold(): void | |
); | ||
} | ||
|
||
public static function batchRecommendQueryProvider(): array | ||
{ | ||
|
||
return [ | ||
[ | ||
[ | ||
(new RecommendRequest([1], [2]))->setLimit(3)->setUsing('image'), | ||
(new RecommendRequest([1, 2], []))->setLimit(3)->setUsing('image'), | ||
(new RecommendRequest([1], [2, 3]))->setLimit(3)->setUsing('image'), | ||
] | ||
] | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider batchRecommendQueryProvider | ||
*/ | ||
public function testBatchRecommendPoint(array $batch): void | ||
{ | ||
$recommendRequest = new BatchRecommendRequest($batch); | ||
|
||
$response = $this->getCollections('sample-collection') | ||
->points() | ||
->recommend() | ||
->batch($recommendRequest); | ||
|
||
$this->assertEquals('ok', $response['status']); | ||
} | ||
|
||
|
||
protected function tearDown(): void | ||
{ | ||
|
37 changes: 37 additions & 0 deletions
37
tests/Unit/Models/Request/Points/BatchRecommendRequestTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
/** | ||
* @since Mar 2023 | ||
* @author Haydar KULEKCI <[email protected]> | ||
*/ | ||
|
||
namespace Qdrant\Tests\Unit\Models\Request\Points; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Qdrant\Models\Filter\Condition\MatchExcept; | ||
use Qdrant\Models\Filter\Filter; | ||
use Qdrant\Models\Request\Points\BatchRecommendRequest; | ||
use Qdrant\Models\Request\Points\RecommendRequest; | ||
|
||
class BatchRecommendRequestTest extends TestCase | ||
{ | ||
public function testBasicRecommendRequest(): void | ||
{ | ||
$request = new BatchRecommendRequest([ | ||
new RecommendRequest([100, 101], [110]), | ||
new RecommendRequest([101, 102], [112]), | ||
]); | ||
|
||
$this->assertEquals([ | ||
'searches' =>[ | ||
[ | ||
'positive' => [100, 101], | ||
'negative' => [110], | ||
], | ||
[ | ||
'positive' => [101, 102], | ||
'negative' => [112], | ||
] | ||
] | ||
], $request->toArray()); | ||
} | ||
} |
Oops, something went wrong.