Skip to content

Commit 5e715fa

Browse files
committed
Add async option to qdrant store
1 parent fc32bc6 commit 5e715fa

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

src/store/src/Bridge/Qdrant/Store.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public function __construct(
3333
private readonly string $collectionName,
3434
private readonly int $embeddingsDimension = 1536,
3535
private readonly string $embeddingsDistance = 'Cosine',
36+
private readonly bool $async = true,
3637
) {
3738
}
3839

@@ -60,7 +61,8 @@ public function add(VectorDocument ...$documents): void
6061
{
6162
$this->request('PUT', \sprintf('collections/%s/points', $this->collectionName), [
6263
'points' => array_map($this->convertToIndexableArray(...), $documents),
63-
]);
64+
],
65+
!$this->async ? ['wait' => 'true'] : []);
6466
}
6567

6668
/**
@@ -105,14 +107,15 @@ public function drop(): void
105107
*
106108
* @return array<string, mixed>
107109
*/
108-
private function request(string $method, string $endpoint, array $payload = []): array
110+
private function request(string $method, string $endpoint, array $payload = [], array $queryParameters = []): array
109111
{
110112
$url = \sprintf('%s/%s', $this->endpointUrl, $endpoint);
111113

112114
$response = $this->httpClient->request($method, $url, [
113115
'headers' => [
114116
'api-key' => $this->apiKey,
115117
],
118+
'query' => $queryParameters,
116119
'json' => $payload,
117120
]);
118121

src/store/tests/Bridge/Qdrant/StoreTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,39 @@ public function testStoreCanAdd()
172172
$this->assertSame(1, $httpClient->getRequestsCount());
173173
}
174174

175+
public function testStoreCanAddSynchronously()
176+
{
177+
$document = new VectorDocument(Uuid::v4(), new Vector([0.1, 0.2, 0.3]));
178+
179+
$httpClient = new MockHttpClient(static function (string $method, string $url, array $options) use ($document): JsonMockResponse {
180+
self::assertArrayHasKey('wait', $options['query']);
181+
self::assertEquals('true', $options['query']['wait']);
182+
183+
return new JsonMockResponse([
184+
'time' => 0.002,
185+
'status' => 'ok',
186+
'result' => [
187+
'points' => [
188+
[
189+
'id' => (string) $document->id,
190+
'payload' => (array) $document->metadata,
191+
'vector' => $document->vector->getData(),
192+
]
193+
],
194+
],
195+
], [
196+
'http_code' => 200,
197+
]);
198+
}, 'http://127.0.0.1:6333');
199+
200+
$store = new Store($httpClient, 'http://127.0.0.1:6333', 'test', 'test', async: false);
201+
202+
$store->add($document);
203+
204+
$this->assertSame(1, $httpClient->getRequestsCount());
205+
$this->assertSame(1, $httpClient->getRequestsCount());
206+
}
207+
175208
public function testStoreCannotQueryOnInvalidResponse()
176209
{
177210
$httpClient = new MockHttpClient([

0 commit comments

Comments
 (0)