Replies: 1 comment 8 replies
-
To save only part of the metadata in the node but save all of the metadata in the docstore, you can follow this approach:
Here is a simplified example of how you might implement this: from llama_index.legacy.schema import BaseNode
from llama_index.storage.kvstore.azure import AzureKVStore
from llama_index.storage.kvstore.azure.base import ServiceMode
import json
# Initialize the AzureKVStore
kv_store = AzureKVStore(service_mode=ServiceMode.STORAGE)
# Function to save node with partial metadata
def save_node_with_partial_metadata(node: BaseNode, partial_metadata: dict):
# Save the node with partial metadata
node.metadata = partial_metadata
kv_store.save_node(node)
# Function to save full metadata in docstore
def save_full_metadata_in_docstore(node_id: str, full_metadata: dict):
# Save the full metadata in the docstore
kv_store.save_item(node_id, full_metadata)
# Example usage
node = BaseNode(id="node1", data="some data")
partial_metadata = {"key1": "value1"} # Partial metadata
full_metadata = {"key1": "value1", "key2": "value2", "key3": "value3"} # Full metadata
save_node_with_partial_metadata(node, partial_metadata)
save_full_metadata_in_docstore(node.id, full_metadata) Additionally, you can use the utility functions provided in Here is how you can use these utility functions: from llama_index.core.vector_stores.utils import node_to_metadata_dict, metadata_dict_to_node
# Convert node to metadata dictionary
metadata_dict = node_to_metadata_dict(node, remove_text=True)
# Convert metadata dictionary back to node
restored_node = metadata_dict_to_node(metadata_dict) By using these utility functions, you can ensure that the metadata is correctly handled and stored in both the node and the docstore [1][2][3]. |
Beta Was this translation helpful? Give feedback.
-
How can I save only part of the metadata in the node, but save all of the metadata in docstore?
Beta Was this translation helpful? Give feedback.
All reactions