HTTP API

When the server is running, the full API schema is available at:

http://localhost:8000/openapi.json
http://localhost:8000/docs

The schema documents every endpoint, parameter name, type, default, and constraint. Check it first before probing endpoints manually. A build-time-generated version of that same schema is available in the Reference section for browsing without a running server.

Endpoints

Method Path Description
GET / Browser UI
GET /api/health Server status and configuration
POST /api/embed Embed a single text string
POST /api/embed/batch Embed multiple texts
POST /api/query/sql Run a read-only SQL query
GET /api/query/templates List built-in query templates
GET /api/query/templates/{name} Get a template's SQL
POST /api/query/templates/{name}/run Run a template against the database
GET /api/query/similar Semantic similarity search (parameter: text, k)
GET /api/graph/vertices Search vertices by name, label, or path
GET /api/graph/traverse Traverse the graph from a vertex

SQL schema

The two core tables are:

vertices — one row per code symbol:

Column Type Notes
id TEXT UUID, used for graph traversal
label TEXT module, class, function, external
name TEXT Symbol name
path TEXT Absolute file path
line INTEGER Line number (null for modules)
complexity INTEGER McCabe complexity (functions only)
properties_json TEXT JSON blob with source, docstring, and all other properties

edges — relationships between vertices:

Column Type Notes
id TEXT UUID
label TEXT defines, has_method, imports, calls
out_v_id TEXT Source vertex id
in_v_id TEXT Target vertex id
properties_json TEXT {"resolution": "exact"} or {"resolution": "inferred"} on Python calls edges (see below); {} otherwise

Edge labels and their meaning:

Label Meaning
defines Module → class or function it defines
has_method Class → method
imports Module → external symbol it imports
calls Function → function it calls

For Python, calls edges are resolved the way Python resolves names: enclosing function scopes, then the module, then imports (absolute, relative, aliased, star imports and package re-exports); self./cls. methods and super() through base classes; and Class.method. A call such as mapping.get(...) on a receiver whose type is unknown is linked only when exactly one method in the project has that name and the name is not a method of a builtin or common standard library type; production code is never linked to test code this way. Those edges have {"resolution": "inferred"}; all other Python call edges have {"resolution": "exact"}. Calls into builtins and third-party libraries get no edge. Other languages still link calls by name.

Incremental re-indexing keeps the calls within the changed file; calls to and from other files come back on the next full th index.

Coverage (filled by th coverage import):

Table / view Notes
line_coverage path, line, hits: one row per measurable line; hits = 0 means it never ran
coverage_files path: every file the report mentions, including files with no measurable lines
function_coverage View: each function and class with statements, covered, coverage_pct over its body (the lines after its def/class line, through end_line), and measured (0 when its file is not in the report). Nested definitions count toward the enclosing one.
-- Complex functions that the tests barely run
SELECT name, path, line, complexity, coverage_pct
FROM function_coverage
WHERE label = 'function' AND measured = 1 AND coverage_pct < 50
ORDER BY complexity DESC;

source and docstring live inside properties_json rather than as top-level columns. To filter on them in SQL, use json_extract:

-- Functions whose source mentions "HTTPException"
SELECT name, path, line
FROM vertices
WHERE label = 'function'
  AND json_extract(properties_json, '$.source') LIKE '%HTTPException%'

-- Functions with a docstring
SELECT name, path
FROM vertices
WHERE label = 'function'
  AND json_extract(properties_json, '$.docstring') IS NOT NULL

HTTP query examples

# Health check
curl http://localhost:8000/api/health

# Embed text
curl -X POST http://localhost:8000/api/embed \
  -H "Content-Type: application/json" \
  -d '{"text": "hello world"}'

# Semantic search — note the parameter is "k", not "limit"
curl "http://localhost:8000/api/query/similar?text=route+registration&k=5"

# Filter semantic search to functions only
curl "http://localhost:8000/api/query/similar?text=route+registration&k=5&label=function"

# SQL query
curl -X POST http://localhost:8000/api/query/sql \
  -H "Content-Type: application/json" \
  -d '{"sql": "SELECT label, COUNT(*) AS n FROM vertices GROUP BY label"}'

# Find a vertex by name, then get its id for traversal
curl "http://localhost:8000/api/graph/vertices?name=ui_dashboard&label=function"

# Traverse outward along call edges only (shows what a function calls)
curl "http://localhost:8000/api/graph/traverse?vertex_id=<id>&direction=out&depth=2&edge_labels=calls"

# Traverse inward along call edges only (shows what calls a function)
curl "http://localhost:8000/api/graph/traverse?vertex_id=<id>&direction=in&depth=2&edge_labels=calls"

# Run a built-in query template
curl http://localhost:8000/api/query/templates
curl -X POST http://localhost:8000/api/query/templates/function_complexity/run

Built-in query templates

Templates are pre-built SQL queries runnable without writing any SQL. Categories:

Category Templates
quality function_complexity, missing_docstrings, undocumented_public_api, todo_fixme_inventory
testing symbols_not_represented_by_tests, test_coverage_ratio_by_file, largest_untested_symbols (name matching only, no measurement)
coverage coverage_risk_hotspots, uncovered_functions, coverage_by_file, unmeasured_files (measured; need th coverage import)
architecture duplicate_symbol_names, dependency_hotspots, external_dependency_pressure
calls most_called_functions, call_graph_hubs
data_health missing_source_for_functions, orphan_edges

Typical workflow for code exploration

  1. Find a starting point — use semantic search or /api/graph/vertices?name=... to locate a vertex and grab its id.
  2. Understand its call chain — traverse outward with edge_labels=calls to see what it calls; inward to see its callers.
  3. Understand its structure — traverse with edge_labels=defines,has_method to see what a module or class contains.
  4. Run quality checks — use the built-in templates for complexity, missing docs, or dependency hotspots without writing SQL; import coverage to rank risky, untested code.
  5. Ad-hoc queries — use /api/query/sql with json_extract to filter on source content, docstrings, or any property.