Frag das Portal durchsucht alles, neue Demo-Inhalte (0.66.0)
All checks were successful
CI / PHP 8.3 / mariadb:10.6 (pull_request) Has been skipped
CI / PHP 8.4 / mariadb:10.6 (pull_request) Has been skipped
CI / PHP 8.3 / mariadb:11.4 (pull_request) Has been skipped
CI / PHP 8.4 / mariadb:11.4 (pull_request) Has been skipped
CI / PHP 8.3 / mysql:8.0 (pull_request) Has been skipped
CI / PHP 8.4 / mysql:8.0 (pull_request) Has been skipped
CI / PHP 8.3 / mysql:8.4 (pull_request) Has been skipped
CI / PHP 8.4 / mysql:8.4 (pull_request) Has been skipped
CI / Browser-Tests (pull_request) Successful in 8m33s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 9m8s
CI / PHP 8.3 / mysql:8.4-1 (pull_request) Successful in 17m55s
CI / Build-Artefakte aktuell (pull_request) Successful in 9m50s
All checks were successful
CI / PHP 8.3 / mariadb:10.6 (pull_request) Has been skipped
CI / PHP 8.4 / mariadb:10.6 (pull_request) Has been skipped
CI / PHP 8.3 / mariadb:11.4 (pull_request) Has been skipped
CI / PHP 8.4 / mariadb:11.4 (pull_request) Has been skipped
CI / PHP 8.3 / mysql:8.0 (pull_request) Has been skipped
CI / PHP 8.4 / mysql:8.0 (pull_request) Has been skipped
CI / PHP 8.3 / mysql:8.4 (pull_request) Has been skipped
CI / PHP 8.4 / mysql:8.4 (pull_request) Has been skipped
CI / Browser-Tests (pull_request) Successful in 8m33s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 9m8s
CI / PHP 8.3 / mysql:8.4-1 (pull_request) Successful in 17m55s
CI / Build-Artefakte aktuell (pull_request) Successful in 9m50s
- Wissensquellen: Termine, Downloads, Formulare, Stellen, Ideen, Umfragen, Personen, eigene IT-Tickets/Geräte (OpenNIT, je Anfrage zwischengespeichert) - Ranking mit IDF, Abfrage je Begriff, Abkürzungen als ganze Wörter, LIKE unabhängig von Groß-/Kleinschreibung (JSON-Spalten), Datum im Prompt - Demo-Inhalte für einen Träger der Eingliederungshilfe (DemoData), mehrseitige PDFs, vorhandene Inhalte je Bereich entfernen Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
1656cd8090
commit
3addc09c38
165 changed files with 2258 additions and 814 deletions
|
|
@ -85,9 +85,11 @@ class AskPortal
|
|||
}
|
||||
|
||||
/**
|
||||
* Treffer nach Begriffen gewichten: im Titel dreifach, im Text je Begriff höchstens
|
||||
* fünf Fundstellen. Wer nur einen von mehreren Begriffen enthält, fällt hinter die zurück,
|
||||
* die mehrere enthalten – und ganz heraus, wenn es bessere gibt.
|
||||
* Treffer nach Begriffen gewichten: im Titel dreifach, im Text je Begriff höchstens fünf
|
||||
* Fundstellen. Seltene Begriffe zählen mehr als häufige (wie bei Suchmaschinen): Bei
|
||||
* „Sammelplatz bei Feuer in der Werkstatt“ entscheidet „Sammelplatz“, nicht „Werkstatt“.
|
||||
* Wer nur einen von mehreren Begriffen enthält, fällt hinter die zurück, die mehrere
|
||||
* enthalten – und ganz heraus, wenn es bessere gibt.
|
||||
*
|
||||
* @param list<array<string, mixed>> $documents
|
||||
* @param list<string> $terms
|
||||
|
|
@ -95,29 +97,44 @@ class AskPortal
|
|||
*/
|
||||
private function rank(array $documents, array $terms): array
|
||||
{
|
||||
if ($terms === []) {
|
||||
if ($terms === [] || $documents === []) {
|
||||
return [];
|
||||
}
|
||||
|
||||
foreach ($documents as &$doc) {
|
||||
$hits = [];
|
||||
$df = array_fill_keys($terms, 0);
|
||||
|
||||
foreach ($documents as $i => $doc) {
|
||||
$title = mb_strtolower($doc['title']);
|
||||
$text = mb_strtolower($doc['text']);
|
||||
$distinct = 0;
|
||||
$score = 0;
|
||||
|
||||
foreach ($terms as $term) {
|
||||
$inTitle = mb_substr_count($title, $term);
|
||||
$inText = min(5, mb_substr_count($text, $term));
|
||||
$hits[$i][$term] = [Knowledge::occurrences($title, $term), min(5, Knowledge::occurrences($text, $term))];
|
||||
|
||||
if (array_sum($hits[$i][$term]) > 0) {
|
||||
$df[$term]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$count = count($documents);
|
||||
$weight = array_map(fn (int $n) => 1 + log(($count + 1) / ($n + 1)), $df);
|
||||
|
||||
foreach ($documents as $i => &$doc) {
|
||||
$distinct = 0;
|
||||
$score = 0.0;
|
||||
|
||||
foreach ($terms as $term) {
|
||||
[$inTitle, $inText] = $hits[$i][$term];
|
||||
|
||||
if ($inTitle + $inText > 0) {
|
||||
$distinct++;
|
||||
$score += $weight[$term] * ($inTitle * 3 + $inText + 4);
|
||||
}
|
||||
|
||||
$score += $inTitle * 3 + $inText;
|
||||
}
|
||||
|
||||
$doc['distinct'] = $distinct;
|
||||
$doc['score'] = $score + $distinct * 4;
|
||||
$doc['score'] = round($score, 1);
|
||||
}
|
||||
unset($doc);
|
||||
|
||||
|
|
@ -172,7 +189,7 @@ class AskPortal
|
|||
|
||||
foreach ($chunks as $i => $chunk) {
|
||||
$lower = mb_strtolower($chunk);
|
||||
$scored[$i] = count(array_filter($terms, fn (string $t) => str_contains($lower, $t))) * 10 - $i * 0.01;
|
||||
$scored[$i] = count(array_filter($terms, fn (string $t) => Knowledge::occurrences($lower, $t) > 0)) * 10 - $i * 0.01;
|
||||
}
|
||||
|
||||
arsort($scored);
|
||||
|
|
@ -200,6 +217,7 @@ class AskPortal
|
|||
|
||||
Regeln:
|
||||
- Antworte kurz und konkret auf Deutsch: höchstens vier Sätze oder eine kurze Liste mit „- “.
|
||||
- Bei Terminen nenne Datum, Uhrzeit und Ort. Vergangene Termine nur, wenn danach gefragt ist.
|
||||
- Belege jede Aussage mit der Nummer des Auszugs in eckigen Klammern, z. B. [2].
|
||||
- Nutze nur, was in den Auszügen steht. Erfinde nichts, ergänze kein Allgemeinwissen.
|
||||
- Beantworten die Auszüge die Frage nicht, antworte nur mit: NICHTS_GEFUNDEN
|
||||
|
|
@ -221,7 +239,10 @@ class AskPortal
|
|||
$blocks[] = $head."\n".self::excerpt($doc['text'], $terms);
|
||||
}
|
||||
|
||||
return "Auszüge aus dem Intranet:\n\n".implode("\n\n", $blocks)."\n\nFrage: ".$question;
|
||||
// Datum für Fragen wie „nächste Woche“ oder „morgen“
|
||||
$today = now()->locale('de')->translatedFormat('l, j. F Y');
|
||||
|
||||
return "Heute ist {$today}.\n\nAuszüge aus dem Intranet:\n\n".implode("\n\n", $blocks)."\n\nFrage: ".$question;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue