Ai Models
Collection
4 items
β’
Updated
β’
1
Advanced strategic forecasting and simulation engine combining RAG, SQLite, ChromaDB, and Claude AI
A production-ready geopolitical analysis system that:
"Where will Russia's tank stock be in 5 years with 15% annual
losses and 200 tanks/year production?"
"What's China's timeline to semiconductor parity with Taiwan
if sanctions continue vs. if they're lifted?"
"How long can Iran sustain its proxy network at $60/barrel
vs $100/barrel oil prices?"
"Model European energy security in 2030 under three scenarios:
diversified LNG, accelerated renewables, or partial Russian
reconciliation"
cd geopolitical-agent/backend
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
Create .env file:
ANTHROPIC_API_KEY=your_key_here
python -c "from models.database import init_db; init_db()"
python app.py
Server starts on http://localhost:8000
Open frontend/index.html in browser or:
cd frontend
python -m http.server 8080
Click "Load Sample Data" button in UI or:
curl -X POST http://localhost:8000/api/data/load-sample-data
βββββββββββββββββββββββββββββββββββββββββββββββββββ
β Frontend (HTML/JS) β
βββββββββββββββββββ¬ββββββββββββββββββββββββββββββββ
β REST API
βββββββββββββββββββ΄ββββββββββββββββββββββββββββββββ
β FastAPI Backend β
β β
β ββββββββββββββββββββββββββββββββββββββββββββ β
β β Analysis Service (Claude + RAG) β β
β βββββββββββ¬βββββββββββββββββββββ¬ββββββββββββ β
β β β β
β ββββββββββ΄βββββββββ ββββββββ΄ββββββββββββ β
β β RAG Service β β Data Ingestion β β
β ββββββββββ¬βββββββββ ββββββββ¬ββββββββββββ β
β β β β
β ββββββββββ΄βββββββββ ββββββββ΄ββββββββββββ β
β β ChromaDB β β SQLite β β
β β (Vectors) β β (Structured) β β
β βββββββββββββββββββ ββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββ
geopolitical-agent/
βββ backend/
β βββ app.py # Main FastAPI app
β βββ config.py # Configuration
β βββ requirements.txt # Dependencies
β βββ models/
β β βββ database.py # SQLAlchemy models
β β βββ embeddings.py # ChromaDB manager
β βββ services/
β β βββ rag_service.py # RAG orchestration
β β βββ analysis_service.py # Analysis engine
β β βββ data_ingestion.py # Data loading
β βββ routes/
β β βββ query.py # Query endpoints
β β βββ data.py # Data endpoints
β βββ data/
β βββ geopolitical.db # SQLite database
β βββ chroma_db/ # Vector store
βββ frontend/
β βββ index.html # Web interface
βββ data/
β βββ sample_data/ # Sample datasets
β βββ training/ # Fine-tuning prep
βββ docs/
βββ SETUP.md # Setup guide
βββ API.md # API documentation
curl -X POST http://localhost:8000/api/query/analyze \
-H "Content-Type: application/json" \
-d '{
"query": "Your geopolitical question here",
"use_cache": true
}'
curl -X POST http://localhost:8000/api/data/add-document \
-H "Content-Type: application/json" \
-d '{
"text": "Your geopolitical knowledge document",
"metadata": {"type": "report", "country": "China"}
}'
Full API documentation: docs/API.md
from models.database import SessionLocal, AnalysisCache
import json
db = SessionLocal()
analyses = db.query(AnalysisCache).all()
training_data = []
for analysis in analyses:
training_data.append({
"messages": [
{
"role": "system",
"content": "You are a geopolitical analysis expert..."
},
{
"role": "user",
"content": analysis.query_text
},
{
"role": "assistant",
"content": analysis.analysis_result
}
]
})
with open("training_data.jsonl", "w") as f:
for item in training_data:
f.write(json.dumps(item) + "\n")
Use the exported data to fine-tune a LoRA adapter on geopolitical data:
analysis_cache tablefrom models.database import SessionLocal, Country
db = SessionLocal()
country = Country(
name="Pakistan",
iso_code="PAK",
region="South Asia",
population=235000000,
gdp_usd=376000000000,
military_budget_usd=11000000000
)
db.add(country)
db.commit()
from models.database import MilitaryAsset
asset = MilitaryAsset(
country_id=country.id,
asset_type="Fighter Aircraft",
asset_name="JF-17 Thunder",
quantity=150,
operational_rate=0.75,
production_rate_yearly=25,
attrition_rate_yearly=0.05
)
db.add(asset)
db.commit()
from services.data_ingestion import DataIngestionService
service = DataIngestionService()
service.add_knowledge_document(
text="Your geopolitical analysis or fact...",
metadata={
"type": "intelligence_assessment",
"country": "Iran",
"classification": "open_source"
}
)
Edit backend/config.py:
# Embedding model (smaller = faster, larger = better)
EMBEDDING_MODEL = "sentence-transformers/all-MiniLM-L6-v2"
# RAG retrieval settings
TOP_K_RESULTS = 5 # Number of relevant chunks
SIMILARITY_THRESHOLD = 0.7 # Minimum relevance score
# Claude settings
DEFAULT_MODEL = "claude-sonnet-4-20250514"
MAX_TOKENS = 4000
TEMPERATURE = 0.3 # Lower = more analytical
TOP_K_RESULTS and SIMILARITY_THRESHOLDuse_cache=true for repeated queriesAreas for contribution:
MIT License - See LICENSE file
If you use this system in research:
@software{geopolitical_analysis_agent,
title={Geopolitical Analysis Agent: RAG-based Strategic Forecasting},
author={[Your Name]},
year={2025},
url={https://github.com/yourusername/geopolitical-agent}
}
docs/docs/API.mddocs/SETUP.mdBuilt with:
Ready to analyze the world? Start with python app.py π