VectorV17 commited on
Commit
a02a082
·
verified ·
1 Parent(s): fbaf552

Create seed.py

Browse files
Files changed (1) hide show
  1. seed.py +70 -0
seed.py ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from database import db
2
+
3
+ def seed_database():
4
+ if not db.is_connected():
5
+ print("❌ Cannot seed: CognoDB Cloud instance is offline or unreachable.")
6
+ print("Please check your COGNODB_URI, COGNODB_USER, and COGNODB_PASSWORD environment variables.")
7
+ return
8
+
9
+ print("Cleaning existing database graph...")
10
+ clear_query = "MATCH (n) DETACH DELETE n"
11
+
12
+ print("Seeding Graph Schema & Knowledge Data...")
13
+ seed_query = """
14
+ // 1. Create Categories
15
+ CREATE (catAuth:Category {name: 'Authentication & Security'})
16
+ CREATE (catBilling:Category {name: 'Billing & Subscriptions'})
17
+ CREATE (catApi:Category {name: 'API Infrastructure'})
18
+
19
+ // 2. Create Systems
20
+ CREATE (sysGateway:System {name: 'Auth-Gateway-v2', status: 'Operational'})
21
+ CREATE (sysGraph:System {name: 'CognoDB-Cloud', status: 'Operational'})
22
+
23
+ // 3. Create Issues
24
+ CREATE (err401:Issue {code: 'ERR_401_UNAUTHORIZED', description: 'API Key missing or invalid token signature'})
25
+ CREATE (err429:Issue {code: 'ERR_429_RATE_LIMIT', description: 'Exceeded maximum prompt token quota'})
26
+
27
+ // 4. Create Articles
28
+ CREATE (a1:Article {
29
+ id: 'kb_101',
30
+ title: 'How to rotate and verify your API keys',
31
+ content: 'Navigate to Developer Settings > API Keys. Click Rotate Key and update your environment secrets immediately.'
32
+ })
33
+
34
+ CREATE (a2:Article {
35
+ id: 'kb_102',
36
+ title: 'Troubleshooting HTTP 401 Unauthorized Errors',
37
+ content: 'Check that your Authorization header uses "Bearer <token>". Verify key expiry and active system status.'
38
+ })
39
+
40
+ CREATE (a3:Article {
41
+ id: 'kb_103',
42
+ title: 'Optimizing Token Economics with Graph Context',
43
+ content: 'Use graph-aware retrieval to trim unneeded tokens. Pass only connected neighborhoods to cut context bloat by up to 98%.'
44
+ })
45
+
46
+ // 5. Establish Graph Relationships
47
+ CREATE (a1)-[:BELONGS_TO]->(catApi)
48
+ CREATE (a2)-[:BELONGS_TO]->(catAuth)
49
+ CREATE (a3)-[:BELONGS_TO]->(catBilling)
50
+
51
+ CREATE (a2)-[:RESOLVES]->(err401)
52
+ CREATE (a3)-[:RESOLVES]->(err429)
53
+
54
+ CREATE (a2)-[:MENTIONS]->(sysGateway)
55
+ CREATE (a3)-[:MENTIONS]->(sysGraph)
56
+
57
+ // Multi-Hop Prerequisite Relation: Resolving 401 requires rotating keys first
58
+ CREATE (a2)-[:REQUIRES_PREREQUISITE]->(a1)
59
+ """
60
+
61
+ try:
62
+ with db.driver.session() as session:
63
+ session.run(clear_query)
64
+ session.run(seed_query)
65
+ print("✅ CognoDB Cloud successfully seeded with Graph Nodes & Relationships!")
66
+ except Exception as e:
67
+ print(f"❌ Error while seeding database: {e}")
68
+
69
+ if __name__ == "__main__":
70
+ seed_database()