AnswerDotAI / rerankers

A lightweight, low-dependency, unified API to use all common reranking and cross-encoder models.
Apache License 2.0
784 stars 40 forks source link

cross-encoders fail with single document: AttributeError: 'Result' object has no attribute 'results' #7

Closed tarasglek closed 5 months ago

tarasglek commented 5 months ago

docs = ["foo"] breaks docs = ["foo", ""] works

  File "/Users/taras/Documents/onnx/tagging.py", line 52, in <listcomp>
    for result in r.rank(query=tag, docs=docs).results
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/taras/Documents/onnx/.pixi/env/lib/python3.11/site-packages/pydantic/main.py", line 767, in __getattr__
    raise AttributeError(f'{type(self).__name__!r} object has no attribute {item!r}')
AttributeError: 'Result' object has no attribute 'results'
bclavie commented 5 months ago

Thank you for flagging. This is because it defaults to returning a Result rather a RankedResults object when only ranking a single document, but that's actually counter-intuitive behaviour as most people wouldn't expect the output format to change. Fixed in 0.1.2post1/https://github.com/AnswerDotAI/rerankers/pull/9