Files
fil/docs/snippets/php/advanced/chunking_rag.md
Henrik Jess Nielsen b4c07d3693
All checks were successful
Deploy fil (kreuzberg) / deploy (push) Successful in 49s
Nomad changes
2026-06-01 23:40:55 +02:00

40 lines
1.1 KiB
Markdown

```php title="PHP"
<?php
declare(strict_types=1);
use Kreuzberg\Kreuzberg;
use Kreuzberg\ExtractionConfig;
use Kreuzberg\ChunkingConfig;
use Kreuzberg\EmbeddingConfig;
$config = new ExtractionConfig(
chunking: new ChunkingConfig(
maxCharacters: 500,
overlap: 50,
embedding: new EmbeddingConfig(
normalize: true,
batchSize: 32
)
)
);
$result = Kreuzberg::extractFileSync('research_paper.pdf', null, $config);
if ($result->getChunks()) {
foreach ($result->getChunks() as $chunk) {
$metadata = $chunk->getMetadata();
if ($metadata) {
echo "Chunk " . ($metadata->getChunkIndex() + 1) . "/" . $metadata->getTotalChunks() . "\n";
echo "Position: " . $metadata->getByteStart() . "-" . $metadata->getByteEnd() . "\n";
echo "Content: " . substr($chunk->getContent(), 0, 100) . "...\n";
if ($chunk->getEmbedding()) {
echo "Embedding: " . count($chunk->getEmbedding()) . " dimensions\n";
}
}
echo "\n";
}
}
?>
```