Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Community: RankLLMRerank AttributeError (Handle list-based rerank results) #29840

Merged
merged 4 commits into from
Feb 20, 2025

Conversation

b8zhong
Copy link
Contributor

@b8zhong b8zhong commented Feb 17, 2025

community: Fix AttributeError in RankLLMRerank (list object has no attribute candidates)

Description

This PR fixes an issue in RankLLMRerank where reranking fails with the following error:

AttributeError: 'list' object has no attribute 'candidates'

The issue arises because rerank_batch() returns a List[Result] instead of an object containing .candidates.

Changes Introduced

  • Adjusted compress_documents() to support both:
    • Old API format: rerank_results.candidates
    • New API format: rerank_results as a list
    • Also fix wrong .txt location parsing while I was at it.

Issue

Fixes AttributeError in RankLLMRerank when using compression_retriever.invoke(). The issue is observed when rerank_batch() returns a list instead of an object with .candidates.

Relevant log:

AttributeError: 'list' object has no attribute 'candidates'

Dependencies

  • No additional dependencies introduced.

Checklist

  • Backward compatible with previous API versions
  • Tested locally with different RankLLM models
  • No new dependencies introduced
  • Linted with make format && make lint
  • Ready for review

Testing

  • Ran compression_retriever.invoke(query)

Reviewers

If no review within a few days, please @mention one of:

Sorry, something went wrong.

Verified

This commit was signed with the committer’s verified signature.
Tyriar Daniel Imms
Copy link

vercel bot commented Feb 17, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
langchain ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 17, 2025 4:57am

@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Feb 17, 2025
@dosubot dosubot bot added community Related to langchain-community 🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature labels Feb 17, 2025
@b8zhong
Copy link
Contributor Author

b8zhong commented Feb 17, 2025

Also gonna go ahead and update

text-embedding-ada-002 => text-embedding-3-large

And

gpt-3.5-turbo => gpt-4o-mini

For deprecation purposes. And, there was output changes so added that for consistency

@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Feb 17, 2025
@b8zhong
Copy link
Contributor Author

b8zhong commented Feb 18, 2025

@ccurme Hey! Would you happen to mind taking a look? Thanks in advance :)

@dosubot dosubot bot added the lgtm PR looks good. Use to confirm that a PR is ready for merging. label Feb 20, 2025
@ccurme ccurme merged commit a70f31d into langchain-ai:master Feb 20, 2025
21 checks passed
@b8zhong b8zhong deleted the fix/rankllm-updates branch February 20, 2025 18:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature community Related to langchain-community lgtm PR looks good. Use to confirm that a PR is ready for merging. size:L This PR changes 100-499 lines, ignoring generated files.
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

2 participants