Metadata for citation continuity
Citations have to point to the same source even after a handoff between subagents or a follow-up question. The trick is loading every chunk with metadata that names the document, the section, and an anchor inside it. Citations become stable strings that any subagent can render.
Metadata as the citation backbone
Document, section, and chunk anchor flow with the chunk through retrieval and into the final answer.
ingest/policy_pdf.py
python
def chunk_to_record(chunk: dict, doc_name: str) -> dict:
return {
'id': f"{doc_name}::{chunk['section']}::{chunk['anchor']}",
'text': chunk['text'],
'metadata': {
'document': doc_name,
'section': chunk['section'],
'anchor': chunk['anchor'],
'page': chunk['page'],
},
}A composite id and a small metadata block per chunk give every retrieval result a stable citation. Subagents render the same string regardless of who asked.
Quiz: Quiz
Loading practice…