DocumentSplitter misplaces repeated literal chunks from an overlapping custom splitter

Aperta Adatta ai principianti
#13,806 2 commenti 0 reazioni 1 assegnatario Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@davidsbatista ci sta già lavorando.

Dal 19/11/2026.

  • #13807 di @lakshya-dhariwal — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
backend, data

Direzione di ricerca

Leggi la ricerca personalizzata degli offset di suddivisione in haystack/components/preprocessors/document_splitter.py, intorno alle righe 349–373, e il test esistente della finestra scorrevole in test/components/preprocessors/test_document_splitter.py, intorno alle righe 346–371. Inizia eseguendo quel test e adattandone il caso a chunk ripetuti e sovrapposti. La correzione è completata quando i quattro chunk iniziano da [0, 3, 6, 9], i relativi metadati di sovrapposizione corrispondono agli intervalli di origine e il retriever restituisce go go go go go go.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

P2

Describe the bug

When a custom DocumentSplitter callback returns overlapping windows of repeated text, later copies can be picked in place of the actual overlapping windows. Some split_idx_start values then point beyond the source. A SentenceWindowRetriever using those chunks returns duplicated text.

Error message

No exception is raised.

Expected behavior

The four windows below have exactly four increasing literal source starts, [0, 3, 6, 9]. Their overlap metadata should describe those ranges, and the retrieved window should be go go go go go go. The existing custom-splitter test checks source offsets and overlap metadata for a sliding window with distinct text. Existing sliding-window test

Additional context

The splitter searches from the end of the previous chunk and only tries an earlier overlap when that search fails. For the second chunk below, it finds a later occurrence at offset 9. The third and fourth chunks then take the running fallback offsets, 17 and 25. Built-in word splitting with the same source and window sizes gives the expected offsets and text. Custom split offset lookup

To Reproduce

from haystack import Document
from haystack.components.preprocessors import DocumentSplitter
from haystack.components.retrievers import SentenceWindowRetriever
from haystack.document_stores.in_memory import InMemoryDocumentStore


def sliding_window(text):
    words = text.split(" ")
    return [" ".join(words[i : i + 3]) for i in range(len(words) - 2)]


text = "go go go go go go"
splitter = DocumentSplitter(
    split_by="function",
    splitting_function=sliding_window,
    split_length=3,
    split_overlap=2,
)
chunks = splitter.run(documents=[Document(content=text)])["documents"]

store = InMemoryDocumentStore()
store.write_documents(chunks)
retriever = SentenceWindowRetriever(document_store=store, window_size=len(chunks))
result = retriever.run(retrieved_documents=[chunks[2]])
print([chunk.meta["split_idx_start"] for chunk in chunks])
print(result["context_windows"][0])

Output on main:

[0, 9, 17, 25]
go go gogo go gogo go gogo go go

FAQ Check

System

  • Ubuntu 24.04.2 LTS, x86_64
  • Python 3.12.14
  • Haystack main at bbf5b2b429670fa866e388f9a734ff3b1c652bf8 (VERSION.txt reports 3.6.0-rc0)

OpenAI Codex prepared and ran the reproduction.

Lingua principale
Python
Stelle
27.1k
Fork
3.5k
Merge medio
1g 8h
PR unite (30g)
239

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di deepset-ai/haystack

Tutte le issue di deepset-ai/haystack

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.