Skip to content

Commit

Permalink
add matching source_node.node_id verification (#13109)
Browse files Browse the repository at this point in the history
* add matching source_node.node_id verification

* check that source_node exists

---------

Co-authored-by: Adam Lineberry <adam.lineberry@kensho.com>
  • Loading branch information
alineberry and Adam Lineberry committed May 1, 2024
1 parent dd3a25c commit 8bf72cc
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions llama-index-core/llama_index/core/node_parser/interface.py
Expand Up @@ -99,11 +99,22 @@ def get_nodes_from_documents(
)

if self.include_prev_next_rel:
if i > 0:
# establish prev/next relationships if nodes share the same source_node
if (
i > 0
and node.source_node
and nodes[i - 1].source_node
and nodes[i - 1].source_node.node_id == node.source_node.node_id
):
node.relationships[NodeRelationship.PREVIOUS] = nodes[
i - 1
].as_related_node_info()
if i < len(nodes) - 1:
if (
i < len(nodes) - 1
and node.source_node
and nodes[i + 1].source_node
and nodes[i + 1].source_node.node_id == node.source_node.node_id
):
node.relationships[NodeRelationship.NEXT] = nodes[
i + 1
].as_related_node_info()
Expand Down

0 comments on commit 8bf72cc

Please sign in to comment.