Hard constraint 和 preference 怎么分开处理?
日期、人名为什么不能只靠模型?
先弄清楚:每个概念是什么
- Hard constraint
- 必须满足的条件,不满足就是错。例:“上个月”“Tim 发的”。
- Preference
- 尽量满足的条件,用来排序。例:“最好是意大利菜”“越新越好”。
- Interpretation
- 模型把自然语言解析成结构化条件。例:今天是 2026-11-09,“上个月”解析成 2026-10-01 到 2026-10-31。
- Enforcement
- 由 index 的 metadata filter 执行条件,不靠模型自觉。
- Semantic 与 structured search
- embedding 只能说两段话意思相近,不能保证日期在某个区间里,硬条件要靠 structured filter。
30 秒回答
I separate interpretation from enforcement. The model interprets the request into structured constraints, like a date range and a person ID. The index enforces them as metadata filters, so we don't rely on the model to remember them. Semantic similarity can't enforce "last month" or "from Tim"; it only says two texts are related. Preferences become ranking signals, not filters. If the filters return nothing, the system says so and offers to relax a specific constraint, rather than returning something close.
两者的区别
| Hard constraint | Preference | |
|---|---|---|
| 谁来执行 | index 的 metadata filter | reranker 的 feature |
| 没有结果时 | 明说,并提议放宽哪一条 | 忽略这条偏好 |
Pre-filter 还是 post-filter:pre-filter 先过滤再搜,结果一定满足条件,剩得很少时直接 scan。post-filter 先做 ANN 再过滤,可能凑不够 k 条,要多取。按 filter 的 selectivity 选。
必答点
- 模型负责 interpretation,index 负责 enforcement
- embedding 管语义,metadata filter 管硬条件
- preference 是 ranking signal,不是 filter
- 没结果要明说,并提议放宽具体哪一条
追问
模型把“上周五”解析错了怎么办?
把解析结果说给用户听(“在 10 月 30 日的邮件里找”),错了能马上纠正。日期计算用代码,eval 时单独评 slot accuracy。
“一共几封”“最新的一封”这类问题怎么办?
计数和取最新由 tool 做 structured query,不让模型去数检索回来的片段。Apple 官方的 tool 支持 "a pipeline of search and computation stages"。
人名怎么变成可以 filter 的 ID?
先做 entity resolution,从 contacts 生成候选,用邮箱、电话、互动频率打分。分数接近时问用户。
用户中途说“不限上个月了”,怎么办?
维护一份结构化的 constraint state,去掉这一条后重新检索,其他条件不变。不指望模型从对话历史里记住哪些条件还有效。
来源PracHub:Design an Agentic Search Experience · WWDC26 246:SpotlightSearchTool · MicroNN(Apple)(on-device vector search,支持 structured attribute filter)