-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
recommendation endpoint request improvement and filter min_should implementation. GeoPolygon request model implementation improved recommendation endpoint improved tests
- Loading branch information
Showing
12 changed files
with
487 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
/** | ||
* Payload | ||
* | ||
* @since Mar 2023 | ||
* @author Haydar KULEKCI <haydarkulekci@gmail.com> | ||
*/ | ||
|
||
namespace Qdrant\Endpoints\Collections\Points; | ||
|
||
use Qdrant\Endpoints\AbstractEndpoint; | ||
use Qdrant\Exception\InvalidArgumentException; | ||
use Qdrant\Models\Request\Points\BatchRecommendRequest; | ||
use Qdrant\Models\Request\Points\GroupRecommendRequest; | ||
use Qdrant\Models\Request\Points\RecommendRequest; | ||
use Qdrant\Response; | ||
|
||
class Recommend extends AbstractEndpoint | ||
{ | ||
/** | ||
* Retrieves points that are closer to stored positive examples and further from negative examples. | ||
* | ||
* @throws InvalidArgumentException | ||
*/ | ||
public function recommend(RecommendRequest $request, array $queryParams = []): Response | ||
{ | ||
return $this->client->execute( | ||
$this->createRequest( | ||
'POST', | ||
'/collections/' . $this->getCollectionName() . '/points/recommend' . $this->queryBuild($queryParams), | ||
$request->toArray() | ||
) | ||
); | ||
} | ||
|
||
/** | ||
* Retrieves points in batches that are closer to stored positive examples and further from negative examples. | ||
* | ||
* @param BatchRecommendRequest $request | ||
* @param array $queryParams | ||
* @return Response | ||
*/ | ||
public function batch(BatchRecommendRequest $request, array $queryParams = []): Response | ||
{ | ||
|
||
return $this->client->execute( | ||
$this->createRequest( | ||
'POST', | ||
'/collections/' . $this->getCollectionName() . '/points/recommend/batch' . $this->queryBuild($queryParams), | ||
$request->toArray() | ||
) | ||
); | ||
} | ||
|
||
/** | ||
* @throws InvalidArgumentException | ||
*/ | ||
public function groups(GroupRecommendRequest $request, array $queryParams = []): Response | ||
{ | ||
return $this->client->execute( | ||
$this->createRequest( | ||
'POST', | ||
'/collections/' . $this->getCollectionName() . '/points/recommend/groups' . $this->queryBuild($queryParams), | ||
$request->toArray() | ||
) | ||
); | ||
} | ||
} |
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,42 @@ | ||
<?php | ||
/** | ||
* @since May 2023 | ||
* @author Haydar KULEKCI <haydarkulekci@gmail.com> | ||
*/ | ||
|
||
namespace Qdrant\Models\Filter\Condition; | ||
|
||
use Qdrant\Exception\InvalidArgumentException; | ||
use Qdrant\Domain\Assert; | ||
|
||
class GeoPolygon extends AbstractCondition implements ConditionInterface | ||
{ | ||
public function __construct(string $key, protected array $exterior, protected ?array $interiors = null) | ||
{ | ||
parent::__construct($key); | ||
|
||
if (empty($this->exterior)) { | ||
throw new InvalidArgumentException('Exteriors required!'); | ||
} | ||
|
||
foreach ($this->exterior as $point) { | ||
Assert::keysExists($point, ['lat', 'lon'], 'Each point of polygon needs lat and lon parameters'); | ||
} | ||
if ($interiors) { | ||
foreach ($this->interiors as $point) { | ||
Assert::keysExists($point, ['lat', 'lon'], 'Each point of polygon needs lat and lon parameters'); | ||
} | ||
} | ||
} | ||
|
||
public function toArray(): array | ||
{ | ||
return [ | ||
'key' => $this->key, | ||
'geo_polygon' => [ | ||
'exterior' => $this->exterior, | ||
'interiors' => $this->interiors ?? [] | ||
] | ||
]; | ||
} | ||
} |
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 <greg@siteorigin.com> | ||
*/ | ||
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 <greg@siteorigin.com> | ||
* @author Haydar KULEKCI <haydarkulekci@gmail.com> | ||
*/ | ||
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
Oops, something went wrong.