Skip to content

About

No description, website, or topics provided.

Resources

Stars

4 stars

Watchers

0 watching

Forks

Repository files navigation

Narrative Consistency Verification System

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.


🎯 Problem Statement

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

🏗️ Architecture

┌─────────────────────────────────────────────────────────────────┐
│                    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                      │
└─────────────────────────────────────────────────────────────────┘

📁 Project Structure

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

🚀 Quick Start

1. Install Dependencies

pip install -r requirements.txt

2. Configure API Keys

cp .env.example .env
# Edit .env with your API keys

Required:

  • ANTHROPIC_API_KEY - For Claude LLM reasoning
  • OPENAI_API_KEY - For embeddings (optional)

3. Run Verification

# 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.csv

4. Check Results

Results 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 German

🔑 Key Features

Pathway Integration (Track A Requirement)

The system uses Pathway for:

  1. Document Indexing: VectorStoreServer for efficient vector storage
  2. File Connectors: pw.io.fs.read for novel ingestion
  3. Streaming Ready: Architecture supports real-time document updates
  4. Chunking: TokenCountSplitter for 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)

Multi-Layer Verification

  1. Rule-Based Layer: Instant constraint checking (nationality, profession, timeline)
  2. Historical Layer: Validates historical claims (e.g., Waterloo outcome)
  3. RAG Layer: Retrieves and scores evidence from source text
  4. LLM Layer: Complex reasoning for ambiguous cases

Character Constraint System

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

📊 Performance

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

🔧 Configuration

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
}

🎯 Unique Differentiators

  1. Narrative Constraint Graph: Pre-computed character knowledge graph
  2. Multi-Layer Verification: Catches different contradiction types
  3. Meaningful Pathway Usage: Not just a checkbox, actual RAG infrastructure
  4. Fallback Resilience: Works without API keys (reduced accuracy)
  5. Evidence-Based Rationale: Returns novel excerpts supporting decisions

📝 Output Format

story_id,prediction,rationale
1,1,Earlier economic shock makes outcome necessary
2,0,Proposed backstory contradicts later actions - character cannot be German

🏆 Competition Notes

  • Track A: Pathway framework integration (mandatory)
  • Binary Classification: 1 = consistent, 0 = contradicts
  • Rationale: Optional but encouraged for transparency

📜 License

MIT License - KDSH 2026 Hackathon Submission


🤝 Team

Track A Submission - KDSH 2026 Hackathon

About

No description, website, or topics provided.

Resources

Stars

4 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages