Skip to content

fix(rankers): rank documents that carry no score instead of failing the run - #1178

Open
xdAsaah wants to merge 1 commit into
dynamiq-ai:mainfrom
xdAsaah:fix/recency-ranker-missing-score
Open

xdAsaah wants to merge 1 commit into
dynamiq-ai:mainfrom
xdAsaah:fix/recency-ranker-missing-score

Conversation

@xdAsaah

@xdAsaah xdAsaah commented Nov 28, 2026

Copy link
Copy Markdown

TimeWeightedDocumentRanker failed on documents that carry no score, which is the default state of Document and the only state every converter produces:

  • Document.score defaults to None, and adjust_similarity_scores multiplied it: unsupported operand type(s) for *: 'NoneType' and 'float'.
  • A document with no date and no score stayed None, and the sort compared it: '<' not supported between instances of 'NoneType' and 'float'.
  • Through Node.run both surface as RunnableStatus.FAILURE carrying that bare message, so the flow stops.

No construction is needed to reach this: converter components return {"documents": [...]} built as Document(content=..., metadata=...) — the exact key this ranker takes — and Retriever.get_documents_by_id also returns score-less documents. Ranking freshly loaded chunks by their date is what a time-weighted ranker is for.

An unscored document with a date now takes a neutral base score of 1.0, so recency decides alone. One with neither a score nor a date keeps None and sorts last, preserving its input order.

Compatibility

No change for scored documents: a document with a score and a date is adjusted exactly as before, and a scored document without a date keeps its score. Only documents that previously failed the run now rank.

Verified

  • Added tests/unit/nodes/rankers/test_recency_ranker_score.py: unscored documents ranked by recency, unscored documents without a date sorted after scored ones, the all-undated case keeping input order, and top_k still applying.
  • Without the change: 4 failed.
  • With the change: 4 passed; together with the existing tests/integration/nodes/rerankers/test_recency.py, 11 passed.
  • Mutation check, one guard at a time: dropping the neutral base score fails the two dated cases; restoring the plain sort key fails the two undated cases.
  • Whole ranker suite: pytest tests/unit/nodes/rankers tests/integration/nodes/rerankers → 15 passed. flake8 and isort --check-only clean.

This change was prepared with AI assistance.

…he run

Document.score defaults to None, which is also the only state every converter produces
(Document(content=..., metadata=...)) and what get_documents_by_id returns.
adjust_similarity_scores multiplied that None: "unsupported operand type(s) for *:
'NoneType' and 'float'". A document with no date either stayed None and broke the sort:
"'<' not supported between instances of 'NoneType' and 'float'". Through Node.run both
surface as a FAILURE with the bare message, so a flow that ranks freshly loaded chunks by
their date cannot run at all.

An unscored document with a date now takes a neutral base of 1.0, so recency decides
alone; one with neither a score nor a date keeps None and sorts last in input order.
@xdAsaah
xdAsaah requested a review from a team as a code owner November 28, 2026 04:04

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant