get_graph_neighborhoodΒΆ
Extract a focused subgraph containing nodes within k hops of a center node. Prevents graph explosion when analyzing large codebases.
Quick ReferenceΒΆ
get_graph_neighborhood(
center_node_id: str, # Center node ID
k: int = 2, # Max hops from center
max_nodes: int = 100, # Max nodes to include
direction: str = "both", # outgoing, incoming, or both
min_confidence: float = 0.0, # Min edge confidence
project_root: str = None, # Project directory
query: str = None # Graph query (Enterprise)
) -> GraphNeighborhood
User StoriesΒΆ
| Persona | Story | Tool Value |
|---|---|---|
| π§ Chris (OSS Contributor) | "Extract focused subgraph for targeted analysis without loading entire codebase" | Memory efficiency |
| π’ Jennifer (Enterprise Architect) | "Analyze k-hop neighborhoods in large monorepos without memory exhaustion" | Enterprise-scale analysis |
| π₯ David (Team Lead) | "Focus on relevant code sections during impact analysis" | Focused reviews |
ParametersΒΆ
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
center_node_id | string | Yes | - | Node ID (format: lang::module::type::name) |
k | int | No | 2 | Maximum hops from center |
max_nodes | int | No | 100 | Maximum nodes to include |
direction | string | No | "both" | "outgoing", "incoming", or "both" |
min_confidence | float | No | 0.0 | Minimum edge confidence |
project_root | string | No | cwd | Project root directory |
query | string | No | None | Graph query language (Enterprise) |
Node ID FormatΒΆ
Node IDs follow the pattern: language::module::type::name
Examples: - python::services::function::process_order - python::models.user::class::User - python::utils::function::validate_email
Response SchemaΒΆ
{
"data": {
"center_node": "string",
"k": "integer",
"nodes": [
{
"id": "string",
"name": "string",
"type": "string",
"file": "string",
"line": "integer",
"distance": "integer"
}
],
"edges": [
{
"source": "string",
"target": "string",
"type": "string",
"confidence": "float"
}
],
"truncated": "boolean",
"truncation_warning": "string | null",
"mermaid_diagram": "string"
},
"tier_applied": "string",
"duration_ms": "integer"
}
ExamplesΒΆ
Get 2-Hop NeighborhoodΒΆ
{
"data": {
"center_node": "python::services::function::process_order",
"k": 2,
"nodes": [
{
"id": "python::services::function::process_order",
"name": "process_order",
"type": "function",
"file": "services/order_service.py",
"line": 45,
"distance": 0
},
{
"id": "python::validators::function::validate_order",
"name": "validate_order",
"file": "validators/order.py",
"line": 10,
"distance": 1
},
{
"id": "python::db::function::save_order",
"name": "save_order",
"file": "db/orders.py",
"line": 25,
"distance": 1
},
{
"id": "python::db::function::execute_query",
"name": "execute_query",
"file": "db/connection.py",
"line": 15,
"distance": 2
},
{
"id": "python::validators::function::validate_items",
"name": "validate_items",
"file": "validators/items.py",
"line": 5,
"distance": 2
}
],
"edges": [
{"source": "process_order", "target": "validate_order", "type": "calls"},
{"source": "process_order", "target": "save_order", "type": "calls"},
{"source": "save_order", "target": "execute_query", "type": "calls"},
{"source": "validate_order", "target": "validate_items", "type": "calls"}
],
"truncated": false,
"mermaid_diagram": "graph TD\n process_order((process_order))\n process_order --> validate_order\n process_order --> save_order\n save_order --> execute_query\n validate_order --> validate_items"
},
"tier_applied": "community",
"duration_ms": 95
}
Outgoing Calls OnlyΒΆ
{
"data": {
"center_node": "UserService.get_user",
"direction": "outgoing",
"nodes": [
{"id": "...", "name": "get_user", "distance": 0},
{"id": "...", "name": "validate_id", "distance": 1},
{"id": "...", "name": "query_user", "distance": 1},
{"id": "...", "name": "execute_query", "distance": 2}
],
"edges": [
{"source": "get_user", "target": "validate_id"},
{"source": "get_user", "target": "query_user"},
{"source": "query_user", "target": "execute_query"}
]
}
}
Incoming Calls (Callers)ΒΆ
{
"data": {
"center_node": "execute_query",
"direction": "incoming",
"nodes": [
{"name": "execute_query", "distance": 0},
{"name": "save_order", "distance": 1},
{"name": "get_user", "distance": 1},
{"name": "process_order", "distance": 2},
{"name": "handle_request", "distance": 2}
],
"edges": [
{"source": "save_order", "target": "execute_query"},
{"source": "get_user", "target": "execute_query"},
{"source": "process_order", "target": "save_order"},
{"source": "handle_request", "target": "get_user"}
]
}
}
With TruncationΒΆ
High Confidence Edges OnlyΒΆ
Graph Query Language (Enterprise)ΒΆ
Enterprise tier supports a query language:
{
"center_node_id": "python::controllers::function::handle_request",
"query": "MATCH (n)-[:calls]->(m:function) WHERE m.name CONTAINS 'DB' RETURN n, m"
}
Mermaid DiagramΒΆ
The tool generates neighborhood visualizations:
graph TD
center((process_order))
center --> validate_order
center --> save_order
validate_order --> validate_items
save_order --> execute_query
style center fill:#f96 Tier DifferencesΒΆ
This tool is available at all tiers. What differs are the limits and capabilities:
| Feature | Community | Pro | Enterprise |
|---|---|---|---|
| Availability | β Available | β Available | β Available |
| Basic neighborhood | β | β | β |
| Max k (hops) | 2 | 5 | Unlimited |
| Max nodes | 50 | 200 | Unlimited |
| K-hop traversal | β | β | β |
| Direction filter | β | β | β |
| Confidence filter | Not available | β | β |
| Semantic neighbors | Not available | β Similar functions | β Advanced |
| Graph query language | Not available | Not available | β Custom queries |
Use CasesΒΆ
1. Impact AnalysisΒΆ
# Before changing a function, see what it affects
result = get_graph_neighborhood(
center_node_id="python::utils::function::calculate_total",
k=3,
direction="incoming" # What calls this?
)
2. Security AnalysisΒΆ
# Find path from user input to database
# Start from a known sink
result = get_graph_neighborhood(
center_node_id="python::db::function::execute_query",
k=5,
direction="incoming",
min_confidence=0.7
)
# Check if any nodes are user input sources
3. Focused RefactoringΒΆ
# Extract subgraph for a specific feature
result = get_graph_neighborhood(
center_node_id="python::services::function::process_payment",
k=2,
direction="both"
)
# combined_code shows what's needed for the payment feature
Tier LimitsΒΆ
get_graph_neighborhood capabilities vary by tier:
| Feature | Community | Pro | Enterprise |
|---|---|---|---|
| Max k-hops | 1 | 5 | Unlimited |
| Max nodes | 20 | 100 | Unlimited |
| Direction filtering | β | β | β |
| Confidence filtering | β | β | β |
| Mermaid diagrams | β | β | β Enhanced |
| Semantic neighbors | β | β | β |
| Logical relationships | β | β | β |
| Graph query language | β | β | β |
Community TierΒΆ
- β Extract 1-hop neighborhood around any node
- β Filter by edge direction (incoming/outgoing/both)
- β Filter by minimum confidence score
- β Basic Mermaid visualization
- β οΈ Max k=1 - Only immediate neighbors
- β οΈ Max 20 nodes - Small subgraphs only
- β No semantic neighbor detection
- β No graph query language
Pro TierΒΆ
- β All Community features
- β Max k=5 - Multi-hop neighborhood exploration
- β Max 100 nodes - Larger subgraphs
- β Semantic neighbors - Find conceptually related nodes
- β Logical relationships - Understand node connections
- β Enhanced visualization - Better Mermaid diagrams
- β Truncation warnings - Know when graph is incomplete
Enterprise TierΒΆ
- β All Pro features
- β Unlimited k-hops - Complete neighborhood
- β Unlimited nodes - No size restrictions
- β Graph query language - Custom queries (e.g., "MATCH (n)-[:calls]->(m:function) WHERE m.name CONTAINS 'DB' RETURN n, m")
- β Advanced relationship detection - Deep semantic analysis
- β Interactive exploration - Navigate graph dynamically
Key Difference: Neighborhood Size and Queries - Community: k=1, 20 nodes - Immediate neighbors only - Pro: k=5, 100 nodes, semantic neighbors - Multi-hop exploration - Enterprise: Unlimited k, unlimited nodes, query language - Complete graph analysis
Best PracticesΒΆ
- Start with small k - Increase if needed
- Use direction - Focus on callers OR callees
- Set max_nodes - Prevent memory issues
- Check truncation - Results may be incomplete
- Use for focused analysis - Not full project graphs
Related ToolsΒΆ
- get_call_graph - Full project call graph
- get_cross_file_dependencies - Dependency chains
- get_project_map - Project overview