This commit is contained in:
27
docs/snippets/kotlin/advanced/embedding_with_chunking.md
Normal file
27
docs/snippets/kotlin/advanced/embedding_with_chunking.md
Normal file
@@ -0,0 +1,27 @@
|
||||
```kotlin title="Kotlin"
|
||||
import dev.kreuzberg.*
|
||||
import java.nio.file.Paths
|
||||
import java.util.Optional
|
||||
|
||||
fun main() {
|
||||
val embedding = EmbeddingConfig.builder()
|
||||
.withModel(EmbeddingModelType.Preset("balanced"))
|
||||
.withNormalize(true)
|
||||
.withBatchSize(32L)
|
||||
.withShowDownloadProgress(false)
|
||||
.build()
|
||||
|
||||
val chunking = ChunkingConfig.builder()
|
||||
.withMaxCharacters(1024L)
|
||||
.withOverlap(100L)
|
||||
.withEmbedding(Optional.of(embedding))
|
||||
.build()
|
||||
|
||||
val config = ExtractionConfig.builder()
|
||||
.withChunking(Optional.of(chunking))
|
||||
.build()
|
||||
|
||||
val result = Kreuzberg.extractFileSync(Paths.get("document.pdf"), null, config)
|
||||
println("Chunks with embeddings: ${result.chunks()?.size ?: 0}")
|
||||
}
|
||||
```
|
||||
Reference in New Issue
Block a user