add new route for global reindex
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user