Skip to content
HKUSTDialPublic

About

Document-to-Database Extraction

Resources

Stars

7 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

6 Commits

Folders and files

Repository files navigation

DataMosaic: Document-to-Database Extraction

Papers: Document-to-Database (VLDB 2026) Β· DataMosaic Demo (VLDB 2026)

DataMosaic bridges the gap between unstructured enterprise knowledge and structured analytics. While Large Language Models (LLMs) excel at processing local text, they often struggle with global database semanticsβ€”failing to respect schemas, foreign keys, and integrity constraints.

DataMosaic solves this by mediating between LLM extraction and strict database logic. Instead of a one-shot prompt, it uses an orchestrator-managed closed loop to ensure the final database is not just filled with text, but is structurally sound and analytically useful.

This repository contains the full open-source release, including the algorithm core (modules/), a Flask + WebSocket backend (backend/), a React + TypeScript frontend (frontend/), and an evaluation harness.


πŸ“„ Papers

This work is associated with two publications:

[1] Zhengxuan Zhang, Zhuowen Liang, Jiazhuo Chen, Haixun Wang, and Nan Tang. Document-to-Database: Extraction Meets Relational Semantics. VLDB, 2026. [PDF]

[2] Zhengxuan Zhang, Zhuowen Liang, Haixun Wang, and Nan Tang. DataMosaic: An Interactive Demonstration of Constraint-Driven Document-to-Database Construction. VLDB Demo, 2026. [PDF]


✨ Key Features

  • πŸ—οΈ Schema-Driven Extraction. DataMosaic takes an ER schema (with integrity and business constraints) as input and ensures the extracted data actually fits your database structure.
  • πŸ”„ Closed-Loop Refinement. Implements an Extraction β†’ Verification β†’ Repair loop. It detects constraint violations (e.g., broken foreign keys) and performs targeted re-extraction to fix them.
  • πŸ›‘οΈ Semantic Consistency. Distinguishes between intrinsic document ambiguity and correctable extraction errors.
  • πŸ”Œ Pluggable Architecture. Supports third-party LLM extractors, domain-specific verifiers, and custom repair operators via the MCP (Multi-Constraint-Plugin) registry.
  • πŸ–₯️ Full-stack UI. A React frontend lets you upload documents, define schemas (form-based or natural language), watch the agent loop run in real-time, and inspect / export the resulting database.

πŸ“ Repository Layout

DataMosaic/
β”œβ”€β”€ backend/                      # Flask API + WebSocket service
β”‚   β”œβ”€β”€ app.py                    # Service entry point
β”‚   β”œβ”€β”€ config.py                 # Paths, CORS, ports
β”‚   β”œβ”€β”€ routes/                   # REST endpoints
β”‚   β”‚   β”œβ”€β”€ file_routes.py        # Upload / file listing
β”‚   β”‚   β”œβ”€β”€ doc2db_routes.py      # Extraction jobs & SSE stream
β”‚   β”‚   β”œβ”€β”€ memory_routes.py      # Snapshots / violations / fixes
β”‚   β”‚   β”œβ”€β”€ database_routes.py    # SQLite DB management
β”‚   β”‚   └── settings_routes.py    # Model & API key settings
β”‚   β”œβ”€β”€ utils/                    # File / history / websocket helpers
β”‚   └── websocket_signals.py      # Realtime signal broadcaster
β”‚
β”œβ”€β”€ frontend/                     # React + TypeScript SPA
β”‚   β”œβ”€β”€ public/                   # Static assets
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ App.tsx               # Root component
β”‚   β”‚   β”œβ”€β”€ components/           # Layout, panels, dialogs
β”‚   β”‚   β”‚   β”œβ”€β”€ Doc2DBProcessor/  # Main extraction UI (config, steps, results)
β”‚   β”‚   β”‚   β”œβ”€β”€ Doc2DBHistoryPanel.tsx
β”‚   β”‚   β”‚   β”œβ”€β”€ DatabaseManager.tsx
β”‚   β”‚   β”‚   └── FileLibraryWithUpload.tsx
β”‚   β”‚   β”œβ”€β”€ hooks/                # useFiles, usePanel, useDoc2DB
β”‚   β”‚   β”œβ”€β”€ services/             # WebSocket client
β”‚   β”‚   β”œβ”€β”€ constants/            # Theme & config (models, project)
β”‚   β”‚   └── styles/
β”‚   β”œβ”€β”€ package.json
β”‚   └── tsconfig.json
β”‚
β”œβ”€β”€ modules/                      # Core algorithm (the "DataMosaic" engine)
β”‚   β”œβ”€β”€ agents/
β”‚   β”‚   β”œβ”€β”€ extractor/            # Entity & relation extractors (base + utils)
β”‚   β”‚   β”œβ”€β”€ verifier/             # MCP router + MCP-based verifier
β”‚   β”‚   β”œβ”€β”€ fixer/                # MCP-based repair operators
β”‚   β”‚   β”œβ”€β”€ orchestrator/         # Unified/parallel orchestrators, signal coordinator
β”‚   β”‚   └── mcp/                  # Pluggable constraint servers
β”‚   β”‚       β”œβ”€β”€ config/           # MCP plugin configuration
β”‚   β”‚       └── ...               # structure / value / logic / type /
β”‚   β”‚                               # temporal / aggregation / reference /
β”‚   β”‚                               # format / data quality
β”‚   β”œβ”€β”€ core/                     # IO + ID generation (io.py, ids.py)
β”‚   β”œβ”€β”€ memory/                   # Memory manager, snapshots, tables,
β”‚   β”‚                             # violations, fixes
β”‚   β”œβ”€β”€ services/                 # Doc2DBService (used by the Flask backend)
β”‚   β”œβ”€β”€ signals/                  # Internal signal bus (core + handlers)
β”‚   └── utils/                    # Orchestrator logging, task helpers
β”‚
β”œβ”€β”€ llm/                          # LLM client routers (GPT / DeepSeek / Qwen)
β”‚   β”œβ”€β”€ main.py                   # Unified get_answer() entry
β”‚   β”œβ”€β”€ global_config.py          # Current model selector
β”‚   β”œβ”€β”€ gpt.py / qwen.py / deepseek.py / utils.py
β”‚   └── .env.example              # Copy to .env and fill in your keys
β”‚
β”œβ”€β”€ dataset/                      # Open-source evaluation datasets
β”‚   β”œβ”€β”€ FinanceDB/ LegalDB/ PaperDB/ StudentDB/
β”‚   β”‚   └── <case>/docs/          # Per-case documents + schema
β”‚
β”œβ”€β”€ tests/                        # Unit tests (service, memory manager)
β”‚
β”œβ”€β”€ scripts/                      # Convenience launchers
β”‚   β”œβ”€β”€ start_backend.sh
β”‚   └── start_frontend.sh
β”‚
β”œβ”€β”€ test_dataset_evaluate.py      # Full system evaluation script
β”œβ”€β”€ llm_evaluate.py               # LLM-only baseline evaluator
β”œβ”€β”€ update_experiment/            # Schema-update robustness experiments
β”‚   └── C01_... C12_...           # Add / delete / update scenarios
β”œβ”€β”€ results.md                    # Published evaluation comparison
β”œβ”€β”€ requirements.txt
└── README.md

πŸš€ Quick Start

Prerequisites

  • Python 3.8+
  • Node.js 18+ and npm
  • One LLM API key (OpenAI-compatible, DeepSeek, or Qwen/DashScope)

1. Clone & install Python dependencies

cd DataMosaic
python3 -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt

2. Configure API keys

cp llm/.env.example llm/.env
# Edit llm/.env with your real keys, then:

llm/.env example:

API_KEY=sk-...
API_URL=https://api.openai.com/v1
DEEPSEEK_KEY=...
DEEPSEEK_URL=https://api.deepseek.com
QWEN_KEY=...
QWEN_URL=https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions

3. Start the backend

./scripts/start_backend.sh
# or manually:
#   cd backend && python app.py

The backend exposes:

  • http://localhost:5000 β€” REST API
  • ws://localhost:8765 β€” realtime signal stream

4. Start the frontend (in a second terminal)

./scripts/start_frontend.sh
# or manually:
#   cd frontend && npm install && npm start

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


πŸ§ͺ Evaluation

Full system evaluation

python test_dataset_evaluate.py --dataset FinanceDB --case case1 --model gpt-4o

Parameters:

Flag Description
--dataset FinanceDB, PaperDB, StudentDB, or LegalDB
--case Test case within the dataset (e.g. case1)
--model LLM model identifier (e.g. gpt-4o, claude-3-5-sonnet, qwen2.5-72b-instruct)
--run_name Custom output run identifier

LLM-only baseline

python llm_evaluate.py --dataset FinanceDB --case case1 --model gpt-4o

Metrics produced: Precision / Recall / F1 / LLM-Score (0–100). See results.md for a published comparison.


πŸ”Œ REST API (highlights)

Endpoint Purpose
GET /api/health Health check
POST /api/upload/batch Upload one or more documents
GET /api/files List uploaded documents
POST /api/doc2db/process Start an extraction job
GET /api/doc2db/stream/<task_id> Server-Sent Events progress stream
GET /api/doc2db/status/<task_id> Poll task status
GET /api/doc2db/history List historical runs
GET /api/memory/snapshots/<run_id> Inspect table snapshots
GET /api/memory/violations/<run_id> Inspect detected violations
GET /api/memory/fixes/<run_id> Inspect repair operations
GET /api/databases / POST .../tables SQLite database management
GET /api/settings / POST /api/settings Read / update active model and keys

🧩 Architecture in One Picture

                β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
   Documents ──▢│  Extractor (entities + relations)            β”‚
                β”‚  └─ LLM calls via llm.main.get_answer()      β”‚
                β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                            β–Ό
                β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                β”‚  Verifier (MCP plugins)                      β”‚
                β”‚  structure / type / value / logic / format / β”‚
                β”‚  temporal / reference / aggregation / DQ     β”‚
                β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                            β–Ό violations
                β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                β”‚  Fixer  (targeted re-extraction / repair)    β”‚
                β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                            β–Ό
                β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                β”‚  Orchestrator (signal-driven closed loop)    β”‚
                β”‚  β†’ memory snapshots β†’ final DB instance      β”‚
                β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

The full pipeline is exposed both as a service (modules.services.Doc2DBService, used by the Flask backend) and as an importable Python library (use the modules directly without the HTTP layer).


πŸ“¦ What is not included (by design)

To keep this repository clean and reproducible we exclude:

  • backend/history/, backend/output/, backend/uploads/, backend/logs/ β€” runtime artifacts
  • frontend/node_modules/, frontend/build/ β€” install / build outputs
  • llm/.env β€” your private credentials (only .env.example is shipped)

These paths are pre-listed in .gitignore.


πŸ“œ License

Released under the project's open-source license. See LICENSE (if present) for full terms.

πŸ™ Acknowledgements

DataMosaic uses Material-UI for the frontend.

πŸ“ Citation

If you find this work helpful, please consider citing our papers:

@inproceedings{datamosaic,
  title={Document-to-Database: Extraction Meets Relational Semantics},
  author={Zhang, Zhengxuan and Liang, Zhuowen and Chen, Jiazhuo and Wang, Haixun and Tang, Nan},
  year={2026},
  journal={Proceedings of the VLDB Endowment},
  volume={19},
  number={9},
  pages={2522--2535},
  year={2026},
  publisher={VLDB Endowment}
}

@inproceedings{datamosaic_demo,
  title={DataMosaic: An Interactive Demonstration of Constraint-Driven Document-to-Database Construction},
  author={Zhang, Zhengxuan and Liang, Zhuowen and Wang, Haixun and Tang, Nan},
  journal={Proceedings of the VLDB Endowment},
  volume={19},
  number={12},
  pages={4570--4573},
  year={2026},
  publisher={VLDB Endowment},
}

About

Document-to-Database Extraction

Resources

Stars

7 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages