Production-ready RAG architecture powered by 28,027 historical battles
Features โข Quick Start โข Architecture โข API โข Benchmarks โข Contributing
| Metric | Value |
|---|---|
| ๐๏ธ Battle Records | 28,027 |
| ๐พ Database Size | 261 MB |
| โก Avg Response Time | 2.3s |
| ๐ง Model Parameters | 70B |
| ๐ Vector Dimensions | 384 |
| ๐ API Endpoints | 2 |
|
|
|
|
# 1๏ธโฃ Clone the repository
git clone https://github.com/Ninja-69/War-Strategy-AI.git
cd War-Strategy-AI
# 2๏ธโฃ Extract battle database (this will create data/vectordb)
tar -xzf military_ai_data.tar.gz -C data/
# 3๏ธโฃ Install Python dependencies
pip install -r requirements.txt
# Or manually:
# pip install flask flask-cors chromadb groq python-dotenv
# 4๏ธโฃ Configure environment
cp .env.example .env
nano .env # Add your Groq API key
# 5๏ธโฃ Launch the server
cd backend
python3 api/server.py
๐ https://console.groq.com/keys
Free tier includes:
- โ Llama 3.3 70B access
- โ 14,400 requests/day
- โ No credit card required
# Test health endpoint
curl http://localhost:5000/health
# Expected output:
# {"battles":28027,"status":"PERFECTION ONLINE","version":"15.0"}
๐ Server running at http://localhost:5000
graph TB
A[Client Request] --> B[Flask API Server]
B --> C{Route Handler}
C -->|/health| D[Health Check]
C -->|/api/ask| E[Strategy Engine]
E --> F[ChromaDB Vector Search]
F --> G[Retrieve 50 Battles]
G --> H[Context Builder]
H --> I[Groq LLM API]
I --> J[Llama 3.3 70B]
J --> K[Stream Response]
K --> L[Client]
style B fill:#2C3E50,stroke:#3498DB,stroke-width:2px,color:#ECF0F1
style E fill:#E74C3C,stroke:#C0392B,stroke-width:2px,color:#ECF0F1
style F fill:#9B59B6,stroke:#8E44AD,stroke-width:2px,color:#ECF0F1
style J fill:#F39C12,stroke:#E67E22,stroke-width:2px,color:#ECF0F1
| Layer | Technology | Purpose |
|---|---|---|
| ๐ API Layer | Flask 3.0 + CORS | RESTful HTTP interface |
| ๐ง AI Layer | Groq + Llama 3.3 70B | Strategic analysis engine |
| ๐พ Vector Store | ChromaDB (Persistent) | Semantic battle search |
| ๐ Data Layer | 28,027 battle records | Historical context database |
War-Strategy-AI/
โโโ ๐ backend/
โ โโโ ๐ api/
โ โโโ ๐ server.py # Flask REST API (main entry)
โโโ ๐ data/
โ โโโ ๐ vectordb/
โ โ โโโ ๐ battle_vectordb/ # 28K battles (ChromaDB)
โ โโโ ๐ battles/ # Raw CSV data
โ โโโ ๐ฆ military_ai_data.tar.gz # Compressed database
โโโ ๐ src/ # Data scrapers (optional)
โโโ ๐ requirements.txt # Python dependencies
โโโ ๐ .env.example # Environment template
โโโ ๐ .gitignore # Git exclusions
โโโ ๐ README.md # This file
http://localhost:5000
GET /health - Health Check
Description: Verify server status and database connectivity
Response:
{
"status": "PERFECTION ONLINE",
"battles": 28027,
"version": "15.0"
}
Status Codes:
200 OK- Server operational500 Internal Server Error- Server unavailable
POST /api/ask - Strategy Query
Description: Generate military strategy analysis with historical context
Request:
{
"question": "Analyze the Battle of Waterloo",
"mode": "war_simulator"
}
Parameters:
question(string, required) - Strategic query or scenariomode(string, optional) - Analysis mode (default: "war_simulator")
Response:
- Streaming text (text/plain)
- Real-time token generation
- Average 50 tokens/second
Example:
curl -X POST http://localhost:5000/api/ask \
-H 'Content-Type: application/json' \
-d '{
"question": "Compare ancient vs modern siege tactics"
}'
Status Codes:
200 OK- Streaming response400 Bad Request- Invalid query500 Internal Server Error- Processing error
import requests
def query_ares(question: str) -> None:
"""Stream military strategy analysis"""
url = "http://localhost:5000/api/ask"
payload = {
"question": question,
"mode": "war_simulator"
}
response = requests.post(url, json=payload, stream=True)
for chunk in response.iter_content(chunk_size=None, decode_unicode=True):
if chunk:
print(chunk, end='', flush=True)
# Example usage
query_ares("Analyze asymmetric warfare tactics in urban environments")
async function queryAres(question) {
const response = await fetch('http://localhost:5000/api/ask', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ question, mode: 'war_simulator' })
});
const reader = response.body.getReader();
const decoder = new TextDecoder();
while (true) {
const { done, value } = await reader.read();
if (done) break;
process.stdout.write(decoder.decode(value));
}
}
// Example
queryAres('Analyze the Battle of Thermopylae');
# Basic query
curl -X POST http://localhost:5000/api/ask \
-H 'Content-Type: application/json' \
-d '{"question":"Quick battle analysis test"}'
# Detailed scenario analysis
curl -X POST http://localhost:5000/api/ask \
-H 'Content-Type: application/json' \
-d '{
"question": "Provide a complete OPORD for defending a fortified position against numerically superior forces, including historical precedents from Thermopylae, Alamo, and Bastogne",
"mode": "war_simulator"
}'
| Test | Result | Details |
|---|---|---|
| ๐ Cold Start | 3.2s | Initial server startup |
| โก First Token | 2.1s | Time to first response |
| ๐ Throughput | 48 tok/s | Token generation rate |
| ๐พ Memory Usage | 1.5 GB | Peak RAM consumption |
| ๐ Vector Search | 120ms | ChromaDB query time |
| ๐ง Context Window | 8,000 tokens | Max prompt size |
# Concurrent request test (10 simultaneous users)
ab -n 100 -c 10 -p query.json -T application/json \
http://localhost:5000/api/ask
# Results:
# Requests per second: 4.23 [#/sec]
# Time per request: 236ms (mean)
# 99th percentile: 512ms
Create a .env file in the project root:
# Required
GROQ_API_KEY=gsk_your_api_key_here
# Optional
FLASK_ENV=production # development | production
HOST=0.0.0.0 # Bind address
PORT=5000 # Server port
DEBUG=False # Debug mode
Custom Vector Database Path
Edit backend/api/server.py:
vectordb_path = "/custom/path/to/vectordb"
chroma_client = chromadb.PersistentClient(path=vectordb_path)
Adjust Context Window
Modify the number of retrieved battles:
results = collection.query(
query_texts=[question],
n_results=100 # Default: 50
)
Change AI Model
Switch Groq model:
stream = groq_client.chat.completions.create(
model="llama-3.1-70b-versatile", # Alternative models
# model="mixtral-8x7b-32768",
# model="llama-3.1-8b-instant",
...
)
โ Port 5000 already in use
# Find process using port
sudo lsof -ti:5000
# Kill the process
sudo lsof -ti:5000 | xargs sudo kill -9
# Or use different port
export PORT=8000
python3 api/server.py
โ Collection 'battles' not found
# Ensure database is extracted
tar -xzf military_ai_data.tar.gz -C data/
# Verify vectordb exists
ls -la data/vectordb/battle_vectordb/chroma.sqlite3
# Check collection
python3 -c "
import chromadb
client = chromadb.PersistentClient(path='data/vectordb/battle_vectordb')
print(client.list_collections())
"
โ Groq API key error
# Verify .env file
cat .env | grep GROQ_API_KEY
# Test API key
curl https://api.groq.com/openai/v1/models \
-H "Authorization: Bearer $GROQ_API_KEY"
# Regenerate at: https://console.groq.com/keys
โ Slow response times
Optimization tips:
- Reduce
n_resultsin vector query (50 โ 25) - Use smaller model:
llama-3.1-8b-instant - Enable response caching
- Deploy closer to Groq servers (US region)
- Use production WSGI server (gunicorn)
# Install gunicorn
pip install gunicorn
# Run with multiple workers
cd backend
gunicorn -w 4 -b 0.0.0.0:5000 --timeout 120 api.server:app
FROM python:3.10-slim
WORKDIR /app
COPY . .
RUN tar -xzf military_ai_data.tar.gz -C data/
RUN pip install -r requirements.txt
EXPOSE 5000
CMD ["python3", "backend/api/server.py"]
# Build and run
docker build -t ares-ai .
docker run -p 5000:5000 -e GROQ_API_KEY=your_key ares-ai
[Unit]
Description=ARES Military AI Service
After=network.target
[Service]
Type=simple
User=www-data
WorkingDirectory=/opt/War-Strategy-AI/backend
ExecStart=/usr/bin/python3 api/server.py
Restart=always
Environment="GROQ_API_KEY=your_key"
[Install]
WantedBy=multi-user.target
We welcome contributions! Here's how you can help:
|
Report Bugs |
Request Features |
Submit PR |
Star Project |
# Fork and clone
git clone https://github.com/YOUR_USERNAME/War-Strategy-AI.git
cd War-Strategy-AI
# Create feature branch
git checkout -b feature/amazing-feature
# Make changes and test
python3 backend/api/server.py
# Commit and push
git commit -m "Add amazing feature"
git push origin feature/amazing-feature
# Open Pull Request on GitHub
- Follow PEP 8 for Python code
- Add docstrings to all functions
- Include type hints where applicable
- Write unit tests for new features
This project is licensed under the MIT License - see the LICENSE file for details.
MIT License
Copyright (c) 2025 Ninja-69
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction...
Special thanks to the open-source community and these amazing projects:
|
Groq Lightning-fast AI inference |
ChromaDB Vector database engine |
![]() Flask Web framework |
Meta AI Llama 3.3 70B model |
Data Sources:
- Wikipedia Military History Project
- CGSC Historical Resources
- Modern War Institute Archives
- DoD Historical Battle Compilations
- Web-based UI dashboard
- Multi-language support
- Real-time collaboration mode
- Advanced analytics dashboard
- Mobile app (iOS/Android)
- Extended battle database (50K+)
- Custom fine-tuned models
- Export to PDF/DOCX
- Voice input/output
- Integration with mapping tools
Built with โ๏ธ by Ninja-69
If this project helped you, please โญ star it and share!
Last updated: October 2025
