Skip to content

Commit

Permalink
community[patch]: fix llama index imports and fields access (langchai…
Browse files Browse the repository at this point in the history
…n-ai#17870)

- **Description:** Fixing outdated imports after v0.10 llama index
update and updating metadata and source text access
  - **Issue:** langchain-ai#17860
  - **Twitter handle:** @maximeperrin_

---------

Co-authored-by: Maxime Perrin <mperrin@doing.fr>
  • Loading branch information
2 people authored and gkorland committed Mar 30, 2024
1 parent dd1a0af commit 4f43be7
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions libs/community/langchain_community/retrievers/llama_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand All @@ -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

Expand All @@ -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."
Expand All @@ -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

0 comments on commit 4f43be7

Please sign in to comment.