Build the Outline and Search Tools

Challenge

Two tools give your agent grounded navigation: outline.py renders the ToC shape, search.py adds ranked full-text entry points. Both ship with their plumbing complete and their shape-materializing queries left to you - the spec is the contract, your coding agent is the pair programmer.

This completes Building Block 1: "The agent can navigate what’s there" ✓

Build the outline query

Open skill/scripts/outline.py. The renderer - grouping, sibling sorting, dotted rows - is given; the WIRE query is marked BUILD FROM SPEC. Hand your agent the wire contract from docs/outline-format.md and review what it writes. The reasoning it must land on:

cypher
The walk that materializes a tree of unknown depth
MATCH path = (root)-[:HAS*0..25]->(n)

One variable-length pattern reaches every descendant; length(path) is the depth; the second-to-last node on the path is the parent.

Test it:

shell
python skill/scripts/outline.py
python skill/scripts/outline.py technical-library/bulletins/tsb-21-114.pdf

You should see the full library ToC, then the bulletin’s subtree - with rows showing its citations into the recall and its derived links into the manuals. Copy any URI from the output and drill into it: that round-trip is the shape doing its job.

Build the search query

Open skill/scripts/search.py - same deal, the fulltext call is marked BUILD FROM SPEC. The index already exists (the pipeline created content_search over Document|Section); the query calls it, then scopes by subtree:

cypher
The index ranks, the graph scopes
CALL db.index.fulltext.queryNodes('content_search', $lucene)
YIELD node, score
WHERE $under IS NULL OR node.uri STARTS WITH $under

The hierarchical URIs earn their keep here: one STARTS WITH turns any subtree into a search scope.

Test it:

shell
python skill/scripts/search.py 'misfire OR "rough idle"' -k 4
python skill/scripts/search.py 'coil' --under technical-library/recalls

Semantic expansion is the agent’s job

The index is lexical - "stumble" never matches "misfire". The skill instructs your agent to rewrite thin queries with OR-alternates it knows. Try asking your agent: "search the library for anything about engines shaking" - and watch what query it actually runs.

Stuck or out of sync?

Complete versions are in solutions/scripts/ - compare or copy, then keep moving.

Validate the Graph

Your tools build on the loaded graph - click the Check Database button to confirm both halves are in place.

Hint

The load pipeline builds everything: python load/load_graph.py in your Codespace. It is safe to re-run - every write is a MERGE.

Check:

  • Your .env points at this sandbox (the credentials from Module 1)

  • The pipeline printed "Graph ready" with 10 documents and 30 vehicles

Solution

Run the pipeline from the Codespace terminal:

shell
python load/load_graph.py

Then check the counts:

cypher
RETURN COUNT { (:Document) } AS documents,
       COUNT { (:Section) } AS sections,
       COUNT { ()-[:LINKS_TO]->() } AS links,
       COUNT { (:Vehicle) } AS vehicles

You should see 10 documents, 37 sections, 42 links, and 30 vehicles.

If verification fails:

  • Confirm .env has the sandbox credentials from Module 1, then re-run the pipeline

  • If the database has stray data, clear it with MATCH (n) DETACH DELETE n and re-run

Summary

You built the navigation shapes:

  • outline.py - a variable-length HAS walk rendered as a ToC with copy-pasteable URIs

  • search.py - fulltext ranking scoped by URI prefix, with semantic expansion left to the agent

  • Building Block 1: "The agent can navigate what’s there" ✓

In the next challenge, you will put both tools to work on Dani’s questions.

Chatbot

How can I help you today?

Data Model

Your data model will appear here.