Skip to content

[BUG] Reranker.rerank() modifies input document dictionaries in-place #814

Description

@suhaniiz

Description of the Bug

The current implementation of the rerank method directly assigns scores to the input list objects using doc["rerank_score"] = float(score). Because dictionaries in Python are passed by reference, this mutates the user's original data structure outside the scope of the class. If the application reuses this list of documents elsewhere, it contains unexpected mutated state data.

Steps to Reproduce

my_docs = [{"text": "Hello world"}]
reranker.rerank("query", my_docs)
print(my_docs)

Output contains 'rerank_score' even though we didn't explicitly modify my_docs

Expected Behavior

The rerank method should return a brand-new list containing shallow copies (doc.copy()) of the dictionaries with the appended scores, leaving the caller's original data intact and pristine.

Screenshots / Logs

No response

Environment

=

GSSoC '26

  • Yes, I am participating in GirlScript Summer of Code and would like to fix this.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinggssocGirlScript Summer of Code 2026 issue/PR

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions