Open OKC13 opened 3 weeks ago
query_engine = RetrieverQueryEngine.from_args( streaming=False, retriever=hybrid_retriever,
node_postprocessors=[rerank_llm],
response_synthesizer=response_synthesizer,
llm=llm,
similarity_top_k=5
)
To remove metadata in the context of using RetrieverQueryEngine
, you can create a deep copy of the nodes and then filter out the metadata fields you want to exclude. Here is a code snippet to achieve this:
from copy import deepcopy
# Create a deep copy of the nodes
nodes_no_metadata = deepcopy(uber_nodes) + deepcopy(lyft_nodes)
# Remove all metadata except for "page_label" and "file_name"
for node in nodes_no_metadata:
node.metadata = {
k: node.metadata[k]
for k in node.metadata
if k in ["page_label", "file_name"]
}
# Print the content to verify the metadata removal
print(
"LLM sees:\n",
(nodes_no_metadata)[9].get_content(metadata_mode=MetadataMode.LLM),
)
This code ensures that only the "page_label" and "file_name" metadata fields are retained, effectively removing all other metadata [1].
To continue talking to Dosu, mention @dosu.
Question Validation
Question
how to remove metadata ?