Skip to content

Commit

Permalink
add matching source_node.node_id verification (run-llama#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 <[email protected]>
  • Loading branch information
2 people authored and JuHyung-Son committed May 1, 2024
1 parent 554d32f commit 05ab98c
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 05ab98c

Please sign in to comment.