Skip to content

Repository files navigation

NSQA Banner

简体中文 | English

NSQA

Neural-Symbolic Question Answering
Academic paper QA with hybrid retrieval, knowledge graph, and multi-hop reasoning

Python FastAPI License Milvus Neo4j


Features

  • PDF Parsing — MinerU-powered academic PDF extraction with multi-view classification (text, table, formula, image)
  • Multi-View Retrieval — Per-view-type embedding and storage for precise semantic search
  • Hybrid Search — Neural + lexical (BM25) + symbolic (conference/year filter) triple retrieval
  • Knowledge Graph — Paper triple extraction → Neo4j graph → KG-enhanced retrieval
  • Multi-Hop Reasoning — Automatic multi-hop evidence discovery and fusion across papers
  • Formula & Table Support — Dedicated formula normalization, semantic anchor enhancement
  • Evaluation Framework — Built-in benchmark system with rule-based + LLM-backed scoring
  • Model Pool — Multi-LLM routing with round-robin / least-active strategies

Architecture

┌─────────────────────────────────────────────────────────┐
│                       NSQA System                        │
│                                                         │
│  PDF ──► MinerU Parse ──► Multi-View Classify ──► Chunk │
│                                                   │     │
│                                    ┌──────────────┘     │
│                                    ▼                    │
│  ┌──────────┐  ┌──────────┐  ┌──────────┐             │
│  │  Vector  │  │   BM25   │  │  Symbolic │  ◄─ Hybrid │
│  │ (Milvus) │  │ (MySQL)  │  │  Filter   │    Search  │
│  └────┬─────┘  └────┬─────┘  └────┬─────┘             │
│       └──────────┬───┘──────────┬──┘                   │
│                  ▼              ▼                       │
│          ┌──────────────┐ ┌───────────┐                │
│          │ Answer Gen   │ │ KG (Neo4j)│                │
│          │ + Judge      │ │ Multi-Hop │                │
│          └──────────────┘ └───────────┘                │
│                  │                                      │
│                  ▼                                      │
│           Evaluation Report                            │
└─────────────────────────────────────────────────────────┘

Quick Start

Prerequisites

  • Python 3.11+
  • MySQL 8.0+
  • Milvus 2.x
  • Neo4j 5.x (optional, for KG retrieval)
  • MinerU API token (mineru.net)

Installation

git clone https://github.com/ArtLjn/NSQA.git
cd NSQA

python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

Configuration

cp src/config/config.example.ini src/config/config.ini
Section What to configure
[mineru] api_token — your MinerU API token
[mysql] host, user, password — MySQL connection
[milvus] host, port — Milvus vector DB
[neo4j] uri, user, password — Neo4j graph DB
[embedding] provider — google / openai / local / ollama
[llm_evaluation] api_key, base_url, model — LLM backend

Initialize Database

mysql -u root -p < sql/airqa_neusym.sql

Launch

# Development
./start_api.sh

# Production (Linux)
./deploy/scripts/bootstrap_linux.sh   # first time setup
./deploy/scripts/start_airqa.sh        # start service

Docker

cd deploy
cp config/config.example.ini src/config/config.ini  # edit credentials
docker compose up --build

Project Structure

NSQA/
├── src/
│   ├── api/                  # FastAPI routes & schemas
│   ├── chunking/             # PDF parsing, multi-view classification, embedding
│   ├── retrieval/            # Hybrid retriever, KG, multi-hop, context enhancer
│   ├── evaluation/           # Benchmark, scoring, answer generation
│   ├── services/             # Task management, sync coordination
│   ├── config/               # Configuration & model pool
│   └── db/                   # MySQL connection pool
├── scripts/                  # Utility & maintenance scripts
├── frontend/                 # Web UI (vanilla HTML/JS)
├── deploy/                   # Docker, systemd, bootstrap scripts
├── tests/                    # pytest test suite
├── docs/                     # Documentation
├── sql/                      # Database schema
└── data/                     # Runtime data (gitignored)

Evaluation

NSQA includes a built-in evaluation framework that compares retrieval backends:

POST /api/evaluation/batch-evaluate
{
  "backend": "both",      # airqa / kg / both
  "sample_source": "all",
  "max_workers": 2
}

Results are rendered as interactive frontend reports with per-sample analysis.

Tech Stack

Component Technology
API Framework FastAPI + Uvicorn
PDF Parsing MinerU (VLM)
Vector DB Milvus
Graph DB Neo4j
Relational DB MySQL 8.0
Embedding Google Gemini / OpenAI / Ollama
LLM ModelScope / OpenAI-compatible APIs
Frontend Vanilla HTML/CSS/JS

License

MIT

About

Neural-Symbolic Question Answering — Academic paper QA with hybrid retrieval, knowledge graph, and multi-hop reasoning

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages