Designing Metadata for Precise Retrieval
This lesson explains how a metadata framework adds the facts that semantic similarity cannot capture, such as a document's date, product or audience.
Learning outcomes
After completing this lesson, you will be able to:
- Design a metadata schema.
- Capture metadata where documents are created.
- Filter retrieval with metadata at query time.
Designing the metadata schema
Vector similarity alone cannot tell whether a document is current, which product it covers or whether the user may see it. Metadata answers these questions and allows retrieval to be filtered, for example to documents about one product that are still in effect. A metadata framework defines a small, consistent set of attributes recorded for every document.
Typical attributes are the source system and URL, the document type, the domain or department, the product or service, the author and owner, the language, the security classification and allowed groups, the effective date, the last modified timestamp and the version. Values come from a controlled vocabulary, an agreed list of allowed values often called a tagging taxonomy, so that filters match reliably. If some documents are tagged "HR" and others "Human Resources", a filter on either value silently misses half of them.
A useful metadata schema
Capturing metadata
Metadata is most reliable when it is captured where documents are created, rather than guessed later. S3 object metadata and object tags can hold timestamps, owners and classifications set by the system that uploads each document. Connectors for sources such as Confluence or SharePoint carry fields such as author, space and modification date automatically. When documents arrive with no metadata, Amazon Comprehend can classify them into domains or extract entities such as product names, and an FM can do the same for less common categories.
For Bedrock Knowledge Bases with an Amazon S3 data source, attributes are supplied in a companion file named <document>.metadata.json stored next to each document. The knowledge base reads the file during ingestion and stores the attributes with every chunk of that document, so they can be used in retrieval filters, as in the following example.
// s3://kb-docs/hr/leave-policy.pdf.metadata.json
{
"metadataAttributes": {
"department": "HR",
"doc_type": "policy",
"region": "EU",
"effective_year": 2026,
"author": "People Operations"
}
}Using metadata at query time
Metadata filters restrict retrieval to matching chunks before or during the vector search. Bedrock Knowledge Bases support operators such as equals, notEquals, greaterThan, lessThan, in, startsWith, stringContains and listContains, combined with andAll and orAll. Implicit filtering lets a model derive filters from the question, for example extracting "EU" and "2026" from "What is the EU leave policy this year?". Metadata returned with each chunk lets the prompt state dates and authors, lets the application show citations and enforces document-level access by filtering on the user's groups.
"retrievalConfiguration": {"vectorSearchConfiguration": {
"numberOfResults": 8,
"filter": {"andAll": [
{"equals": {"key": "department", "value": "HR"}},
{"greaterThanOrEquals": {"key": "effective_year", "value": 2025}},
{"in": {"key": "region", "value": ["EU", "GLOBAL"]}}
]}
}}The following table shows common attributes and what they enable.
| Attribute | Enables |
|---|---|
| Effective date, version | Excluding outdated documents; preferring the latest |
| Product, domain, department | Narrowing search to the relevant area |
| Allowed groups, classification | Document-level access control |
| Author, source URL | Attribution and citations |
| Language | Answering from documents in the user's language |
The following diagram compares retrieval with and without a metadata filter when an outdated policy and its replacement are almost identical.

Filtering with metadata
Outdated answers
A knowledge base of HR policies sometimes answers with rules from a superseded 2023 policy, because old and new versions are semantically almost identical.
Better embeddings will not fix this, because the versions really are similar. Adding effective_year and status (current or superseded) metadata to every document, and filtering retrieval to current documents, solves it. Removing superseded documents from the data source is even simpler when history is not needed.
How is metadata supplied for documents in an S3 data source of a knowledge base?
Show answer
In a .metadata.json file next to each document, which the ingestion job reads and indexes for filtering.
Exam Tips
Remember for the exam
- Use a small, controlled set of metadata attributes for every document.
- Knowledge Bases S3 sources: .metadata.json files next to each document.
- Filter on date, version, product and access groups at query time.
- Implicit filtering derives filters from the question.