Skip to content

The agent engineering platform.

community[patch]: Handle when documents are not provided in the Cohere response (#16144)

BeatrixCohereb0c3e3db2b24
diff --git a/libs/community/langchain_community/retrievers/cohere_rag_retriever.py b/libs/community/langchain_community/retrievers/cohere_rag_retriever.py
index 39dcc30f3b..91f4c3a088 100644
--- a/libs/community/langchain_community/retrievers/cohere_rag_retriever.py
+++ b/libs/community/langchain_community/retrievers/cohere_rag_retriever.py
@@ -17,10 +17,14 @@ if TYPE_CHECKING:
def _get_docs(response: Any) -> List[Document]:
- docs = [
- Document(page_content=doc["snippet"], metadata=doc)
- for doc in response.generation_info["documents"]
- ]
+ docs = (
+ []
+ if "documents" not in response.generation_info
+ else [
+ Document(page_content=doc["snippet"], metadata=doc)
+ for doc in response.generation_info["documents"]
+ ]
+ )
docs.append(
Document(
page_content=response.message.content,