rm CachedRetriever.php

add second shopsearch
This commit is contained in:
team 1
2026-04-19 14:20:23 +02:00
parent a71426c300
commit 4d944a5113
9 changed files with 1075 additions and 129 deletions

View File

@@ -1,50 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Knowledge\Retrieval;
use Psr\Cache\CacheItemPoolInterface;
use Psr\Cache\InvalidArgumentException;
final readonly class CachedRetriever implements RetrieverInterface
{
public function __construct(
private RetrieverInterface $inner,
private CacheItemPoolInterface $cache,
private int $ttlSeconds = 300,
) {
}
/**
* @return string[]
* @throws InvalidArgumentException
*/
public function retrieve(string $prompt): array
{
$key = $this->buildCacheKey($prompt);
$item = $this->cache->getItem($key);
if ($item->isHit()) {
$cached = $item->get();
return is_array($cached) ? $cached : [];
}
$result = $this->inner->retrieve($prompt);
$item->set($result);
$item->expiresAfter($this->ttlSeconds);
$this->cache->save($item);
return $result;
}
private function buildCacheKey(string $prompt): string
{
$normalized = mb_strtolower(trim($prompt));
$normalized = preg_replace('/\s+/u', ' ', $normalized) ?? $normalized;
return 'rag_retrieval_' . sha1($normalized);
}
}