add activate document versions

This commit is contained in:
team 1
2026-02-16 08:43:29 +01:00
parent 3416678cf4
commit 93c4a53589
4 changed files with 59 additions and 43 deletions

View File

@@ -40,35 +40,6 @@ final readonly class PromptBuilder
// ------------------------------------------------------------
// 1) SYSTEM INSTRUCTIONS
// ------------------------------------------------------------
//ToDO: remove old systemLines
/*$systemLines = [
'You are a conversational AI assistant.',
'Respond clearly, precisely, and in context of the ongoing conversation.',
'The conversation context is authoritative and must be respected.',
'External knowledge is supporting information only.',
'If the user asks for contact details such as phone number, email address, postal address or contact person, and the provided context contains such information, answer explicitly with the concrete data.',
'Do not omit contact details.',
'It is allowed and desired to quote contact data verbatim if it appears in the context.',
"Current date and time: {$now}",
'',
'IMPORTANT FORMATTING RULES:',
'- Always answer in valid Markdown.',
'- Use headings, lists, and paragraphs where appropriate.',
'- Insert line breaks early and often.',
'- Never write long paragraphs without newlines.',
'- Each list item must start on a new line.',
'- Prefer short paragraphs over dense text blocks.',
'',
'IMPORTANT LANGUAGE RULES:',
'- If the user input contains misspellings, silently use the correct canonical terms in your answer.',
'- Never mention, explain, or point out spelling mistakes.',
'- Do not ask clarifying questions about possible misspellings.',
'- Do not repeat or quote misspelled terms from the user input.',
'- Always use the correct technical spelling found in the provided context.',
'- Answer directly and confidently using always correct canonical terminology.'
];
$systemBlock = "SYSTEM:\n" . implode("\n", $systemLines);*/
$activePrompt = $this->systemPromptRepository->findActive();

View File

@@ -187,7 +187,12 @@ class DocumentController extends AbstractController
throw $this->createNotFoundException();
}
try {
$documentService->activateVersion($version);
$this->addFlash('success', 'Version aktiviert und Index aktualisiert.');
} catch (\Throwable $e) {
$this->addFlash('danger', 'Aktivierung/Re-Ingest fehlgeschlagen: ' . $e->getMessage());
}
return $this->redirectToRoute('admin_document_show', [
'id' => $version->getDocument()->getId()

View File

@@ -5,12 +5,15 @@ namespace App\Service;
use App\Entity\Document;
use App\Entity\DocumentVersion;
use App\Entity\User;
use App\Ingest\IngestFlow;
use Doctrine\ORM\EntityManagerInterface;
class DocumentService
{
public function __construct(
private EntityManagerInterface $em
private EntityManagerInterface $em,
private LockService $lockService,
private IngestFlow $ingestFlow,
) {}
/**
@@ -70,12 +73,24 @@ class DocumentService
}
/**
* Aktiviert eine Version (setzt andere inaktiv)
* Aktiviert eine Version (setzt andere inaktiv) und aktualisiert den Index.
*
* Beim Aktivieren wird deterministisch sichergestellt, dass nur diese
* Version im Index vorhanden ist:
* - alle Chunks des Dokuments werden aus index.ndjson entfernt (streaming compaction)
* - die aktive Version wird neu ge-chunkt und appended
* - FAISS wird vollständig aus index.ndjson neu gebaut
*/
public function activateVersion(DocumentVersion $version): void
{
if (!$this->lockService->acquire()) {
throw new \RuntimeException('Another ingest job is already running.');
}
try {
$document = $version->getDocument();
// 1) Aktiv-Status in DB konsistent setzen (genau 1 aktive Version)
foreach ($document->getVersions() as $existingVersion) {
$existingVersion->setActive(false);
}
@@ -83,7 +98,24 @@ class DocumentService
$version->setActive(true);
$document->setCurrentVersion($version);
// 2) Ingest-Status (UI) wird im Fehlerfall auf FAILED gesetzt
$version->setIngestStatus(DocumentVersion::INGEST_RUNNING);
$this->em->flush();
// 3) Deterministischer Re-Ingest: alte Chunks raus, neue rein, FAISS rebuild
$this->ingestFlow->ingestDocumentVersion($version);
$version->setIngestStatus(DocumentVersion::INGEST_INDEXED);
$this->em->flush();
} catch (\Throwable $e) {
// Aktivierung bleibt in DB bestehen, aber Index ist ggf. nicht aktuell → Status markieren
$version->setIngestStatus(DocumentVersion::INGEST_FAILED);
$this->em->flush();
throw $e;
} finally {
$this->lockService->release();
}
}
/**

View File

@@ -107,6 +107,7 @@
<td>
{% if version.isActive %}
{# Optional: manuelles Re-Ingest nur bei PENDING/FAILED #}
{% if version.ingestStatus in ['PENDING', 'FAILED'] %}
<form method="post"
@@ -123,7 +124,14 @@
{% endif %}
{% else %}
<span class="text-muted">Nicht aktiv</span>
<form method="post"
action="{{ path('admin_document_version_activate', {versionId: version.id}) }}"
style="display:inline;">
<input type="hidden" name="_token" value="{{ csrf_token('activate_version') }}">
<button class="btn btn-sm btn-outline-light">
Aktivieren
</button>
</form>
{% endif %}
</td>