You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
graph=ProjectRelationshipGraph()
# Add projectgraph.add_project(project_metadata)
# Get projectproject=graph.get_project("project-id")
# List all projectsprojects=graph.list_projects()
# Update projectgraph.update_project("project-id", {"indexed": True})
# Remove projectgraph.remove_project("project-id")
Edge Operations
# Add relationshipgraph.add_relationship(
from_id="frontend",
to_id="backend",
rel_type=RelationshipType.API_CLIENT,
weight=0.9, # 0.0-1.0, default: 1.0description="Frontend calls API",
metadata={ # Optional custom data"api_endpoints": ["/api/users"],
}
)
# Get relationshiprel=graph.get_relationship("frontend", "backend")
# List relationships (all or for specific project)all_rels=graph.list_relationships()
project_rels=graph.list_relationships("frontend")
# Remove relationshipgraph.remove_relationship("frontend", "backend")
Dependency Analysis
# Get dependencies (direct)deps=graph.get_dependencies("project-id", depth=1)
# Get transitive dependenciesdeps=graph.get_dependencies("project-id", depth=2)
# Get reverse dependencies (who depends on me)dependents=graph.get_dependents("project-id")
# Get related projects by similarityrelated=graph.get_related_projects(
"project-id",
threshold=0.7# Minimum similarity score
)
# Returns: [(project_id, score), ...]
Cycle Detection
# Check for cycleshas_cycles=graph.has_circular_dependencies()
# Detect all cyclescycles=graph.detect_circular_dependencies()
# Returns: [['a', 'b', 'c'], ...]# Get topological order (build order)order=graph.get_topological_order()
# Returns: ['project1', 'project2', ...] or None if cycles exist
# Save to JSONjson_str=graph.to_json("/path/to/graph.json")
# Load from JSONgraph=ProjectRelationshipGraph.from_json(file_path="/path/to/graph.json")
# Or from stringgraph=ProjectRelationshipGraph.from_json(json_str=json_str)
Visualization
# Export to Graphviz DOTdot_str=graph.export_dot("/path/to/graph.dot")
# Render with Graphviz (if installed)# dot -Tpng graph.dot -o graph.png
Caching
# Clear similarity cachegraph.clear_similarity_cache()
# Refresh all cachesgraph.refresh_cache()
# Cache is automatically invalidated on updates
# Projects must exist before adding relationshipstry:
graph.add_relationship("unknown1", "unknown2", RelationshipType.IMPORTS)
exceptValueErrorase:
print(f"Error: {e}") # Both projects must exist in the graph# Robust file operationstry:
summary=awaitdiscover_workspace_relationships(graph, projects)
exceptFileNotFoundError:
print("Project path does not exist")
exceptPermissionError:
print("Permission denied reading project files")
Performance Tips
Use depth parameter wisely - depth=1 is much faster than depth=3+