5D Library › Retrieval-Augmented Generation Geometry, Reciprocal Rank Fusion and Multi-Agent Error Cascades · 中文
Chapter 7. The Routing of the Qilue and Han Fei’s Canyan: Two Ancient Methods of Retrieval and Verification
Why read Liu Xiang, Liu Xin and Han Fei here
The imperial library of two thousand years ago faced a retrieval problem too: more and more books, and how was anyone to find them? At the end of the Western Han, Liu Xiang and his son Liu Xin collated the library, wrote a summary of each work, and divided the whole catalogue into a few great divisions — the Qilue (Seven Summaries), China’s earliest systematic catalogue. Earlier still, Han Fei had asked another question: how is one to judge whether a claim is credible? His answer was canyan — checking claims against several lines of evidence. This chapter reads the two as ancient designs for a retrieval system — routing by category and verification by several sources — and uses the models of Chapters 1 and 4 to work out when each works and when it fails.
The texts
Source text
Ban Gu, Hanshu, “Treatise on Literature”.
每一書已,向輒條其篇目,撮其指意,錄而奏之。會向卒,哀帝復使向子侍中奉車都尉歆卒父業。歆於是總群書而奏其七略,故有輯略,有六藝略,有諸子略,有詩賦略,有兵書略,有術數略,有方技略。
Whenever a book was finished, Xiang listed its sections, summarised its import, wrote this down and presented it to the throne. When Xiang died, Emperor Ai had Xiang’s son Xin, Palace Attendant and Commandant of Imperial Equipages, complete his father’s work. Xin then gathered all the books and presented his Seven Summaries: there were the Summary of Collections, the Summary of the Six Arts, the Summary of the Masters, the Summary of Poetry and Rhapsodies, the Summary of Military Texts, the Summary of Calculations and Arts, and the Summary of Recipes and Techniques.
Han Feizi, “Xianxue” (Eminent Teachings).
無參驗而必之者,愚也;弗能必而據之者,誣也。
To assert something as certain without checking it against evidence is foolish; to rely on what one cannot be certain of is deceit.
Note
Edition and checking. The Hanshu passage has been checked word for word against the text on Wikisource. The Han Feizi sentence has been checked against Wang Xianshen’s Han Feizi jijie. The account of Liu Xiang’s collation — one person reading and checking the text against itself is jiao, one holding the copy while another reads aloud, “like enemies facing each other”, is chou — survives as fragments of the Bielu quoted in later compendia; this book paraphrases it rather than quoting it, and its source has been checked. The English renderings are the author’s own.
The Qilue: first classify, then search
Liu Xin divided the books into six divisions, plus the overview of the Summary of Collections. In today’s terms this is two-stage retrieval: first decide which division a book belongs to (routing), then search within that division. Part A of the fifteenth program puts it into Chapter 1’s extreme-value model: routing is right with probability , and a wrong route finds nothing.
Calculation
# 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.Searching all sixty thousand chunks directly, first place is right 0.286 of the time; searching only one division of ten thousand, 0.436 — the smaller the collection, the weaker its strongest distractor (Chapter 1). But classification has a price: if the routing is wrong, no search can help. As long as routing accuracy exceeds 0.656, classified retrieval beats searching the whole collection; at 0.60 it does not. That is the mathematical meaning of bibliography for a retrieval system: the value of a classification depends on the reliability of the classification itself — a book shelved in the wrong division can never be found in the right one.
Canyan: the conditions for checking against several sources
Han Fei says that asserting without checking is foolish, and acting on what cannot be made certain is deceit. In Chapter 4’s terms, canyan is a vote among several independent sources. Part B gives sources, each right with probability 0.8, and takes the majority: with independent sources, three lift accuracy to 0.8960 and seven to 0.9667. But if in a share of cases all the sources are really repeating one original, then sources are worth one: at seven sources reach only 0.8667.
Part C models Liu Xiang’s collation by two readers: each catches seven errors in ten. If their misses are independent, together they catch 0.910; if in six cases in ten they miss the same errors, only 0.784.
Hypothesis · not established
The author’s hypothesis about the text (not yet tested): Han Fei’s canyan stresses the independence of the lines of evidence (name against reality, words against deeds), not their number; so the Han Feizi should treat claims that “everyone says the same” with suspicion rather than trust. What would show it wrong: passages in the Han Feizi that take many voices saying the same thing as sufficient grounds for belief, without asking whether they share a source.
Note
The limits of the analogy. This chapter reads ancient cataloguing and checking as models of retrieval and voting, to bring out their mathematical structure. It does not claim that Liu Xiang, Liu Xin or Han Fei had probability concepts in a modern sense, nor does it assess the scholarly merits of the Qilue’s classification.
Summary
The Qilue’s classify-then-search is two-stage retrieval: searching a smaller collection is more accurate, but it beats searching everything only if the classification itself is more than about 0.656 accurate. Han Fei’s canyan is a vote among sources: with independent sources, seven that are each 80 % reliable lift accuracy to 0.9667; sources that share an origin are worth one however many there are. Two-reader collation works the same way: independent misses let the pair catch 0.910 of errors, shared misses only 0.784. The two ancient methods reach the same conclusion as Chapters 1 and 4 — reliability comes from independence, not from numbers.
References
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).