Skip to content

Fleonex-dev/GraphRAG

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 

Repository files navigation

ContextGraph

A True Context Graph implementation for intelligent document understanding β€” capturing not just what entities exist, but how decisions were made and why.

🎯 Learning Project - Exploring modern AI engineering: context graphs, decision tracing, causal reasoning, and LLM orchestration.

πŸ’° 100% Free - Runs entirely on local models (Ollama) with no API costs.


🧠 What is a Context Graph?

Context Graph vs Knowledge Graph

Aspect Knowledge Graph Context Graph
Focus "What is" β€” static entities & relationships "How & Why" β€” decision traces, reasoning paths
Structure Entities β†’ Relationships Entities + Decisions + States + Evidence
Time Optional timestamps Core feature β€” captures world state at each decision
Purpose Answer factual queries Trace reasoning, replay decisions, learn from precedents
Graph Type General graph DAG (Directed Acyclic Graph) β€” causal flow

The Key Insight

A knowledge graph answers: "Who is the CEO of Company X?"

A context graph answers: "Why did the board choose Alice as CEO, what evidence was considered, who else was evaluated, and what was the company's state at that time?"


πŸ—οΈ Context Graph Architecture

                            CONTEXT GRAPH (DAG)
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚                                                                 β”‚
    β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                                               β”‚
    β”‚   β”‚   SOURCE    β”‚  ← Document/Evidence that triggered the graph β”‚
    β”‚   β”‚  DOCUMENT   β”‚                                               β”‚
    β”‚   β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜                                               β”‚
    β”‚          β”‚ extracted_from                                       β”‚
    β”‚          β–Ό                                                      β”‚
    β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    based_on     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”               β”‚
    β”‚   β”‚   STATE     │◄────────────────│  EVIDENCE   β”‚               β”‚
    β”‚   β”‚  (t=2023)   β”‚                 β”‚   (facts)   β”‚               β”‚
    β”‚   β”‚             β”‚                 β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜               β”‚
    β”‚   β”‚ β€’ revenue   β”‚                                               β”‚
    β”‚   β”‚ β€’ headcount β”‚                                               β”‚
    β”‚   β”‚ β€’ market    β”‚                                               β”‚
    β”‚   β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜                                               β”‚
    β”‚          β”‚ led_to                                               β”‚
    β”‚          β–Ό                                                      β”‚
    β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    considered    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”              β”‚
    β”‚   β”‚  DECISION   │◄─────────────────│ ALTERNATIVE β”‚              β”‚
    β”‚   β”‚             β”‚                  β”‚  (rejected) β”‚              β”‚
    β”‚   β”‚ "Acquire    β”‚                  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜              β”‚
    β”‚   β”‚  Startup B" β”‚                                               β”‚
    β”‚   β”‚             │────────────────────────┐                      β”‚
    β”‚   β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜                        β”‚                      β”‚
    β”‚          β”‚ resulted_in                   β”‚ rationale            β”‚
    β”‚          β–Ό                               β–Ό                      β”‚
    β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                 β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”               β”‚
    β”‚   β”‚   ACTION    β”‚                 β”‚  REASONING  β”‚               β”‚
    β”‚   β”‚             β”‚                 β”‚             β”‚               β”‚
    β”‚   β”‚ "Signed     β”‚                 β”‚ "Strategic  β”‚               β”‚
    β”‚   β”‚  agreement" β”‚                 β”‚  fit for    β”‚               β”‚
    β”‚   β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜                 β”‚  AI market" β”‚               β”‚
    β”‚          β”‚ caused                 β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜               β”‚
    β”‚          β–Ό                                                      β”‚
    β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                                               β”‚
    β”‚   β”‚  OUTCOME    β”‚                                               β”‚
    β”‚   β”‚  (t=2024)   β”‚  ← New state after the decision               β”‚
    β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                                               β”‚
    β”‚                                                                 β”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

    Node Types:
    β”œβ”€β”€ πŸ“„ SOURCE      - Document/input that provides information
    β”œβ”€β”€ 🌍 STATE       - Snapshot of world/context at a point in time
    β”œβ”€β”€ πŸ“Š EVIDENCE    - Facts, data, observations supporting decisions
    β”œβ”€β”€ πŸ€” DECISION    - A choice point with alternatives considered
    β”œβ”€β”€ ❌ ALTERNATIVE - Options that were NOT chosen (important!)
    β”œβ”€β”€ πŸ’­ REASONING   - The "why" behind a decision
    β”œβ”€β”€ ⚑ ACTION      - What was done as result of decision
    └── 🎯 OUTCOME     - Resulting state after action

πŸ”„ System Pipeline

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                              CONTEXTGRAPH PIPELINE                           β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                              β”‚
β”‚  ╔═══════════════════════════════════════════════════════════════════════╗   β”‚
β”‚  β•‘                         1. INGESTION                                  β•‘   β”‚
β”‚  ╠═══════════════════════════════════════════════════════════════════════╣   β”‚
β”‚  β•‘  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”β•‘   β”‚
β”‚  β•‘  β”‚ Document │──▢│   Chunker    │──▢│  Decision/State Extractor       β”‚β•‘   β”‚
β”‚  β•‘  β”‚  Loader  β”‚   β”‚  (Semantic)  β”‚   β”‚  (LLM identifies decision pts)  β”‚β•‘   β”‚
β”‚  β•‘  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜β•‘   β”‚
β”‚  β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•   β”‚
β”‚                                      β”‚                                       β”‚
β”‚                                      β–Ό                                       β”‚
β”‚  ╔═══════════════════════════════════════════════════════════════════════╗   β”‚
β”‚  β•‘                       2. GRAPH CONSTRUCTION                           β•‘   β”‚
β”‚  ╠═══════════════════════════════════════════════════════════════════════╣   β”‚
β”‚  β•‘  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β•‘   β”‚
β”‚  β•‘  β”‚  DAG Builder    │──▢│ Causal Linker   │──▢│ Temporal Annotator  β”‚  β•‘   β”‚
│  ║  │ (nodes/edges)   │   │ (cause→effect)  │   │ (timestamps/order)  │  ║   │
β”‚  β•‘  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β•‘   β”‚
β”‚  β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•   β”‚
β”‚                                      β”‚                                       β”‚
β”‚                                      β–Ό                                       β”‚
β”‚  ╔═══════════════════════════════════════════════════════════════════════╗   β”‚
β”‚  β•‘                         3. STORAGE                                    β•‘   β”‚
β”‚  ╠═══════════════════════════════════════════════════════════════════════╣   β”‚
β”‚  β•‘     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β•‘   β”‚
β”‚  β•‘     β”‚    NetworkX DAG     β”‚         β”‚      ChromaDB Vectors       β”‚   β•‘   β”‚
β”‚  β•‘     β”‚  (graph structure)  β”‚         β”‚  (semantic search on nodes) β”‚   β•‘   β”‚
β”‚  β•‘     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β•‘   β”‚
β”‚  β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•   β”‚
β”‚                                      β”‚                                       β”‚
β”‚                                      β–Ό                                       β”‚
β”‚  ╔═══════════════════════════════════════════════════════════════════════╗   β”‚
β”‚  β•‘                        4. QUERY ENGINE                                β•‘   β”‚
β”‚  ╠═══════════════════════════════════════════════════════════════════════╣   β”‚
β”‚  β•‘  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β•‘   β”‚
β”‚  β•‘  β”‚ Query Analyzer │──▢│  Path Finder   │──▢│  Reasoning Assembler   β”‚ β•‘   β”‚
β”‚  β•‘  β”‚(what/why/how?) β”‚   β”‚(trace through  β”‚   β”‚(build explanation from β”‚ β•‘   β”‚
β”‚  β•‘  β”‚                β”‚   β”‚ DAG causally)  β”‚   β”‚ decision trace)        β”‚ β•‘   β”‚
β”‚  β•‘  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β•‘   β”‚
β”‚  β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•   β”‚
β”‚                                      β”‚                                       β”‚
β”‚                                      β–Ό                                       β”‚
β”‚  ╔═══════════════════════════════════════════════════════════════════════╗   β”‚
β”‚  β•‘                      5. RESPONSE GENERATION                           β•‘   β”‚
β”‚  ╠═══════════════════════════════════════════════════════════════════════╣   β”‚
β”‚  β•‘           β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β•‘   β”‚
β”‚  β•‘           β”‚              Ollama (Local LLM)                 β”‚         β•‘   β”‚
β”‚  β•‘           β”‚  Llama 3.2 / Mistral / Gemma 2                  β”‚         β•‘   β”‚
β”‚  β•‘           β”‚                                                 β”‚         β•‘   β”‚
β”‚  β•‘           β”‚  Input: Query + Decision Trace from DAG         β”‚         β•‘   β”‚
β”‚  β•‘           β”‚  Output: Answer with reasoning provenance       β”‚         β•‘   β”‚
β”‚  β•‘           β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β•‘   β”‚
β”‚  β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•   β”‚
β”‚                                                                              β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

✨ Features

Core Context Graph Features

  • πŸ“„ Document Ingestion - PDF, Markdown, TXT files
  • πŸ” Decision Point Extraction - LLM identifies decisions, states, and reasoning
  • 🌳 DAG Construction - Builds causal graph with proper temporal ordering
  • βͺ Decision Replay - Trace back through any decision to understand "why"
  • οΏ½ Causal Reasoning - Follow causeβ†’effect chains through the graph

Bleeding-Edge Features

  • οΏ½ Reasoning Provenance - Every answer cites the decision trace that supports it
  • πŸ”„ Incremental Updates - Add new documents, graph merges intelligently
  • οΏ½ State Diffing - Compare world state before/after decisions
  • 🎯 Counterfactual Queries - "What if alternative X was chosen instead?"
  • πŸ“ˆ Decision Confidence - Track extraction confidence and evidence strength

πŸ› οΈ Tech Stack (100% Free)

Component Technology Cost
Language Python 3.11+ Free
LLM Ollama (Llama 3.2 / Mistral / Gemma 2) Free (local)
Embeddings Ollama embeddings or sentence-transformers Free
Graph NetworkX (DAG) Free
Persistence SQLite + JSON serialization Free
Vector Store ChromaDB Free
CLI Typer Free
Visualization Pyvis / Graphviz Free
Web UI Streamlit (optional) Free

Why Ollama?

  • Runs completely locally on your machine
  • Supports multiple models: Llama 3.2 (8B), Mistral (7B), Gemma 2 (9B)
  • No API keys, no usage limits, no costs
  • GPU acceleration if available, CPU fallback

πŸ“ Project Structure

ContextGraph/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ ingestion/              # Document processing
β”‚   β”‚   β”œβ”€β”€ loader.py           # Multi-format document loading
β”‚   β”‚   β”œβ”€β”€ chunker.py          # Semantic chunking
β”‚   β”‚   └── decision_extractor.py  # Extract decisions, states, reasoning
β”‚   β”‚
β”‚   β”œβ”€β”€ graph/                  # DAG operations
β”‚   β”‚   β”œβ”€β”€ dag_builder.py      # Construct the context DAG
β”‚   β”‚   β”œβ”€β”€ causal_linker.py    # Link cause β†’ effect relationships
β”‚   β”‚   β”œβ”€β”€ temporal.py         # Temporal ordering and state tracking
β”‚   β”‚   └── node_types.py       # Decision, State, Evidence, Action, etc.
β”‚   β”‚
β”‚   β”œβ”€β”€ retrieval/              # Query processing
β”‚   β”‚   β”œβ”€β”€ query_analyzer.py   # Classify: what/why/how queries
β”‚   β”‚   β”œβ”€β”€ path_finder.py      # Trace causal paths through DAG
β”‚   β”‚   └── reasoning_assembler.py  # Build explanation from trace
β”‚   β”‚
β”‚   β”œβ”€β”€ storage/                # Persistence
β”‚   β”‚   β”œβ”€β”€ graph_store.py      # NetworkX ↔ SQLite/JSON
β”‚   β”‚   └── vector_store.py     # ChromaDB for semantic search
β”‚   β”‚
β”‚   β”œβ”€β”€ generation/             # Response generation
β”‚   β”‚   └── generator.py        # Ollama-powered response with provenance
β”‚   β”‚
β”‚   └── interfaces/             # User interfaces
β”‚       β”œβ”€β”€ cli.py              # Typer CLI
β”‚       └── web.py              # Streamlit dashboard (optional)
β”‚
β”œβ”€β”€ config/
β”‚   └── settings.yaml           # Configuration (model selection, etc.)
β”‚
β”œβ”€β”€ tests/                      # Test suite
β”œβ”€β”€ examples/                   # Example documents & queries
└── README.md

πŸš€ Planned Usage

CLI

# Initialize (downloads Ollama model if needed)
contextgraph init --model llama3.2

# Ingest a document (builds/updates context graph)
contextgraph ingest ./documents/company_report.pdf

# Query with reasoning trace
contextgraph query "Why did the company acquire Startup B?"

# Visualize the decision graph
contextgraph visualize --output decision_graph.html

# Trace a specific decision
contextgraph trace --decision "acquisition of Startup B"

Python API

from contextgraph import ContextGraph

# Initialize with local Ollama
cg = ContextGraph(model="llama3.2")

# Ingest documents
cg.ingest("./documents/board_meeting.pdf")

# Query with decision trace
response = cg.query("Why was Alice chosen as CEO?")

print(response.answer)           # Natural language answer
print(response.decision_trace)   # DAG path: Evidence β†’ State β†’ Decision β†’ Reasoning
print(response.confidence)       # How confident based on evidence
print(response.alternatives)     # What other options were considered

Example Query Flow

User Query: "Why did the company decide to enter the AI market?"

1. Query Analyzer β†’ Detected: "WHY" query about a DECISION
2. Path Finder β†’ Located decision node "Enter AI Market" 
   β†’ Traced backward through DAG
3. Reasoning Assembler β†’ Built trace:
   
   EVIDENCE: "Competitor X launched AI product (2023-Q2)"
        ↓ observed
   STATE: "Market share declining 5% YoY"
        ↓ led_to
   DECISION: "Enter AI market via acquisition"
        ↓ rationale
   REASONING: "Build vs Buy analysis favored acquisition 
               due to time-to-market pressure"
        ↓ considered
   ALTERNATIVES: ["Build in-house team", "Partner with AI startup"]

4. Generator β†’ Produces answer with full provenance

🎯 Learning Objectives

This project covers cutting-edge AI engineering concepts:

  1. Context Graphs - Beyond knowledge graphs: decision traces, state tracking
  2. DAG Algorithms - Topological sort, causal path finding, cycle detection
  3. Temporal Reasoning - State snapshots, event ordering, time-aware queries
  4. Causal Inference - Modeling cause→effect in structured graphs
  5. Reasoning Provenance - Explainable AI with traceable decision paths
  6. Local LLM Engineering - Ollama setup, prompt design, structured extraction
  7. Hybrid Retrieval - Combining graph traversal + vector similarity

πŸ“‹ Implementation Phases

Phase 1: Foundation πŸ—οΈ

  • Project setup with dependencies
  • Ollama integration and model management
  • Basic document loader (PDF, TXT, MD)
  • Node type definitions (Decision, State, Evidence, etc.)
  • Simple CLI with Typer

Phase 2: Graph Construction πŸ”—

  • Decision/State extraction with LLM
  • NetworkX DAG builder
  • Causal relationship linking
  • Temporal ordering enforcement
  • Graph persistence (SQLite/JSON)

Phase 3: Query Engine οΏ½

  • Query type classification (what/why/how)
  • Causal path finding algorithms
  • ChromaDB integration for semantic search
  • Reasoning assembler (build explanations from traces)
  • Response generation with Ollama

Phase 4: Advanced Features πŸš€

  • Graph visualization (Pyvis)
  • Incremental graph updates
  • State diffing (before/after comparisons)
  • Counterfactual reasoning ("what if X instead?")
  • Streamlit web dashboard

Phase 5: Polish ✨

  • Confidence scoring
  • Multi-document temporal alignment
  • Graph export formats
  • Comprehensive test suite
  • Documentation

πŸ“š Resources & References


πŸ”§ Prerequisites

  1. Python 3.11+
  2. Ollama - Install from ollama.ai
    # After installing Ollama, pull a model
    ollama pull llama3.2
  3. ~8GB RAM minimum for running local LLMs

πŸ“„ License

MIT License - Built for learning. Modify freely!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors