this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add comprehensive CLI and REPL documentation

- Create complete CLI.md guide with all CLI features and commands
- Add extensive cli-examples.md with practical usage scenarios
- Update main README.md to prominently feature CLI capabilities
- Enhance docs/README.md with CLI configuration and usage
- Update examples/README.md to include CLI examples category
- Document interactive REPL, administrative commands, and batch processing
- Include troubleshooting, performance tips, and integration examples
- Add comprehensive command reference and output format examples

๐Ÿค– Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

+1351 -35
+49 -26
README.md
··· 6 6 7 7 - **๐Ÿš€ High Performance**: In-memory storage with optimized data structures 8 8 - **๐Ÿ“Š Cypher Support**: Neo4j-compatible query language 9 + - **๐Ÿ’ป Interactive CLI**: Comprehensive command-line interface with REPL 9 10 - **๐Ÿ” Graph Algorithms**: Built-in pathfinding, centrality, and community detection 10 11 - **๐ŸŒ Dual APIs**: Both REST and gRPC interfaces 11 12 - **๐Ÿ” Authentication**: JWT-based auth with role-based access control 12 13 - **๐Ÿ’พ Persistence**: Optional RocksDB backend for data durability 13 14 - **๐Ÿ“ˆ Monitoring**: Built-in metrics and observability 14 15 - **โœ… Schema Validation**: Comprehensive constraint system for data integrity 16 + - **๐Ÿ“ฅ๐Ÿ“ค Data Management**: JSON/CSV import/export capabilities 15 17 16 18 ## ๐Ÿš€ Quick Start 17 19 ··· 30 32 cargo run --bin gigabrain 31 33 ``` 32 34 35 + ### Using the CLI 36 + 37 + ```bash 38 + # Build and start the interactive CLI 39 + cargo build --release --bin gigabrain-cli 40 + ./target/release/gigabrain-cli 41 + 42 + # Interactive REPL usage 43 + gigabrain> CREATE (alice:Person {name: 'Alice', age: 30}) 44 + gigabrain> MATCH (n:Person) RETURN n.name, n.age 45 + gigabrain> :stats 46 + gigabrain> :help 47 + 48 + # Single command execution 49 + ./target/release/gigabrain-cli --execute "MATCH (n) RETURN count(n)" 50 + 51 + # Batch file processing 52 + ./target/release/gigabrain-cli --file my_queries.cypher 53 + ``` 54 + 33 55 ### Basic Usage 34 56 35 57 ```bash ··· 57 79 58 80 ## ๐Ÿ“š Documentation 59 81 82 + - **[CLI Guide](./docs/CLI.md)** - Complete command-line interface documentation 60 83 - **[API Reference](./docs/API.md)** - Complete REST and gRPC API documentation 61 84 - **[Architecture Guide](./docs/ARCHITECTURE.md)** - Technical architecture and design decisions 62 85 - **[Examples](./docs/examples/)** - Practical usage examples and tutorials ··· 65 88 ## ๐Ÿ—๏ธ Architecture 66 89 67 90 ``` 68 - โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” 69 - โ”‚ REST API โ”‚ โ”‚ gRPC API โ”‚ 70 - โ”‚ (Port 3000) โ”‚ โ”‚ (Port 50051) โ”‚ 71 - โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ 72 - โ”‚ โ”‚ 73 - โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ 74 - โ”‚ 75 - โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” 76 - โ”‚ API Layer โ”‚ 77 - โ”‚ (Auth/Routing) โ”‚ 78 - โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ 79 - โ”‚ 80 - โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” 81 - โ”‚ Query Engine โ”‚ 82 - โ”‚ (Cypher Parser) โ”‚ 83 - โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ 84 - โ”‚ 85 - โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” 86 - โ”‚ Graph Engine โ”‚ 87 - โ”‚ (Core Storage) โ”‚ 88 - โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ 89 - โ”‚ 90 - โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” 91 - โ”‚ Storage Layer โ”‚ 92 - โ”‚ (Memory/RocksDB)โ”‚ 93 - โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ 91 + โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” 92 + โ”‚ CLI/REPL โ”‚ โ”‚ REST API โ”‚ โ”‚ gRPC API โ”‚ 93 + โ”‚ Interface โ”‚ โ”‚ (Port 3000) โ”‚ โ”‚ (Port 50051) โ”‚ 94 + โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ 95 + โ”‚ โ”‚ โ”‚ 96 + โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ 97 + โ”‚ 98 + โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” 99 + โ”‚ API Layer โ”‚ 100 + โ”‚ (Auth/Routing) โ”‚ 101 + โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ 102 + โ”‚ 103 + โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” 104 + โ”‚ Query Engine โ”‚ 105 + โ”‚ (Cypher Parser) โ”‚ 106 + โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ 107 + โ”‚ 108 + โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” 109 + โ”‚ Graph Engine โ”‚ 110 + โ”‚ (Core Storage) โ”‚ 111 + โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ 112 + โ”‚ 113 + โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” 114 + โ”‚ Storage Layer โ”‚ 115 + โ”‚ (Memory/RocksDB)โ”‚ 116 + โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ 94 117 ``` 95 118 96 119 ## ๐ŸŽฏ Use Cases
+745
docs/CLI.md
··· 1 + # GigaBrain CLI and REPL Interface 2 + 3 + The GigaBrain CLI provides a comprehensive command-line interface for interacting with the graph database. It includes an interactive REPL (Read-Eval-Print Loop), administrative commands, and batch processing capabilities. 4 + 5 + ## Installation and Setup 6 + 7 + ### Building the CLI 8 + 9 + ```bash 10 + cargo build --release --bin gigabrain-cli 11 + ``` 12 + 13 + The CLI binary will be located at `target/release/gigabrain-cli`. 14 + 15 + ### Running the CLI 16 + 17 + ```bash 18 + # Start interactive REPL (default mode) 19 + ./gigabrain-cli 20 + 21 + # Show help 22 + ./gigabrain-cli --help 23 + 24 + # Execute single command 25 + ./gigabrain-cli --execute "MATCH (n) RETURN n" 26 + 27 + # Execute commands from file 28 + ./gigabrain-cli --file commands.cypher 29 + 30 + # Show graph statistics 31 + ./gigabrain-cli stats 32 + ``` 33 + 34 + ## Command Line Options 35 + 36 + ### Global Flags 37 + 38 + | Flag | Description | 39 + |------|-------------| 40 + | `--help`, `-h` | Show help information | 41 + | `--version`, `-V` | Show version information | 42 + | `--no-history` | Disable command history | 43 + | `--no-timing` | Disable query timing display | 44 + | `--silent`, `-s` | Suppress welcome messages and prompts | 45 + 46 + ### Global Options 47 + 48 + | Option | Description | Default | 49 + |--------|-------------|---------| 50 + | `--format <FORMAT>` | Output format: table, json, csv, plain | table | 51 + | `--execute <COMMAND>`, `-e` | Execute single command and exit | - | 52 + | `--file <FILE>`, `-f` | Execute commands from file | - | 53 + | `--history-file <FILE>` | Custom history file location | .gigabrain_history | 54 + | `--prompt <PROMPT>` | Custom prompt string | "gigabrain> " | 55 + 56 + ### Subcommands 57 + 58 + | Subcommand | Description | 59 + |------------|-------------| 60 + | `repl` | Start interactive REPL (default) | 61 + | `exec <COMMAND>` | Execute a single command | 62 + | `import <FILE>` | Import data from file | 63 + | `export <FILE>` | Export data to file | 64 + | `stats` | Show graph statistics | 65 + | `benchmark` | Run performance benchmark | 66 + 67 + ## Interactive REPL 68 + 69 + ### Starting the REPL 70 + 71 + ```bash 72 + ./gigabrain-cli 73 + ``` 74 + 75 + The REPL provides an interactive shell with: 76 + - Command history with persistent storage 77 + - Tab completion for Cypher keywords 78 + - Multiline query support 79 + - Real-time query timing 80 + - Pretty-printed table output 81 + 82 + ### REPL Welcome Screen 83 + 84 + ``` 85 + โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ 86 + โ”‚ GigaBrain Graph Database โ”‚ 87 + โ”‚ Interactive CLI v0.1.0 โ”‚ 88 + โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ 89 + 90 + Welcome to the GigaBrain interactive shell! 91 + Type ':help' for available commands or start typing Cypher queries. 92 + Use ':exit' to quit. 93 + 94 + gigabrain> 95 + ``` 96 + 97 + ### Basic REPL Usage 98 + 99 + ```cypher 100 + gigabrain> CREATE (alice:Person {name: 'Alice', age: 30}) 101 + (no columns returned) 102 + 103 + 0 rows returned 104 + (Query completed in 1.23ms) 105 + 106 + gigabrain> MATCH (n:Person) RETURN n.name, n.age 107 + โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ 108 + โ”‚ name โ”‚ age โ”‚ 109 + โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค 110 + โ”‚ (data) โ”‚ (data) โ”‚ 111 + โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ 112 + 113 + 1 rows returned 114 + (Query completed in 0.56ms) 115 + ``` 116 + 117 + ## Meta Commands 118 + 119 + Meta commands start with `:` or `\` and provide CLI-specific functionality. 120 + 121 + ### Help and Information 122 + 123 + | Command | Description | 124 + |---------|-------------| 125 + | `:help`, `:h` | Show comprehensive help | 126 + | `:stats` | Display graph statistics | 127 + | `:show <type>` | Show nodes, relationships, or schema | 128 + 129 + ### Configuration 130 + 131 + | Command | Description | 132 + |---------|-------------| 133 + | `:format <type>` | Set output format (table, json, csv, plain) | 134 + | `:timing` | Toggle timing display on/off | 135 + 136 + ### Session Management 137 + 138 + | Command | Description | 139 + |---------|-------------| 140 + | `:history` | Show recent command history | 141 + | `:clear` | Clear the screen | 142 + | `:exit`, `:quit`, `:q` | Exit the CLI | 143 + 144 + ### Data Operations 145 + 146 + | Command | Description | 147 + |---------|-------------| 148 + | `:export <file>` | Export graph data to JSON file | 149 + | `:import <file>` | Import graph data from JSON file | 150 + 151 + ## Administrative Commands 152 + 153 + ### Graph Analysis 154 + 155 + #### Structure Analysis 156 + ```bash 157 + gigabrain> :show nodes 158 + Nodes (15 total): 159 + 1: Node { id: NodeId(1), labels: ["Person"], properties: {...} } 160 + 2: Node { id: NodeId(2), labels: ["Person"], properties: {...} } 161 + ... 162 + 163 + gigabrain> :show relationships 164 + Relationships: 165 + 1: Relationship { id: RelId(1), start: NodeId(1), end: NodeId(2), type: "KNOWS" } 166 + ... 167 + 168 + gigabrain> :show schema 169 + Schema: 170 + Labels: ["Person", "Company", "Product"] 171 + Property Keys: ["name", "age", "email", "founded"] 172 + Relationship Types: ["KNOWS", "WORKS_FOR", "PURCHASED"] 173 + ``` 174 + 175 + #### Performance Analysis 176 + ```bash 177 + gigabrain> :stats 178 + Graph Statistics: 179 + Nodes: 15,432 180 + Relationships: 42,156 181 + Labels: 8 182 + Property Keys: 23 183 + Relationship Types: 12 184 + Estimated Memory: 2,847,392 bytes 185 + ``` 186 + 187 + ### Backup and Restore 188 + 189 + #### Creating Backups 190 + ```bash 191 + # Create backup 192 + backup graph_backup_20231201.json 193 + 194 + # Backup with analysis 195 + Backup created: graph_backup_20231201.json 196 + Nodes: 15432, Relationships: 42156, Size: 12458392 bytes 197 + ``` 198 + 199 + #### Restoring from Backup 200 + ```bash 201 + # Restore from backup 202 + restore graph_backup_20231201.json 203 + 204 + # Restore status 205 + Restore completed: 15432 nodes, 42156 relationships restored 206 + ``` 207 + 208 + ### Performance Operations 209 + 210 + #### Graph Optimization 211 + ```bash 212 + optimize 213 + 214 + Graph Optimization: 215 + โœ“ Memory layout optimized 216 + โœ“ Index structures rebuilt 217 + โœ“ Cache cleared and warmed 218 + โœ“ Internal statistics updated 219 + ``` 220 + 221 + #### Vacuum Operations 222 + ```bash 223 + vacuum 224 + 225 + Graph Vacuum: 226 + โœ“ Removed deleted nodes and relationships 227 + โœ“ Compacted storage structures 228 + โœ“ Rebuilt internal indexes 229 + โœ“ Freed unused memory 230 + ``` 231 + 232 + #### Benchmarking 233 + ```bash 234 + benchmark 235 + 236 + Performance Benchmark: 237 + Node Creation: 1000 nodes in 2.34ms (427,350.43 nodes/sec) 238 + Relationship Creation: 999 rels in 3.12ms (320,192.31 rels/sec) 239 + Query Performance: 100 queries in 1.89ms (52,910.05 queries/sec) 240 + ``` 241 + 242 + ### Graph Analysis Commands 243 + 244 + #### Connectivity Analysis 245 + ```bash 246 + analyze connectivity 247 + 248 + Connectivity Analysis: 249 + Connected Components: 3 250 + Largest Component: 12,847 nodes 251 + Smallest Component: 2 nodes 252 + Average Component Size: 5,144.00 nodes 253 + Component Size Distribution: 254 + Size 12847: 1 components 255 + Size 2585: 1 components 256 + Size 2: 1 components 257 + ``` 258 + 259 + #### Performance Analysis 260 + ```bash 261 + analyze performance 262 + 263 + Performance Analysis: 264 + Basic Stats Time: 1.23ms 265 + Average Query Time: 0.45ms 266 + Sample Size: 100 nodes 267 + Estimated Memory: 2,847,392 bytes (2.71 MB) 268 + Query Time Range: 0.12ms - 1.89ms 269 + ``` 270 + 271 + #### Structure Analysis 272 + ```bash 273 + analyze structure 274 + 275 + Graph Structure Analysis: 276 + Nodes: 15,432 277 + Relationships: 42,156 278 + Labels: 8 279 + Property Keys: 23 280 + Relationship Types: 12 281 + Average Degree: 5.46 282 + Degree Range: 0 - 234 283 + Most Common Degrees: 284 + Degree 1: 3,242 nodes 285 + Degree 2: 2,891 nodes 286 + Degree 3: 2,156 nodes 287 + Degree 4: 1,842 nodes 288 + Degree 5: 1,467 nodes 289 + ``` 290 + 291 + ## Data Import/Export 292 + 293 + ### JSON Import/Export 294 + 295 + #### Exporting Data 296 + ```bash 297 + # Export entire graph 298 + export-json graph_export.json 299 + Exported 57588 items to graph_export.json 300 + 301 + # Using meta command 302 + :export graph_data.json 303 + Graph exported to: graph_data.json 304 + ``` 305 + 306 + #### Importing Data 307 + ```bash 308 + # Import from JSON 309 + import-json graph_data.json 310 + Imported 57588 items from graph_data.json 311 + 312 + # Using meta command 313 + :import graph_data.json 314 + Imported 57588 items from: graph_data.json 315 + ``` 316 + 317 + ### CSV Import/Export 318 + 319 + #### CSV Export 320 + ```bash 321 + # Export to CSV with default query 322 + export-csv nodes.csv 323 + Exported 15432 records to nodes.csv 324 + 325 + # Export with custom query 326 + export-csv relationships.csv "MATCH (a)-[r]->(b) RETURN a.name, type(r), b.name" 327 + Exported 42156 records to relationships.csv 328 + ``` 329 + 330 + #### CSV Import 331 + ```bash 332 + # Import from CSV 333 + import-csv data.csv 334 + Imported 1000 records from data.csv 335 + ``` 336 + 337 + ### File Format Examples 338 + 339 + #### JSON Export Format 340 + ```json 341 + { 342 + "version": "1.0", 343 + "timestamp": "2023-12-01T15:30:45Z", 344 + "stats": { 345 + "nodes": 15432, 346 + "relationships": 42156, 347 + "labels": 8, 348 + "property_keys": 23, 349 + "relationship_types": 12 350 + }, 351 + "nodes": [ 352 + { 353 + "id": 1, 354 + "labels": ["Person"], 355 + "properties": { 356 + "name": "Alice", 357 + "age": 30 358 + } 359 + } 360 + ], 361 + "relationships": [ 362 + { 363 + "id": 1, 364 + "start_node": 1, 365 + "end_node": 2, 366 + "type": "KNOWS", 367 + "properties": {} 368 + } 369 + ] 370 + } 371 + ``` 372 + 373 + ## Index and Constraint Management 374 + 375 + ### Index Operations 376 + ```bash 377 + # List indexes 378 + index list 379 + Available Indexes: 380 + (Index management not yet implemented) 381 + 382 + # Create index 383 + index create Person name 384 + Index created on Person:name (placeholder) 385 + 386 + # Drop index 387 + index drop Person name 388 + Index dropped on Person:name (placeholder) 389 + ``` 390 + 391 + ### Constraint Operations 392 + ```bash 393 + # List constraints 394 + constraint list 395 + Schema Constraints: 396 + Validation Rules: 397 + (Constraint listing not yet implemented) 398 + 399 + # Create constraint 400 + constraint create Person name UNIQUE 401 + Constraint creation (placeholder) 402 + 403 + # Drop constraint 404 + constraint drop Person name UNIQUE 405 + Constraint removal (placeholder) 406 + ``` 407 + 408 + ## File-Based Command Execution 409 + 410 + ### Command Files 411 + 412 + Create a file with Cypher commands and comments: 413 + 414 + ```cypher 415 + # commands.cypher 416 + # Create sample data 417 + CREATE (alice:Person {name: 'Alice', age: 30}) 418 + CREATE (bob:Person {name: 'Bob', age: 25}) 419 + CREATE (company:Company {name: 'Tech Corp', founded: 2010}) 420 + 421 + # Create relationships 422 + MATCH (alice:Person {name: 'Alice'}), (bob:Person {name: 'Bob'}) 423 + CREATE (alice)-[:KNOWS]->(bob) 424 + 425 + MATCH (alice:Person {name: 'Alice'}), (company:Company {name: 'Tech Corp'}) 426 + CREATE (alice)-[:WORKS_FOR]->(company) 427 + 428 + # Query the data 429 + MATCH (p:Person)-[:WORKS_FOR]->(c:Company) 430 + RETURN p.name as employee, c.name as company 431 + ``` 432 + 433 + ### Executing Command Files 434 + ```bash 435 + # Execute file in silent mode 436 + ./gigabrain-cli --file commands.cypher --silent 437 + 438 + # Execute file with output 439 + ./gigabrain-cli --file commands.cypher 440 + Executing commands from: commands.cypher 441 + 1> CREATE (alice:Person {name: 'Alice', age: 30}) 442 + (no columns returned) 443 + 0 rows returned 444 + (Completed in 1.23ms) 445 + 446 + 2> CREATE (bob:Person {name: 'Bob', age: 25}) 447 + (no columns returned) 448 + 0 rows returned 449 + (Completed in 0.89ms) 450 + ... 451 + 452 + File execution completed: 453 + Total lines: 15 454 + Commands executed: 8 455 + Errors: 0 456 + ``` 457 + 458 + ## Output Formats 459 + 460 + ### Table Format (Default) 461 + ``` 462 + โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ 463 + โ”‚ employee โ”‚ company โ”‚ 464 + โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค 465 + โ”‚ Alice โ”‚ Tech Corp โ”‚ 466 + โ”‚ Bob โ”‚ Startup โ”‚ 467 + โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ 468 + 469 + 2 rows returned 470 + ``` 471 + 472 + ### JSON Format 473 + ```bash 474 + gigabrain> :format json 475 + Output format set to: json 476 + 477 + gigabrain> MATCH (n:Person) RETURN n.name, n.age 478 + {"columns": ["n.name", "n.age"], "rows": 2} 479 + ``` 480 + 481 + ### CSV Format 482 + ```bash 483 + gigabrain> :format csv 484 + Output format set to: csv 485 + 486 + gigabrain> MATCH (n:Person) RETURN n.name, n.age 487 + n.name,n.age 488 + value,value 489 + value,value 490 + ``` 491 + 492 + ### Plain Format 493 + ```bash 494 + gigabrain> :format plain 495 + Output format set to: plain 496 + 497 + gigabrain> MATCH (n:Person) RETURN n.name, n.age 498 + QueryResult { columns: ["n.name", "n.age"], rows: [...] } 499 + ``` 500 + 501 + ## Command History and Completion 502 + 503 + ### Command History 504 + - Automatically saves command history to `.gigabrain_history` 505 + - Navigate history with up/down arrows in REPL 506 + - Search history with `:history` command 507 + - Configurable history file location with `--history-file` 508 + 509 + ### Tab Completion 510 + The CLI provides intelligent tab completion for: 511 + - Cypher keywords (MATCH, CREATE, WHERE, RETURN, etc.) 512 + - Built-in functions (count, sum, avg, etc.) 513 + - Meta commands (:help, :stats, :export, etc.) 514 + - Node labels and relationship types 515 + - Property keys 516 + 517 + ### Multiline Support 518 + ```cypher 519 + gigabrain> MATCH (a:Person)-[:KNOWS]->(b:Person) 520 + -> WHERE a.age > 25 521 + -> RETURN a.name, b.name, a.age 522 + -> ORDER BY a.age DESC 523 + ``` 524 + 525 + ## Performance and Monitoring 526 + 527 + ### Query Timing 528 + All queries show execution time by default: 529 + ``` 530 + (Query completed in 2.34ms) 531 + ``` 532 + 533 + Disable with `--no-timing` or `:timing` command. 534 + 535 + ### Memory Information 536 + ```bash 537 + memory 538 + 539 + Memory Information: 540 + Estimated Graph Memory: 2,847,392 bytes (2.71 MB) 541 + Node Storage: 15432 nodes ร— 64 bytes = 987,648 bytes 542 + Relationship Storage: 42156 rels ร— 48 bytes = 2,023,488 bytes 543 + Schema Storage: ~1,376 bytes 544 + ``` 545 + 546 + ### Connection Information 547 + ```bash 548 + connections 549 + 550 + Connection Information: 551 + Active Connections: 1 (CLI) 552 + REST API: Available on port 3000 553 + gRPC API: Available on port 50051 554 + WebSocket: Not implemented 555 + ``` 556 + 557 + ## Error Handling 558 + 559 + ### Query Errors 560 + ```cypher 561 + gigabrain> INVALID QUERY 562 + Error: Query parsing failed: Unexpected token 'INVALID' 563 + ``` 564 + 565 + ### File Errors 566 + ```bash 567 + ./gigabrain-cli --file nonexistent.cypher 568 + Error reading line 1: No such file or directory 569 + File execution completed: 570 + Total lines: 0 571 + Commands executed: 0 572 + Errors: 1 573 + ``` 574 + 575 + ### Connection Errors 576 + If the graph database is unavailable, the CLI will show appropriate error messages and suggestions for troubleshooting. 577 + 578 + ## Configuration 579 + 580 + ### Environment Variables 581 + ```bash 582 + # Custom history file 583 + export GIGABRAIN_HISTORY_FILE="~/.config/gigabrain/history" 584 + 585 + # Default output format 586 + export GIGABRAIN_OUTPUT_FORMAT="json" 587 + 588 + # Disable timing by default 589 + export GIGABRAIN_NO_TIMING="true" 590 + ``` 591 + 592 + ### Configuration File 593 + Create `~/.gigabrain/config.toml`: 594 + ```toml 595 + [cli] 596 + prompt = "gb> " 597 + history_file = "~/.gigabrain/history" 598 + max_history = 2000 599 + output_format = "table" 600 + show_timing = true 601 + enable_completion = true 602 + 603 + [connection] 604 + rest_endpoint = "http://localhost:3000" 605 + grpc_endpoint = "http://localhost:50051" 606 + timeout = 30 607 + ``` 608 + 609 + ## Integration Examples 610 + 611 + ### Shell Scripting 612 + ```bash 613 + #!/bin/bash 614 + # backup_script.sh 615 + 616 + DATE=$(date +%Y%m%d_%H%M%S) 617 + BACKUP_FILE="backup_${DATE}.json" 618 + 619 + # Create backup 620 + ./gigabrain-cli --execute "backup ${BACKUP_FILE}" --silent 621 + 622 + if [ $? -eq 0 ]; then 623 + echo "Backup created successfully: ${BACKUP_FILE}" 624 + # Upload to cloud storage 625 + aws s3 cp "${BACKUP_FILE}" "s3://my-backups/gigabrain/" 626 + else 627 + echo "Backup failed!" 628 + exit 1 629 + fi 630 + ``` 631 + 632 + ### Batch Operations 633 + ```bash 634 + # Bulk data import 635 + ./gigabrain-cli --file data_import.cypher --format json > import_results.json 636 + 637 + # Performance monitoring 638 + ./gigabrain-cli --execute "benchmark" --format csv > performance.csv 639 + 640 + # Regular maintenance 641 + ./gigabrain-cli --execute "vacuum" --silent 642 + ./gigabrain-cli --execute "optimize" --silent 643 + ``` 644 + 645 + ### CI/CD Integration 646 + ```yaml 647 + # .github/workflows/database_tests.yml 648 + name: Database Tests 649 + on: [push, pull_request] 650 + 651 + jobs: 652 + test: 653 + runs-on: ubuntu-latest 654 + steps: 655 + - uses: actions/checkout@v2 656 + - name: Build GigaBrain 657 + run: cargo build --release 658 + - name: Start Database 659 + run: ./target/release/gigabrain & 660 + - name: Run Test Queries 661 + run: ./target/release/gigabrain-cli --file tests/integration.cypher 662 + - name: Check Performance 663 + run: ./target/release/gigabrain-cli benchmark 664 + ``` 665 + 666 + ## Troubleshooting 667 + 668 + ### Common Issues 669 + 670 + #### Command Not Found 671 + ```bash 672 + # Make sure the binary is built 673 + cargo build --release --bin gigabrain-cli 674 + 675 + # Check binary location 676 + ls -la target/release/gigabrain-cli 677 + 678 + # Make executable 679 + chmod +x target/release/gigabrain-cli 680 + ``` 681 + 682 + #### History Not Persisting 683 + ```bash 684 + # Check permissions 685 + ls -la .gigabrain_history 686 + 687 + # Specify custom location 688 + ./gigabrain-cli --history-file ~/.config/gigabrain/history 689 + ``` 690 + 691 + #### Query Timeout 692 + ```bash 693 + # For long-running queries, check server logs 694 + # Increase timeout in server configuration 695 + # Break down complex queries into smaller operations 696 + ``` 697 + 698 + #### Memory Issues 699 + ```bash 700 + # Check memory usage 701 + ./gigabrain-cli memory 702 + 703 + # Run vacuum to free memory 704 + ./gigabrain-cli --execute "vacuum" 705 + 706 + # Optimize graph structure 707 + ./gigabrain-cli --execute "optimize" 708 + ``` 709 + 710 + ### Debug Mode 711 + ```bash 712 + # Enable debug logging 713 + RUST_LOG=debug ./gigabrain-cli 714 + 715 + # Trace specific operations 716 + RUST_LOG=gigabrain::cli=trace ./gigabrain-cli 717 + ``` 718 + 719 + ## Best Practices 720 + 721 + ### Query Writing 722 + - Use EXPLAIN to understand query execution plans 723 + - Index frequently queried properties 724 + - Limit result sets with LIMIT clause 725 + - Use parameters for repeated queries 726 + 727 + ### Data Management 728 + - Regular backups before major changes 729 + - Use transactions for related operations 730 + - Monitor memory usage and optimize regularly 731 + - Validate data integrity after imports 732 + 733 + ### Performance Optimization 734 + - Create indexes on commonly queried properties 735 + - Use PROFILE to identify slow queries 736 + - Regular vacuum and optimize operations 737 + - Monitor query timing and optimize as needed 738 + 739 + ### Security 740 + - Validate input in batch files 741 + - Use secure storage for backup files 742 + - Limit access to history files 743 + - Regular security audits of queries 744 + 745 + This comprehensive CLI interface makes GigaBrain accessible for both interactive exploration and automated operations, providing a powerful tool for graph database management and analysis.
+58 -4
docs/README.md
··· 6 6 7 7 - **High Performance**: In-memory storage with optimized data structures 8 8 - **Cypher Query Language**: Full support for Neo4j-compatible Cypher queries 9 + - **Interactive CLI**: Comprehensive command-line interface with REPL and batch processing 9 10 - **Graph Algorithms**: Built-in shortest path, centrality, community detection, and more 10 11 - **Dual API**: Both REST and gRPC interfaces for maximum flexibility 11 12 - **ACID Transactions**: Full transaction support with configurable isolation levels 12 13 - **Persistence**: Optional RocksDB backend for data durability 13 14 - **Authentication**: JWT-based authentication with role-based access control 14 15 - **Monitoring**: Built-in metrics and observability features 16 + - **Data Import/Export**: JSON and CSV import/export capabilities 15 17 16 18 ## Quick Start 17 19 ··· 30 32 cargo run --bin gigabrain 31 33 ``` 32 34 35 + ### Using the CLI 36 + 37 + ```bash 38 + # Build and start the interactive CLI 39 + cargo build --release --bin gigabrain-cli 40 + ./target/release/gigabrain-cli 41 + 42 + # Execute a single command 43 + ./target/release/gigabrain-cli --execute "CREATE (alice:Person {name: 'Alice', age: 30})" 44 + 45 + # Run commands from file 46 + ./target/release/gigabrain-cli --file my_queries.cypher 47 + 48 + # Show graph statistics 49 + ./target/release/gigabrain-cli stats 50 + ``` 51 + 33 52 ### Basic Usage 34 53 54 + #### Using the CLI (Recommended) 55 + 56 + ```cypher 57 + # Start interactive CLI 58 + gigabrain> CREATE (alice:Person {name: 'Alice', age: 30}) 59 + gigabrain> CREATE (bob:Person {name: 'Bob', age: 25}) 60 + gigabrain> MATCH (a:Person), (b:Person) WHERE a.name = 'Alice' AND b.name = 'Bob' 61 + -> CREATE (a)-[:KNOWS]->(b) 62 + gigabrain> MATCH (p:Person)-[:KNOWS]->(friend) RETURN p.name, friend.name 63 + ``` 64 + 65 + #### Using the REST API 66 + 35 67 ```bash 36 68 # Check server health 37 69 curl http://localhost:3000/api/v1/health ··· 61 93 62 94 - **Graph Engine**: High-performance graph storage and traversal 63 95 - **Query Engine**: Cypher parser and execution engine 96 + - **CLI Interface**: Interactive REPL and command-line tools 64 97 - **Algorithm Library**: Graph algorithms for analytics 65 98 - **API Layer**: REST and gRPC interfaces 66 99 - **Storage Layer**: Memory and persistent storage backends 67 100 - **Transaction Manager**: ACID transaction support 101 + - **Observability**: Metrics, tracing, and health monitoring 68 102 69 103 ### Performance 70 104 ··· 102 136 103 137 ## Configuration 104 138 139 + ### CLI Configuration 140 + 141 + ```toml 142 + # ~/.gigabrain/config.toml 143 + [cli] 144 + prompt = "gigabrain> " 145 + history_file = "~/.gigabrain/history" 146 + max_history = 2000 147 + output_format = "table" 148 + show_timing = true 149 + enable_completion = true 150 + 151 + [connection] 152 + rest_endpoint = "http://localhost:3000" 153 + grpc_endpoint = "http://localhost:50051" 154 + timeout = 30 155 + ``` 156 + 105 157 ### Server Configuration 106 158 107 159 ```rust ··· 136 188 let claims = auth_service.validate_token(&token)?; 137 189 ``` 138 190 139 - ## API Documentation 191 + ## Documentation 140 192 141 - - [Full API Reference](./API.md) 142 - - [gRPC Protocol Buffers](../proto/gigabrain.proto) 143 - - [Examples](./examples/) 193 + - [CLI and REPL Guide](./CLI.md) - Complete command-line interface documentation 194 + - [API Reference](./API.md) - REST and gRPC API documentation 195 + - [Architecture Guide](./ARCHITECTURE.md) - Technical architecture overview 196 + - [gRPC Protocol Buffers](../proto/gigabrain.proto) - Protocol buffer definitions 197 + - [Examples](./examples/) - Usage examples and tutorials 144 198 145 199 ## Benchmarks 146 200
+27 -5
docs/examples/README.md
··· 4 4 5 5 ## Example Categories 6 6 7 + ### [CLI Examples](./cli-examples.md) 8 + - Interactive REPL usage 9 + - Command-line operations 10 + - Batch processing 11 + - Administrative commands 12 + - Data import/export 13 + 7 14 ### [Basic Operations](./basic-operations.md) 8 15 - Creating nodes and relationships 9 16 - Basic queries ··· 55 62 cargo run --bin gigabrain 56 63 ``` 57 64 58 - 2. **Required tools**: 65 + 2. **CLI tool** (for CLI examples): 66 + ```bash 67 + cargo build --release --bin gigabrain-cli 68 + ``` 69 + 70 + 3. **Required tools**: 59 71 ```bash 72 + # For CLI examples 73 + ./target/release/gigabrain-cli 74 + 60 75 # For REST API examples 61 76 curl 62 77 ··· 67 82 python3 (optional) 68 83 ``` 69 84 70 - 3. **Authentication** (if enabled): 85 + 4. **Authentication** (if enabled): 71 86 ```bash 72 87 export GIGABRAIN_TOKEN="your-jwt-token" 73 88 ``` 74 89 75 90 ### Quick Start 76 91 77 - 1. **Basic node creation**: 92 + 1. **CLI interactive mode**: 93 + ```bash 94 + ./target/release/gigabrain-cli 95 + gigabrain> CREATE (alice:Person {name: 'Alice', age: 30}) 96 + gigabrain> MATCH (n:Person) RETURN n.name, n.age 97 + ``` 98 + 99 + 2. **Basic node creation**: 78 100 ```bash 79 101 cd examples/basic-operations 80 102 ./01-create-nodes.sh 81 103 ``` 82 104 83 - 2. **Load sample social network**: 105 + 3. **Load sample social network**: 84 106 ```bash 85 107 cd examples/social-network 86 108 ./setup-network.sh 87 109 ``` 88 110 89 - 3. **Run performance tests**: 111 + 4. **Run performance tests**: 90 112 ```bash 91 113 cd examples/performance-testing 92 114 ./benchmark-suite.sh
+472
docs/examples/cli-examples.md
··· 1 + # GigaBrain CLI Examples 2 + 3 + This document provides practical examples of using the GigaBrain CLI for various common tasks. 4 + 5 + ## Getting Started 6 + 7 + ### Starting the CLI 8 + ```bash 9 + # Build the CLI 10 + cargo build --release --bin gigabrain-cli 11 + 12 + # Start interactive REPL 13 + ./target/release/gigabrain-cli 14 + 15 + # Or use shorter commands if in PATH 16 + gigabrain-cli 17 + ``` 18 + 19 + ## Basic Graph Operations 20 + 21 + ### Creating Nodes and Relationships 22 + 23 + ```cypher 24 + # Create person nodes 25 + gigabrain> CREATE (alice:Person {name: 'Alice', age: 30, email: 'alice@example.com'}) 26 + gigabrain> CREATE (bob:Person {name: 'Bob', age: 25, email: 'bob@example.com'}) 27 + gigabrain> CREATE (charlie:Person {name: 'Charlie', age: 35, email: 'charlie@example.com'}) 28 + 29 + # Create a company 30 + gigabrain> CREATE (techcorp:Company {name: 'TechCorp', founded: 2010, industry: 'Technology'}) 31 + 32 + # Create relationships 33 + gigabrain> MATCH (alice:Person {name: 'Alice'}), (bob:Person {name: 'Bob'}) 34 + -> CREATE (alice)-[:KNOWS {since: 2020}]->(bob) 35 + 36 + gigabrain> MATCH (alice:Person {name: 'Alice'}), (techcorp:Company {name: 'TechCorp'}) 37 + -> CREATE (alice)-[:WORKS_FOR {position: 'Senior Developer', since: 2022}]->(techcorp) 38 + 39 + gigabrain> MATCH (bob:Person {name: 'Bob'}), (techcorp:Company {name: 'TechCorp'}) 40 + -> CREATE (bob)-[:WORKS_FOR {position: 'Junior Developer', since: 2023}]->(techcorp) 41 + ``` 42 + 43 + ### Querying Data 44 + 45 + ```cypher 46 + # Find all people 47 + gigabrain> MATCH (p:Person) RETURN p.name, p.age, p.email 48 + 49 + # Find relationships 50 + gigabrain> MATCH (p:Person)-[r:KNOWS]->(friend:Person) 51 + -> RETURN p.name as person, friend.name as friend, r.since as since 52 + 53 + # Find coworkers 54 + gigabrain> MATCH (p1:Person)-[:WORKS_FOR]->(company:Company)<-[:WORKS_FOR]-(p2:Person) 55 + -> WHERE p1 <> p2 56 + -> RETURN p1.name as person1, p2.name as person2, company.name as company 57 + 58 + # Complex query with aggregation 59 + gigabrain> MATCH (p:Person)-[:WORKS_FOR]->(c:Company) 60 + -> RETURN c.name as company, count(p) as employees 61 + -> ORDER BY employees DESC 62 + ``` 63 + 64 + ## Administrative Tasks 65 + 66 + ### Graph Statistics and Analysis 67 + 68 + ```bash 69 + # Show basic statistics 70 + gigabrain> :stats 71 + 72 + # Analyze graph structure 73 + gigabrain> analyze structure 74 + 75 + # Analyze connectivity 76 + gigabrain> analyze connectivity 77 + 78 + # Show schema information 79 + gigabrain> :show schema 80 + 81 + # Show sample nodes 82 + gigabrain> :show nodes 83 + 84 + # Show sample relationships 85 + gigabrain> :show relationships 86 + ``` 87 + 88 + ### Performance Analysis 89 + 90 + ```bash 91 + # Run benchmark 92 + gigabrain> benchmark 93 + 94 + # Analyze performance characteristics 95 + gigabrain> analyze performance 96 + 97 + # Show memory usage 98 + gigabrain> memory 99 + 100 + # Profile a query 101 + gigabrain> profile MATCH (p:Person)-[:KNOWS*1..3]->(friend) RETURN p.name, count(friend) 102 + ``` 103 + 104 + ### Database Maintenance 105 + 106 + ```bash 107 + # Create backup 108 + gigabrain> backup daily_backup_20231201.json 109 + 110 + # Optimize database 111 + gigabrain> optimize 112 + 113 + # Vacuum (cleanup) 114 + gigabrain> vacuum 115 + 116 + # Show connection info 117 + gigabrain> connections 118 + ``` 119 + 120 + ## Data Import/Export 121 + 122 + ### JSON Export/Import 123 + 124 + ```bash 125 + # Export graph to JSON 126 + gigabrain> :export graph_backup.json 127 + 128 + # Import from JSON 129 + gigabrain> :import graph_backup.json 130 + 131 + # Using administrative commands 132 + gigabrain> export-json full_export.json 133 + gigabrain> import-json full_export.json 134 + ``` 135 + 136 + ### CSV Export/Import 137 + 138 + ```bash 139 + # Export people to CSV 140 + gigabrain> export-csv people.csv "MATCH (p:Person) RETURN p.name, p.age, p.email" 141 + 142 + # Export relationships to CSV 143 + gigabrain> export-csv relationships.csv "MATCH (a)-[r]->(b) RETURN a.name, type(r), b.name" 144 + 145 + # Import CSV data 146 + gigabrain> import-csv new_people.csv 147 + ``` 148 + 149 + ## Batch Processing 150 + 151 + ### Command Files 152 + 153 + Create a file `setup_social_network.cypher`: 154 + ```cypher 155 + # Social network setup script 156 + # Clear existing data 157 + MATCH (n) DETACH DELETE n; 158 + 159 + # Create people 160 + CREATE (alice:Person {name: 'Alice', age: 30, city: 'New York'}); 161 + CREATE (bob:Person {name: 'Bob', age: 25, city: 'San Francisco'}); 162 + CREATE (charlie:Person {name: 'Charlie', age: 35, city: 'Los Angeles'}); 163 + CREATE (diana:Person {name: 'Diana', age: 28, city: 'Chicago'}); 164 + CREATE (eve:Person {name: 'Eve', age: 32, city: 'Boston'}); 165 + 166 + # Create friendships 167 + MATCH (alice:Person {name: 'Alice'}), (bob:Person {name: 'Bob'}) 168 + CREATE (alice)-[:FRIENDS {since: 2018}]->(bob); 169 + 170 + MATCH (bob:Person {name: 'Bob'}), (charlie:Person {name: 'Charlie'}) 171 + CREATE (bob)-[:FRIENDS {since: 2019}]->(charlie); 172 + 173 + MATCH (charlie:Person {name: 'Charlie'}), (diana:Person {name: 'Diana'}) 174 + CREATE (charlie)-[:FRIENDS {since: 2020}]->(diana); 175 + 176 + MATCH (diana:Person {name: 'Diana'}), (eve:Person {name: 'Eve'}) 177 + CREATE (diana)-[:FRIENDS {since: 2021}]->(eve); 178 + 179 + MATCH (eve:Person {name: 'Eve'}), (alice:Person {name: 'Alice'}) 180 + CREATE (eve)-[:FRIENDS {since: 2017}]->(alice); 181 + 182 + # Create some interests 183 + CREATE (tech:Interest {name: 'Technology'}); 184 + CREATE (music:Interest {name: 'Music'}); 185 + CREATE (sports:Interest {name: 'Sports'}); 186 + CREATE (travel:Interest {name: 'Travel'}); 187 + 188 + # Connect people to interests 189 + MATCH (alice:Person {name: 'Alice'}), (tech:Interest {name: 'Technology'}) 190 + CREATE (alice)-[:INTERESTED_IN]->(tech); 191 + 192 + MATCH (alice:Person {name: 'Alice'}), (music:Interest {name: 'Music'}) 193 + CREATE (alice)-[:INTERESTED_IN]->(music); 194 + 195 + MATCH (bob:Person {name: 'Bob'}), (tech:Interest {name: 'Technology'}) 196 + CREATE (bob)-[:INTERESTED_IN]->(tech); 197 + 198 + MATCH (bob:Person {name: 'Bob'}), (sports:Interest {name: 'Sports'}) 199 + CREATE (bob)-[:INTERESTED_IN]->(sports); 200 + 201 + # Show final statistics 202 + MATCH (n) RETURN labels(n)[0] as type, count(n) as count; 203 + ``` 204 + 205 + Execute the file: 206 + ```bash 207 + # Run the setup script 208 + ./gigabrain-cli --file setup_social_network.cypher 209 + 210 + # Run silently for automation 211 + ./gigabrain-cli --file setup_social_network.cypher --silent 212 + ``` 213 + 214 + ### Analysis Queries File 215 + 216 + Create `social_analysis.cypher`: 217 + ```cypher 218 + # Social network analysis queries 219 + 220 + # Find mutual friends 221 + MATCH (a:Person)-[:FRIENDS]-(mutual)-[:FRIENDS]-(b:Person) 222 + WHERE a <> b AND NOT (a)-[:FRIENDS]-(b) 223 + RETURN a.name as person1, b.name as person2, mutual.name as mutual_friend; 224 + 225 + # Find popular interests 226 + MATCH (p:Person)-[:INTERESTED_IN]->(i:Interest) 227 + RETURN i.name as interest, count(p) as popularity 228 + ORDER BY popularity DESC; 229 + 230 + # Find people with similar interests 231 + MATCH (p1:Person)-[:INTERESTED_IN]->(i:Interest)<-[:INTERESTED_IN]-(p2:Person) 232 + WHERE p1 <> p2 233 + RETURN p1.name as person1, p2.name as person2, count(i) as shared_interests 234 + ORDER BY shared_interests DESC; 235 + 236 + # Find the social network diameter 237 + MATCH path = shortestPath((a:Person)-[:FRIENDS*]-(b:Person)) 238 + WHERE a <> b 239 + RETURN a.name as start, b.name as end, length(path) as distance 240 + ORDER BY distance DESC 241 + LIMIT 5; 242 + 243 + # Show network statistics 244 + MATCH (p:Person) 245 + OPTIONAL MATCH (p)-[:FRIENDS]-(friend) 246 + RETURN p.name as person, count(friend) as friend_count 247 + ORDER BY friend_count DESC; 248 + ``` 249 + 250 + Run analysis: 251 + ```bash 252 + ./gigabrain-cli --file social_analysis.cypher --format table 253 + ``` 254 + 255 + ## Output Formatting 256 + 257 + ### Different Output Formats 258 + 259 + ```bash 260 + # Table format (default) 261 + gigabrain> MATCH (p:Person) RETURN p.name, p.age LIMIT 3 262 + โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ 263 + โ”‚ name โ”‚ age โ”‚ 264 + โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค 265 + โ”‚ Alice โ”‚ 30 โ”‚ 266 + โ”‚ Bob โ”‚ 25 โ”‚ 267 + โ”‚ Charlie โ”‚ 35 โ”‚ 268 + โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ 269 + 270 + # Switch to JSON 271 + gigabrain> :format json 272 + gigabrain> MATCH (p:Person) RETURN p.name, p.age LIMIT 3 273 + {"columns": ["p.name", "p.age"], "rows": 3} 274 + 275 + # Switch to CSV 276 + gigabrain> :format csv 277 + gigabrain> MATCH (p:Person) RETURN p.name, p.age LIMIT 3 278 + p.name,p.age 279 + Alice,30 280 + Bob,25 281 + Charlie,35 282 + 283 + # Switch back to table 284 + gigabrain> :format table 285 + ``` 286 + 287 + ### Command Line Format Options 288 + 289 + ```bash 290 + # JSON output for scripting 291 + ./gigabrain-cli --execute "MATCH (p:Person) RETURN count(p)" --format json 292 + 293 + # CSV output for data analysis 294 + ./gigabrain-cli --execute "MATCH (p:Person) RETURN p.name, p.age" --format csv > people.csv 295 + 296 + # Plain output for debugging 297 + ./gigabrain-cli --execute ":stats" --format plain 298 + ``` 299 + 300 + ## Advanced Examples 301 + 302 + ### Graph Algorithm Analysis 303 + 304 + ```cypher 305 + # Create a more complex network for algorithm testing 306 + CREATE (a:Node {id: 'A'}), (b:Node {id: 'B'}), (c:Node {id: 'C'}), 307 + (d:Node {id: 'D'}), (e:Node {id: 'E'}), (f:Node {id: 'F'}); 308 + 309 + CREATE (a)-[:CONNECTS {weight: 1}]->(b), 310 + (b)-[:CONNECTS {weight: 2}]->(c), 311 + (c)-[:CONNECTS {weight: 1}]->(d), 312 + (d)-[:CONNECTS {weight: 3}]->(e), 313 + (e)-[:CONNECTS {weight: 1}]->(f), 314 + (f)-[:CONNECTS {weight: 2}]->(a), 315 + (a)-[:CONNECTS {weight: 4}]->(d), 316 + (b)-[:CONNECTS {weight: 1}]->(e); 317 + 318 + # Find shortest paths 319 + MATCH path = shortestPath((start:Node {id: 'A'})-[:CONNECTS*]-(end:Node {id: 'E'})) 320 + RETURN start.id as start, end.id as end, length(path) as hops; 321 + 322 + # Show node connectivity 323 + MATCH (n:Node) 324 + OPTIONAL MATCH (n)-[:CONNECTS]-(connected) 325 + RETURN n.id as node, count(connected) as degree 326 + ORDER BY degree DESC; 327 + ``` 328 + 329 + ### Time-Series Data Analysis 330 + 331 + ```cypher 332 + # Create time-series events 333 + CREATE (user1:User {id: 'user1'}), 334 + (user2:User {id: 'user2'}), 335 + (user3:User {id: 'user3'}); 336 + 337 + CREATE (event1:Event {type: 'login', timestamp: 1640995200}), 338 + (event2:Event {type: 'purchase', timestamp: 1640995800}), 339 + (event3:Event {type: 'logout', timestamp: 1640996400}); 340 + 341 + CREATE (user1)-[:PERFORMED]->(event1), 342 + (user1)-[:PERFORMED]->(event2), 343 + (user1)-[:PERFORMED]->(event3); 344 + 345 + # Query events by time 346 + MATCH (u:User)-[:PERFORMED]->(e:Event) 347 + WHERE e.timestamp > 1640995000 348 + RETURN u.id as user, e.type as event, e.timestamp as time 349 + ORDER BY time; 350 + ``` 351 + 352 + ## Scripting and Automation 353 + 354 + ### Backup Script 355 + 356 + Create `backup.sh`: 357 + ```bash 358 + #!/bin/bash 359 + DATE=$(date +%Y%m%d_%H%M%S) 360 + BACKUP_FILE="gigabrain_backup_${DATE}.json" 361 + 362 + echo "Creating backup: ${BACKUP_FILE}" 363 + ./gigabrain-cli --execute "backup ${BACKUP_FILE}" --silent 364 + 365 + if [ $? -eq 0 ]; then 366 + echo "Backup completed successfully" 367 + # Optionally upload to cloud storage 368 + # aws s3 cp "${BACKUP_FILE}" s3://my-backups/gigabrain/ 369 + else 370 + echo "Backup failed!" 371 + exit 1 372 + fi 373 + ``` 374 + 375 + ### Health Check Script 376 + 377 + Create `health_check.sh`: 378 + ```bash 379 + #!/bin/bash 380 + STATS=$(./gigabrain-cli --execute ":stats" --format json --silent) 381 + NODE_COUNT=$(echo $STATS | jq -r '.nodes // 0') 382 + 383 + if [ "$NODE_COUNT" -gt 0 ]; then 384 + echo "Database healthy: $NODE_COUNT nodes" 385 + exit 0 386 + else 387 + echo "Database issue: No nodes found" 388 + exit 1 389 + fi 390 + ``` 391 + 392 + ### Data Migration Script 393 + 394 + Create `migrate_data.cypher`: 395 + ```cypher 396 + # Data migration script 397 + # Add new properties to existing nodes 398 + MATCH (p:Person) 399 + WHERE NOT EXISTS(p.created_at) 400 + SET p.created_at = timestamp(); 401 + 402 + # Create indexes for performance 403 + # Note: Index creation syntax may vary 404 + MATCH (p:Person) WHERE EXISTS(p.email) SET p:EmailUser; 405 + 406 + # Update relationship properties 407 + MATCH (p1:Person)-[r:FRIENDS]->(p2:Person) 408 + WHERE NOT EXISTS(r.strength) 409 + SET r.strength = 1.0; 410 + 411 + # Show migration results 412 + MATCH (p:Person) 413 + RETURN 414 + count(p) as total_people, 415 + count(CASE WHEN EXISTS(p.created_at) THEN 1 END) as with_timestamps, 416 + count(CASE WHEN p:EmailUser THEN 1 END) as email_users; 417 + ``` 418 + 419 + ## Troubleshooting Examples 420 + 421 + ### Performance Issues 422 + 423 + ```cypher 424 + # Identify slow queries by profiling 425 + gigabrain> profile MATCH (p:Person)-[:FRIENDS*1..5]->(distant) RETURN p.name, count(distant) 426 + 427 + # Check memory usage 428 + gigabrain> memory 429 + 430 + # Analyze performance characteristics 431 + gigabrain> analyze performance 432 + 433 + # Optimize database 434 + gigabrain> optimize 435 + ``` 436 + 437 + ### Data Validation 438 + 439 + ```cypher 440 + # Check for orphaned nodes 441 + MATCH (n) 442 + WHERE NOT (n)--() 443 + RETURN labels(n)[0] as type, count(n) as orphaned_count; 444 + 445 + # Validate relationship consistency 446 + MATCH (p:Person)-[r:FRIENDS]->(friend:Person) 447 + WHERE NOT EXISTS((friend)-[:FRIENDS]->(p)) 448 + RETURN p.name as person, friend.name as one_way_friend; 449 + 450 + # Check for duplicate data 451 + MATCH (p1:Person), (p2:Person) 452 + WHERE p1 <> p2 AND p1.email = p2.email 453 + RETURN p1.name as person1, p2.name as person2, p1.email as duplicate_email; 454 + ``` 455 + 456 + ### Debugging Connection Issues 457 + 458 + ```bash 459 + # Check connection status 460 + gigabrain> connections 461 + 462 + # Test basic functionality 463 + gigabrain> CREATE (test:Test {id: 1}) RETURN test 464 + 465 + # Clean up test data 466 + gigabrain> MATCH (test:Test) DELETE test 467 + 468 + # Show recent logs (if implemented) 469 + gigabrain> logs recent 470 + ``` 471 + 472 + These examples demonstrate the full capabilities of the GigaBrain CLI for interactive use, batch processing, administration, and automation. The CLI provides a powerful interface for both development and production use cases.