Optional Library Practice

Optional Practice

You built the outline and search tools. In this lesson, you will practice the model underneath them - the HAS tree, the URIs, and the link types - with four more questions from the AutoFix shop floor.

Advanced learners: Skip to Module 4.

Beginners: These exercises build the traversal fluency the themes and judgment tools rely on.

Exercise 1: Size up the estate

Which document has the most sections, and how deep does each tree go?

Details
cypher
Sections per document
MATCH path = (d:Document)-[:HAS*]->(s:Section)
RETURN d.displayName AS document,
       count(s) AS sections,
       max(length(path)) AS maxDepth
ORDER BY sections DESC

Counting over the variable-length pattern gives the size of each tree, and the longest path gives its depth - manuals reach depth 2, bulletins and recalls stay at depth 1.

Try experimenting:

  • Add WHERE d:Bulletin to size up only the bulletins

  • Start the walk from a Folder instead, and watch the depths shift by one

Exercise 2: Read around a section

A technician is reading the Falcon manual’s misfire diagnosis. What comes immediately before and after it, in reading order?

Details
cypher
The reading-order window
MATCH (s:Section {uri: 'technical-library/manuals/man-fal-3.pdf#engine/misfire-diagnosis'})
OPTIONAL MATCH (prev)-[:NEXT_SECTION]->(s)
OPTIONAL MATCH (s)-[:NEXT_SECTION]->(next)
RETURN prev.displayName AS before, s.displayName AS here, next.displayName AS after

NEXT_SECTION threads the document the way a human reads it - so an agent can widen its context window around any hit by one hop in each direction, without re-deriving order from the tree.

Try experimenting:

  • Chain two hops: (s)-[:NEXT_SECTION*1..2]→(n) for a wider window

The library has two kinds of cross-document connections. How many of each, and which sections explicitly cite another document?

Details
cypher
The two link kinds
MATCH (s:Section)-[l:LINKS_TO]->(t)
RETURN CASE WHEN l.citation THEN 'citation' ELSE 'derived' END AS kind,
       count(*) AS links
cypher
Who cites whom
MATCH (s:Section)-[l:LINKS_TO {citation: true}]->(d:Document)
RETURN s.uri AS fromSection, d.id AS citesDocument

Citations exist because a section’s text names another document; derived links exist because two sections reference the same part or code - and carry sharedKeys saying exactly which.

Try experimenting:

  • Return l.sharedKeys for the derived links and find the strongest one (l.strength)

Exercise 4: Subtree scoping with URIs

Count the sections under each folder - without touching the tree.

Details
cypher
Prefix matching replaces a traversal
MATCH (f:Folder)
MATCH (s:Section) WHERE s.uri STARTS WITH f.uri + '/'
RETURN f.name AS folder, count(s) AS sections
ORDER BY sections DESC

Because URIs encode the hierarchy, subtree questions can be answered by string prefix alone - the same trick your search tool’s --under scope and the theme tool’s document collapse use.

Try experimenting:

  • Compare with the traversal form (f)-[:HAS*]→(s:Section) - same counts, two different reasoning styles

Summary

In this optional practice, you exercised the model:

  • Tree aggregation - counting and depth over [:HAS*]

  • Reading order - NEXT_SECTION windows around any section

  • Link kinds - explicit citations versus derived shared-key links

  • URI scoping - subtree questions as string prefixes

Module 4 builds the themes shape on exactly these pieces.

Chatbot

How can I help you today?

Data Model

Your data model will appear here.