phase a audit
This commit is contained in:
72
src/Ingest/ChunkWriteService.php
Normal file
72
src/Ingest/ChunkWriteService.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Ingest;
|
||||
|
||||
use App\Entity\DocumentVersion;
|
||||
use App\Knowledge\ChunkManager;
|
||||
use Symfony\Component\Uid\Uuid;
|
||||
|
||||
final readonly class ChunkWriteService
|
||||
{
|
||||
public function __construct(
|
||||
private ChunkManager $chunkManager,
|
||||
) {}
|
||||
|
||||
public function getIndexPath(): string
|
||||
{
|
||||
return $this->chunkManager->getIndexPath();
|
||||
}
|
||||
|
||||
public function countAllChunks(): int
|
||||
{
|
||||
return $this->chunkManager->countAllChunks();
|
||||
}
|
||||
|
||||
public function compactByDocumentId(Uuid $documentId): void
|
||||
{
|
||||
$this->chunkManager->compactByDocument($documentId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param iterable<array<string,mixed>> $chunks
|
||||
*/
|
||||
public function appendChunks(iterable $chunks): void
|
||||
{
|
||||
$this->chunkManager->appendChunks($chunks);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lokaler Ingest für eine einzelne DocumentVersion.
|
||||
*
|
||||
* Ablauf:
|
||||
* 1. Entfernt bestehende Chunks dieses Dokuments
|
||||
* 2. Appendet neue Chunks
|
||||
*
|
||||
* @param iterable<array<string,mixed>> $chunks
|
||||
*/
|
||||
public function writeForDocumentVersion(
|
||||
DocumentVersion $version,
|
||||
iterable $chunks
|
||||
): void {
|
||||
$documentId = $version->getDocument()->getId();
|
||||
|
||||
if (!$documentId instanceof Uuid) {
|
||||
throw new \RuntimeException('Document ID must be a Uuid instance');
|
||||
}
|
||||
|
||||
$this->chunkManager->compactByDocument($documentId);
|
||||
$this->chunkManager->appendChunks($chunks);
|
||||
}
|
||||
|
||||
/**
|
||||
* Vollständiger Rewrite des NDJSON-Index (Global Reindex).
|
||||
*
|
||||
* @param iterable<array<string,mixed>> $allChunks
|
||||
*/
|
||||
public function rewriteAll(iterable $allChunks): void
|
||||
{
|
||||
$this->chunkManager->rewriteAll($allChunks);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user