first update to external config values

This commit is contained in:
team 1
2026-04-24 13:13:56 +02:00
parent 868f9a8857
commit 26ec0afc5c
11 changed files with 292 additions and 187 deletions

View File

@@ -15,41 +15,16 @@ final class TagRoutingService
/**
* Number of raw tag hits requested from the vector service.
*/
private const DEFAULT_TOPK = 8;
/**
* Hard minimum confidence required to activate tag-based document routing.
*
* This intentionally aligns with the tag vector client gate to avoid
* misleading secondary thresholds in this class.
*/
private const MIN_BEST_SCORE = 0.72;
/**
* Only keep tag hits that stay reasonably close to the best hit.
* This reduces semantic spillover into weakly related document spaces.
*/
private const MAX_SCORE_DROP_FROM_BEST = 0.08;
/**
* Maximum number of tag hits that may influence routing.
*/
private const MAX_ROUTING_TAGS = 5;
/**
* Maximum number of candidate documents passed into scoped chunk search.
*/
private const MAX_CANDIDATE_DOCS = 80;
/**
* Small bonus for documents matched by multiple routed tags.
*/
private const MULTI_TAG_BONUS_PER_EXTRA_TAG = 0.05;
private const MAX_MULTI_TAG_BONUS = 0.15;
public function __construct(
private readonly TagVectorSearchClient $tagSearch,
private readonly EntityManagerInterface $em,
private readonly int $defaultTopK = 8,
private readonly float $minBestScore = 0.72,
private readonly float $maxScoreDropFromBest = 0.08,
private readonly int $maxRoutingTags = 5,
private readonly int $maxCandidateDocs = 80,
private readonly float $multiTagBonusPerExtraTag = 0.05,
private readonly float $maxMultiTagBonus = 0.15,
) {
}
@@ -71,7 +46,7 @@ final class TagRoutingService
}
$hits = $this->filterRoutingHits(
$this->tagSearch->search($query, self::DEFAULT_TOPK)
$this->tagSearch->search($query, $this->defaultTopK)
);
if ($hits === []) {
@@ -159,8 +134,8 @@ final class TagRoutingService
if ($matchedTagCount > 1) {
$documentScores[$documentId] += min(
self::MAX_MULTI_TAG_BONUS,
($matchedTagCount - 1) * self::MULTI_TAG_BONUS_PER_EXTRA_TAG
$this->maxMultiTagBonus,
($matchedTagCount - 1) * $this->multiTagBonusPerExtraTag
);
}
}
@@ -170,7 +145,7 @@ final class TagRoutingService
return array_slice(
array_keys($documentScores),
0,
self::MAX_CANDIDATE_DOCS
$this->maxCandidateDocs
);
}
@@ -196,13 +171,13 @@ final class TagRoutingService
$bestScore = (float) ($hits[0]['score'] ?? 0.0);
if ($bestScore < self::MIN_BEST_SCORE) {
if ($bestScore < $this->minBestScore) {
return [];
}
$minimumAcceptedScore = max(
self::MIN_BEST_SCORE,
$bestScore - self::MAX_SCORE_DROP_FROM_BEST
$this->minBestScore,
$bestScore - $this->maxScoreDropFromBest
);
$filtered = [];
@@ -230,7 +205,7 @@ final class TagRoutingService
'tag_type' => $tagType,
];
if (count($filtered) >= self::MAX_ROUTING_TAGS) {
if (count($filtered) >= $this->maxRoutingTags) {
break;
}
}