Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix with_payload and with_vector params. #59

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Models/Request/ScrollRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ public function toArray(): array
if ($this->offset) {
$body['offset'] = $this->offset;
}
if ($this->withVector) {
if ($this->withVector !== null) {
$body['with_vector'] = $this->withVector;
}
if ($this->withPayload) {
if ($this->withPayload !== null) {
$body['with_payload'] = $this->withPayload;
}
if ($this->orderBy) {
Expand Down
6 changes: 3 additions & 3 deletions src/Models/Request/SearchRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,14 @@ public function toArray(): array
if ($this->offset) {
$body['offset'] = $this->offset;
}
if ($this->withVector) {
if ($this->withVector !== null) {
$body['with_vector'] = $this->withVector;
}
if ($this->withPayload) {
if ($this->withPayload !== null) {
$body['with_payload'] = $this->withPayload;
}

return $body;
}

}
}
118 changes: 118 additions & 0 deletions tests/Integration/Endpoints/Collections/SearchPayloadTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<?php
/**
* @since Mar 2023
* @author Haydar KULEKCI <[email protected]>
*/

namespace Qdrant\Tests\Integration\Endpoints\Collections;

use Qdrant\Endpoints\Collections;
use Qdrant\Exception\InvalidArgumentException;
use Qdrant\Models\PointsStruct;
use Qdrant\Models\Request\CreateIndex;
use Qdrant\Models\Request\ScrollRequest;
use Qdrant\Models\VectorStruct;
use Qdrant\Tests\Integration\AbstractIntegration;

class SearchPayloadTest extends AbstractIntegration
{
/**
* @throws InvalidArgumentException
*/
public function setUp(): void
{
parent::setUp();

$this->createCollections('sample-collection');

$response = $this->getCollections('sample-collection')->index()->create(
(new CreateIndex('payload', [
'type' => 'integer',
'range' => true,
'lookup' => false,
'is_principal' => true
])),
[
'wait' => 'true'
]
);

$this->assertEquals('ok', $response['status']);
$this->assertEquals('completed', $response['result']['status']);

$response = $this->getCollections('sample-collection')->points()
->upsert(
PointsStruct::createFromArray(self::basicPointDataProvider()[0][0]),
[
'wait' => 'true'
]
);

$this->assertEquals('ok', $response['status']);
$this->assertEquals('completed', $response['result']['status']);
}

public static function basicPointDataProvider(): array
{
return [
[
[
[
'id' => 1,
'vector' => new VectorStruct([1, 3, 400], 'image'),
'payload' => [
'sort' => 1,
'color' => 'red'
]
],
[
'id' => 2,
'vector' => new VectorStruct([1, 3, 300], 'image'),
'payload' => [
'sort' => 2,
'color' => 'red'
]
],
[
'id' => 3,
'vector' => new VectorStruct([1, 3, 300], 'image'),
'payload' => [
'sort' => 3,
'color' => 'green'
]
],
]
]
];
}

public function testScrollWithPayload(): void
{
$scroll = (new ScrollRequest())->setWithPayload(true);
$response = $this->getCollections('sample-collection')->points()->scroll($scroll);

$this->assertEquals('ok', $response['status']);
$this->assertCount(2, $response['result']);
$this->assertCount(3, $response['result']['points']);
$this->assertArrayHasKey('payload', $response['result']['points'][0]);
}

public function testScrollWithoutPayload(): void
{
$scroll = (new ScrollRequest())->setWithPayload(false);
$response = $this->getCollections('sample-collection')->points()->scroll($scroll);

$this->assertEquals('ok', $response['status']);
$this->assertCount(2, $response['result']);
$this->assertCount(3, $response['result']['points']);
$this->assertArrayNotHasKey('payload', $response['result']['points'][0]);
}

protected function tearDown(): void
{
parent::tearDown();
$collections = new Collections($this->client);

$collections->setCollectionName('sample-collection')->delete();
}
}
118 changes: 118 additions & 0 deletions tests/Integration/Endpoints/Collections/SearchVectorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<?php
/**
* @since Mar 2023
* @author Haydar KULEKCI <[email protected]>
*/

namespace Qdrant\Tests\Integration\Endpoints\Collections;

use Qdrant\Endpoints\Collections;
use Qdrant\Exception\InvalidArgumentException;
use Qdrant\Models\PointsStruct;
use Qdrant\Models\Request\CreateIndex;
use Qdrant\Models\Request\ScrollRequest;
use Qdrant\Models\VectorStruct;
use Qdrant\Tests\Integration\AbstractIntegration;

class SearchVectorTest extends AbstractIntegration
{
/**
* @throws InvalidArgumentException
*/
public function setUp(): void
{
parent::setUp();

$this->createCollections('sample-collection');

$response = $this->getCollections('sample-collection')->index()->create(
(new CreateIndex('payload', [
'type' => 'integer',
'range' => true,
'lookup' => false,
'is_principal' => true
])),
[
'wait' => 'true'
]
);

$this->assertEquals('ok', $response['status']);
$this->assertEquals('completed', $response['result']['status']);

$response = $this->getCollections('sample-collection')->points()
->upsert(
PointsStruct::createFromArray(self::basicPointDataProvider()[0][0]),
[
'wait' => 'true'
]
);

$this->assertEquals('ok', $response['status']);
$this->assertEquals('completed', $response['result']['status']);
}

public static function basicPointDataProvider(): array
{
return [
[
[
[
'id' => 1,
'vector' => new VectorStruct([1, 3, 400], 'image'),
'payload' => [
'sort' => 1,
'color' => 'red'
]
],
[
'id' => 2,
'vector' => new VectorStruct([1, 3, 300], 'image'),
'payload' => [
'sort' => 2,
'color' => 'red'
]
],
[
'id' => 3,
'vector' => new VectorStruct([1, 3, 300], 'image'),
'payload' => [
'sort' => 3,
'color' => 'green'
]
],
]
]
];
}

public function testScrollWithVector(): void
{
$scroll = (new ScrollRequest())->setWithVector(true);
$response = $this->getCollections('sample-collection')->points()->scroll($scroll);

$this->assertEquals('ok', $response['status']);
$this->assertCount(2, $response['result']);
$this->assertCount(3, $response['result']['points']);
$this->assertArrayHasKey('vector', $response['result']['points'][0]);
}

public function testScrollWithoutVector(): void
{
$scroll = (new ScrollRequest())->setWithPayload(false);
$response = $this->getCollections('sample-collection')->points()->scroll($scroll);

$this->assertEquals('ok', $response['status']);
$this->assertCount(2, $response['result']);
$this->assertCount(3, $response['result']['points']);
$this->assertArrayNotHasKey('vector', $response['result']['points'][0]);
}

protected function tearDown(): void
{
parent::tearDown();
$collections = new Collections($this->client);

$collections->setCollectionName('sample-collection')->delete();
}
}
Loading