new version ndjson
This commit is contained in:
44
src/Knowledge/Retrieval/NdjsonChunkLookup.php
Normal file
44
src/Knowledge/Retrieval/NdjsonChunkLookup.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user