Create a new text chunk
(content: String, start_index: usize, end_index: usize, chunk_index: usize)
| 139 | impl TextChunk { |
| 140 | /// Create a new text chunk |
| 141 | pub fn new(content: String, start_index: usize, end_index: usize, chunk_index: usize) -> Self { |
| 142 | let mut metadata = HashMap::new(); |
| 143 | metadata.insert( |
| 144 | "length".to_string(), |
| 145 | serde_json::Value::Number(content.chars().count().into()), |
| 146 | ); |
| 147 | |
| 148 | Self { |
| 149 | content, |
| 150 | start_index, |
| 151 | end_index, |
| 152 | chunk_index, |
| 153 | metadata, |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | /// Add metadata to the chunk |
| 158 | pub fn with_metadata(mut self, key: String, value: serde_json::Value) -> Self { |