docs(comments): 注释中文化 · internal/runtime/memory(31 文件,纯替换)
CI / Backend (build / vet / test / cross-compile) (push) Has been cancelled
CI / Frontend (tsc + vite build) (push) Has been cancelled

- 只翻注释/文档字符串:820 增 / 820 删 严格 1:1;剥掉整行注释与行尾注释尾巴后,
  逐文件与 HEAD 比对「代码部分差异 = 0」;裁决/design 编号计数逐项与 HEAD 一致
- 保留可执行 SQL 样例、SQLite 报错原文、pgvector/HNSW/ANN/BLOB 等技术词原文
- 复核:go build 绿 + memory/projectindex/vector 三包测试绿;gofmt 仅剩 2 个既有未格式化文件(改动前即如此,未顺手修)
This commit is contained in:
AskaEth committed 2026-10-04 13:32:54 +08:00
1 parent eb1828ee7a
commit 61cf80d5ee
31 files changed
+820 -820

No files matched your search

+15 -15
View File
@@ -9,8 +9,8 @@ import (
"git.yeij.top/AskaEth/Cyrene_v2/internal/runtime/memory/vector"
)
// mockVectorIndex is a scriptable vector.Index for tests. With no fns it emits
// one-hot vectors and returns no search hits.
// mockVectorIndex 是测试用的可脚本化 vector.Index。未设置 fns 时它
// 发出 one-hot 向量且不返回检索命中。
type mockVectorIndex struct {
dim int
embedFn func(ctx context.Context, texts []string) ([]vector.Vector, error)
@@ -59,9 +59,9 @@ func TestRetriever_Retrieve_WithVectorIndex_正常(t *testing.T) {
ctx := context.Background()
s := newTestStore(t)
// Both items are in English while the query is Chinese, so the keyword path
// shares no token and contributes nothing. The ranking is therefore driven
// entirely by the vector index, proving the persistent vector path is used.
// 两条条目都是英文而 query 是中文,因此关键词路径
// 不共享任何 token、毫无贡献。排名因此完全由
// 向量索引驱动,证明走的是持久化向量路径。
item1 := addItem(t, s, MemoryItem{
PersonaID: "persona.a", Content: "she is a morning person",
Scope: ScopePersona, Kind: KindRelationship,
@@ -110,11 +110,11 @@ func TestRetriever_Retrieve_WithVectorIndex_PartialHits_正常(t *testing.T) {
Scope: ScopePersona, Kind: KindRelationship,
})
// The vector index only knows about item1; item2 is absent from it, so it
// carries no semantic score. With a Chinese query that the keyword path
// cannot match, only item1 is relevant: it must rank at the top with a
// positive score while item2 scores 0, proving the semantic contribution
// comes strictly from the vector index.
// 向量索引只知道 item1;item2 不在其中,因此它
// 没有语义得分。在关键词路径无法匹配的中文 query 下,
// 只有 item1 相关:它必须以正得分排在
// 首位,而 item2 得 0 分,证明语义贡献
// 严格来自向量索引。
idx := &mockVectorIndex{
searchFn: func(_ context.Context, _ vector.Vector, _ int) ([]vector.Hit, error) {
return []vector.Hit{{ID: item1.ID, Score: 0.9}}, nil
@@ -135,8 +135,8 @@ func TestRetriever_Retrieve_WithVectorIndex_PartialHits_正常(t *testing.T) {
if results[0].Score <= 0 {
t.Fatalf("top result score = %v, want > 0", results[0].Score)
}
// item2 has no vector hit and no keyword overlap, so it scores 0 (matched
// mode) and sorts below.
// item2 既无向量命中也无关键词重叠,因此得 0 分(已匹配
// 模式)并排在后面。
if results[1].Item.ID != item2.ID {
t.Fatalf("second result id = %q, want item2", results[1].Item.ID)
}
@@ -179,7 +179,7 @@ func TestRetriever_Retrieve_ProjectLink_正常(t *testing.T) {
t.Parallel()
ctx := context.Background()
// Separate project-index DB, so it shares no connection with the memory store.
// 独立的项目索引 DB,因此与记忆存储不共享连接。
projDB, err := db.Open(ctx, ":memory:", testLogger())
if err != nil {
t.Fatalf("open project db: %v", err)
@@ -233,8 +233,8 @@ func TestRetriever_Retrieve_ProjectLink_NoStore_正常(t *testing.T) {
Scope: ScopeProject, ProjectID: "project.alpha", Kind: KindWorldEvent,
})
// Without a project-index store wired, the hit still returns and Project is
// simply left unset (no error).
// 未接入项目索引存储时,命中仍会返回,Project
// 只是不设置(不报错)。
r := NewRetriever(ms)
results, err := r.Retrieve(ctx, "persona.a", "Alpha", 10)
if err != nil {