diff --git a/config/services.yaml b/config/services.yaml index 26cfab6..a468fe7 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -3,6 +3,8 @@ # ------------------------------------------------------------ parameters: + mto.kernel.dir: '%kernel.project_dir%' + mto.index.chunk_size: 800 mto.index.chunk_overlap: 100 mto.index.embedding_model: 'nomic-embed-text' @@ -11,6 +13,8 @@ parameters: mto.vector.python_bin: '/var/www/html/.venv/bin/python3' mto.vector.ingest_script: '/src/Vector/vector_ingest.py' + + mto.vector.data.path: '%kernel.project_dir%/var/knowledge' mto.vector.timeout: 600 # ------------------------------------------------------------ @@ -42,7 +46,7 @@ services: App\Controller\: resource: '../src/Controller/' - tags: ['controller.service_arguments'] + tags: [ 'controller.service_arguments' ] # ------------------------------------------------------------ # AI Agent – Infrastructure diff --git a/src/Controller/Admin/DashboardController.php b/src/Controller/Admin/DashboardController.php index a349225..be978b2 100644 --- a/src/Controller/Admin/DashboardController.php +++ b/src/Controller/Admin/DashboardController.php @@ -14,4 +14,5 @@ final class DashboardController extends AbstractController { return $this->render('admin/dashboard/index.html.twig'); } + } diff --git a/src/Controller/Admin/DocumentController.php b/src/Controller/Admin/DocumentController.php index e8bcc12..9e62de1 100644 --- a/src/Controller/Admin/DocumentController.php +++ b/src/Controller/Admin/DocumentController.php @@ -8,24 +8,21 @@ use App\Entity\IngestJob; use App\Service\DocumentService; use App\Service\FormatText; use App\Service\IngestJobService; +use Doctrine\DBAL\Connection; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; -use Symfony\Component\HttpFoundation\RedirectResponse; -use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\Routing\Attribute\Route; -use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; -use Symfony\Component\Uid\Uuid; -use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\HttpFoundation\File\Exception\FileException; +use Symfony\Component\HttpFoundation\RedirectResponse; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; +use Symfony\Component\Routing\Attribute\Route; +use Symfony\Component\Uid\Uuid; #[Route('/admin/documents')] class DocumentController extends AbstractController { - public function __construct( - private readonly FormatText $formatText, - ) - { - } #[Route('', name: 'admin_documents')] public function index(EntityManagerInterface $em): Response @@ -63,14 +60,14 @@ class DocumentController extends AbstractController } #[Route('/new', name: 'admin_document_new')] - public function new(Request $request, DocumentService $documentService): Response + public function new(Request $request, DocumentService $documentService, FormatText $formatText): Response { if ($request->isMethod('POST')) { - $file = $request->files->get('file'); + $file = $request->files->get('file'); $title = $request->request->get('title') ?: $file->getClientOriginalName(); - $title = $this->formatText->slugify($title); + $title = $formatText->slugify($title); if (!$file || !$title) { $this->addFlash('error', 'Titel und Datei sind erforderlich.'); @@ -107,11 +104,12 @@ class DocumentController extends AbstractController #[Route('/{id}/version/new', name: 'admin_document_version_new', requirements: ['id' => '[0-9a-fA-F\-]{36}'])] public function newVersion( - string $id, - Request $request, + string $id, + Request $request, EntityManagerInterface $em, - DocumentService $documentService - ): Response { + DocumentService $documentService + ): Response + { $document = $em->getRepository(Document::class)->find($id); @@ -165,11 +163,12 @@ class DocumentController extends AbstractController methods: ['POST'] )] public function activateVersion( - string $versionId, - Request $request, + string $versionId, + Request $request, EntityManagerInterface $em, - DocumentService $documentService - ): RedirectResponse { + DocumentService $documentService + ): RedirectResponse + { if (!$this->isCsrfTokenValid('activate_version', $request->request->get('_token'))) { throw $this->createAccessDeniedException(); @@ -195,11 +194,12 @@ class DocumentController extends AbstractController methods: ['POST'] )] public function ingestVersion( - string $versionId, - Request $request, + string $versionId, + Request $request, EntityManagerInterface $em, - IngestJobService $jobService, - ): ?RedirectResponse { + IngestJobService $jobService, + ): ?RedirectResponse + { $dryRun = false; if (!$this->isCsrfTokenValid('ingest_version', $request->request->get('_token'))) { throw $this->createAccessDeniedException(); @@ -238,14 +238,14 @@ class DocumentController extends AbstractController ); // Hintergrundprozess starten (Provider-kompatibel, kein Worker/Daemon) - $projectDir = (string) $this->getParameter('kernel.project_dir'); - $console = $projectDir . '/bin/console'; + $projectDir = (string)$this->getParameter('kernel.project_dir'); + $console = $projectDir . '/bin/console'; $cmd = sprintf( '%s %s %s %s > /dev/null 2>&1 &', escapeshellarg($console), escapeshellarg('mto:agent:ingest:run'), - escapeshellarg((string) $job->getId()), + escapeshellarg((string)$job->getId()), escapeshellarg('--no-interaction'), ); @@ -261,8 +261,32 @@ class DocumentController extends AbstractController exec($cmd); return $this->redirectToRoute('admin_job_show', [ - 'id' => (string) $job->getId(), + 'id' => (string)$job->getId(), ]); } + #[Route( + '/reset', + name: 'admin_document_reset', + methods: ['POST'] + )] + public function resetCompleteSystem(ParameterBagInterface $params, Connection $connection): ?RedirectResponse + { + @unlink($params->get('mto.vector.data.path') . '/index.ndjson'); + @unlink($params->get('mto.vector.data.path') . '/vector.index'); + @unlink($params->get('mto.vector.data.path') . '/vector.index.meta.json'); + $sql = ' + SET FOREIGN_KEY_CHECKS = 0; + TRUNCATE TABLE db.document; + SET FOREIGN_KEY_CHECKS = 1; + SET FOREIGN_KEY_CHECKS = 0; + TRUNCATE TABLE db.document_version; + SET FOREIGN_KEY_CHECKS = 1; + SET FOREIGN_KEY_CHECKS = 0; + TRUNCATE TABLE db.ingest_job; + SET FOREIGN_KEY_CHECKS = 1; + '; + $connection->executeQuery($sql); + return $this->redirectToRoute('admin_dashboard'); + } } diff --git a/templates/admin/dashboard/index.html.twig b/templates/admin/dashboard/index.html.twig index 255a8f7..0504c5d 100644 --- a/templates/admin/dashboard/index.html.twig +++ b/templates/admin/dashboard/index.html.twig @@ -16,6 +16,17 @@