A sophisticated multi-layer verification system that determines whether character backstories are logically consistent with source novels (100k+ words). Built using the Pathway framework for real-time document processing and RAG capabilities.
Given a character backstory, determine if it is:
- Consistent (1): The backstory is logically consistent with the novel
- Contradicts (0): The backstory contains contradictions to established facts
┌─────────────────────────────────────────────────────────────────┐
│ MULTI-LAYER VERIFICATION │
├─────────────────────────────────────────────────────────────────┤
│ Layer 1: Rule-Based Constraints │
│ ├── Character nationality/profession checks │
│ ├── Timeline validation │
│ └── Cross-character impossibility detection │
├─────────────────────────────────────────────────────────────────┤
│ Layer 2: Historical Fact Verification │
│ ├── Known historical event validation │
│ └── Date/period consistency checking │
├─────────────────────────────────────────────────────────────────┤
│ Layer 3: Pathway RAG Evidence Retrieval │
│ ├── Document chunking with VectorStoreServer │
│ ├── Semantic + keyword hybrid search │
│ └── Character-tagged passage retrieval │
├─────────────────────────────────────────────────────────────────┤
│ Layer 4: LLM-Based Reasoning │
│ ├── Atomic claim extraction │
│ ├── Evidence-claim alignment scoring │
│ └── Multi-hop reasoning for complex claims │
└─────────────────────────────────────────────────────────────────┘
Kharagpur/
├── Dataset/
│ ├── Books/
│ │ ├── In search of the castaways.txt
│ │ └── The Count of Monte Cristo.txt
│ ├── train.csv
│ └── test.csv
├── src/
│ ├── __init__.py
│ ├── config.py # Configuration and character constraints
│ ├── pathway_pipeline.py # Pathway RAG integration
│ ├── document_processor.py # Novel chunking and processing
│ ├── character_profiler.py # Character fact extraction
│ ├── claim_extractor.py # Backstory claim decomposition
│ ├── retriever.py # Hybrid retrieval system
│ ├── verifier.py # Multi-layer verification engine
│ └── pipeline.py # Main orchestration
├── results/ # Output directory
├── cache/ # Pathway cache
├── run.py # Entry point
├── requirements.txt
├── .env.example
└── README.md
pip install -r requirements.txtcp .env.example .env
# Edit .env with your API keysRequired:
ANTHROPIC_API_KEY- For Claude LLM reasoningOPENAI_API_KEY- For embeddings (optional)
# Full run with all features
python run.py
# Quick test mode (5 samples)
python run.py --test-mode
# Without LLM (faster, uses rule-based only)
python run.py --no-llm
# Custom output path
python run.py --output my_results.csvResults are saved to results/results.csv:
story_id,prediction,rationale
1,1,Backstory is consistent with novel events
2,0,Character nationality contradiction - Paganel is French, not GermanThe system uses Pathway for:
- Document Indexing:
VectorStoreServerfor efficient vector storage - File Connectors:
pw.io.fs.readfor novel ingestion - Streaming Ready: Architecture supports real-time document updates
- Chunking:
TokenCountSplitterfor intelligent text segmentation
from pathway.xpacks.llm.vector_store import VectorStoreServer
from pathway.xpacks.llm.splitters import TokenCountSplitter
# Meaningful Pathway usage
server = VectorStoreServer(documents_table, embedder=embedder, splitter=splitter)
server.run_server(host="localhost", port=8080)- Rule-Based Layer: Instant constraint checking (nationality, profession, timeline)
- Historical Layer: Validates historical claims (e.g., Waterloo outcome)
- RAG Layer: Retrieves and scores evidence from source text
- LLM Layer: Complex reasoning for ambiguous cases
Pre-defined constraints for all 6 characters:
| Character | Novel | Key Constraints |
|---|---|---|
| Jacques Paganel | In Search of the Castaways | French, geographer, no prior Britannia connection |
| Thalcave | In Search of the Castaways | Patagonian, never left South America |
| Tom Ayrton | In Search of the Castaways | British, quartermaster, led mutiny |
| Kai-Koumou | In Search of the Castaways | Maori chief, New Zealand only |
| Noirtier | Count of Monte Cristo | French, Bonapartist, paralyzed later |
| Faria | Count of Monte Cristo | Italian abbé, died in prison |
| Mode | Speed | Accuracy | Best For |
|---|---|---|---|
| Full (with LLM) | ~5s/sample | Highest | Final submission |
| No LLM | ~0.5s/sample | Good | Quick testing |
| Test Mode | ~15s total | - | Development |
Edit src/config.py to customize:
# Retrieval settings
RETRIEVAL_CONFIG = {
"chunk_size": 1500, # Characters per chunk
"chunk_overlap": 300, # Overlap between chunks
"top_k": 15, # Results per query
}
# LLM settings
LLM_CONFIG = {
"provider": "anthropic",
"model": "claude-sonnet-4-20250514",
"temperature": 0.1, # Low for consistency
}- Narrative Constraint Graph: Pre-computed character knowledge graph
- Multi-Layer Verification: Catches different contradiction types
- Meaningful Pathway Usage: Not just a checkbox, actual RAG infrastructure
- Fallback Resilience: Works without API keys (reduced accuracy)
- Evidence-Based Rationale: Returns novel excerpts supporting decisions
story_id,prediction,rationale
1,1,Earlier economic shock makes outcome necessary
2,0,Proposed backstory contradicts later actions - character cannot be German- Track A: Pathway framework integration (mandatory)
- Binary Classification: 1 = consistent, 0 = contradicts
- Rationale: Optional but encouraged for transparency
MIT License - KDSH 2026 Hackathon Submission
Track A Submission - KDSH 2026 Hackathon