harden semantic match sby tags

This commit is contained in:
team2
2026-02-28 19:04:01 +01:00
parent ff01919b30
commit 1b5cff1c53
4 changed files with 134 additions and 56 deletions

View File

@@ -4,17 +4,15 @@ declare(strict_types=1);
namespace App\Knowledge\Retrieval;
use App\Catalog\EntityCatalogService;
use App\Entity\ModelGenerationConfig;
use App\Intent\CatalogIntentLite;
use App\Intent\IntentLite;
use App\Intent\SalesIntentLite;
use App\Knowledge\QueryCleaner;
use App\Repository\ModelGenerationConfigRepository;
use App\Routing\IntentRouteResolver;
use App\Tag\TagRoutingService;
use App\Vector\VectorSearchClient;
use App\Catalog\EntityCatalogService;
use App\Knowledge\Retrieval\NdjsonChunkLookup;
use App\Knowledge\Retrieval\RetrieverInterface;
final class NdjsonHybridRetriever implements RetrieverInterface
{
@@ -38,13 +36,13 @@ final class NdjsonHybridRetriever implements RetrieverInterface
private readonly IntentLite $intentLite,
private readonly SalesIntentLite $salesIntentLite,
private readonly CatalogIntentLite $catalogIntent,
private readonly IntentRouteResolver $routeResolver,
private readonly EntityCatalogService $entityCatalogService
)
{
) {
}
// =========================================================
// PRODUCTION (UNVERÄNDERTES VERHALTEN)
// PRODUCTION
// =========================================================
public function retrieve(string $prompt): array
@@ -60,17 +58,32 @@ final class NdjsonHybridRetriever implements RetrieverInterface
public function retrieveInternal(string $prompt, ModelGenerationConfig $config): array
{
// 🔵 ENTITY CATALOG EARLY EXIT (jetzt auch im Admin-Test aktiv)
$entityTerm = $this->catalogIntent->detect($prompt);
// ------------------------------------------------------------
// ROUTING-MATRIX (minimal, ohne Core zu zerlegen)
// ------------------------------------------------------------
if ($entityTerm !== null) {
$catalogBlock = $this->entityCatalogService->listByTerm($entityTerm);
// 1) Entity (semantisch über Tag-Vektor)
$entityLabel = $this->catalogIntent->detect($prompt);
// 2) Intent (regelbasiert)
$intent = (string)($this->salesIntentLite->detect($prompt)['intent'] ?? SalesIntentLite::DISCOVERY);
// 3) Route bestimmen (Intent + Entity)
$route = $this->routeResolver->resolve($intent, $entityLabel);
// 4) Early Exit nur für catalog_list
if ($route === IntentRouteResolver::ROUTE_CATALOG_LIST && $entityLabel !== null) {
$catalogBlock = $this->entityCatalogService->listByTerm($entityLabel);
if ($catalogBlock !== null) {
return [$catalogBlock];
}
}
// ------------------------------------------------------------
// NORMALER CORE
// ------------------------------------------------------------
$core = $this->runCore($prompt, $config, false);
if ($core['ranked_chunk_ids'] === [] || $core['rows'] === []) {
@@ -95,7 +108,7 @@ final class NdjsonHybridRetriever implements RetrieverInterface
}
// =========================================================
// DEBUG (NEU, ABER NICHT IM PRODUKTIONS-PFAD)
// DEBUG (unverändert, kein Early-Exit damit Debug immer Core zeigt)
// =========================================================
/**