Commit 589e56a
feat: MarkdownHeaderSplitter (#9660)
* implement md-header-splitter and add tests
* rework md-header splitter to rewrite md-header levels
* remove deprecated test
* Update haystack/components/preprocessors/markdown_header_splitter.py
use haystack logging
Co-authored-by: Sebastian Husch Lee <10526848+sjrl@users.noreply.github.com>
* use native types
* move to haystack logging
* docstrings improvements
* Update haystack/components/preprocessors/markdown_header_splitter.py
remove temp toc
Co-authored-by: Sebastian Husch Lee <10526848+sjrl@users.noreply.github.com>
* fix CustomDocumentSplitter arguments
* remove header prefix from content
* rework split_id assignment to avoid collisions
* remove unneeded dese methods
* cleanup
* cleanup
* add tests
cleanup
* move initialization of secondary-splitter out of run method
* move _custom_document_splitter to class method
* removed the _CustomDocumentSplitter class. splitting logic is now encapsulated within the MarkdownHeaderSplitter class as private methods.
* return to standard feed-forward character and add tests for page break handling
* quit exposing splitting_function param since it shouldn't be changed anyway
* remove test section in module
* add license header
* add release note
* minor refactor for type safety
* Update haystack/components/preprocessors/markdown_header_splitter.py
Co-authored-by: Sebastian Husch Lee <10526848+sjrl@users.noreply.github.com>
* remove unneeded release notes entries
* improved documentation for methods
* improve method naming
* improved page-number assignment & added return in docstring
minor cleanup
* unified page-counting
* simplify conditional secondary-split initialization and usage
* fix linting error
* clearly specify the use of ATX-style headers (#) only
* reference doc_id when logging no headers found
* initialize md-header pattern as private variable once
* add example to for inferring header levels to docstring
* improve empty document handling
add more logging for empty documents
* more explicit testing for inferred headers
* fix linting issue
* improved empty content handling test cases
* remove all functionality related to inferring md-header levels
* compile regex-pattern in init for performance gains
* Update haystack/components/preprocessors/markdown_header_splitter.py
Co-authored-by: Sebastian Husch Lee <10526848+sjrl@users.noreply.github.com>
* change all "none" to proper None values
* fix minor
* explicitly test doc content
* rename parentheaders to parent_headers
* test split_id, doc length
* check meta content
* remove unneeded test
* make split_id testing more robust
* more realistic overlap test sample
* assign split_id globally to all output docs
* taste page numbers explicitly
* cleanup pagebreak test
* minor
* return doc unchunked if no headers have content
* add doc-id to logging statement for unsplit documents
* remove unneeded logs
* minor cleanup
* simplify page-number tracking method to not return count, just the updated page number
* add dev comment to mypy check for doc.content is None
* Update haystack/components/preprocessors/markdown_header_splitter.py
Co-authored-by: Sebastian Husch Lee <10526848+sjrl@users.noreply.github.com>
* remove split meta flattening
* keep empty meta return consistent
* remove unneeded content is none check
* update tests to reflect empty meta dict for unsplit docs
* clean up total_page counts
* remove unneeded meta check
* Update test/components/preprocessors/test_markdown_header_splitter.py
Co-authored-by: Sebastian Husch Lee <10526848+sjrl@users.noreply.github.com>
* implement keep_headers parameter
* remove meta-dict flattening
* add minor sanity checks
* Update test/components/preprocessors/test_markdown_header_splitter.py
Co-authored-by: Sebastian Husch Lee <10526848+sjrl@users.noreply.github.com>
* add warmup
* Update haystack/components/preprocessors/markdown_header_splitter.py
Co-authored-by: Sebastian Husch Lee <10526848+sjrl@users.noreply.github.com>
* fix splitting when keeping headers
* test cleanup to cover keep_headers=True
* add tests for keep_headers=False splitting
* remove strip()
* simplify doc handling
* fix split id assignment
* test cleanup
* test splits more explicitly
* cleanup tests
minor commenting
* Update haystack/components/preprocessors/markdown_header_splitter.py
Co-authored-by: Sebastian Husch Lee <10526848+sjrl@users.noreply.github.com>
* Update haystack/components/preprocessors/markdown_header_splitter.py
Co-authored-by: Sebastian Husch Lee <10526848+sjrl@users.noreply.github.com>
* Update haystack/components/preprocessors/markdown_header_splitter.py
Co-authored-by: Sebastian Husch Lee <10526848+sjrl@users.noreply.github.com>
* Update haystack/components/preprocessors/markdown_header_splitter.py
Co-authored-by: Sebastian Husch Lee <10526848+sjrl@users.noreply.github.com>
* Update test/components/preprocessors/test_markdown_header_splitter.py
Co-authored-by: Sebastian Husch Lee <10526848+sjrl@users.noreply.github.com>
* Update haystack/components/preprocessors/markdown_header_splitter.py
Co-authored-by: Sebastian Husch Lee <10526848+sjrl@users.noreply.github.com>
* Update releasenotes/notes/add-md-header-splitter-df5c024a6ddd2718.yaml
Co-authored-by: Sebastian Husch Lee <10526848+sjrl@users.noreply.github.com>
* Update haystack/components/preprocessors/markdown_header_splitter.py
Co-authored-by: Sebastian Husch Lee <10526848+sjrl@users.noreply.github.com>
* Update releasenotes/notes/add-md-header-splitter-df5c024a6ddd2718.yaml
Co-authored-by: Sebastian Husch Lee <10526848+sjrl@users.noreply.github.com>
* Update releasenotes/notes/add-md-header-splitter-df5c024a6ddd2718.yaml
Co-authored-by: Sebastian Husch Lee <10526848+sjrl@users.noreply.github.com>
* Update haystack/components/preprocessors/markdown_header_splitter.py
Co-authored-by: Sebastian Husch Lee <10526848+sjrl@users.noreply.github.com>
* fix test now that meta is always kept regardless of headers
* update tests to consider headers always part of meta
* remove trailing whitespace removal
* remove redundant test
* make test_split_multiple_documents more explicit
* make tests more explicit
* remove header level inference from release notes
* improve splitting log message
* add split ids and more explicit string assertions
* add fixture & appropriate assertions for sample text with page breaks
* add md-header-splitter to preprocessors api
---------
Co-authored-by: Sebastian Husch Lee <10526848+sjrl@users.noreply.github.com>1 parent 554267b commit 589e56a
4 files changed
Lines changed: 915 additions & 0 deletions
File tree
- haystack/components/preprocessors
- pydoc
- releasenotes/notes
- test/components/preprocessors
Lines changed: 334 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
Lines changed: 8 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
0 commit comments