A Local 27B Model Builds a 5,816-Entity Knowledge Graph from a 120-Chapter Classic
A 27B model on a laptop can now produce a citation-backed knowledge graph from a full-length novel in half a day, with every relation traceable to source text. That makes local graph construction a realistic option for privacy-sensitive or iterative document analysis, and gives a concrete baseline for memory, token, and cost tradeoffs.
A local run of Qwen 27B (via Ollama, NVFP4 quantized) turned all 120 chapters of Dream of the Red Chamber into a knowledge graph with 5,816 entities, 5,165 relations, 1,951 attributes, and 10,145 evidence passages. The pipeline splits the text by chapter, extracts entities and relations with a 32K context window, then reviews each candidate against original text before aligning identities across chapters. The total wall time from import to publication was 12 hours 27 minutes on a MacBook Pro with 48GB unified memory.
The work is part of DocFlow, a full-stack project combining agents, RAG, and knowledge graphs. The graph feeds an agent that can answer cross-chapter questions with explicit source citations. A key test case was distinguishing Jia Baoyu from Zhen Baoyu, two nearly identical names that must not collapse into one node.
The article also details memory sizing: BF16 weights would need ~54GB, so quantization plus a ~2GiB KV cache at 32K context is what makes it fit. Token usage totaled 2.98M input and 1.53M output across 806 model calls. The same load on DeepSeek-flash would cost roughly ¥9 to ¥18, but the local choice keeps the full corpus on-device and allows rule changes to be re-run directly.
The three-stage process makes identity disambiguation the real bottleneck, not entity extraction: the same person has multiple names, different people share names, and model guesses need a dedicated reconciliation pass plus human-verifiable evidence.
The cost comparison with DeepSeek-flash (¥9-18 for the whole job) shows the local choice is not about saving money; it is about keeping the full corpus on-device and being able to re-run the pipeline whenever extraction rules change.
The 12.5-hour wall time is dominated by orchestration and post-processing, not raw generation: 4.5M total tokens across 806 calls implies per-call latency is modest, so batch throughput and review logic set the practical ceiling.