Skip to content

fix: sort SentenceWindowRetriever context before merging text - #12976

Open
LindseyZ1205 wants to merge 2 commits into
deepset-ai:mainfrom
LindseyZ1205:fix/sentence-window-retriever-context-order
Open

LindseyZ1205 wants to merge 2 commits into
deepset-ai:mainfrom
LindseyZ1205:fix/sentence-window-retriever-context-order

Conversation

@LindseyZ1205

@LindseyZ1205 LindseyZ1205 commented Sep 26, 2026 •

Copy link
Copy Markdown

Related Issues

Proposed Changes:

The shared _assemble_context path merges context text before sorting documents by split_id. When chunks have no split_idx_start (for example chunks from MarkdownHeaderSplitter), merge_documents_text concatenates them in the Document Store's return order, while context_documents is sorted. Sort once before assembling both outputs. This preserves the upstream batched retrieval used by both run and run_async.

How did you test it?

  • Existing shuffled custom-field tests now assert the exact context text and split ID order for both sync and async calls. On the current upstream logic, these two regression tests fail; with this fix, the two retriever unit-test files pass (37 passed, 4 integration cases deselected).
  • hatch run fmt-check and hatch run test:types pass for the changed source and two test files; git diff --check passes.

Notes for the reviewer

The run() docstring says context_documents are sorted by the split_idx_start meta field, but the code sorts by split_id_meta_field. I left it unchanged to keep this PR focused, happy to update it here if you prefer.

AI assistance: Claude Code assisted with the original bug investigation and patch. Codex assisted with adapting the fix to upstream batched retrieval, resolving the merge conflict, and running the checks above.

Checklist

  • I have read the contributors guidelines and the code of conduct.
  • I have updated the related issue with new insights and changes.
  • I have added unit tests and updated the docstrings.
  • I've used one of the conventional commit types for my PR title: fix:, feat:, build:, chore:, ci:, docs:, style:, refactor:, perf:, test: and added ! in case the PR includes breaking changes.
  • I have documented my code.
  • I have added a release note file, following the contributors guidelines.
  • I have run pre-commit hooks and fixed any issue.

🤖 Generated with Claude Code

The context documents were merged into `context_windows` before being
sorted by `split_id`. When chunks have no `split_idx_start` (for example
chunks from MarkdownHeaderSplitter), `merge_documents_text` concatenates
them in the order returned by the Document Store, so the context text
could be scrambled while `context_documents` was correctly sorted.

Sort first and merge the sorted list, in both run and run_async.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@LindseyZ1205
LindseyZ1205 requested a review from a team as a code owner September 26, 2026 20:18
@LindseyZ1205
LindseyZ1205 requested review from bogdankostic and removed request for a team September 26, 2026 20:18
@vercel

vercel Bot commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

@LindseyZ1205 is attempting to deploy a commit to the deepset Team on Vercel.

A member of the Team first needs to authorize it.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SentenceWindowRetriever returns context_windows in Document Store order when chunks have no split_idx_start

1 participant