Skip to content

HarshSharma0007/AegisLogic

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

9 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ›‘οΈ AegisLogic (PCRA)
Persistent Cognitive Retrieval Architecture

Python LangGraph Ollama Docker M4


A local-first, zero-cloud-dependency AI retrieval system that combines three concurrent data tracks β€” temporal session history (SQLite), causal graph traversal (KuzuDB), and semantic vector search (Qdrant) β€” fused via Reciprocal Rank Fusion (RRF) and powered by a locally-running Llama 3.1 8B model on Apple Silicon hardware.

Built for the domain of cyber threat intelligence (CTI) β€” a vertical requiring strict temporal awareness of breach timelines, multi-hop causal reasoning across MITRE ATT&CK relationships, and zero hallucination tolerance when attributing threat actors to malware and mitigations.

Architecture Overview

                            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                            β”‚     User Query Input     β”‚
                            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                         β”‚
                            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                            β”‚  Query Planner / Router  β”‚
                            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                         β”‚
              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
              β–Ό                          β–Ό                          β–Ό
   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
   β”‚   Hindsight Track   β”‚  β”‚     KAG Track        β”‚  β”‚     RAG Track       β”‚
   β”‚  (SQLite History)   β”‚  β”‚  (KuzuDB Graph)      β”‚  β”‚  (Qdrant Vectors)   β”‚
   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
              β”‚                        β”‚                          β”‚
              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”˜β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                     β”‚  asyncio.gather (parallel)
                            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                            β”‚  RRF Fusion Engine   β”‚
                            β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                     β”‚
                            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                            β”‚ Context Compression  β”‚
                            β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                     β”‚
                            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                            β”‚  Llama 3.1 (Ollama)  β”‚
                            β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                     β”‚
                            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                            β”‚  Grounded Response   β”‚
                            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

What You Install (on your MacBook M4)

Component Where It Runs Install Method Why
Docker Desktop Host (macOS) Download Runs Qdrant + the Python app containers
Ollama Host (macOS) brew install ollama Must run on host to leverage M4 Neural Engine / GPU acceleration β€” Docker can't access Apple's ANE
Git Host (macOS) Pre-installed on macOS Version control

Everything else runs inside Docker β€” you don't install Python, pip packages, KuzuDB, Qdrant, or sentence-transformers on your Mac directly.

Memory Budget (16 GB Unified Memory)

Subsystem Allocation Technology
macOS System ~3.50 GB Apple Silicon unified memory
Ollama LLM ~4.80 GB Llama 3.1 8B Q4_K_M (4-bit quantized)
KuzuDB Graph ~200 MB In-process columnar (inside Docker)
Qdrant Vectors ~150 MB Docker container
SQLite Index ~50 MB Disk-backed (inside Docker)
Python + LangGraph ~300 MB Docker container
Available Headroom ~6.97 GB Buffer for OS paging

Project Structure

PCRA/
β”œβ”€β”€ src/                          # Application source code
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ main.py                   # CLI entry point β€” runs the full pipeline
β”‚   β”œβ”€β”€ config.py                 # Environment config (Ollama, Qdrant, paths)
β”‚   β”œβ”€β”€ state.py                  # AgentState TypedDict + QueryIntent Pydantic schema
β”‚   β”œβ”€β”€ entity_resolver.py        # RapidFuzz fuzzy entity normalization
β”‚   β”œβ”€β”€ graph.py                  # LangGraph state machine assembly
β”‚   β”œβ”€β”€ workers/                  # Async retrieval workers (one per data track)
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   β”œβ”€β”€ hindsight.py          # Track A β€” SQLite temporal session history
β”‚   β”‚   β”œβ”€β”€ kag.py                # Track B β€” KuzuDB Cypher graph traversal
β”‚   β”‚   └── rag.py                # Track C β€” Qdrant semantic vector search
β”‚   └── nodes/                    # LangGraph pipeline nodes
β”‚       β”œβ”€β”€ __init__.py
β”‚       β”œβ”€β”€ retrieval.py          # Parallel retrieval orchestrator (asyncio.gather)
β”‚       β”œβ”€β”€ fusion.py             # Reciprocal Rank Fusion (RRF) scoring
β”‚       β”œβ”€β”€ compression.py        # Context compression (regex boilerplate stripping)
β”‚       └── generation.py         # LLM generation via Ollama (Llama 3.1)
β”œβ”€β”€ data/                         # Runtime data stores
β”‚   β”œβ”€β”€ knowledge_base/           # MITRE ATT&CK PDFs and threat intelligence reports for RAG ingestion
β”‚   β”œβ”€β”€ graph_schema/             # KuzuDB schema + seed data
β”‚   β”‚   └── seed.cypher           # Cypher seed script (threat actors, malware, mitigations)
β”‚   └── sessions/                 # SQLite DB file (created at runtime)
β”œβ”€β”€ eval/                         # Evaluation framework
β”‚   β”œβ”€β”€ evaluation_dataset.json   # Cybersecurity test queries (RAGAS harness)
β”‚   β”œβ”€β”€ run_ragas_groq.py         # RAGAS evaluation runner (Groq 70B judge)
β”‚   β”œβ”€β”€ debug_relevancy.py        # AnswerRelevancy diagnostic probe
β”‚   β”œβ”€β”€ check_noncommittal.py     # Noncommittal classifier debug script
β”‚   β”œβ”€β”€ ragas_report_groq.json    # Full evaluation results (70B)
β”‚   β”œβ”€β”€ ragas_noncommittal_penalty.md  # πŸ“„ Technical write-up: metric design flaw
β”‚   └── run_ragas.py              # Legacy evaluation runner
β”œβ”€β”€ Dockerfile                    # Multi-stage Python build (slim, non-root)
β”œβ”€β”€ docker-compose.yml            # 2 services: aegis-app + qdrant
β”œβ”€β”€ .dockerignore                 # Excludes .git, docs, node_modules from build
β”œβ”€β”€ .env.example                  # Environment variable template
β”œβ”€β”€ .gitignore                    # Python, Docker, data, IDE exclusions
β”œβ”€β”€ requirements.txt              # Pinned Python dependencies
β”œβ”€β”€ report.md                     # Full system engineering specification
└── README.md                     # ← You are here

Quick Start

1. Prerequisites

# Install Ollama (runs on your Mac host for M4 GPU acceleration)
brew install ollama

# Pull the quantized Llama 3.1 model (~4.8 GB download, one-time)
ollama pull llama3.1:8b-instruct-q4_K_M

# Verify Ollama is running
ollama list

2. Clone & Configure

git clone https://github.com/HarshSharma0007/PCRA.git
cd PCRA

# Create your local environment config
cp .env.example .env

3. Launch with Docker

# Build and start all services (Qdrant + AegisLogic app)
docker compose up --build

# Or run in detached mode
docker compose up --build -d

4. Run a Query

# Via Docker
docker exec -it aegis-app python -m src.main "Which courses of action mitigate the attack pattern used by the Lazarus Group?"

# Or run locally (if you have Python 3.11+ installed)
pip install -r requirements.txt
python -m src.main "What tools does APT29 use for spearphishing, and are there any recent VCDB incidents involving phishing?"

5. Run Evaluation

docker exec -it aegis-app python -m eval.run_ragas_groq

Evaluation Highlights

The system was evaluated using the RAGAS framework with both Llama 3.1 8B (local) and Llama 3.3 70B (Groq API) as LLM judges.

Metric 8B Judge 70B Judge Notes
Faithfulness 0.750 1.000 βœ… Perfect grounding β€” zero hallucination
Answer Relevancy 0.647 0.486 ⚠️ Impacted by noncommittal penalty (see below)
Context Recall 0.625 0.750 Improved with stronger judge

πŸ” Key Finding: The RAGAS "Noncommittal Penalty"

During evaluation, two queries scored exactly 0.000 for Answer Relevancy despite having perfect Faithfulness. A source-level investigation revealed a hardcoded binary penalty in the RAGAS AnswerRelevancy scorer that zeroes out scores when the LLM includes honest caveats like "I couldn't find specific information about..."

The root cause was traced to this line in the RAGAS source:

score = cosine_sim.mean() * int(not all_noncommittal)

πŸ“„ Full technical write-up: eval/ragas_noncommittal_penalty.md
πŸ”§ Debug probes: eval/debug_relevancy.py | eval/check_noncommittal.py

Research Foundation

This architecture is grounded in 7 peer-reviewed AI papers:

# Paper Venue Used For
1 RAG for Knowledge-Intensive NLP Tasks NeurIPS 2020 Core retrieval-augmented generation paradigm
2 Sufficient Context ICLR 2025 Guided abstention when context is insufficient
3 KAG: Knowledge Augmented Generation Ant Group 2024 Graph-based knowledge augmentation layer
4 Speculative RAG arXiv 2024 Parallel draft-verify retrieval architecture
5 Agentic RAG Survey arXiv 2026 Multi-loop agentic execution patterns
6 Hindsight Memory arXiv 2025 Structured agent memory (retain, recall, reflect)
7 AgentHER arXiv 2026 Hindsight experience replay for trajectory learning

Tech Stack

Layer Technology Role
Orchestration LangGraph + asyncio State machine + parallel async fan-out
LLM Inference Ollama + Llama 3.1 8B Q4_K_M Local generation on M4 hardware
Vector Store Qdrant (Docker) Semantic similarity search
Graph Database KuzuDB (embedded) Causal/relational path traversal
Relational Store SQLite Temporal session history
Embeddings all-MiniLM-L6-v2 384-dim local sentence embeddings
Entity Resolution RapidFuzz Fuzzy matching to canonical forms
Evaluation RAGAS Faithfulness + context recall metrics
Containerization Docker + Docker Compose Reproducible deployment

Known Limitations

  • Entity normalization relies on a static canonical list (future: auto-populate from KuzuDB nodes)
  • RRF treats all three tracks with equal weight (future: learnable track weighting)
  • No TLP (Traffic Light Protocol) classification layer (recommended for real CTI deployment)
  • Hindsight Critic Node is architecturally defined but not yet wired as a conditional LangGraph edge

License

MIT

About

AegisLogic (PCRA): A novel, local-first retrieval architecture (PCRA) for zero-hallucination Cyber Threat Intelligence. Synthesizes Graph (KuzuDB), Vector (Qdrant), and Temporal data via a LangGraph state machine. Includes empirical research on LLM evaluation metrics.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages