diff --git a/src/Controller/Admin/DocumentController.php b/src/Controller/Admin/DocumentController.php index a581cb0..3f6a476 100644 --- a/src/Controller/Admin/DocumentController.php +++ b/src/Controller/Admin/DocumentController.php @@ -234,7 +234,7 @@ class DocumentController extends AbstractController ): RedirectResponse { - if (!$this->isCsrfTokenValid('activate_version_'.$versionId, $request->request->get('_token'))) { + if (!$this->isCsrfTokenValid('activate_version_' . $versionId, $request->request->get('_token'))) { throw $this->createAccessDeniedException(); } @@ -313,7 +313,7 @@ class DocumentController extends AbstractController ): ?RedirectResponse { $dryRun = false; - if (!$this->isCsrfTokenValid('ingest_version_'.$versionId, $request->request->get('_token'))) { + if (!$this->isCsrfTokenValid('ingest_version_' . $versionId, $request->request->get('_token'))) { throw $this->createAccessDeniedException(); } @@ -425,6 +425,7 @@ class DocumentController extends AbstractController EntityManagerInterface $em, IngestJobService $jobService, LockService $lockService, + DocumentService $documentService ): RedirectResponse { if (!$this->isCsrfTokenValid('delete_document_' . $id, $request->request->get('_token'))) { diff --git a/src/Vector/VectorIndexBuilder.php b/src/Vector/VectorIndexBuilder.php index b4598fb..e7c3572 100644 --- a/src/Vector/VectorIndexBuilder.php +++ b/src/Vector/VectorIndexBuilder.php @@ -46,12 +46,35 @@ final class VectorIndexBuilder { $this->assertPreconditions(); + // -------------------------------------------- + // 🔵 FALL: NDJSON ist leer → kein Vector Index + // -------------------------------------------- + if (filesize($this->indexNdjsonPath) === 0) { + + // Alten Index entfernen + @unlink($this->vectorIndexPath); + @unlink($this->vectorMetaPath); + + if ($logPath !== null) { + @file_put_contents( + $logPath, + "NDJSON empty → Vector index removed\n", + FILE_APPEND + ); + } + + return; // WICHTIG: kein Python, kein tmp, kein Fehler + } + + // -------------------------------------------- + // 🟢 FALL: NDJSON enthält Chunks + // -------------------------------------------- + if (!is_file($this->indexMetaPath)) { $this->initializeIndexMeta(); } $indexMeta = $this->readIndexMeta(); - $embeddingModel = $indexMeta['embedding_model']; $tmpVectorIndexPath = $this->vectorIndexPath . '.tmp'; diff --git a/src/Vector/vector_ingest.py b/src/Vector/vector_ingest.py index fd97374..ebc847b 100644 --- a/src/Vector/vector_ingest.py +++ b/src/Vector/vector_ingest.py @@ -80,8 +80,16 @@ with open(index_path, "r", encoding="utf-8") as f: ids.append(chunk_id) if not texts: - print("ERROR: No valid chunks found in index.ndjson") - sys.exit(21) + print("No chunks found. Removing vector index.") + + if out_path.exists(): + out_path.unlink() + + meta_path = out_path.with_suffix(".meta.json") + if meta_path.exists(): + meta_path.unlink() + + sys.exit(0) print(f"Loaded {len(texts)} chunks.")