clarkkitchen22 commited on
Commit
ff8be8f
·
verified ·
1 Parent(s): 16a6218

Upload updated README

Browse files
Files changed (1) hide show
  1. README.md +403 -3
README.md CHANGED
@@ -1,3 +1,403 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 🌍 Geopolitical Analysis Agent
2
+
3
+ **Advanced strategic forecasting and simulation engine combining RAG, SQLite, ChromaDB, and Claude AI**
4
+
5
+ ## What Is This?
6
+
7
+ A production-ready geopolitical analysis system that:
8
+ - **Answers complex "what-if" questions** about world events
9
+ - **Models quantitative scenarios** (tank stocks, production rates, timelines)
10
+ - **Combines structured data + unstructured knowledge** via RAG
11
+ - **Provides rigorous analysis** like a think tank war games coordinator
12
+ - **Prepares training data** for fine-tuning specialized models
13
+
14
+ ## Key Features
15
+
16
+ ### 🧠 Intelligent RAG Architecture
17
+ - **Vector search** with ChromaDB for semantic retrieval
18
+ - **Structured database** with SQLite for facts, metrics, inventories
19
+ - **Hybrid retrieval** combining both sources for comprehensive context
20
+
21
+ ### 📊 Quantitative Modeling
22
+ - Project military inventories over time
23
+ - Calculate attrition rates and production capacities
24
+ - Model economic sustainability scenarios
25
+ - Compare alternative pathways
26
+
27
+ ### 💾 Production-Ready Stack
28
+ - FastAPI backend with async support
29
+ - SQLAlchemy ORM for database management
30
+ - Sentence Transformers for embeddings
31
+ - Claude Sonnet 4 for analysis
32
+ - Clean HTML/JS frontend
33
+
34
+ ### 🎯 Example Queries
35
+
36
+ ```
37
+ "Where will Russia's tank stock be in 5 years with 15% annual
38
+ losses and 200 tanks/year production?"
39
+
40
+ "What's China's timeline to semiconductor parity with Taiwan
41
+ if sanctions continue vs. if they're lifted?"
42
+
43
+ "How long can Iran sustain its proxy network at $60/barrel
44
+ vs $100/barrel oil prices?"
45
+
46
+ "Model European energy security in 2030 under three scenarios:
47
+ diversified LNG, accelerated renewables, or partial Russian
48
+ reconciliation"
49
+ ```
50
+
51
+ ## Quick Start
52
+
53
+ ### 1. Install
54
+
55
+ ```bash
56
+ cd geopolitical-agent/backend
57
+ python3 -m venv venv
58
+ source venv/bin/activate
59
+ pip install -r requirements.txt
60
+ ```
61
+
62
+ ### 2. Configure
63
+
64
+ Create `.env` file:
65
+ ```bash
66
+ ANTHROPIC_API_KEY=your_key_here
67
+ ```
68
+
69
+ ### 3. Initialize
70
+
71
+ ```bash
72
+ python -c "from models.database import init_db; init_db()"
73
+ ```
74
+
75
+ ### 4. Run
76
+
77
+ ```bash
78
+ python app.py
79
+ ```
80
+
81
+ Server starts on http://localhost:8000
82
+
83
+ ### 5. Open Frontend
84
+
85
+ Open `frontend/index.html` in browser or:
86
+ ```bash
87
+ cd frontend
88
+ python -m http.server 8080
89
+ ```
90
+
91
+ ### 6. Load Sample Data
92
+
93
+ Click "Load Sample Data" button in UI or:
94
+ ```bash
95
+ curl -X POST http://localhost:8000/api/data/load-sample-data
96
+ ```
97
+
98
+ ## Architecture
99
+
100
+ ```
101
+ ┌─────────────────────────────────────────────────┐
102
+ │ Frontend (HTML/JS) │
103
+ └─────────────────┬───────────────────────────────┘
104
+ │ REST API
105
+ ┌─────────────────┴───────────────────────────────┐
106
+ │ FastAPI Backend │
107
+ │ │
108
+ │ ┌──────────────────────────────────────────┐ │
109
+ │ │ Analysis Service (Claude + RAG) │ │
110
+ │ └─────────┬────────────────────┬───────────┘ │
111
+ │ │ │ │
112
+ │ ┌────────┴────────┐ ┌──────┴───────────┐ │
113
+ │ │ RAG Service │ │ Data Ingestion │ │
114
+ │ └────────┬────────┘ └──────┬───────────┘ │
115
+ │ │ │ │
116
+ │ ┌────────┴────────┐ ┌──────┴───────────┐ │
117
+ │ │ ChromaDB │ │ SQLite │ │
118
+ │ │ (Vectors) │ │ (Structured) │ │
119
+ │ └─────────────────┘ └──────────────────┘ │
120
+ └─────────────────────────────────────────────────┘
121
+ ```
122
+
123
+ ## Project Structure
124
+
125
+ ```
126
+ geopolitical-agent/
127
+ ├── backend/
128
+ │ ├── app.py # Main FastAPI app
129
+ │ ├── config.py # Configuration
130
+ │ ├── requirements.txt # Dependencies
131
+ │ ├── models/
132
+ │ │ ├── database.py # SQLAlchemy models
133
+ │ │ └── embeddings.py # ChromaDB manager
134
+ │ ├── services/
135
+ │ │ ├── rag_service.py # RAG orchestration
136
+ │ │ ├── analysis_service.py # Analysis engine
137
+ │ �� └── data_ingestion.py # Data loading
138
+ │ ├── routes/
139
+ │ │ ├── query.py # Query endpoints
140
+ │ │ └── data.py # Data endpoints
141
+ │ └── data/
142
+ │ ├── geopolitical.db # SQLite database
143
+ │ └── chroma_db/ # Vector store
144
+ ├── frontend/
145
+ │ └── index.html # Web interface
146
+ ├── data/
147
+ │ ├── sample_data/ # Sample datasets
148
+ │ └── training/ # Fine-tuning prep
149
+ └── docs/
150
+ ├── SETUP.md # Setup guide
151
+ └── API.md # API documentation
152
+ ```
153
+
154
+ ## Database Schema
155
+
156
+ ### Countries
157
+ - Basic country attributes
158
+ - GDP, population, military budget
159
+ - Regional categorization
160
+
161
+ ### Military Assets
162
+ - Equipment inventories (tanks, aircraft, etc.)
163
+ - Operational rates
164
+ - Production and attrition rates
165
+
166
+ ### Geopolitical Events
167
+ - Timeline of significant events
168
+ - Impact scoring
169
+ - Related countries tracking
170
+
171
+ ### Metrics Time Series
172
+ - Economic indicators
173
+ - Production statistics
174
+ - Any quantitative metric over time
175
+
176
+ ### Knowledge Sources
177
+ - Document provenance tracking
178
+ - Credibility scoring
179
+ - Source metadata
180
+
181
+ ## API Examples
182
+
183
+ ### Analyze Query
184
+ ```bash
185
+ curl -X POST http://localhost:8000/api/query/analyze \
186
+ -H "Content-Type: application/json" \
187
+ -d '{
188
+ "query": "Your geopolitical question here",
189
+ "use_cache": true
190
+ }'
191
+ ```
192
+
193
+ ### Add Knowledge
194
+ ```bash
195
+ curl -X POST http://localhost:8000/api/data/add-document \
196
+ -H "Content-Type: application/json" \
197
+ -d '{
198
+ "text": "Your geopolitical knowledge document",
199
+ "metadata": {"type": "report", "country": "China"}
200
+ }'
201
+ ```
202
+
203
+ Full API documentation: `docs/API.md`
204
+
205
+ ## Fine-Tuning Preparation
206
+
207
+ ### Export Training Data
208
+
209
+ ```python
210
+ from models.database import SessionLocal, AnalysisCache
211
+ import json
212
+
213
+ db = SessionLocal()
214
+ analyses = db.query(AnalysisCache).all()
215
+
216
+ training_data = []
217
+ for analysis in analyses:
218
+ training_data.append({
219
+ "messages": [
220
+ {
221
+ "role": "system",
222
+ "content": "You are a geopolitical analysis expert..."
223
+ },
224
+ {
225
+ "role": "user",
226
+ "content": analysis.query_text
227
+ },
228
+ {
229
+ "role": "assistant",
230
+ "content": analysis.analysis_result
231
+ }
232
+ ]
233
+ })
234
+
235
+ with open("training_data.jsonl", "w") as f:
236
+ for item in training_data:
237
+ f.write(json.dumps(item) + "\n")
238
+ ```
239
+
240
+ ### LoRA Training
241
+
242
+ Use the exported data to fine-tune a LoRA adapter on geopolitical data:
243
+
244
+ 1. Export queries/responses from `analysis_cache` table
245
+ 2. Format as JSONL for LoRA training
246
+ 3. Train LoRA adapter on domain-specific data
247
+ 4. Deploy fine-tuned model for specialized analysis
248
+
249
+ ## Extending the System
250
+
251
+ ### Add New Countries
252
+
253
+ ```python
254
+ from models.database import SessionLocal, Country
255
+
256
+ db = SessionLocal()
257
+ country = Country(
258
+ name="Pakistan",
259
+ iso_code="PAK",
260
+ region="South Asia",
261
+ population=235000000,
262
+ gdp_usd=376000000000,
263
+ military_budget_usd=11000000000
264
+ )
265
+ db.add(country)
266
+ db.commit()
267
+ ```
268
+
269
+ ### Add Military Assets
270
+
271
+ ```python
272
+ from models.database import MilitaryAsset
273
+
274
+ asset = MilitaryAsset(
275
+ country_id=country.id,
276
+ asset_type="Fighter Aircraft",
277
+ asset_name="JF-17 Thunder",
278
+ quantity=150,
279
+ operational_rate=0.75,
280
+ production_rate_yearly=25,
281
+ attrition_rate_yearly=0.05
282
+ )
283
+ db.add(asset)
284
+ db.commit()
285
+ ```
286
+
287
+ ### Add Knowledge Documents
288
+
289
+ ```python
290
+ from services.data_ingestion import DataIngestionService
291
+
292
+ service = DataIngestionService()
293
+ service.add_knowledge_document(
294
+ text="Your geopolitical analysis or fact...",
295
+ metadata={
296
+ "type": "intelligence_assessment",
297
+ "country": "Iran",
298
+ "classification": "open_source"
299
+ }
300
+ )
301
+ ```
302
+
303
+ ## Configuration
304
+
305
+ Edit `backend/config.py`:
306
+
307
+ ```python
308
+ # Embedding model (smaller = faster, larger = better)
309
+ EMBEDDING_MODEL = "sentence-transformers/all-MiniLM-L6-v2"
310
+
311
+ # RAG retrieval settings
312
+ TOP_K_RESULTS = 5 # Number of relevant chunks
313
+ SIMILARITY_THRESHOLD = 0.7 # Minimum relevance score
314
+
315
+ # Claude settings
316
+ DEFAULT_MODEL = "claude-sonnet-4-20250514"
317
+ MAX_TOKENS = 4000
318
+ TEMPERATURE = 0.3 # Lower = more analytical
319
+ ```
320
+
321
+ ## Performance Tips
322
+
323
+ 1. **Adjust retrieval**: Tune `TOP_K_RESULTS` and `SIMILARITY_THRESHOLD`
324
+ 2. **Enable caching**: Set `use_cache=true` for repeated queries
325
+ 3. **Batch document ingestion**: Use bulk-add for multiple documents
326
+ 4. **Index optimization**: Add SQLite indexes for frequent queries
327
+
328
+ ## Use Cases
329
+
330
+ ### Strategic Planning
331
+ - War games scenario modeling
332
+ - Resource sustainability analysis
333
+ - Timeline projections
334
+
335
+ ### Intelligence Analysis
336
+ - Capability gap assessments
337
+ - Economic constraint modeling
338
+ - Production capacity tracking
339
+
340
+ ### Academic Research
341
+ - Geopolitical trend analysis
342
+ - Historical pattern recognition
343
+ - Comparative case studies
344
+
345
+ ### Policy Analysis
346
+ - Sanction impact modeling
347
+ - Alliance dynamics assessment
348
+ - Economic leverage analysis
349
+
350
+ ## Roadmap
351
+
352
+ - [ ] Real-time data ingestion from news sources
353
+ - [ ] Multi-agent debate for competing analyses
354
+ - [ ] Temporal reasoning for historical patterns
355
+ - [ ] Export to PDF reports
356
+ - [ ] WebSocket streaming for long analyses
357
+ - [ ] Named Entity Recognition for auto-tagging
358
+ - [ ] Graph database for relationship modeling
359
+
360
+ ## Contributing
361
+
362
+ Areas for contribution:
363
+ 1. **Data**: Add domain-specific geopolitical datasets
364
+ 2. **Models**: Integrate specialized embedding models
365
+ 3. **Analysis**: Enhance quantitative modeling functions
366
+ 4. **UI**: Improve frontend visualization
367
+ 5. **Documentation**: Add tutorials and examples
368
+
369
+ ## License
370
+
371
+ MIT License - See LICENSE file
372
+
373
+ ## Citation
374
+
375
+ If you use this system in research:
376
+
377
+ ```bibtex
378
+ @software{geopolitical_analysis_agent,
379
+ title={Geopolitical Analysis Agent: RAG-based Strategic Forecasting},
380
+ author={[Your Name]},
381
+ year={2025},
382
+ url={https://github.com/yourusername/geopolitical-agent}
383
+ }
384
+ ```
385
+
386
+ ## Support
387
+
388
+ - Documentation: `docs/`
389
+ - API Reference: `docs/API.md`
390
+ - Setup Guide: `docs/SETUP.md`
391
+ - Issues: GitHub Issues
392
+
393
+ ## Acknowledgments
394
+
395
+ Built with:
396
+ - [FastAPI](https://fastapi.tiangolo.com/)
397
+ - [ChromaDB](https://www.trychroma.com/)
398
+ - [Anthropic Claude](https://www.anthropic.com/)
399
+ - [Sentence Transformers](https://www.sbert.net/)
400
+
401
+ ---
402
+
403
+ **Ready to analyze the world? Start with `python app.py`** 🚀