新增节点:
index.insert_nodes([doc_single])
doc_single必须是一个 TextNode 对象。
构造TextNode对象:
from llama_index.core.schema import TextNode
nodes = [
TextNode(
text="The Shawshank Redemption",
metadata={
"author": "Stephen King",
"theme": "Friendship",
"year": 1994,
},
),
TextNode(
text="The Godfather",
metadata={
"director": "Francis Ford Coppola",
"theme": "Mafia",
"year": 1972,
},
)
]
index.insert_nodes(nodes)
删除节点:
index.docstore.delete_document('51595901-ebe3-48b5-b57b-dc8794ef4556')