SynapsesOS
Reference

Context Carving

Context Carving Configuration

Context carving controls how Synapses extracts a relevant subgraph around a target entity. It uses BFS (Breadth-First Search) with decay to build a token-budgeted context slice.

{
"context_carve": {
"default_depth": 2,
"decay_factor": 0.6,
"token_budget": 4000,
"min_relevance": 0.05,
"exclude_test_files": true,
"direction_boost": 0.2
}
}

Fields

FieldTypeDefaultDescription
default_depthint2Maximum BFS hops from root entity
decay_factorfloat0.6Relevance multiplier per hop. At depth 2: weight × 0.6²
token_budgetint4000Maximum output size in tokens (~4 chars per token)
min_relevancefloat0.05Drop nodes below this relevance threshold
exclude_test_filesbooltrueExclude *_test.go and similar test files
direction_boostfloat0.2Bonus for outgoing CALLS edges (callees)

How It Works

  1. Start at the target entity (root node)
  2. BFS outward along graph edges
  3. Each hop multiplies relevance by decay_factor
  4. Edge weight modulates relevance: relevance = edge_weight × decay^depth
  5. Nodes below min_relevance are dropped
  6. Results are token-budgeted — highest relevance nodes included first
  7. Output formatted as compact context with signatures, relationships, and metadata

Advanced: Personalized PageRank

For large codebases, Synapses can use PPR (Personalized PageRank) instead of BFS for more accurate relevance scoring:

  • Alpha (teleport probability): 0.15 default — higher = more focused on root
  • HybridLambda: Blend between structural and semantic similarity (0.0-1.0)
  • CrossDomainDecay: Penalty when crossing domain boundaries (default 0.5)

PPR is enabled automatically for large projects or when use_flat_graph is true.

Tuning Tips

  • Small projects: Default depth 2 is fine. You might increase token_budget to 8000.
  • Large monorepos: Consider lower decay_factor (0.4) to stay focused, or lower default_depth to 1.
  • Debugging: Use intent "debug" which auto-adjusts weights to trace data flow upstream.
  • Code review: Use intent "review" which emphasizes interface contracts.