Find answers from the community

Updated 2 years ago

How do I use SimpleNodeParser

At a glance
How do I use SimpleNodeParser?

I've attempted to import and use it as follows:


from llama_index.node_parser import SimpleNodeParser parser = SimpleNodeParser.from_defaults( chunk_size=300, include_extra_info=False, include_prev_next_rel=False, ) nodes = parser.get_nodes_from_documents(documents)

However, I receive this error message: AttributeError: type object 'SimpleNodeParser' has no attribute 'from_defaults'.

I guess it's deprecated or something, but I can't find it in the codebase.
L
B
4 comments
It seems to work fine for me... maybe try with a fresh venv?

Plain Text
>>> from llama_index.node_parser import SimpleNodeParser
>>> from llama_index import Document
>>> parser = SimpleNodeParser.from_defaults(chunk_size=300, include_extra_info=False, include_prev_next_rel=False)
>>> nodes = parser.get_nodes_from_documents([Document("hello world")])
>>> nodes
[Node(text='hello world', doc_id='19e9c1ed-ff54-4f64-871a-494409c3afdb', embedding=None, doc_hash='fa7e170768add0c94a32db49b036276a3181ce802ae79d0217cdda3314e11cac', extra_info=None, node_info={'start': 0, 'end': 11, '_node_type': <NodeType.TEXT: '1'>}, relationships={<DocumentRelationship.SOURCE: '1'>: 'a54c33e8-1742-47cc-b3e6-881b825d3388'})]
>>> 
Thanks! I upgraded the version and now it´s working,
Add a reply
Sign up and join the conversation on Discord