跳到主要内容

搜索背后的数学 — 查准、查全与齐普夫定律

这一章讲三件事: 简单搜索的幕后六机制为什么全在讨好查准率; 两个公式(查准率/查全率)怎么算、为什么不可能同时拉满; 以及齐普夫定律——目录越爬越大之后,搜索质量下滑的数学原因与唯一解药。 这是全书技术含量最高的一章,也是把第 05 章「词表」的因果讲完的一章。

1. 先看现象:随手一搜,结果却「恰好」合理

你在搜索栏打了一个拼错的词,目录却依然给了正确的结果;你换台机器搜同样的词, 排第一的还是你上次点开的那份报表。这不是运气。书里说得很直白: 简单搜索的幕后跑着一整套数学程序——你永远看不到它们(那是供应商的知识产权), 但一旦拿掉,「简单搜索给你的只会是一团毫无意义的噪声」,拼错个词就全军覆没1

简单搜索按定义是「往搜索栏打一两个词」2——它看起来简单,恰恰是因为复杂被藏起来了。

2. 简单搜索的幕后:六套机制,一个目的

书里列了六套幕后机制。逐个看它们各自替你挡了什么麻烦3:

机制它替你解决什么书里的例子
自动补全你只记得半截词边打边猜词尾,词表越丰富猜得越准4
模糊匹配(书里叫字符串匹配:把你的输入当一串字符去近似比对)你拼错了、或写法不同陀思妥耶夫斯基的两种英文拼法、20-05-2022 与「5月20日」、NATO 与 OTAN5
同义环这东西换过名、或两地叫法不同项目改名、制药公司在不同销售区用不同产品名6
叙词表你搜的词太窄整个词簇(第 05 章的 PT/VT/RT)一起影响排序7
本体你漏了业务关联建在知识图谱上的目录,把目标节点的近邻也提到前面8
搜索行为结果千人一面目录记住你搜过什么、最终点了什么,下次据此排序9

书里还补了一句直白的工程判断:叙词表建得越好、用得越多,简单搜索就越好10—— 六套机制里有三套(同义环、叙词表、本体)直接长在词表和图谱上。 回忆第 05 章那句话:「搜索好不好,取决于元数据质量,不取决于源数据质量」—— 这里是它的机制版。

把六套机制记住一个共同点,下一节要用:它们全部是幕后自动发生的,全部在为同一个目标服务—— 把最对的那一两条顶到最前面。这个目标的名字叫查准率。

3. 复杂搜索:对你复杂,对软件简单

复杂搜索是另一极:你自己写整条查询语句——栏位名、值、布尔运算符(AND/OR/NOT)、 括号分组,一个都不能错11。第 02 章走查里那行 Data Owner: "Kris*" AND business glossary: "Data Science" AND Asset Type: "Data Product" 就是它。书里给的两条注意12:

  • 语法(写法格式)要精确:拼错运算符或值,查询直接跑不动;
  • 语义要自省:查询跑得动,但找回来的东西是不是你真想要的?逻辑有没有写反?括号有没有分组错? 语法错是响亮的失败,语义错是无声的失败——后者更危险。

书里在这里放了一个漂亮的对称,原文叫「阴阳」13:

简单搜索:对你简单,幕后复杂(一大堆计算)。 复杂搜索:对你复杂,幕后简单(软件只做一件事:执行你写的运算符)。

由此还有两个实用推论。其一,复杂搜索所见即所得——没有幕后的戏法, 结果好坏全看你的语句;其二,写错复杂查询没有任何计算代价——大胆发出去, 看结果、调整、再搜,这与「在数据里查」完全不同14

复杂搜索的产物通常是一张长列表,需要你精读(perusing)——逐条仔细过,而不是浏览式地扫15

它和前面几章的积木接得上:第 06 章贴的分类标签、第 04 章划的能力域,都是复杂搜索可以直接 引用的栏位。书里给的真实式子——「找出 HR 能力域下所有敏感级数据」——写作16:

Capability: HR AND ClassificationOfSensitivity: Sensitive

第 04 章的路径成了第一个条件,第 06 章的敏感性标签成了第二个条件—— 组织篇的功课在查询语句里逐字兑现。

4. 对话式搜索:第三种形态

对话式搜索不是搜索引擎的加速版——书里反复强调,它改变了搜索的性质: 过去用关键词语言「想都不敢想」表达的复杂话题,现在用一句自然语言就能开口17。 按书里的说法,它是搜索的另一个维度:深度的、上下文复杂的主题, 终于能被一个不懂 IRQL 的普通用户完整表达18

但书里同时压住了期待:「AI 时代还在婴儿期,别指望这个能力已经全面替代复杂搜索」19。 三种形态因此是并存关系,不是替代关系——第 09 章的六种模式会逐一展示 「关键词版」与「对话版」的对照。

5. 主走查:一次搜索穿过混淆矩阵

现在给「查准率/查全率」装上数字。书里借了医学诊断的比喻20: 医生判断你有没有湿疹,其实有四种结局——判「有」且真有(真阳性)、 判「有」但其实没有(假阳性)、判「没有」但其实有(假阴性)、判「没有」也真没有(真阴性)。 这套四格账有个名字:混淆矩阵——书里的断言是:任何一次搜索都逃不出它21

设你在目录里搜「敏感个人数据」。目录里实际存在 40 份相关资产(这个数只有上帝和目录管理员知道)。 你的搜索返回了 25 条命中,其中 20 条真的相关(这组数是为演示编的,不是真实数值):

相关 不相关
搜到的(25) 20 真阳性 5 假阳性
没搜到的 20 假阴性 (真阴性:搜不到也无所谓)

查全率 recall = 真阳性 / (真阳性 + 假阴性) = 20 / (20 + 20) = 0.5
↑「该找到的,我找到了多少」
查准率 precision = 真阳性 / (真阳性 + 假阳性) = 20 / (20 + 5) = 0.8
↑「我找到的,有多少是对的」

书里给的公式与这两个数一一对应22,并配了四条实操判断:

  • 查全率难算:假阴性(没搜到的)你数不清——只能估。书里给的经验线: 觉得不够就去粗估一个相对值,把比值往 0.7523;
  • 查准率好算:只看结果集,不用知道错过了什么;书里说可以放心冲 0.924;
  • 简单搜索的六套机制,服务的全是查准率——「只要此刻手上这一条是对的」25;
  • 复杂搜索的机制(由你自己执行的),服务的全是查全率——「凡是沾点边的都别漏」26

为什么不可能双高? 书里的论证一句话:你没法同时「只留最对的」和「一个不漏」—— 收紧网眼(准)必然漏鱼(全),放大网眼(全)必然进杂物(不准)27。 第 05 章的两把尺在这里接入:词表穷尽性高(词分得细、覆盖全)会抬高查全率、压低查准率28—— 所以词表功课做得好不好,最终在搜索数学里结账。

6. 齐普夫定律:为什么爬得越多,反而越糊涂

最后一块拼图回答一个反直觉的问题:目录越爬越大、元数据越来越多,搜索理应越来越好—— 为什么反而越来越差?

书里先把现象摆出来29:公司里几百张表都有一列叫 ResultEfficiencyScore。 这些名字都没错——各自表里,它们如实描述了列里的值。但这些表彼此毫无关系: 财务的 Score、生产的 Score、HR 的 Score,说的是三件事。目录照单全收之后, 你搜 Result,几百张互不相干的表一起涌出来——每一条都「对」,合起来全是噪声

背后的规律叫齐普夫定律(Zipf's law,以语言学家 George Kingsley Zipf 命名): 一个词的使用频率,与它的排名大致成反比——第 1 名的词出现得越频繁, 后面名次的词出现频率一路下滑。书里的数字:英文里最常见的词「the」, 每 10 个词出现 1 次;第 2 名「of」,每 20 个词出现 1 次,一路滑下去30。 (书里还顺手拆穿:Zipf 并不是真正的发现者,这也不是一条严格定律31。)

Zipf 对语言给了两股对冲的力32,书里把它们对应到元数据上33:

语言里: 统一化(泛词,一词多义) vs 多样化(专名,词义精确)
↓ 映射 ↓ 映射
目录里: 描述(把资产说出来) vs 区分(把资产分开)

爬取的元数据天生全是「描述」这一侧:
数据源越多 → 泛名越多 → 同一个词背起越多含义 → 资产越难分不开

而且这条定律有个狠毒的性质:爬得越多,它越准——新源带来的又是新一批 Result/Score/Efficiency,撞名只会更多34

解药只有一个:人工打的词表术语。 书里的原话:要抵消齐普夫定律, 就得给资产打上词表术语,让它们从「同款泛名」里站出来35。 第 05 章走查过的那组标签在这里收尾:同样叫 Score 的三张表, 分别打上「木材耐久」「客户满意」「员工绩效」,搜索从此能把它们分开36。 这正是「人写的元数据必须服务于区分」(第 05 章)的数学根据——区分不是文风偏好, 是对抗词频规律的必需品

7. 作者的判断与证据

书里给出处的:

  • 混淆矩阵、召回率(即查全率的另一译名)/查准率是分类与信息检索的标准数学,书里给了 Chowdhury 教科书与 《Essential Math for AI》的章节出处37;
  • 齐普夫定律在检索中的「描述 vs 区分」对应,书里引了 Blair 2002 年的检索研究38

作者的立场:

  • 「简单搜索的幕后机制是供应商知识产权」——事实性描述;
  • 「叙词表越好简单搜索越好」——工程经验,没有具体数字;
  • 0.75 与 0.9 两个数字,书里是当「经验目标」给的,不是定理。

判断(我们的,不是书里的): 这一章其实解释了「目录为什么必须有人养」的根本原因。 连接器爬取是机器干的事,它天然只能产出「描述」侧的泛词;「区分」侧的功课 (词表、打标、内容分类)是纯人工的,而且随数据增长一路变重—— 齐普夫定律保证没有「爬完就好了」的那一天。第 03 章的数据发现团队, 干的就是这份逆水行舟的活。 如果错,会错在: 如果元数据抽取技术进步到能自动产出高区分度的语义标签 (而不是泛词),「人工打标」的必要性会下降——书里在「AI 帮倒忙」一节(第 05 章) 对此持怀疑态度,但这是可能被技术推翻的判断,不是数学必然。

8. 边界与局限

  • 六套幕后机制只是清单。 每套机制内部怎么实现(比如模糊匹配的具体实现),书里明说 属于供应商的知识产权,不展开。
  • 0.75/0.9 无依据。 两个目标数是作者的经验值,书里没有给出处;照抄前先量自己的目录。
  • 齐普夫定律是「最原教旨」的形态。 现代目录还有列级血缘、使用统计等辅助信号, 泛名撞车没有书里写的那么绝望——但「靠泛名区分资产」依然靠不住。
  • 对话式搜索与简单搜索的排序机制是否一致,书里没有讲(这属于各供应商实现)。

9. 可带走的

  1. 简单搜索对你简单、幕后不简单:自动补全、模糊匹配、同义环、叙词表、本体、搜索行为六件套;
  2. 复杂搜索对你复杂、幕后简单:所见即所得,写错查询零计算代价,放心试错;
  3. 语法错是响亮的失败,语义错是无声的失败——后者才是复杂搜索的真正风险;
  4. 任何搜索都逃不出混淆矩阵;查全率 = 找回的相关/全部相关,查准率 = 找回里对的部分;
  5. 查全率难算(假阴性数不清,经验线 0.75),查准率好算(冲 0.9);两者不可兼得;
  6. 简单搜索的全部幕后机制服务查准率;复杂搜索服务查全率——选形态就是选目标;
  7. 齐普夫定律:爬得越多,泛名越多,资产越难区分;这是搜索质量随规模下滑的数学原因;
  8. 唯一解药是人工词表打标——「区分」不是文风,是对抗词频规律的必需品。

10. 原文地图

主题原书章原文位置
简单搜索其实不简单第 3 章text/20-fm-features-search-features-in-a-data-catalog.txt:69(搜「it is not simple」)
六机制清单第 3 章text/20-fm-features-search-features-in-a-data-catalog.txt:115(搜「Autocomplete」)
自动补全第 3 章text/20-fm-features-search-features-in-a-data-catalog.txt:124(搜「live suggestion」)
字符串匹配/模糊第 3 章text/20-fm-features-search-features-in-a-data-catalog.txt:128(搜「fuzzy logic」) · text/20-fm-features-search-features-in-a-data-catalog.txt:130(搜「Dostoevsky」)
同义环第 3 章text/20-fm-features-search-features-in-a-data-catalog.txt:133(搜「Synonym ring」)
叙词表扩大同义环第 3 章text/20-fm-features-search-features-in-a-data-catalog.txt:141(搜「broadening of synonym rings」)
本体近邻提权第 3 章text/20-fm-features-search-features-in-a-data-catalog.txt:144(搜「nodes close to」)
搜索行为记忆第 3 章text/20-fm-features-search-features-in-a-data-catalog.txt:149(搜「remembers your search habits」)
叙词表越好搜索越好第 3 章text/20-fm-features-search-features-in-a-data-catalog.txt:147(搜「The better you build your thesaurus」)
复杂搜索的语法/语义第 3 章text/20-fm-features-search-features-in-a-data-catalog.txt:221(搜「Complex search」)
阴阳对称第 3 章text/20-fm-features-search-features-in-a-data-catalog.txt:239(搜「yin-yang」)
写错查询零代价第 3 章text/20-fm-features-search-features-in-a-data-catalog.txt:234(搜「no computational cost」)
精读 vs 浏览第 3 章text/20-fm-features-search-features-in-a-data-catalog.txt:266(搜「Perusing is to read」)
对话式换了性质第 3 章text/20-fm-features-search-features-in-a-data-catalog.txt:277(搜「changed the very nature」) · text/20-fm-features-search-features-in-a-data-catalog.txt:281(搜「another dimension of search」)
「AI 在婴儿期」第 3 章text/21-fm-mechanics-the-mathematics-behind-search.txt:3(搜「in its infancy」)
湿疹与四格第 3 章text/21-fm-mechanics-the-mathematics-behind-search.txt:22(搜「eczema」)
混淆矩阵与搜索第 3 章text/21-fm-mechanics-the-mathematics-behind-search.txt:32(搜「confusion matrix」) · text/21-fm-mechanics-the-mathematics-behind-search.txt:45(搜「escapes the confusion matrix」)
两个公式第 3 章text/21-fm-mechanics-the-mathematics-behind-search.txt:56(搜「Recall = tp」) · text/21-fm-mechanics-the-mathematics-behind-search.txt:72(搜「Precision = tp」)
0.75 与 0.9第 3 章text/21-fm-mechanics-the-mathematics-behind-search.txt:67(搜「0.75」) · text/21-fm-mechanics-the-mathematics-behind-search.txt:76(搜「aim for 0.9」)
简单服务准、复杂服务全第 3 章text/21-fm-mechanics-the-mathematics-behind-search.txt:96(搜「purpose of precision」) · text/21-fm-mechanics-the-mathematics-behind-search.txt:105(搜「purpose of recall」)
不可兼得第 3 章text/21-fm-mechanics-the-mathematics-behind-search.txt:91(搜「maximizes both at the same time」)
穷尽性→召回↑精确↓第 3 章text/21-fm-mechanics-the-mathematics-behind-search.txt:115(搜「increases recall and decreases precision」)
爬得越多越糊涂第 3 章text/21-fm-mechanics-the-mathematics-behind-search.txt:119(搜「loses its meaning」)
Result/Score/Efficiency 例第 3 章text/21-fm-mechanics-the-mathematics-behind-search.txt:122(搜「column called Efficiency」)
齐普夫定律与 the/of第 3 章text/21-fm-mechanics-the-mathematics-behind-search.txt:130(搜「inversely proportional」) · text/21-fm-mechanics-the-mathematics-behind-search.txt:134(搜「the most common word in English」)
统一化 vs 多样化=描述 vs 区分第 3 章text/21-fm-mechanics-the-mathematics-behind-search.txt:139(搜「unification equals description」)
词越多含义越多第 3 章text/21-fm-mechanics-the-mathematics-behind-search.txt:143(搜「will inevitably have」)
词表是解药第 3 章text/21-fm-mechanics-the-mathematics-behind-search.txt:146(搜「counteract」)
打标后的三张 Score 表第 3 章末text/22-fm-summary.txt:4(搜「wood durability」)
Zipf 非发明者、非定律第 3 章text/21-fm-mechanics-the-mathematics-behind-search.txt:149(搜「didn't really invent」)

Footnotes

  1. 出处:「Features: Search Features in a Data Catalog」第 105 段(text/20-fm-features-search-features-in-a-data-catalog.txt:105,搜「intellectual property」)与第 107 段(text/20-fm-features-search-features-in-a-data-catalog.txt:107,搜「meaningless noise」)。

  2. 出处:「Features: Search Features in a Data Catalog」第 65 段(text/20-fm-features-search-features-in-a-data-catalog.txt:65,搜「type a word or two」)。

  3. 出处:「Features: Search Features in a Data Catalog」第 116 段(text/20-fm-features-search-features-in-a-data-catalog.txt:116,搜「String matching」)列出的完整清单。

  4. 出处:「Features: Search Features in a Data Catalog」第 124 段(text/20-fm-features-search-features-in-a-data-catalog.txt:124,搜「live suggestion」):自动补全取材于词表,词表越富、搜索越多,预测越准。

  5. 出处:「Features: Search Features in a Data Catalog」第 130 段(text/20-fm-features-search-features-in-a-data-catalog.txt:130,搜「Dostoevsky」)与第 132 段(text/20-fm-features-search-features-in-a-data-catalog.txt:132,搜「NATO/OTAN」)。

  6. 出处:「Features: Search Features in a Data Catalog」第 138 段(text/20-fm-features-search-features-in-a-data-catalog.txt:138,搜「sales regions」)。

  7. 出处:「Features: Search Features in a Data Catalog」第 141 段(text/20-fm-features-search-features-in-a-data-catalog.txt:141,搜「broadening of synonym rings」):叙词表是同义环向全局词表的扩展,整个词簇影响命中的选择与排序。

  8. 出处:「Features: Search Features in a Data Catalog」第 144 段(text/20-fm-features-search-features-in-a-data-catalog.txt:144,搜「nodes close to」)。

  9. 出处:「Features: Search Features in a Data Catalog」第 149 段(text/20-fm-features-search-features-in-a-data-catalog.txt:149,搜「remembers your search habits」)。

  10. 出处:「Features: Search Features in a Data Catalog」第 147 段(text/20-fm-features-search-features-in-a-data-catalog.txt:147,搜「The better you build your thesaurus」)。

  11. 出处:「Features: Search Features in a Data Catalog」第 210 段(text/07-fm-the-core-functionality-of-a-data-catalog.txt:210,搜「Data Owner」)与「Features: Search Features in a Data Catalog」第 221 段(text/20-fm-features-search-features-in-a-data-catalog.txt:221,搜「Complex search」)。

  12. 出处:「Features: Search Features in a Data Catalog」第 225 段(text/20-fm-features-search-features-in-a-data-catalog.txt:225,搜「correct syntax」)与第 227 段(text/20-fm-features-search-features-in-a-data-catalog.txt:227,搜「semantics in your search」)。

  13. 出处:「Features: Search Features in a Data Catalog」第 239 段(text/20-fm-features-search-features-in-a-data-catalog.txt:239,搜「yin-yang」):「simple search may appear very easy to you, but it takes computational efforts…」

  14. 出处:「Features: Search Features in a Data Catalog」第 232 段(text/20-fm-features-search-features-in-a-data-catalog.txt:232,搜「fire off wrong queries」)与第 234 段(text/20-fm-features-search-features-in-a-data-catalog.txt:234,搜「no computational cost」)。

  15. 出处:「Features: Search Features in a Data Catalog」第 266 段(text/20-fm-features-search-features-in-a-data-catalog.txt:266,搜「Perusing is to read」)。

  16. 出处:「Features: Search Features in a Data Catalog」第 92 段(text/20-fm-features-search-features-in-a-data-catalog.txt:92,搜「ClassificationOfSensitivity」)。原文示例:组合能力域与敏感性分类两个条件。

  17. 出处:「Features: Search Features in a Data Catalog」第 277 段(text/20-fm-features-search-features-in-a-data-catalog.txt:277,搜「changed the very nature」)。

  18. 出处:「Features: Search Features in a Data Catalog」第 281 段(text/20-fm-features-search-features-in-a-data-catalog.txt:281,搜「another dimension of search」)。

  19. 出处:「Mechanics: The Mathematics Behind Search」第 3 段(text/21-fm-mechanics-the-mathematics-behind-search.txt:3,搜「in its infancy」)。

  20. 出处:「Mechanics: The Mathematics Behind Search」第 22 段(text/21-fm-mechanics-the-mathematics-behind-search.txt:22,搜「eczema」)。

  21. 出处:「Mechanics: The Mathematics Behind Search」第 45 段(text/21-fm-mechanics-the-mathematics-behind-search.txt:45,搜「escapes the confusion matrix」)。

  22. 出处:「Mechanics: The Mathematics Behind Search」第 56 段(text/21-fm-mechanics-the-mathematics-behind-search.txt:56,搜「Recall = tp」)与第 72 段(text/21-fm-mechanics-the-mathematics-behind-search.txt:72,搜「Precision = tp」)。

  23. 出处:「Mechanics: The Mathematics Behind Search」第 67 段(text/21-fm-mechanics-the-mathematics-behind-search.txt:67,搜「0.75」)。

  24. 出处:「Mechanics: The Mathematics Behind Search」第 76 段(text/21-fm-mechanics-the-mathematics-behind-search.txt:76,搜「aim for 0.9」)。

  25. 出处:「Mechanics: The Mathematics Behind Search」第 78 段(text/21-fm-mechanics-the-mathematics-behind-search.txt:78,搜「ranks precision highest」)与第 96 段(text/21-fm-mechanics-the-mathematics-behind-search.txt:96,搜「purpose of precision」)。

  26. 出处:「Mechanics: The Mathematics Behind Search」第 103 段(text/21-fm-mechanics-the-mathematics-behind-search.txt:103,搜「are not taking place behind the scenes」)与第 105 段(text/21-fm-mechanics-the-mathematics-behind-search.txt:105,搜「purpose of recall」)。

  27. 出处:「Mechanics: The Mathematics Behind Search」第 91 段(text/21-fm-mechanics-the-mathematics-behind-search.txt:91,搜「maximizes both at the same time」)。

  28. 出处:「Mechanics: The Mathematics Behind Search」第 115 段(text/21-fm-mechanics-the-mathematics-behind-search.txt:115,搜「increases recall and decreases precision」)。

  29. 出处:「Mechanics: The Mathematics Behind Search」第 122 段(text/21-fm-mechanics-the-mathematics-behind-search.txt:122,搜「column called Efficiency」)与第 126 段(text/21-fm-mechanics-the-mathematics-behind-search.txt:126,搜「do not have anything in common」)。

  30. 出处:「Mechanics: The Mathematics Behind Search」第 134 段(text/21-fm-mechanics-the-mathematics-behind-search.txt:134,搜「the most common word in English」)与第 136 段(text/21-fm-mechanics-the-mathematics-behind-search.txt:136,搜「every 20 words」)。

  31. 出处:「Mechanics: The Mathematics Behind Search」第 149 段(text/21-fm-mechanics-the-mathematics-behind-search.txt:149,搜「didn't really invent」),书脚注引 Aiden & Michel《Uncharted》。

  32. 出处:「Mechanics: The Mathematics Behind Search」第 137 段(text/21-fm-mechanics-the-mathematics-behind-search.txt:137,搜「unification」)。

  33. 出处:「Mechanics: The Mathematics Behind Search」第 139 段(text/21-fm-mechanics-the-mathematics-behind-search.txt:139,搜「unification equals description」)。

  34. 出处:「Mechanics: The Mathematics Behind Search」第 142 段(text/21-fm-mechanics-the-mathematics-behind-search.txt:142,搜「more true the more times」)与第 143 段(text/21-fm-mechanics-the-mathematics-behind-search.txt:143,搜「will inevitably have」)。

  35. 出处:「Mechanics: The Mathematics Behind Search」第 146 段(text/21-fm-mechanics-the-mathematics-behind-search.txt:146,搜「counteract」)。

  36. 出处:「Summary」第 4 段(text/22-fm-summary.txt:4,搜「wood durability」)。

  37. 出处:「Mechanics: The Mathematics Behind Search」脚注第 84 段(text/21-fm-mechanics-the-mathematics-behind-search.txt:84,搜「Chowdhury」):引 Chowdhury 教科书第 9 章与 H. Nelson《Essential Math for AI》第 109–111 页。

  38. 出处:「Mechanics: The Mathematics Behind Search」脚注第 151 段(text/21-fm-mechanics-the-mathematics-behind-search.txt:151,搜「Blair」):David C. Blair,「The Challenge of Commercial Document Retrieval, Part I」(2002)。