1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
30 small wins to finish your pathNext lesson →
Metadata: what gets embedded and what the model sees
Metadata is the set of facts attached to a node, and LlamaIndex lets you choose, per key, whether each fact is embedded, shown to the model, or kept out of both.
Last updated: 28 Sep, 2026 · LlamaIndex 0.14
The last two lessons attached metadata such as the file name to every node. This lesson controls where each key goes, because a key can help matching, help answering, both, or neither.
Reading a node two ways
get_content takes a metadata_mode: EMBED shows what the embedding model receives, LLM what the model reads. Each key is written as a key: value line above the text:
from llama_index.core import Document
from llama_index.core.schema import MetadataMode
doc = Document(text="Standard delivery takes 3 to 5 working days.", metadata={"file_name": "delivery.md", "reviewed_by": "ops-team"})
print(doc.get_content(metadata_mode=MetadataMode.EMBED))
print("---")
print(doc.get_content(metadata_mode=MetadataMode.LLM))Seeing the embed and LLM views
from llama_index.core import Document
from llama_index.core.schema import MetadataMode
doc = Document(text="Standard delivery takes 3 to 5 working days.", metadata={"file_name": "delivery.md", "reviewed_by": "ops-team"})
print(doc.get_content(metadata_mode=MetadataMode.EMBED))
print("---")
print(doc.get_content(metadata_mode=MetadataMode.LLM))Output
file_name: delivery.md reviewed_by: ops-team Standard delivery takes 3 to 5 working days. --- file_name: delivery.md reviewed_by: ops-team Standard delivery takes 3 to 5 working days.
Reading the two views
- Both views include every metadata key for a Document you build yourself, as
key: valuelines above the text. - reviewed_by appears in both, so it would be embedded and shown to the model, though it helps with neither.
- SimpleDirectoryReader sets exclusions for the file keys it adds, which is why the query-engine lesson later shows none of them in the prompt.
Excluding a key from both views
Two lists on the document decide what to leave out of each view:
doc.excluded_embed_metadata_keys = ["reviewed_by"]
doc.excluded_llm_metadata_keys = ["reviewed_by"]
print(doc.get_content(metadata_mode=MetadataMode.EMBED))
print("---")
print(doc.get_content(metadata_mode=MetadataMode.LLM))Excluding a key from embedding and the prompt
doc.excluded_embed_metadata_keys = ["reviewed_by"]
doc.excluded_llm_metadata_keys = ["reviewed_by"]
print(doc.get_content(metadata_mode=MetadataMode.EMBED))
print("---")
print(doc.get_content(metadata_mode=MetadataMode.LLM))Output
file_name: delivery.md Standard delivery takes 3 to 5 working days. --- file_name: delivery.md Standard delivery takes 3 to 5 working days.
Reading the excluded views
- reviewed_by is gone from both views, so it no longer affects matching or answering.
- It stays on the node for filtering or auditing; excluding it changes only what the two views show.
- file_name remains in the model's view here, so a model could name the file it answered from.
MetadataMode.EMBED vs MetadataMode.LLM
| MetadataMode.EMBED | MetadataMode.LLM | |
|---|---|---|
| Reaches | The embedding model | The answering model |
| Affects | Which chunk matches a question | What the model can read and cite |
| Exclude with | excluded_embed_metadata_keys | excluded_llm_metadata_keys |
| Keep for a title | Yes, it helps matching | Yes, it helps citing |
When to exclude a key
- Embed what helps a question find the chunk, such as a title or product name.
- Show the model what helps it answer or cite, such as the file name.
- Keep audit fields, ids and machine paths out of both, on the node for filtering only.
Watch out. Metadata you forget to exclude is embedded silently, so a noisy key such as a timestamp or a reviewer name can shift which chunk matches a question without any error. Check both views with
get_content when a match looks wrong.Related
- Previous: Chunking documents with SentenceSplitter
- Next: IngestionPipeline: load, split and embed once
- Reference: Documents and nodes
Try it yourself
- Exclude
file_namefrom the embed view only and print both views. - Add a
"product": "LMP-204"key and check it appears in both views. - Print the content with
MetadataMode.NONE.
You understood something today that you didn't yesterday.