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
| Field | Type | Default | Description |
|---|---|---|---|
default_depth | int | 2 | Maximum BFS hops from root entity |
decay_factor | float | 0.6 | Relevance multiplier per hop. At depth 2: weight × 0.6² |
token_budget | int | 4000 | Maximum output size in tokens (~4 chars per token) |
min_relevance | float | 0.05 | Drop nodes below this relevance threshold |
exclude_test_files | bool | true | Exclude *_test.go and similar test files |
direction_boost | float | 0.2 | Bonus for outgoing CALLS edges (callees) |
How It Works
- Start at the target entity (root node)
- BFS outward along graph edges
- Each hop multiplies relevance by
decay_factor - Edge weight modulates relevance:
relevance = edge_weight × decay^depth - Nodes below
min_relevanceare dropped - Results are token-budgeted — highest relevance nodes included first
- 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.15default — 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_budgetto 8000. - Large monorepos: Consider lower
decay_factor(0.4) to stay focused, or lowerdefault_depthto 1. - Debugging: Use intent
"debug"which auto-adjusts weights to trace data flow upstream. - Code review: Use intent
"review"which emphasizes interface contracts.