withOptions(['verify' => (app()->environment() == 'local') ? false : true])->timeout(800) ->get( 'hhttps://worker-embedding-mag.prime-42b.workers.dev', [ 'query' => $embedding_query, ] ); if (! $response->successful()) { throw new Exception('Embedding response failed, API error'); } $embedding_response = json_decode($response->body(), true); try { return new Vector($embedding_response['response']['data'][0]); } catch (Exception $e) { throw new Exception('Embedding response failed, null response'); } } catch (Exception $e) { $currentAttempt++; if ($currentAttempt >= $maxRetries) { // we can throw exception here } // Optional: Add sleep for a few seconds if you want to delay the next attempt // sleep(1); } } } }