Skip to content

AI 103 · Module 4

Semantic Chunking & Metadata

Helping the agent find the right small piece of knowledge

Start Section 1
0 / 6 completed
Sync my progressJoin a session to keep progress across devices and share it with your instructor

Info

After you join, your completed lesson numbers are sent to your instructor together with your learner code, so they can see your progress. Use the codes your instructor gave you, and do not enter your name, company secrets or other personal data. Progress is kept with the rest of that session's data.

Learning objectives

  • Explain why an agent can still miss the right answer after documents are in the Knowledge Base
  • Distinguish Fixed-Length, Structural and Semantic Chunking, and split by "which content belongs together as one semantic unit"
  • Define Metadata fields and Retrieval Filters for a document
  • Complete a Knowledge Chunk & Metadata Design

The problem and the preparation flow

10 min

The documents are in the knowledge base. Why is the answer still missing?

The last module showed the basic RAG flow: retrieve first, then answer. But putting a document in does not mean it can be found. This module asks: for an agent to find the right small piece of knowledge, what preparation must happen before it is indexed?

Core question

The documents are already in the Knowledge Base. Why does the agent still fail to find the right answer?

Imagine a 40-page leave policy (a simulated scenario). An employee asks: "Does sick leave need a medical certificate?" If the system cuts the document at arbitrary points, retrieval may return the first half of the "sick leave days" rule while the required-certificate rule sits in another piece. The answer looks grounded, but it is incomplete.

Knowledge preparation flow
  1. Document: obtain and load the source document
  2. Structure: identify headings, sections, tables and lists
  3. Chunk: split by meaning into pieces that stand on their own
  4. Metadata: label each piece with source, date, version, access and more
  5. Index: build a searchable index
  6. Retrieve: fetch relevant pieces by question and filters

Info

Much of retrieval quality is decided before retrieval happens. Well-cut, well-labelled knowledge gives the agent a chance to find the right content.

Key takeaway: A missing answer is often a knowledge-preparation problem, not only a model problem.

10 min

Document Loading and Structure: see what the document looks like first

Document Loading reads a document into the system. A document's structure (heading hierarchy, sections, tables, lists, footnotes) carries meaning. If loading flattens everything into one long string of text, that structural information is lost.

Structure preserved

  • Headings and sections stay recognizable
  • Table columns stay attached to their values
  • List items are not scattered
  • You can split by structure later and cite the section in answers

Flattened to plain text

  • Headings look like ordinary sentences
  • Tables become numbers and words that no longer line up
  • List order and levels disappear
  • Hard to tell which section a passage belongs to

Warning

Before loading a document, confirm you are allowed to use it and remove unnecessary personal data and secrets. In practice, use only simulated or already-public documents. Do not enter company secrets, client personal data or unauthorized information.

Different document types stress different structure: an SOP has steps and preconditions, a policy has clauses and exceptions, a report has sections and figure notes. Read the structure first to know where the boundaries might be.

Check yourself

A procurement policy containing tables is flattened into one plain-text string during loading. What is the most likely problem?

A procurement policy containing tables is flattened into one plain-text string during loading. What is the most likely problem?

Key takeaway: Identify and keep the document structure first; it shows where content boundaries lie.

Chunking methods and semantic units

10 min

Three ways to chunk: Fixed-Length, Structural, Semantic

Chunking splits a long document into smaller pieces that can be retrieved independently. There are three common ideas. They do not replace one another; each focuses on a different question.

Comparing three Chunking methods
MethodBasisStrengthRisk
Fixed-LengthA fixed length (characters or tokens)Simple, fast, easy at scaleMay cut through a sentence or clause
StructuralHeadings, sections, paragraphsRespects how the author organized the documentWhen sections are too long or too short, meaning can still be incomplete
SemanticWhether content forms one semantic unitPieces stand alone, answers are more completeNeeds judgment, takes more effort and understanding

Chunk Size and Chunk Overlap are tuning parameters: too large a piece mixes in unrelated content; too small loses context. Some overlap lowers the risk of a cut boundary but adds repetition. These are trade-offs to test against your documents and tasks, not numbers with one right answer.

Warning

This course does not teach a fixed rule such as "the best size is N tokens". The more important question is: does this piece of content form a meaningful unit on its own?
Check yourself

Someone says: "Cut every document into 500 tokens with 50 tokens of overlap, and that is semantic chunking." What is wrong with this?

Someone says: "Cut every document into 500 tokens with 50 tokens of overlap, and that is semantic chunking." What is wrong with this?

Key takeaway: Split by semantic unit; size and overlap are parameters to test, not the rule.

10 min

Which content belongs together as one semantic unit?

When judging a boundary, ask: if this piece were retrieved on its own, could the reader (or agent) understand and use it correctly? If another piece is needed to make sense of it, the two may belong to one unit.

Simulated SOP: handling a refund complaint

"Scope" and "Preconditions" belong together, otherwise nobody knows when the steps apply. "Steps 1 to 4" are one continuous procedure and should not be split. "Exceptions" (for example, past the refund deadline) form a unit of their own and are often queried on their own.

  1. Find natural sections
    Mark headings, steps, tables and exception notes first.
  2. Ask "does it stand alone?"
    Read each candidate piece by itself. Is it still understood correctly?
  3. Keep dependencies together
    Keep a condition with its conclusion, a term with its definition, a step with its precondition, in the same piece where possible.
  4. Name each piece
    State in one sentence what question the piece answers. If you cannot, the boundary may be wrong.

Info

Chunking is judgment, not a formula. Finally, someone who knows the document checks whether the boundaries make sense, because only a person knows which content must be read together in real work.
Check yourself

An SOP's "Preconditions" and "Steps" were cut into two separate pieces, and the agent retrieves only the Steps piece. What could happen?

An SOP's "Preconditions" and "Steps" were cut into two separate pieces, and the agent retrieves only the Steps piece. What could happen?

Key takeaway: Keep content that depends on each other, and must be understood together, in the same piece.

Metadata and practice

10 min

Metadata and retrieval filters, plus practice

Metadata is data that describes a piece: what it is, where it came from, when, and for whom. With Metadata, retrieval does not only match text; it can narrow the scope, for example to "latest version", "HR department" or "public level" pieces only.

Common Metadata fields
FieldPurposeQuestion at retrieval time
SourceWhich document and section the piece came fromIs this a trusted source?
AuthorThe owner or unit responsibleWhom should we ask to confirm?
DateCreated or updated dateIs the information out of date?
TopicSubject categoryIs it relevant to this question?
Document TypeSOP, policy, report, FAQ and so onDo we need a rule or a case?
Access LevelWho may see itIs the asker allowed to read this?
VersionThe document versionIs this the version in force?

Warning

Access Level is only a label on the data; it is not authorization. Real access control must be enforced on the server side, not merely hidden in the front end or left to the agent's own judgment.
  1. Mark chunk boundaries
    Take a simulated SOP, policy or report and decide where each Chunk starts and ends.
  2. Define Metadata
    List the fields each piece needs and how each is filled.
  3. Define retrieval filters
    Write which questions apply which filters, for example "only current-version pieces the asker may access".
  4. Produce the design
    Assemble a Knowledge Chunk & Metadata Design. Do not enter secrets or personal data in practice.
Check yourself

Two versions of a travel policy are in the knowledge base, and the agent often cites the withdrawn one. Which fix is the most direct?

Two versions of a travel policy are in the knowledge base, and the agent often cites the withdrawn one. Which fix is the most direct?

Key takeaway: Metadata lets retrieval narrow by source, freshness, version and access, but authorization must still be enforced on the server.

Recap

5 min

Recap

Done

Good retrieval comes from good knowledge preparation: read the structure, split by meaning, then label source, freshness and access clearly with Metadata.
Knowledge preparation flow recap
  1. Document
  2. Structure
  3. Chunk
  4. Metadata
  5. Index
  6. Retrieve

Designing boundaries and Metadata is human judgment. The agent retrieves according to that design, but whether the design is sound and the data trustworthy is still checked, and owned, by a person. The next module asks: once an agent has knowledge, does it know how to do the work?

Key takeaway: People design and review chunking and Metadata; the agent only retrieves by them.

What next?