Skip to content

Commit 8502e30

Browse files
committed
retry failed QDrant queries
hosted qdrant seems to be a bit unreliable. retrying might help.
1 parent c2f5508 commit 8502e30

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

Storage/QdrantStorage.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function __construct(array $config)
4747
* @return mixed
4848
* @throws \Exception
4949
*/
50-
protected function runQuery($endpoint, mixed $data, $method = 'POST')
50+
protected function runQuery($endpoint, mixed $data, $method = 'POST', $retry = 0)
5151
{
5252
$endpoint = trim($endpoint, '/');
5353
$url = $this->baseurl . '/' . $endpoint . '?wait=true';
@@ -62,6 +62,11 @@ protected function runQuery($endpoint, mixed $data, $method = 'POST')
6262
$response = $this->http->resp_body;
6363

6464
if (!$response) {
65+
if($retry < 3) {
66+
sleep(1 + $retry);
67+
return $this->runQuery($endpoint, $data, $method, $retry + 1);
68+
}
69+
6570
throw new \Exception(
6671
'Qdrant API returned no response. ' . $this->http->error . ' Status: ' . $this->http->status
6772
);
@@ -70,6 +75,11 @@ protected function runQuery($endpoint, mixed $data, $method = 'POST')
7075
try {
7176
$result = json_decode((string)$response, true, 512, JSON_THROW_ON_ERROR);
7277
} catch (\Exception $e) {
78+
if($retry < 3) {
79+
sleep(1 + $retry);
80+
return $this->runQuery($endpoint, $data, $method, $retry + 1);
81+
}
82+
7383
throw new \Exception('Qdrant API returned invalid JSON. ' . $response, 0, $e);
7484
}
7585

0 commit comments

Comments
 (0)