From c06a8732aacb4fbe2124f4c5a4778b0509592ed9 Mon Sep 17 00:00:00 2001 From: Maxime Perrin <63123596+maximeperrindev@users.noreply.github.com> Date: Mon, 26 Feb 2024 03:14:23 +0100 Subject: [PATCH] community[patch]: fix llama index imports and fields access (#17870) - **Description:** Fixing outdated imports after v0.10 llama index update and updating metadata and source text access - **Issue:** #17860 - **Twitter handle:** @maximeperrin_ --------- Co-authored-by: Maxime Perrin --- .../retrievers/llama_index.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/libs/community/langchain_community/retrievers/llama_index.py b/libs/community/langchain_community/retrievers/llama_index.py index 6063efe517806..49d7e242e37b3 100644 --- a/libs/community/langchain_community/retrievers/llama_index.py +++ b/libs/community/langchain_community/retrievers/llama_index.py @@ -22,8 +22,8 @@ def _get_relevant_documents( ) -> List[Document]: """Get documents relevant for a query.""" try: - from llama_index.indices.base import BaseGPTIndex - from llama_index.response.schema import Response + from llama_index.core.base.response.schema import Response + from llama_index.core.indices.base import BaseGPTIndex except ImportError: raise ImportError( "You need to install `pip install llama-index` to use this retriever." @@ -35,9 +35,9 @@ def _get_relevant_documents( # parse source nodes docs = [] for source_node in response.source_nodes: - metadata = source_node.extra_info or {} + metadata = source_node.metadata or {} docs.append( - Document(page_content=source_node.source_text, metadata=metadata) + Document(page_content=source_node.get_content(), metadata=metadata) ) return docs @@ -58,11 +58,11 @@ def _get_relevant_documents( ) -> List[Document]: """Get documents relevant for a query.""" try: - from llama_index.composability.graph import ( + from llama_index.core.base.response.schema import Response + from llama_index.core.composability.base import ( QUERY_CONFIG_TYPE, ComposableGraph, ) - from llama_index.response.schema import Response except ImportError: raise ImportError( "You need to install `pip install llama-index` to use this retriever." @@ -79,8 +79,8 @@ def _get_relevant_documents( # parse source nodes docs = [] for source_node in response.source_nodes: - metadata = source_node.extra_info or {} + metadata = source_node.metadata or {} docs.append( - Document(page_content=source_node.source_text, metadata=metadata) + Document(page_content=source_node.get_content(), metadata=metadata) ) return docs