Find answers from the community

Updated 2 months ago

After updating to the current version of llama_index I get the error "'NodeWithScore' obje

After updating to the current version of llama_index I get the error "'NodeWithScore' object has no attribute 'node_text'". What is the correct attribute now?
k
2 comments
Please stand by @ethan0807 as I search the knowledge base. I normally take about 20 seconds or so. :wave:
----------------------
The error you're encountering is likely due to changes in the LlamaIndex API. In the recent updates, the Node object has been renamed to TextNode and it seems like the attribute node_text is no longer available. Instead, you should use the text attribute to access the text of a TextNode object.

Here is an example of how to instantiate a TextNode and access its text:

Plain Text
from llama_index.schema import TextNode

# Instantiate a TextNode
node = TextNode(text="Your text here")

# Access the text
print(node.text)


For NodeWithScore objects, you can access the TextNode (formerly Node) and its text like this:

Plain Text
from llama_index.schema import NodeWithScore, TextNode

# Instantiate a NodeWithScore
node_with_score = NodeWithScore(node=TextNode(text="Your text here"), score=0.7)

# Access the TextNode and its text
print(node_with_score.node.text)


Please refer to the changelog () and the API reference () for more details.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Add a reply
Sign up and join the conversation on Discord