Cross-Graph is an end-to-end system powered by Large Language Models (LLM) designed to construct knowledge graphs from unstructured text (PDF/TXT/MD) and generate high-quality cross-document multi-hop reasoning questions based on graph paths.
- Bilingual UI Support: Seamlessly switch between Chinese and English interfaces.
- Automated Schema Design: AI-assisted generation of entity and relation schemas based on domain descriptions.
- Data Preprocessing: Batch convert PDF, TXT, and MD files into JSONL format ready for extraction.
- Knowledge Extraction: Parallelized information extraction using LangExtract with OpenAI-compatible LLMs (GPT-4o, DeepSeek, etc.).
- Graph Storage: Automatic import of extracted knowledge into Neo4j graph database.
- Rare Node Analysis: Identify long-tail/rare nodes to discover deep, non-obvious knowledge connections.
- Random Walk Sampling: Generate reasoning paths by performing cross-document random walks starting from rare nodes.
- Complex QA Generation: Produce high-difficulty multi-hop question-answer pairs based on graph paths.
cross_graph/
├── src/
│ ├── core/ # Core Logic Modules
│ │ ├── data_processor.py # Data Preprocessing (Folder -> JSONL)
│ │ ├── extractor.py # Knowledge Extraction (LLM-based)
│ │ ├── graph_importer.py # Neo4j Import
│ │ ├── rare_node_analyzer.py # Rare Node Analysis
│ │ ├── random_walker.py # Random Walk Path Generation
│ │ └── question_generator.py # QA Pair Generation
│ └── ui/ # User Interface
│ └── app.py # Gradio Main Application
├── examples/ # Example Data and Configs
├── docs/ # Documentation
├── requirements.txt # Dependencies
├── README.md # English Documentation
└── README_ZH.md # Chinese Documentation
- Python 3.8+
- Neo4j Database: Ensure Neo4j is installed and running (Community or Enterprise).
Install the required Python packages:
pip install -r requirements.txtRun the following command in the project root directory:
# Default launch (http://127.0.0.1:7860)
python -m src.ui.app
# Custom host and port
python -m src.ui.app --host 0.0.0.0 --port 8000
# Create a public share link (e.g. *.gradio.live)
python -m src.ui.app --shareOnce started, access the web interface at the displayed URL.
Define the structure of your Knowledge Graph.
- Domain Setup: Enter the target domain (e.g., "Finance", "Medicine").
- AI Auto-Gen: Configure your LLM (API Key, Base URL) and click "🚀 AI Auto-Generate Config" to automatically create entities and relations.
- Manual Refinement: Use the UI to add, edit, or delete entities and relations.
- Examples: Provide few-shot examples to improve extraction accuracy.
- Save Config: Click "💾 Save Config" to save
extraction_config.json.
Process raw files and extract knowledge.
- Data Preprocessing:
- Input: Folder path containing source files (PDF/TXT/MD).
- Action: Click "🔄 Execute Preprocessing".
- Output: A
.jsonlfile.
- Knowledge Extraction:
- Input: The generated
.jsonlfile. - Config: Set LLM parameters (API Key, Model, etc.) and Advanced Settings (Concurrency, Batch Size).
- Action: Click "
▶️ Start Extraction". - Output: A
.jsonlfile containing extracted entities and relations.
- Input: The generated
Import data into Neo4j and analyze graph structure.
- Import to Neo4j:
- Enter Neo4j URI, User, and Password.
- Select the extraction output file.
- Click "⬆️ Execute Import".
- Rare Node Analysis:
- Click "🔍 Analyze Rare Nodes" to find nodes with low degree centrality.
- Adjust "Top Percent" to control the rarity threshold.
- Random Walk:
- Generate paths starting from rare nodes to uncover hidden connections.
- Adjust "Max Path Length" and "Cross-document Weight".
Generate high-quality Q&A pairs for training or evaluation.
- Configuration:
- Select the path file generated in Tab 3.
- Configure LLM settings for question generation.
- Generation:
- Click "✨ Start Question Generation".
- The system will use the paths to create multi-hop reasoning questions.
- Results are saved to a JSON file.
extractor.py: Handles parallel knowledge extraction usinglangchainand custom prompts.graph_importer.py: Manages Cypher query generation and batch execution for Neo4j.random_walker.py: Implements biased random walks that prefer cross-document edges.app.py: The Gradio-based frontend orchestration layer.





