Skip to content
ska2704Public

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Axiom

A GraphRAG-powered assessment engine that extracts knowledge graphs from academic PDFs and generates rigorous, hallucination-resistant multiple choice and true/false questions.


The Problem

Standard RAG systems chunk text into vectors and retrieve semantically similar passages. This works fine for question answering, but it falls apart for assessment generation. Two specific failure modes come up constantly:

Context collapse. A vector search for "gradient descent" returns passages about gradient descent. But it has no idea that gradient descent relates to linear regression, logistic regression, and neural networks in structurally different ways. The model ends up writing questions without understanding the broader conceptual landscape of the subject.

Weak distractors. When you ask an LLM to "write three wrong answers" it defaults to obviously wrong ones. A student who has never studied the topic can eliminate them by intuition. The assessments look complete but test nothing.

The Solution

Axiom skips vector databases entirely. Instead it processes a textbook through an LLM to build a literal knowledge graph, loads that graph into Neo4j, and uses graph traversal to find distractors at generation time.

When generating a question about "Random Forest", Axiom queries Neo4j for sibling nodes that share the same parent relationship. Decision Tree, Gradient Boosting, and AdaBoost all connect to the same parent via the same relationship type. That structural proximity is what makes them plausible wrong answers, not a guess from the LLM.

The LLM's job in Axiom is formatting, not reasoning. The knowledge comes from the graph.


Architecture

PDF
 |
 v
pipeline.py          pymupdf extraction, chunking, LLM entity extraction
 |
 v
graph.json           structured knowledge graph (entities + relationships)
 |
 v
neo4j_loader.py      loads graph into Neo4j Community Edition
 |
 v
distractor_engine.py Cypher traversal, 5-strategy distractor selection
 |
 v
mcq_generator.py     Self-Corrective GraphRAG loop, MCQ + T/F generation
 |
 v
api.py               FastAPI REST layer
 |
 v
app.py               Streamlit frontend

Self-Corrective GraphRAG

One of the more interesting design decisions in Axiom is the verification loop around question generation. After the LLM generates an MCQ, the system runs five checks before accepting it:

  1. Does the correct answer concept exist as a node in Neo4j?
  2. Does the MCQ have exactly four options (A, B, C, D)?
  3. Does the correct option contain the concept name?
  4. Is the concept name absent from the question stem (which would give it away)?
  5. Are the distractors structurally distinct from the correct answer?

Checks 1 through 5 are pure Cypher queries against Neo4j. No LLM involved. The sixth and final check asks an LLM to score prose clarity, but only after the structural checks pass.

If a question fails, the loop refreshes the distractor pool from the graph and retries up to three times. The returned question is tagged as either verified: true or verified: false with the specific issues listed.

This is what distinguishes it from standard self-corrective RAG approaches like CRAG or Self-RAG, which use one LLM to check another. Here the verifier is deterministic.


Tech Stack

  • LLM inference: Hugging Face Inference API (Qwen 2.5-7B-Instruct)
  • Graph database: Neo4j Community Edition
  • PDF extraction: pymupdf
  • Backend: FastAPI
  • Frontend: Streamlit
  • Embeddings: not used (vectorless by design)

Project Structure

axiom/
    pipeline.py            PDF ingestion and knowledge graph extraction
    neo4j_loader.py        Loads graph.json into Neo4j
    distractor_engine.py   Graph traversal and distractor selection
    mcq_generator.py       Question generation with self-corrective loop
    api.py                 FastAPI REST endpoints
    guards.py              Input validation and service health checks
    rate_limiter.py        Exponential backoff for HF API rate limits
    eval.py                Automated pipeline evaluation
    app.py                 Streamlit UI

Setup

Requirements

  • Python 3.11+
  • Neo4j Community Edition (running locally on bolt://localhost:7687)
  • A Hugging Face account with an access token

Install dependencies

pip install -r requirements.txt

Environment variables

Create a .env file in the project root:

HUGGINGFACEHUB_ACCESS_TOKEN=your_token_here

Start Neo4j

Download and install Neo4j Community Edition from neo4j.com. Start the service and set a password. Update the NEO4J_PASSWORD constant at the top of each file to match.

Run the API

uvicorn api:app --reload --port 8000

Run the frontend

streamlit run app.py

Open http://localhost:8501 in your browser.


Usage

Ingest a PDF

Go to the Ingest PDF tab, upload any academic PDF, and click Ingest. The pipeline extracts entities and relationships chunk by chunk and loads them into Neo4j. For a 50 page textbook expect roughly 2 to 3 minutes.

Generate an assessment

Go to Generate Assessment, choose random concepts or pick specific ones from the graph, set how many MCQs and T/F questions you want, and click Generate. Each question goes through the self-corrective loop before being returned.

Browse the graph

The Browse Graph tab shows all extracted entities as filterable pills, a relationship count breakdown by type, and a concept detail view that shows the full neighborhood of any node along with its computed distractors.

Run evals

The Eval Dashboard runs a full generation pass and scores it across five metrics: verification rate, distractor quality, question uniqueness, option format, and latency per question.


API

The FastAPI layer exposes these endpoints:

GET  /health                 API and Neo4j connectivity check
POST /ingest/sync            Upload PDF, wait for completion
POST /ingest                 Upload PDF, process in background
GET  /graph/stats            Node and relationship counts
GET  /graph/concepts         List all concepts (filterable by type)
GET  /graph/concept/{name}   Full neighborhood for a single concept
POST /assess                 Generate assessment from concept list
GET  /assess/random          Generate assessment from random concepts

Interactive docs are available at http://localhost:8000/docs when the server is running.


Eval Metrics

Metric Target What it measures
Verification rate 80% Fraction of questions passing all structural checks
Distractor quality 70% Fraction of distractors graph-adjacent to the concept
Question uniqueness 100% No near-duplicate question stems in the same run
Option format 90% MCQ options that are short noun phrases, not sentences
Latency 30s/q Average generation time per question including retries

Limitations

Graph density. The quality of distractors is directly proportional to how connected the knowledge graph is. Concepts with only one or two edges in the graph fall back to random same-type nodes, which can produce off-domain distractors. Ingesting a longer, more comprehensive textbook improves this significantly.

Entity extraction consistency. The extraction pipeline uses an instruction-tuned 7B model on the free HF inference tier. Occasionally the same concept gets extracted under two slightly different names across chunks ("KMeans" vs "K-Means"). The deduplication pass catches most of these but not all.

Rate limits. The free HF inference tier has per-minute rate limits. The rate limiter handles 429 responses with exponential backoff, but very large PDFs processed quickly may still hit sustained limits. Adding a longer delay between chunks (the delay parameter in ingest_pdf) helps.


What I Would Do With More Time

  • Replace the free HF tier with a locally hosted model (Ollama + Mistral-7B) to remove rate limit constraints entirely
  • Add a graph merge strategy for ingesting multiple PDFs into one unified knowledge graph
  • Build a Cypher-based query interface so instructors can inspect and edit the graph before generating assessments
  • Experiment with larger models (Llama-3-70B) for extraction to improve entity consistency across chunks

License

MIT

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages