CLI

embed

Generate an embedding for a piece of text:

th embed "A short sentence to embed"
th embed "A short sentence to embed" --model sentence-transformers/all-mpnet-base-v2

The command prints the embedding as a JSON array of floats.

Optional cache override:

$env:TRAILHEAD_CACHE_DIR = "C:\models\cache"
th embed "A short sentence to embed"
th embed "A short sentence to embed" --cache-dir "C:\another\cache"

index

Index a directory of source files. The graph is persisted to .trailhead/db.sqlite by default (smart sync: full build on first run, incremental on subsequent runs):

th index .

Use --in-memory to build the graph without writing to disk and print a summary:

th index . --in-memory
th index . --in-memory --output json

Preview which files would be indexed without parsing or writing any SQLite state:

th index . --dry-run
th index . --dry-run --output json

Watch for file changes and reindex incrementally (Ctrl-C to stop):

th index . --watch
th index . --sqlite-db ./.trailhead/graph.db --embed-model sentence-transformers/all-MiniLM-L6-v2 --watch

Incremental reindexing updates the changed file in place. For languages that add cross-file edges during a finalize pass, such as Ansible, edges that depend on another file can disappear until the next full th index rebuild.

Use a custom database path or add embeddings:

th index . --sqlite-db ./.trailhead/graph.db
th index . --sqlite-db ./.trailhead/graph.db --embed-model sentence-transformers/all-MiniLM-L6-v2
th index . --sqlite-db ./.trailhead/graph.db --embed-model sentence-transformers/all-MiniLM-L6-v2 --embed-cache-dir C:\models\cache

When sqlite-vector can be loaded, trailhead also initializes vector search for the vertex_embeddings.embedding column. If extension loading is unavailable on your platform build, embeddings are still stored as Float32 BLOBs in SQLite.

Source discovery respects .gitignore and .trailheadignore in the indexed directory. Both use gitignore-style patterns, and .trailheadignore is applied after .gitignore so Trailhead-specific rules take precedence. If you change either ignore file, delete .trailhead/db.sqlite and run th index again to rebuild the index with the new rules.

th index --dry-run --output json returns a file-preview payload with this schema:

{
  "root": "C:/path/to/project",
  "count": 2,
  "files": ["src/app.py", "src/lib/util.py"]
}

serve

Run the warm-model API server with a background indexer. The server watches the source tree, keeps the SQLite graph fresh, and reuses the loaded embedding model across index updates. The database defaults to .trailhead/db.sqlite under the watched directory:

th serve .
th serve . --model sentence-transformers/all-MiniLM-L6-v2
th serve . --sqlite-db ./.trailhead/graph.db --model sentence-transformers/all-MiniLM-L6-v2

The browser UI is available at http://localhost:8000 once the server starts.

query

Run a read-only SQL query against the SQLite database (defaults to ./.trailhead/db.sqlite):

th query sql --sql "SELECT label, COUNT(*) AS n FROM vertices GROUP BY label ORDER BY label"
th query sql --sqlite-db ./.trailhead/graph.db --sql "SELECT label, COUNT(*) AS n FROM vertices GROUP BY label ORDER BY label"

Run a semantic similarity query against stored vertex embeddings:

th query similar "find sqlite vector initialization code"
th query similar "find sqlite vector initialization code" --sqlite-db ./.trailhead/graph.db
th query similar "graph persistence" --sqlite-db ./.trailhead/graph.db --label function -k 5 --output json

List and run the built-in query templates (see Built-in query templates):

th query templates
th query template function_complexity --limit 20
th query template coverage_risk_hotspots --columns name,path,line,complexity,coverage_pct,risk
th query template uncovered_functions --output json

Table output leaves out the long source and docstring columns unless you name them with --columns.

coverage

Import a test coverage report so queries can use measured coverage. The format is detected from the content: coverage.py JSON (coverage json), LCOV (lcov.info), or Cobertura XML (coverage xml, Jest, coverlet, gocover-cobertura and others).

coverage run -m pytest
coverage json                      # writes coverage.json
th index .
th coverage import coverage.json
th query template coverage_risk_hotspots --limit 25

Relative paths in the report are resolved against the directory that holds the report; pass --root when the tests ran somewhere else. If none of the report's files are in the index, nothing is imported and the stored coverage is kept.

Coverage is stored per file and line, so it survives re-indexing. Import again after each test run.

Tests

pytest