ChunkingStrategy.fromJson constructor

ChunkingStrategy.fromJson(
  1. Map<String, dynamic> j
)

Implementation

factory ChunkingStrategy.fromJson(Map<String, dynamic> j) {
  final type = j['type'] as String? ?? 'other';
  if (type == 'static') {
    final s = j['static'] as Map?;
    return StaticChunkingStrategy(
      maxChunkSizeTokens: (s?['max_chunk_size_tokens'] as num?)?.toInt(),
      chunkOverlapTokens: (s?['chunk_overlap_tokens'] as num?)?.toInt(),
    );
  }
  if (type == 'auto') return const AutoChunkingStrategy();
  return const OtherChunkingStrategy();
}