Flowcharts & Graphs
Overview
The Flowcharts & Graphs module allows AI agents to interpret structural visual data that is traditionally difficult for LLMs to process. By converting visual logic, hierarchies, and relational nodes into structured data formats, Deeptrain enables your models to perform reasoning over business processes, system architectures, and data relationship maps.
Supported Content Types
Deeptrain can parse a wide variety of structural diagrams, including but not limited to:
- Flowcharts: Process maps, decision trees, and workflow diagrams.
- Relational Graphs: Network topologies, entity-relationship diagrams (ERDs), and knowledge graphs.
- Organizational Charts: Hierarchical structures and reporting lines.
- Technical Diagrams: UML diagrams, circuit schematics, and system architectures.
Basic Usage
To process a flowchart or graph, use the VisualParser interface. This converts an image or document into a structured representation (JSON or GraphML) that can be injected directly into your LLM's context.
from deeptrain import VisualParser
# Initialize the parser
parser = VisualParser(mode="structural")
# Process a flowchart image
result = parser.parse_graph(
source="path/to/workflow_diagram.png",
output_format="json",
detect_relationships=True
)
# Access the structured data
print(result['nodes']) # List of steps/entities
print(result['edges']) # List of connections and logic paths
API Reference
parse_graph()
The primary method for extracting structural logic from visual inputs.
| Parameter | Type | Description |
| :--- | :--- | :--- |
| source | str | Path to the image file, PDF, or a URL. |
| output_format | str | Format of the returned data: "json", "graphml", or "text_description". |
| detect_relationships| bool | Whether to identify directional arrows and logic gates (default: True). |
| ocr_engine | str | The engine used for text extraction within nodes ("standard" or "enhanced"). |
Returns:
- A
dictorstrcontaining the nodes (entities), edges (connections), and any text labels associated with the diagram.
Integrating with AI Agents
When utilizing Deeptrain with an LLM agent, the output of the Flowcharts & Graphs module acts as a bridge between visual logic and text-based reasoning.
Example: Reasoning over a Decision Tree
import deeptrain
from deeptrain.agents import DataConnector
# Connect the visual data to your LLM agent
connector = DataConnector(model="gpt-4-turbo")
# Map the flowchart logic to the agent's memory
graph_context = deeptrain.parse_graph("troubleshooting_flow.jpg")
connector.add_context(graph_context)
# The agent can now answer complex questions based on the diagram
response = connector.query("What are the steps to take if the 'System Check' fails?")
Configuration & Tuning
To improve accuracy for complex diagrams, you can configure the StructuralSensitivity parameters:
- Node Detection: Adjust the threshold for identifying shapes (rectangles, circles, diamonds) as logical entities.
- Edge Connectivity: Fine-tune the logic that determines how lines and arrows connect disparate nodes.
- Label Mapping: Ensures that text found near a node or on a connecting line is correctly attributed to that specific logical element.
Note: For handwritten flowcharts or low-resolution diagrams, we recommend using the
enhancedOCR engine setting to ensure high fidelity in text-to-node mapping.