45 lines
965 B
PHP
45 lines
965 B
PHP
<?php
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Knowledge\Retrieval;
|
|
|
|
use App\Knowledge\ChunkManager;
|
|
use Symfony\Component\Uid\Uuid;
|
|
|
|
final class NdjsonChunkLookup
|
|
{
|
|
public function __construct(
|
|
private readonly ChunkManager $chunkManager
|
|
)
|
|
{
|
|
}
|
|
|
|
/**
|
|
* @param string[] $chunkIds RFC4122 UUID strings
|
|
* @return array<string,array<string,mixed>> keyed by chunk_id
|
|
*/
|
|
public function findByChunkIds(array $chunkIds): array
|
|
{
|
|
$wanted = array_fill_keys($chunkIds, true);
|
|
$found = [];
|
|
|
|
foreach ($this->chunkManager->streamAll() as $row) {
|
|
$id = $row['chunk_id'] ?? null;
|
|
if (!is_string($id) || !isset($wanted[$id])) {
|
|
continue;
|
|
}
|
|
|
|
$found[$id] = $row;
|
|
|
|
// Early exit sobald alle gefunden
|
|
if (\count($found) === \count($wanted)) {
|
|
break;
|
|
}
|
|
}
|
|
|
|
return $found;
|
|
}
|
|
}
|