5D Library › 检索增强生成几何、倒数秩融合与多智能体误差级联 · English

第七章 《七略》的分类路由与《韩非子》的参验:检索与核验的两种古法

为什么在这里读刘向、刘歆与韩非

两千年前的皇家图书馆也面对检索问题:书越来越多,怎样让人找得到?西汉末年,刘向、刘歆父子校理群书,为每一部书写提要,再把全部书目分成几大类——这就是《七略》,中国最早的系统目录。比他们更早的韩非则讨论过另一个问题:怎样判断一个说法可信?他的答案是「参验」——用多方面的证据互相核对。本章把这两件事读作检索系统的两种古老设计:分类路由与多源核验,并用第一、四章的模型算出它们何时有效、何时失效。

原文

原典

班固《汉书·艺文志》。

每一書已,向輒條其篇目,撮其指意,錄而奏之。會向卒,哀帝復使向子侍中奉車都尉歆卒父業。歆於是總群書而奏其七略,故有輯略,有六藝略,有諸子略,有詩賦略,有兵書略,有術數略,有方技略。

《韩非子·显学》。

無參驗而必之者,愚也;弗能必而據之者,誣也。

(班固 1962; 王先慎 1998; Han 1964)

注

版本与核对。 《汉书·艺文志》一段已与维基文库所载文字逐字核对一致。《韩非子·显学》一句已据王先慎《韩非子集解》核对一致。刘向校书时「一人读书、校其上下为校,一人持本、一人读书、若怨家相对为雠」的说法,见于后世类书所引《别录》佚文,本书只作转述,不作直接引用,出处已核对。

《七略》:先分类,再查找

刘歆把群书分为六略,加上总述性质的《辑略》。用今天的话说,这是一个两级检索:先判断一部书属于哪一略(路由),再在这一略里查找。第十五段程序的 A 段把它放进第一章的极值模型:路由正确的概率为 aa,路由错了就找不到。

推导

# Chapter 7. p15: Liu Xin's catalogue as routing; Han Fei's canyan as voting.
# A. The Qilue sorted the imperial library into six substantive
#    divisions plus a summary. As retrieval: route a query to one of six
#    divisions (right with probability a), then search only that
#    division. Search uses the extreme-value model of p01 with
#    effective dimension 150 and a relevant cosine of 0.30: top-1 is right
#    when the relevant chunk beats the best of M distractors. Flat search
#    over 60,000 chunks against routed search over 10,000.
# B. Canyan, "checking against several sources": k sources each right
#    with 0.8, majority vote. With probability c all k merely repeat one
#    source (shared provenance) - then k sources are worth one.
# C. Jiaochou, collation by two readers: each catches an error with 0.7;
#    with probability c they miss the same errors together.
import math
import random

def erfinv(y):
    x = 0.0 if abs(y) < 0.7 else math.copysign(
        math.sqrt(-math.log((1 - abs(y)) / 2)), y)
    for _ in range(60):
        x -= (math.erf(x) - y) / (2 / math.sqrt(math.pi) * math.exp(-x * x))
    return x

def top1(rng, m, d=150, trials=4000):
    sd = 1 / math.sqrt(d)
    ok = 0
    for _ in range(trials):
        rel = 0.30 + rng.gauss(0, sd)
        u = rng.random() ** (1 / m)
        ok += math.sqrt(2) * erfinv(2 * u - 1) * sd < rel
    return ok / trials

def vote(k, p):
    return sum(math.comb(k, j) * p ** j * (1 - p) ** (k - j)
               for j in range(k // 2 + 1, k + 1))

if __name__ == "__main__":
    rng = random.Random(61015)
    flat = top1(rng, 60000)
    inner = top1(rng, 10000)
    print("A. flat search over 60,000: top-1 {:.3f}".format(flat))
    print("   search inside one division of 10,000: top-1 {:.3f}".format(
        inner))
    print("   routing accuracy   routed top-1   better than flat?")
    for a in (1.0, 0.95, 0.9, 0.8, 0.7, 0.6):
        r = a * inner
        print("        {:.2f}            {:.3f}          {}".format(
            a, r, "yes" if r > flat else "no"))
    print("   break-even routing accuracy: {:.3f}".format(flat / inner))
    print("\nB. majority of k sources, each right with 0.8")
    print("   k    c = 0    c = 0.3   c = 0.6")
    for k in (1, 3, 5, 7):
        print("   {}   {:.4f}   {:.4f}    {:.4f}".format(
            k, *[c * 0.8 + (1 - c) * vote(k, 0.8) for c in (0, 0.3, 0.6)]))
    print("\nC. two collators, each catching 0.7 of errors")
    for c in (0.0, 0.3, 0.6):
        print("   shared misses c = {}: caught {:.3f}".format(
            c, c * 0.7 + (1 - c) * (1 - 0.3 ** 2)))
    print("\nReading: a catalogue helps retrieval only when its routing is")
    print("more reliable than the break-even accuracy - a misfiled book is")
    print("lost however good the shelf search. More sources raise")
    print("accuracy only to the extent that they are independent; sources")
    print("that copy one another add confidence without adding evidence.")
# A. flat search over 60,000: top-1 0.286
#    search inside one division of 10,000: top-1 0.436
#    routing accuracy   routed top-1   better than flat?
#         1.00            0.436          yes
#         0.95            0.414          yes
#         0.90            0.393          yes
#         0.80            0.349          yes
#         0.70            0.305          yes
#         0.60            0.262          no
#    break-even routing accuracy: 0.656
#
# B. majority of k sources, each right with 0.8
#    k    c = 0    c = 0.3   c = 0.6
#    1   0.8000   0.8000    0.8000
#    3   0.8960   0.8672    0.8384
#    5   0.9421   0.8995    0.8568
#    7   0.9667   0.9167    0.8667
#
# C. two collators, each catching 0.7 of errors
#    shared misses c = 0.0: caught 0.910
#    shared misses c = 0.3: caught 0.847
#    shared misses c = 0.6: caught 0.784
#
# Reading: a catalogue helps retrieval only when its routing is
# more reliable than the break-even accuracy - a misfiled book is
# lost however good the shelf search. More sources raise
# accuracy only to the extent that they are independent; sources
# that copy one another add confidence without adding evidence.

在六万块的全库里直接查找,第一名正确的概率是 0.286;只在一个一万块的分类里查找,是 0.436——库小了,最强的干扰块也就弱了(第一章)。但分类有代价:路由错了,查找再好也无济于事。只要路由准确率高于 0.656,分类检索就胜过全库检索;准确率 0.60 时则不如。这就是「目录学」在检索系统中的数学含义:分类的价值取决于分类本身的可靠性——一部被错放到别的略里的书,在原来那一略里永远找不到。

参验:多源核验的条件

韩非说,没有参验就下断语是愚蠢,不能断定却据以行事是欺骗。用第四章的语言,参验就是多个独立来源的表决。B 段令 kk 个来源各自正确的概率为 0.8,取多数:独立时,三个来源把正确率提到 0.8960,七个到 0.9667。但若有比例 cc 的情形,所有来源其实都转述同一个源头,那么 kk 个来源只相当于一个:c=0.6c = 0.6 时七个来源只到 0.8667。

C 段是刘向父子「校雠」的模型:两人各自能发现七成的错误。若他们的疏漏独立,合起来能发现 0.910;若有六成的情形两人会漏掉同样的错误,只剩 0.784。

假说 · 尚未验证

作者关于文本的假说(尚未验证): 韩非所说的「参验」,强调的是证据来源的相互独立(如名与实、言与事的对照),而不是来源的数量;因此,韩非对「众口一词」的说法应当表现出怀疑,而不是信任。什么结果会证明它错:《韩非子》中有段落把多人同声作为可信的充分理由,而没有追问其来源是否相同。

注

类比的界限。 本章把古代的目录与核验读作检索与表决的模型,用来说明其中的数学结构。它不主张刘向父子或韩非有现代意义上的概率概念,也不评价《七略》分类的学术得失。

小结

《七略》的先分类、再查找,相当于两级检索:在小库中查找更准,但只有当分类本身的准确率高于约 0.656 时才胜过全库检索。韩非的参验相当于多源表决:来源独立时,七个各有八成把握的来源可以把正确率提到 0.9667;来源同出一源时,多少个都只相当于一个。校雠的双人核对同理:两人疏漏独立时合起来发现 0.910 的错误,疏漏相同时只有 0.784。古人的这两种方法与第一、四章得到的是同一个结论——可靠性来自独立,而不是来自数量。

参考文献

Han, Fei. 1964. Han Fei Tzu: Basic Writings. Translated by Burton Watson. Columbia University Press.
王先慎. 1998. 韩非子集解. 新编诸子集成. 中华书局.
班固. 1962. 汉书(点校本). 中华书局.

Fan, Y. (2026). Retrieval-Augmented Generation Geometry, Reciprocal Rank Fusion and Multi-Agent Error Cascades: High-Dimensional Concentration of Measure, Hybrid Lexical-Dense Retrieval Bounds and Verifier-Gated Fixed Points [检索增强生成几何、倒数秩融合与多智能体误差级联] (Version 1.0.0). 5D Library. https://doi.org/10.5281/zenodo.24090170 · Licensed under Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0).