langchain/docs
Brayden Zhong a70f31de5f
Community: RankLLMRerank AttributeError (Handle list-based rerank results) (#29840)
# 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**
- [x] **Backward compatible** with previous API versions
- [x] **Tested** locally with different RankLLM models
- [x] **No new dependencies introduced**
- [x] **Linted** with `make format && make lint`
- [x] **Ready for review**

---

## **Testing**
- Ran `compression_retriever.invoke(query)`

## **Reviewers**
If no review within a few days, please **@mention** one of:
- @baskaryan
- @efriis
- @eyurtsev
- @ccurme
- @vbarda
- @hwchase17
2025-02-20 12:38:31 -05:00
..
api_reference infra: migrate to uv (#29566) 2025-02-06 13:36:26 -05:00
cassettes infra: migrate to uv (#29566) 2025-02-06 13:36:26 -05:00
data docs: 👥 Update LangChain people data (#27022) 2024-10-08 17:09:07 +00:00
docs Community: RankLLMRerank AttributeError (Handle list-based rerank results) (#29840) 2025-02-20 12:38:31 -05:00
scripts docs: fix partner package table build for packages with no download stats (#29871) 2025-02-19 11:05:57 +13:00
src docs: Rename IBM product name to IBM watsonx (#29802) 2025-02-15 21:48:02 -05:00
static docs: update apify integration (#29553) 2025-02-12 20:02:55 -08:00
.gitignore infra: cleanup docs build (#21134) 2024-05-01 17:34:05 -07:00
.yarnrc.yml docs[minor]: Add thumbs up/down to all docs pages (#18526) 2024-03-04 15:14:28 -08:00
babel.config.js
docusaurus.config.js Banner for interrupt (#29567) 2025-02-03 17:40:24 -08:00
ignore-step.sh infra: run docs build on packages.yml updates (#29796) 2025-02-19 18:45:30 +00:00
Makefile docs: fix httpx conflicts with overrides in docs build (#29180) 2025-01-13 21:25:00 +00:00
package.json docs: raw loader codeblock (#28548) 2024-12-06 09:26:34 -08:00
README.md docs: reorganize contributing docs (#27649) 2024-10-25 22:41:54 +00:00
sidebars.js docs: reorg sidebar (#27978) 2024-11-15 14:28:18 -08:00
vercel_overrides.txt docs: fix httpx conflicts with overrides in docs build (#29180) 2025-01-13 21:25:00 +00:00
vercel_requirements.txt docs: more useful vercel warnings (#28699) 2024-12-13 03:07:24 +00:00
vercel.json docs: tests/standard tests api ref redirect (#29444) 2025-01-27 23:21:50 -08:00
yarn.lock docs: raw loader codeblock (#28548) 2024-12-06 09:26:34 -08:00

LangChain Documentation

For more information on contributing to our documentation, see the Documentation Contributing Guide