Replies: 2 comments 8 replies
-
🤖 Hey there, @aiwalter! Good to see you back in the LlamaIndex world. Hope your code is behaving today. 😄 Based on the information you provided and the context from the LlamaIndex repository, you can add metadata to the nodes in two ways:
node.metadata = metadata Or when creating a new node = TextNode(text=text, metadata=metadata) If your input documents already have this metadata, it would be inherited to the nodes automatically. For retrieval, you can use metadata filters: from llama_index.vector_stores.types import ExactMatchFilter, MetadataFilters
filters = MetadataFilters(
filters=[ExactMatchFilter(key="key", value="val")]
)
query_engine = index.as_query_engine(similarity_top_k=3, filters=filters) This solution was suggested in a similar issue: [Question]: Add TextNode metadata to help Retriever
from llama_index.extractors.interface import BaseExtractor
from typing import Sequence, List, Dict
from llama_index.schema import BaseNode
class CustomExtractor(BaseExtractor):
async def aextract(self, nodes: Sequence[BaseNode]) -> List[Dict]:
# Implement your custom extraction logic here
pass In this example, You can find more details about creating a custom extractor in the LlamaIndex source code: llama_index/extractors/interface.py I hope this helps! If you have any other questions or need further clarification, feel free to ask. Sources
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. If you want to continue the conversation, start your reply with @dosu-bot. |
Beta Was this translation helpful? Give feedback.
-
@dosubot I managed to add some metadata to the document, how can I use this metadata in |
Beta Was this translation helpful? Give feedback.
-
I am using a query engine and would like to add some matadata of the nodes to the node text, e.g.
file_name
and some other custom metadata. I think there is a class for this inllama_index
but now I cant find it. Or do I need to write sth custom?Beta Was this translation helpful? Give feedback.
All reactions