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
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