Skip to main content

Querying the Knowledge Graph

After you import or create a repository, Atomic can project a knowledge graph (KG) over your codebase. The KG maps out your files, changes, views, identities, and workflow resources (intents, goals, sessions, and more) — who changed what, which view a change is on, and how changes depend on each other.

Code structure (functions, structs, classes, imports, calls) is parsed live from source rather than persisted in the KG. The KG classifies changes, files, views, and workflow resources using class IRIs from the Atomic workflow ontology (https://atomic.dev/ns/workflow#).

This is a queryable model of your entire project that powers:

  • Code search: find source text across your repo's recorded source in the current view
  • Structural search: find KG nodes by class, label, or summary
  • Dependency exploration: trace how files, changes, and views connect
  • AI agent workflows: agents use the KG instead of grep/find for faster, more accurate code discovery

This page is organized by what you want to do: set up the graph, find code, explore relationships, visualize, and automate. All of the commands below live under a single command family: atomic query.

note

atomic vault query … is a documented alias for atomic query …. Both forms work identically. This page uses the canonical atomic query <subcommand> form throughout.

info

The knowledge graph is especially important for AI Agent Workflows. Agent integrations install a code-intelligence skill that teaches agents to query the KG instead of scanning the filesystem. If you're setting up Atomic for agent use, this page is essential reading.

How the graph is organized​

Before querying, it helps to know what the graph contains. The knowledge graph stores several kinds of nodes:

  • file: every tracked file in the repository
  • change: every recorded change, with author and message
  • view: views in the repository (main, dev, feature branches)
  • identity: identities that author changes
  • intent: directive-based units of work from the Atomic vault
  • memory: durable knowledge captured alongside the work
  • goal: goals that group and track work

Every node has a typed ID of the form kind:identifier. You'll use these with neighbors, callers, and anywhere else a node ID is expected:

PrefixFormatExample
file:file:<path>file:src/auth.rs
change:change:<hash>change:R4YQUAS2UZV5
view:view:<name>view:main
identity:did:atomic:<base32>did:atomic:R4YQUAS2UZV5...
intent:intent:<ULID> (upper-cased)intent:01KZE9KMFE9TGASXJRJTYYJ6X8
memory:memory:<ulid> (as stored)memory:01kze82jaq8b4akzagvqpqpswj
warning

An intent's node ID is its ULID, not its human key. A human key like TRAI::lee::4 is for CLI lookup and conversation only: intent:TRAI::lee::4 will not resolve as a node ID; the real ID is intent:01KZE9KMFE9TGASXJRJTYYJ6X8. Use atomic query search to discover the exact ID first. See Train Tracks demo and The Atomic Vault for the four identity forms of an intent (human key, bare UID, canonical RDF identity, and KG node ID).

Edges connect these nodes and encode the relationships between them: a change modifies files, an identity authors changes, an intent derives from the changes that implemented it. The full list of edge types is in Edge types at the end of this page.

Code entities (functions, structs, classes) are not persisted as KG nodes; see List what's in a file for live outlines.

Set up the graph​

Before you can query anything, you need to project the knowledge graph and keep it fresh as your code and vault change. This section covers when and how.

reindex: build the knowledge graph​

Run:

atomic query reindex --full

This projects the workflow ontology over your repository's changes and views:

Projecting workflow graph... ✓
Views: 3
Changes: 15
Identities: 2

KG generation: 2

You can re-run reindex --full at any time to reproject the graph. It's idempotent and replaces the derived KG tables atomically — the core VCS graph is never touched.

The first full writable open mints an unsigned upgrade identity if needed and reprojects the derived graph once. Lightweight, repair, and read-only opens do not run the migration. KG reads on an old generation report KgNeedsRebuild; ordinary repository reads remain available.

warning

Once a repository is reprojected to KG generation 2, older Atomic builds cannot open it — they lack the kg-semweb-v1 required capability. This is a one-way cutover.

Keeping the graph fresh: when to run what​

Which maintenance command you need depends on what has drifted:

  • Fresh clone, or after importing a Git repository or a large pull? Run atomic query reindex --full to project the KG. The KG doesn't update automatically. You control when it reprojects.
  • Git import refresh or post-record updates lagging? Run atomic query index --rebuild to fully rebuild the optional content index (or atomic query index --stats for an incremental update plus statistics). Code search itself reads recorded source through the view, so it never needs an index.
  • Using semantic/RAG features like ask? Run atomic query embed to (re)build the embeddings that power semantic search.
  • Vault content changed (new intents or memories)? Run atomic query reindex --full to reproject the KG from vault entries, and atomic vault sync if you also need to sync the vault itself.

index: update the optional content index​

Content search no longer uses an index, so this is optional. The content index remains for its maintenance consumers — Git import refresh and post-record updates — and you can still build or refresh it explicitly:

atomic query index --stats
Updating content index... done.
files: 42, segments: 3, index size: 1.2 MB
FlagDescription
--rebuildFull rebuild instead of incremental update
--statsShow index statistics after building

validate: evaluate SHACL shapes​

Run builtin or local enterprise SHACL shapes over the workflow snapshot:

atomic query validate --format json
atomic query validate --profile publication --format json
atomic query validate --shape <shape-iri> --node <resource-iri>

Validation runs locally in the CLI using PurRDF 3.0.1. Exit codes are 0 for conformance, 1 for violations, and 3 for shape or engine errors.

embed: rebuild embeddings for vault content​

atomic query embed
Using embedding provider: text-embedding-3-small (1536d)
Embedded 47 total chunks.
FlagDescription
-p, --path <PATH>Embed only a specific vault entry path
info

embed requires an API key for an embedding provider (OPENAI_API_KEY or similar). Embeddings power semantic search in the ask subcommand.

Ignored files and folders are not included

Anything your ignore patterns exclude is intentionally excluded from code intelligence too — not reprojected, not searchable, not graphed. See What's Indexed — and What's Intentionally Excluded below before you conclude a search is broken.

What's Indexed — and What's Intentionally Excluded​

Ignored files and folders are not included in the knowledge graph or in code search. They are intentionally excluded. Ignore patterns define what is not part of your project; code intelligence follows the same policy that status and add already follow.

With this .gitignore:

node_modules/
target/
dist/
*.log

…node_modules/, target/, dist/, and every *.log file are:

  • Not in code search — atomic query code "…" never returns a match from them
  • Not tracked, and therefore never appear as file: nodes or in search results
  • Not visualized by atomic query graph

This is deliberate, not a broken search. If a search doesn't find text you know exists, check whether the file matches an ignore pattern before debugging anything else.

Which ignore rules apply​

Rule sourceHonored by code intelligence
.gitignoreYes
.ignoreYes
.atomicignoreYes — and it wins on conflicting patterns, so a !pattern there re-includes something .gitignore excludes
Global ignore file (~/.atomic/ignore)Yes
Nested ignore files inside subdirectoriesNo — only the ignore files at the repository root are read

Atomic-internal paths are also excluded​

.atomic/, .git/, .vault/, and .atomic-sandbox* are never reprojected or searched. Vault content is already queryable through its own KG nodes (intent:, memory:, goal:), so a file:.vault/… node would only duplicate it.

Size and binary limits​

Recorded search also skips files larger than 10 MiB and files whose contents are detected as binary.

What happens when a file becomes ignored​

Ignore rules govern the discovery of new paths, so the effect depends on the surface:

Query surfaceBehavior for ignored paths
Content search (query code)Excluded. A pattern that starts matching a file removes it from results immediately — even if the file was already recorded — because search reads the view's current ignore rules on every query
VCS-derived KG nodes (file:, change:)A recorded change is an immutable fact: the nodes it created remain until atomic query reindex --full reconciles stale entries
Structure queries (query entities, query callers)Parsed on demand from tracked file contents, so a file that is tracked but currently ignored still parses

Making an ignored file searchable​

Remove the pattern (or re-include the path with ! in .atomicignore). Content search picks the change up on the next query — there is no index to rebuild. To reconcile the graph's file/change nodes as well:

atomic query reindex --full     # reproject the graph's file/change nodes
Why not search everything?

Ignored directories are where build output and dependencies live. Searching them multiplies the work every query does without adding signal — the same reason atomic status skips them. If you genuinely want a file in code intelligence, stop ignoring it.

Searching Source Code​

The code subcommand searches the recorded source in your current view. Atomic renders file bytes straight from the graph through the view's filter, so results reflect exactly what the view contains — including files that are recorded but not materialized on disk — with no index to build and no checkout required. Think of it as a view-accurate alternative to grep:

atomic query code "verify_token" -t rs
src/auth.rs:42: pub fn verify_token(token: &str) -> Result<Claims> {
src/auth.rs:55: let decoded = verify_token_signature(&token)?;
src/middleware.rs:23: let claims = auth::verify_token(&bearer)?;

3 match(es) in 2 file(s).

Options​

FlagDescription
<pattern>Search pattern (supports regex)
-t, --file-type <TYPE>Restrict to file type: rs, py, cpp, ts, etc.
-g, --path-filter <GLOB>Restrict to files matching a path glob
-n, --max-results <N>Maximum results (default: 30)
-i, --case-insensitiveCase-insensitive search
--jsonOutput as JSON

Faceted Results​

When there are more matches than the limit, code shows you how to narrow down:

atomic query code "replication" -t cpp
src/db/repl/coordinator.cpp:42: void ReplicationCoordinator::start() {
src/db/repl/coordinator.cpp:87: bool ReplicationCoordinator::replicate(OpLog& log) {
...

30 match(es) in 8 file(s).
(142 total matches — showing top 30. Narrow with -g or -t.)

Top directories:
-g "src/db/repl/" 87 matches
-g "src/db/storage/" 31 matches
-g "src/db/catalog/" 24 matches

This tells you exactly which -g filter to add to drill into the results you care about.

Find knowledge​

The search subcommand searches across all node types in the KG — files, changes, views, identities, and workflow resources — by keyword:

atomic query search "authentication"
  [file] file:src/auth.rs  Authentication module
[change] change:R4YQUAS2UZV5 fix: token validation edge case
[view] view:main Shared view, 42 changes

3 result(s).

Options​

FlagDescription
<query>Search query text
-k, --limit <N>Maximum results (default: 10)
-t, --kind <KIND>Filter by canonical class IRI, e.g. https://atomic.dev/ns/workflow#File (Change, File, View, Identity, WorkIntent, Goal, …)
--jsonOutput as JSON

Filtering by Kind​

Use -t to narrow results to a specific node class:

# Only changes
atomic query search "authentication" -t Change

# Only files
atomic query search "auth" -t File

# Only views
atomic query search "main" -t View
tip

search is structural — it finds nodes in the KG by their class, descriptions, and names. For finding text inside files, use code instead (Searching source code). Code entities (functions, structs, classes) are parsed live from source and are not KG nodes; use entities for file outlines.

Explore relationships​

The neighbors subcommand shows you everything connected to a node. Give it a node ID:

atomic query neighbors "file:src/auth.rs"
Nodes (4):
[change] change:R4YQUAS2UZV5 fix: token validation edge case
[change] change:ABC12345DEF6 feat: add session management
[view] view:main Shared view, 42 changes
[file] file:src/auth.rs Authentication module

Edges (4):
change:R4YQUAS2UZV5 →[https://atomic.dev/ns/workflow#modifiesFile]→ file:src/auth.rs
change:ABC12345DEF6 →[https://atomic.dev/ns/workflow#modifiesFile]→ file:src/auth.rs
change:R4YQUAS2UZV5 →[https://atomic.dev/ns/workflow#directlyOnView]→ view:main
change:ABC12345DEF6 →[https://atomic.dev/ns/workflow#directlyOnView]→ view:main

From this single query, you can see:

  • Which changes touched the file (modifiesFile edges)
  • Which view each change is on (directlyOnView edges)
  • The full neighborhood of related nodes

Code entities (functions, structs, classes) are not KG nodes — they're parsed live from source. Use the entities subcommand for file outlines.

Options​

FlagDescription
<node_id>Node ID to explore (see How the graph is organized)
-d, --depth <N>Traversal depth: 1 (direct neighbors) or 2 (neighbors of neighbors). Default: 1
--jsonOutput as JSON

Deeper Traversal​

Use --depth 2 to see two hops out from a node. This is useful for understanding indirect relationships (for example, which other files were modified by the same changes that touched your file):

atomic query neighbors "file:src/auth.rs" --depth 2

Exploring Changes​

You can also start from a change to see what it affected:

atomic query neighbors "change:R4YQUAS2UZV5"

This shows you the files modified, which view the change is on, and who authored it. Code entities touched by the change are parsed live from source — use entities <path> for file outlines.

Finding callers​

The callers subcommand answers the reverse question: what code calls this entity? Give it an entity ID and it finds the functions that call it, useful for a blast-radius check before you edit:

atomic query callers "entity:src/auth.rs:verify_token:42"
note

callers resolves the calls relations on demand from tracked file contents, so there is no KG rebuild to run first.

List what's in a file​

The entities subcommand parses a file with tree-sitter and lists all the structural entities it finds — functions, structs, classes, constants, traits, and more. Code entities are parsed live from source and are not persisted in the KG:

atomic query entities src/auth.rs
  function     verify_token                   L42-67   [exported]  pub fn verify_token(token: &str) -> Result<Claims>
function create_session L78-95 [exported] pub fn create_session(user: &User) -> Session
struct Claims L10-16 [exported] pub struct Claims
struct Session L18-25 [exported] pub struct Session
constant TOKEN_EXPIRY L8-8 [exported]

5 entity(ies) in src/auth.rs

This gives you a file outline with:

  • Entity kind (function, struct, constant, etc.)
  • Name and line range
  • Visibility ([exported] for public items)
  • Signature preview

Options​

FlagDescription
<path>File path relative to repo root
--jsonOutput as JSON
note

The entities subcommand requires tree-sitter support for the file's language. Rust, Python, TypeScript, JavaScript, C, C++, Go, Java, and many other languages are supported.

Visualize the graph​

The graph subcommand generates a visual representation of the knowledge graph seeded from a search query. By default, it produces an interactive HTML page with a D3 force-directed layout:

atomic query graph "authentication" -o auth.html
Wrote 23 nodes, 31 edges to auth.html

Open auth.html in a browser to explore the graph interactively: drag nodes, zoom, click to inspect.

To get a feel for what graph output corresponds to, here is the concept, a small slice of the knowledge graph around one file and the changes, identity, and view connected to it (illustrative, rendered as mermaid):

What atomic query graph output corresponds to: seed nodes (from your search query) plus their neighbors, expanded to --depth hops (the same structure neighbors shows), drawn visually instead of as text.

Output Formats​

HTML (default): interactive D3 force-directed graph:

atomic query graph "authentication" -o auth.html

DOT: Graphviz format, pipe to dot for SVG/PNG:

atomic query graph "authentication" --dot | dot -Tsvg -o auth-graph.svg

JSON: machine-readable nodes and edges:

atomic query graph "authentication" --json

Options​

FlagDescription
<query>Search query to seed the graph
-k, --limit <N>Maximum seed nodes from search (default: 10)
--depth <N>Neighbor expansion depth: 1 or 2 (default: 1)
-o, --output <PATH>Write to file (.html, .dot, or .json)
--jsonOutput JSON to stdout
--dotOutput DOT to stdout
--max-nodes <N>Maximum nodes (default: 5000 for HTML, 200 for DOT)
--kinds <KINDS>Comma-separated class IRI suffixes to include (e.g. Change,File,View)
--changes-per-seed <N>Max change nodes per seed during expansion (default: 5, 0 = unlimited)
tip

For large codebases, use --kinds to filter the visualization. For example, --kinds Change,File hides workflow nodes and shows only changes and files. Code entities are not KG nodes and won't appear in the graph.

Automate: plans and AI answers​

Structured Query Plans​

The plan subcommand executes a multi-step query plan from JSON on stdin. This is primarily used by tooling and agents that need to chain KG operations programmatically:

echo '{"steps":[{"type":"kg_search","query":"auth","limit":5}]}' | atomic query plan
Plan executed in 12ms (1 steps)

Step 1: kg_search → 5 results (12ms)

Nodes (5):
[entity] verify_token: Verifies JWT token signature
[file] src/auth.rs: Authentication module
...

Each step in the plan corresponds to a KG operation (search, neighbors, code search, etc.), and steps can reference results from previous steps. A realistic plan (illustrative) chains a search into a neighbors traversal of the top result:

{
"steps": [
{
"type": "kg_search",
"query": "authentication",
"limit": 3,
"id": "find_auth"
},
{
"type": "neighbors",
"node_id": "$find_auth[0].id",
"depth": 2
}
]
}

The output is a per-step report: each step echoes its type, reports timing and result counts, and prints the nodes/edges it produced; with --json, the same report is emitted as a machine-readable JSON object with one entry per step (including each step's results) so callers can consume them programmatically.

FlagDescription
--jsonMachine-readable output

Asking Questions with AI​

The ask subcommand combines the knowledge graph with an LLM to answer natural language questions about your codebase. It uses retrieval-augmented generation (RAG), querying the KG first, then passing relevant context to the model:

atomic query ask "what does the authentication module depend on?"
The authentication module (src/auth.rs) depends on:
- `jsonwebtoken` for JWT verification (verify_token_signature)
- `chrono` for token expiry validation
- The `Session` struct from the same module for session creation

— claude-sonnet-4-5 (3 turns, 4.2s, 1240 in + 312 out tokens)

Options​

FlagDescription
<question>Natural language question
-t, --max-turns <N>Maximum agentic tool-use turns (default: 5)
--jsonOutput as JSON (includes tool trace)
-v, --verboseShow live tool calls as they execute

The agent behind ask can use all the KG query tools (code, search, neighbors, entities) in a loop to find the answer, similar to how an AI coding agent explores a codebase.

note

Requires ANTHROPIC_API_KEY or OPENAI_API_KEY set in your environment. Without a key, ask falls back to search-only mode. It still shows relevant nodes, just no prose answer.

How agents use code intelligence​

When you install an agent integration like atomic-claude or atomic-codex, it includes a code-intelligence skill that teaches the agent to use atomic query commands instead of raw filesystem tools like grep and find.

The mapping works like this:

Agent goalQuery command
Find text in source codeatomic query code "pattern"
Find where something is definedatomic query search or entities
See what a file containsatomic query entities <path>
Understand dependenciesatomic query neighbors <node_id>
See what a change affectedatomic query neighbors "change:HASH"
Visual explorationatomic query graph "topic"

The recommended agent workflow is:

  1. code: find relevant source text (replaces grep)
  2. search: find structural relationships (replaces find + grep)
  3. neighbors: explore connections from any node
  4. entities: get a file outline without reading the whole file
  5. Read file: read only the specific lines you need

This approach is faster and more accurate than scanning the filesystem because the KG already knows the structure. An agent doesn't need to guess file paths or parse import statements. The relationships are pre-computed.

Empty results vs. ignored files

Ignored files and folders are intentionally excluded from the KG and from code search, so code and search return nothing for them. An agent should treat that as an answer, not a failure — and should not fall back to grep/find to read them. If the file genuinely matters, remove the ignore pattern.

tip

If your KG results seem sparse after a fresh import, run atomic query reindex --full to populate it. The agent skill instructions tell agents to do this automatically if queries return empty results.

→ Installing Agent Integrations

Edge types​

KG edges use absolute predicate IRIs from the Atomic workflow ontology (https://atomic.dev/ns/workflow#). In output, they're often shown in compact form (atomic:predicateName):

Edge (IRI)CompactFrom → ToMeaning
https://atomic.dev/ns/workflow#modifiesFileatomic:modifiesFilechange → fileThis change touched this file
https://atomic.dev/ns/workflow#authoredByatomic:authoredBychange → identityWho authored this change
https://atomic.dev/ns/workflow#directlyDependsOnChangeatomic:directlyDependsOnChangechange → changeThis change directly depends on another
https://atomic.dev/ns/workflow#directlyOnViewatomic:directlyOnViewchange → viewThis change is on this view
https://atomic.dev/ns/workflow#referencesatomic:referencesthing → thingGeneric reference relationship

Class assertions (e.g. rdf:type) are stored in kg_types, not as neighborhood edges. Use -t <Class> with search or neighbors to filter by class.

What's next​