Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions docs/qa/RETRIEVAL_BASELINE_V2.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,43 @@ bench:`cargo run -p memori-core --example graph_bench -- <files>`(对每个
### 关于 top1 文档 0.696(非 bug,已用 `top_documents` 诊断坐实)
给 harness 加了 `top_documents` 字段(每题最终证据去重后的有序文档路径)。据此查实:**20 道 top1-miss 里 19 道,排第 1 的都是目标的"同项目兄弟文档"**(检索每次都准确锁定项目,只是没挑中套件指定的那个体裁)。根因是套件"直问-散文事实/改写"题**故意含糊**(只点项目名/代号、不点具体事实,答案关键词不在 query 里),rerank 无法在同项目 7 份文档间区分。**这是 v2 相对 v1 的刻意难度,不是融合/排序 bug;top3 0.913 / top5 片段 0.957 / MRR 0.830 说明召回与答案 chunk 入选均正常。** 把 top1-文档硬拉到 v1 的 ~0.875 只能靠"让 query 重新点名具体事实"=把 v2 退化回 v1 的易,违背 v2 初衷。

## 作答层 LLM-judge 基线(2026-08-24 新增)

此前"答案题正确"只用 top-k 命中当代理(见上表注),**从不看答案文本**。`--judge` 档补齐该闭环:对应答题走真实问答管线生成答案,再由 chat 模型对照 `target_clues` 判 correct/partial/incorrect(correct=1、partial=0.5、incorrect=0),逐题理由写入报告。judge 实现见 `memori-core/src/answer_judge.rs`,harness 入口 `--judge`。

### 首跑环境(本机受限配置,非官方满配)

- 嵌入:`qwen3-embedding:0.6b`(Ollama @ 11434)
- 作答 + judge:`deepseek-r1:1.5b`(最小可用档,替代满配的 7B+)
- **重排:未接入**(rerank_applied_rate=0%)——v2 满配基线的 bge-reranker-v2-m3 在本机不可用
- 图谱端点置为不可达(快速失败,本机显存 6GB 无法同时承载图谱/嵌入/作答)

### 结果(本地 `--judge` 跑数,126 题同一次跑)

> 逐题明细(每题的 judge 判分与理由)**不入库**:这类文件每跑一次基准就整体重写,进仓库只会带来 diff 噪声与体积膨胀。需要存档时以 CI artifact / 附件形式提供;仓库里只保留下面的汇总指标。

| 层 | 指标 | 值 |
| --- | --- | ---: |
| 检索层 | top1 文档命中 | 0.642 |
| 检索层 | top3 文档召回 | **0.877** |
| 检索层 | chunk MRR | 0.717 |
| 检索层 | 引用有效率 | 1.000 |
| 检索层 | 拒答正确率 | 0.635 |
| **作答层** | **answer_correct_rate** | **0.401** |
| **作答层** | 判定分布 correct/partial/incorrect | **35 / 15 / 56** |

judge 判分成功率 106/106(应答题全部产出判定,零失败)。平均每题 1.48s(检索+判答,不含答案生成)。

### 解读

- **检索召回 ≠ 答案正确**:top3 文档召回 0.877 的同时,答案正确率仅 0.401;**47 题"top3 已命中但答案判 incorrect"**——检索层指标无法暴露的作答盲区被 judge 精确量化。
- 本跑与官方 v2 满配基线(reject 0.881、rerank 应用率 0.905)的差距主要来自两个环境缺口:**无 rerank**(gating 的 rerank 置信度放行失效,拒答正确率 0.635 显著低于满配)与 **1.5B 小模型作答**(正确率上限低)。故本数字是**受限配置的作答层下限基线**,不作为产品能力口径。
- 复跑口径:满配环境(7B+ 作答、bge-reranker)下重跑 `--judge`,预期 answer_correct_rate 显著上升;两次跑可直接对比作答层真实增益。

## 下一步杠杆(仅记录,不在本轮)
1. gating 对"单事实低词法覆盖"证据的放行(A 类)。
2. 诱饵代号 / 不存在属性的拒答硬化(B 类残留,需语义级代号核验,见上节)。
3. 长文:分块/gating 对深埋事实的处理(长文题 0/2)。
4. OCR:图片/扫描件可检索(C 类,大功能,需接 tesseract 或视觉模型)。
5. 重排已切到 bge-reranker-v2-m3(见上节 A/B)。若日后要上 Qwen3-Reranker,需先为其近二值分数重调融合权重 + 重标定 gating 阈值,再复测。
6. 作答层:在满配环境重跑 `--judge` 建官方作答层基线(本机受限数字仅作下限参考)。
30 changes: 22 additions & 8 deletions memori-core/examples/retrieval_regression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -602,14 +602,28 @@ async fn prepare_live_engine(
});
}

let embed_health = timeout(
Duration::from_secs(10),
engine
.state()
.embedding_client
.embed_text("memori regression health probe"),
)
.await;
// 探活带冷启动重试:本地模型服务冷载可能超过单次超时(实测 12s+),
// 单次 10s 探活会把"模型还没加载完"误判为服务不可用。
let mut embed_health = None;
for attempt in 1..=3 {
embed_health = Some(
timeout(
Duration::from_secs(20),
engine
.state()
.embedding_client
.embed_text("memori regression health probe"),
)
.await,
);
if matches!(&embed_health, Some(Ok(Ok(embedding))) if !embedding.is_empty()) {
break;
}
if attempt < 3 {
tokio::time::sleep(Duration::from_secs(5)).await;
}
}
let embed_health = embed_health.expect("probe loop runs at least once");
match embed_health {
Ok(Ok(embedding)) if !embedding.is_empty() => {}
Ok(Ok(_)) => {
Expand Down
18 changes: 18 additions & 0 deletions memori-core/src/model_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ pub fn build_openai_url(endpoint: &str, tail: &str) -> String {
if host.ends_with('/') {
return format!("{host}{tail}");
}
// 防御:endpoint 已显式带 /v1(无尾斜杠)时不再重复追加,
// 避免拼成 /v1/v1/... 导致 404(对大小写不敏感)。
if host.to_ascii_lowercase().ends_with("/v1") {
return format!("{host}/{tail}");
}
format!("{}/v1/{}", host.trim_end_matches('/'), tail)
}

Expand Down Expand Up @@ -408,6 +413,19 @@ mod tests {
);
}

/// endpoint 显式带 /v1 但**无尾斜杠**时不应再追加一层 /v1(曾实测拼成 /v1/v1 导致 404)。
#[test]
fn build_openai_url_does_not_double_v1_suffix() {
assert_eq!(
build_openai_url("https://api.example.com/v1", "chat/completions"),
"https://api.example.com/v1/chat/completions"
);
assert_eq!(
build_openai_url("http://localhost:11434/v1", "embeddings"),
"http://localhost:11434/v1/embeddings"
);
}

#[test]
fn build_openai_url_hash_forces_exact_url() {
assert_eq!(
Expand Down
2 changes: 1 addition & 1 deletion memori-core/src/retrieval_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ pub(crate) fn build_text_context_from_evidence_with_budget(
chunk_index = item.chunk.chunk_index,
block_kind = block_kind_label(item.chunk.block_kind),
document_rank = item.document_rank,
document_reason = &item.document_reason,
document_reason = item.document_reason,
score = item.final_score,
reason = evidence_reason(item),
heading = heading,
Expand Down
6 changes: 2 additions & 4 deletions memori-parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1114,10 +1114,8 @@ fn extract_xlsx_sheet(xml: &[u8], shared: &[String], out: &mut String) {
Ok(quick_xml::events::Event::End(e)) => match e.name().as_ref() {
b"v" => in_value = false,
b"t" => in_inline_text = false,
b"row" => {
if row_has_cell {
push_newline_if_needed(out, 1);
}
b"row" if row_has_cell => {
push_newline_if_needed(out, 1);
}
_ => {}
},
Expand Down
2 changes: 2 additions & 0 deletions memori-server/assets/swagger-ui-bundle.js

Large diffs are not rendered by default.

104 changes: 104 additions & 0 deletions memori-server/assets/swagger-ui-bundle.js.LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*!
Copyright (c) 2018 Jed Watson.
Licensed under the MIT License (MIT), see
http://jedwatson.github.io/classnames
*/

/*!
* @description Recursive object extending
* @author Viacheslav Lotsmanov <lotsmanov89@gmail.com>
* @license MIT
*
* The MIT License (MIT)
*
* Copyright (c) 2013-2018 Viacheslav Lotsmanov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

/*!
* The buffer module from node.js, for the browser.
*
* @author Feross Aboukhadijeh <https://feross.org>
* @license MIT
*/

/*!
* https://github.com/Starcounter-Jack/JSON-Patch
* (c) 2017-2021 Joachim Wester
* MIT license
*/

/*!
* https://github.com/Starcounter-Jack/JSON-Patch
* (c) 2017-2022 Joachim Wester
* MIT licensed
*/

/*!
* repeat-string <https://github.com/jonschlinkert/repeat-string>
*
* Copyright (c) 2014-2015, Jon Schlinkert.
* Licensed under the MIT License.
*/

/*! @license DOMPurify 3.4.13 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.4.13/LICENSE */

/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */

/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */

/**
* @license React
* react-dom.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/**
* @license React
* react.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/**
* @license React
* scheduler.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/**
* @license React
* use-sync-external-store-with-selector.production.js
*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
2 changes: 2 additions & 0 deletions memori-server/assets/swagger-ui-standalone-preset.js

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions memori-server/assets/swagger-ui-standalone-preset.js.LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*!
* The buffer module from node.js, for the browser.
*
* @author Feross Aboukhadijeh <https://feross.org>
* @license MIT
*/

/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */

/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */

/**
* @license React
* react.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
3 changes: 3 additions & 0 deletions memori-server/assets/swagger-ui.css

Large diffs are not rendered by default.

31 changes: 31 additions & 0 deletions memori-server/assets/swagger_ui.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Memori-Vault API 文档</title>
<link rel="stylesheet" type="text/css" href="/api/docs/swagger-ui.css" />
<style>
html { box-sizing: border-box; overflow-y: scroll; }
*, *:before, *:after { box-sizing: inherit; }
body { margin: 0; background: #fafafa; }
</style>
</head>
<body>
<div id="swagger-ui"></div>
<script src="/api/docs/swagger-ui-bundle.js" charset="UTF-8"></script>
<script src="/api/docs/swagger-ui-standalone-preset.js" charset="UTF-8"></script>
<script>
window.onload = function () {
window.ui = SwaggerUIBundle({
url: "/api/openapi.json",
dom_id: "#swagger-ui",
deepLinking: true,
displayRequestDuration: true,
presets: [SwaggerUIBundle.presets.apis, SwaggerUIStandalonePreset],
layout: "StandaloneLayout",
});
};
</script>
</body>
</html>
46 changes: 46 additions & 0 deletions memori-server/src/dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ pub(crate) struct AppSettings {
pub(crate) retrieval_gating_profile: Option<String>,
pub(crate) generation_refusal_mode: Option<String>,
pub(crate) gating_retry_on_refusal: Option<bool>,
#[serde(default)]
pub(crate) index_filter: Option<memori_core::IndexFilterConfig>,
// legacy fields for backwards compatibility
pub(crate) provider: Option<String>,
pub(crate) endpoint: Option<String>,
Expand Down Expand Up @@ -530,3 +532,47 @@ impl IntoResponse for ApiError {
.into_response()
}
}

#[cfg(test)]
mod tests {
use super::*;

/// 服务器侧此前会静默丢弃 settings.json 里的 index_filter(字段缺失);
/// 该测试固定反序列化行为,防止服务器模式再次忽略索引筛选配置。
#[test]
fn app_settings_parses_index_filter() {
let json = r#"{
"watch_root": "C:/vault",
"index_filter": {
"enabled": true,
"include_extensions": ["md", "txt"],
"exclude_extensions": ["log"],
"exclude_paths": ["ui/node_modules/**", "target/**"],
"include_paths": [],
"min_mtime": null,
"max_mtime": null,
"min_size": null,
"max_size": null
}
}"#;
let settings: AppSettings = serde_json::from_str(json).expect("settings 反序列化失败");
let filter = settings
.index_filter
.expect("index_filter 应被解析而非丢弃");
assert!(filter.enabled);
assert_eq!(filter.include_extensions, vec!["md", "txt"]);
assert_eq!(filter.exclude_extensions, vec!["log"]);
assert_eq!(
filter.exclude_paths,
vec!["ui/node_modules/**", "target/**"]
);
}

/// 未配置 index_filter 时保持 None(默认放行所有支持格式)。
#[test]
fn app_settings_without_index_filter_defaults_to_none() {
let json = r#"{ "watch_root": "C:/vault" }"#;
let settings: AppSettings = serde_json::from_str(json).expect("settings 反序列化失败");
assert!(settings.index_filter.is_none());
}
}
Loading