Harden vision vector search and embedding jobs.
Add point search, circuit-breaking, and safer gateway limits so artwork similarity lookups fail closed instead of hanging the request path.
This commit is contained in:
@@ -26,14 +26,19 @@ final class ArtworkEmbeddingClient
|
||||
$retries = (int) config('recommendations.embedding.retries', 1);
|
||||
$delay = (int) config('recommendations.embedding.retry_delay_ms', 200);
|
||||
|
||||
$apiKey = trim(
|
||||
(string) config('vision.clip.api_key', '')
|
||||
);
|
||||
|
||||
$response = Http::acceptJson()
|
||||
->withHeaders([
|
||||
'X-API-Key' => $apiKey,
|
||||
])
|
||||
->connectTimeout(max(1, $connectTimeout))
|
||||
->timeout(max(1, $timeout))
|
||||
->retry(max(0, $retries), max(0, $delay), throw: false)
|
||||
->post($url, [
|
||||
'image_url' => $imageUrl,
|
||||
'artwork_id' => $artworkId,
|
||||
'hash' => $sourceHash,
|
||||
'url' => $imageUrl,
|
||||
]);
|
||||
|
||||
if (! $response->ok()) {
|
||||
@@ -53,6 +58,8 @@ final class ArtworkEmbeddingClient
|
||||
|
||||
if (is_array($json) && $this->isNumericVector($json)) {
|
||||
$candidate = $json;
|
||||
} elseif (is_array($json) && isset($json['vector']) && is_array($json['vector'])) {
|
||||
$candidate = $json['vector'];
|
||||
} elseif (is_array($json) && isset($json['embedding']) && is_array($json['embedding'])) {
|
||||
$candidate = $json['embedding'];
|
||||
} elseif (is_array($json) && isset($json['data']['embedding']) && is_array($json['data']['embedding'])) {
|
||||
|
||||
Reference in New Issue
Block a user