add new route for global reindex

This commit is contained in:
team 1
2026-02-17 16:00:59 +01:00
parent 0b96ce6188
commit 2c443c0f1e
4 changed files with 159 additions and 57 deletions

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace App\Ingest;
use App\Entity\Document;
use App\Entity\DocumentVersion;
use App\Index\IndexMetaManager;
use App\Knowledge\ChunkManager;
@@ -40,7 +41,6 @@ final readonly class IngestFlow
try {
// Entfernt alte Chunks dieses Dokuments
$this->chunkManager->compactByDocument($version->getDocument()->getId());
$existing = $this->chunkManager->countAllChunks();
@@ -86,10 +86,39 @@ final readonly class IngestFlow
public function globalReindex(): void
{
$records = $this->knowledgeIngestService->buildAllActiveChunkRecords();
$this->metaManager->validateAgainstCurrent();
// 1⃣ Prüfen ob aktive Dokumente existieren
$activeDocuments = $this->em
->getRepository(Document::class)
->createQueryBuilder('d')
->where('d.status = :status')
->setParameter('status', Document::STATUS_ACTIVE)
->getQuery()
->getResult();
if (empty($activeDocuments)) {
throw new \RuntimeException(
'Global Reindex abgebrochen: Es sind keine aktiven Dokumente vorhanden.'
);
}
// 2⃣ ChunkRecords erzeugen
$records = iterator_to_array(
$this->knowledgeIngestService->buildAllActiveChunkRecords(),
false
);
if (empty($records)) {
throw new \RuntimeException(
'Global Reindex abgebrochen: Es wurden keine Chunks erzeugt. Bitte prüfen Sie die Dokumente.'
);
}
// 3⃣ Rewrite NDJSON
$this->chunkManager->rewriteAll($records);
// 4⃣ Rebuild Vector Index
$this->rebuildIndex(true);
}
@@ -102,20 +131,17 @@ final readonly class IngestFlow
$this->metaManager->validateAgainstCurrent();
$document = $this->em
->getRepository(\App\Entity\Document::class)
->getRepository(Document::class)
->find($documentId);
if (!$document) {
throw new \RuntimeException('Document not found.');
}
// 1) NDJSON bereinigen
$this->chunkManager->compactByDocument($documentId);
// 2) Vector neu bauen
$this->rebuildIndex(false);
// 3) DB Delete (nach rebuild)
$this->em->remove($document);
$this->em->flush();
}