Commit dbf972d
committed
fix: set source_id on RecursiveDocumentSplitter chunks
RecursiveDocumentSplitter wrote only `parent_id` on the chunks it produced.
Every other splitter in the library writes `source_id`, and that is the key the
rest of Haystack reads to tie a chunk back to the document it came from.
The practical effect is that its output does not compose with
SentenceWindowRetriever, which reads `source_id` by default and raises when it
is missing. The same pipeline works with DocumentSplitter and fails with
RecursiveDocumentSplitter:
DocumentSplitter -> OK, 3 context documents
RecursiveDocumentSplitter -> ValueError: The retrieved documents must have
'source_id' in their metadata.
Chunks now carry `source_id` as well as `parent_id`, which keeps its previous
value so callers already reading it are unaffected.
While here, the class docstring example claimed a meta key named `original_id`,
which the code has never written. Its output block also did not match what the
example produces: it was generated with a different `split_length` than the one
shown, and reported `_split_overlap` as `[]` where a run with `split_overlap=0`
gives `None`. The example now reproduces the output it claims.1 parent 757b3e2 commit dbf972d
3 files changed
Lines changed: 54 additions & 5 deletions
File tree
- haystack/components/preprocessors
- releasenotes/notes
- test/components/preprocessors
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
| 41 | + | |
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
54 | 55 | | |
55 | 56 | | |
56 | 57 | | |
| |||
425 | 426 | | |
426 | 427 | | |
427 | 428 | | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
428 | 433 | | |
429 | 434 | | |
430 | 435 | | |
| |||
Lines changed: 12 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
| 15 | + | |
14 | 16 | | |
15 | 17 | | |
16 | 18 | | |
| |||
1055 | 1057 | | |
1056 | 1058 | | |
1057 | 1059 | | |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
| 1069 | + | |
| 1070 | + | |
| 1071 | + | |
| 1072 | + | |
| 1073 | + | |
| 1074 | + | |
| 1075 | + | |
| 1076 | + | |
| 1077 | + | |
| 1078 | + | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
| 1083 | + | |
| 1084 | + | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
| 1089 | + | |
1058 | 1090 | | |
1059 | 1091 | | |
1060 | 1092 | | |
| |||
0 commit comments