docs(comments): 注释中文化 · internal/runtime/memory(31 文件,纯替换)
- 只翻注释/文档字符串: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:
1 parent
eb1828ee7a
commit
61cf80d5ee
31 files changed
+820
-820
No files matched your search
@@ -13,14 +13,14 @@ import (
|
||||
"git.yeij.top/AskaEth/Cyrene_v2/internal/runtime/embedding"
|
||||
)
|
||||
|
||||
// testLogger returns a logger that writes nowhere, keeping test output clean.
|
||||
// testLogger 返回一个不写任何地方的 logger,保持测试输出干净。
|
||||
func testLogger() *slog.Logger {
|
||||
return slog.New(slog.NewTextHandler(io.Discard, nil))
|
||||
}
|
||||
|
||||
// openTestDB opens an isolated in-memory SQLite DB. Each call owns a private DB,
|
||||
// so parallel tests are isolated by construction. The returned DB is closed by
|
||||
// t.Cleanup.
|
||||
// openTestDB 打开一个隔离的内存 SQLite 库。每次调用都拥有私有 DB,
|
||||
// 因此并行测试天生相互隔离。返回的 DB 由
|
||||
// t.Cleanup 关闭。
|
||||
func openTestDB(t *testing.T) *sql.DB {
|
||||
t.Helper()
|
||||
ctx := context.Background()
|
||||
@@ -32,8 +32,8 @@ func openTestDB(t *testing.T) *sql.DB {
|
||||
return d
|
||||
}
|
||||
|
||||
// newInMemorySQLite builds a SQLiteIndex on a fresh in-memory DB with dim
|
||||
// dimensions. The embedder is left unwired so tests control it.
|
||||
// newInMemorySQLite 在全新的内存 DB 上构建维度为 dim 的 SQLiteIndex。
|
||||
// embedder 不接入,由测试自行控制。
|
||||
func newInMemorySQLite(t *testing.T, dim int) *SQLiteIndex {
|
||||
t.Helper()
|
||||
ctx := context.Background()
|
||||
@@ -44,8 +44,8 @@ func newInMemorySQLite(t *testing.T, dim int) *SQLiteIndex {
|
||||
return idx
|
||||
}
|
||||
|
||||
// mockEmbedder is a scriptable embedding.Embedder for tests. With no fn it
|
||||
// returns one-hot vectors, one per input text, so tests can predict results.
|
||||
// mockEmbedder 是测试用的可脚本化 embedding.Embedder。未设置 fn 时它
|
||||
// 返回 one-hot 向量,每段输入文本一个,测试因此可预测结果。
|
||||
type mockEmbedder struct {
|
||||
dim int
|
||||
fn func(ctx context.Context, texts []string) ([]embedding.Vector, error)
|
||||
@@ -98,7 +98,7 @@ func TestNew_SelectsSQLite_WhenPGURLBlank(t *testing.T) {
|
||||
if _, ok := idx.(*SQLiteIndex); !ok {
|
||||
t.Fatalf("New type = %T, want *SQLiteIndex", idx)
|
||||
}
|
||||
// New wires the embedder, so Embed works on the returned index.
|
||||
// New 接入了 embedder,因此返回的索引上 Embed 可用。
|
||||
vs, err := idx.Embed(ctx, []string{"hello"})
|
||||
if err != nil {
|
||||
t.Fatalf("Embed: %v", err)
|
||||
@@ -127,9 +127,9 @@ func TestNew_PGURLWhitespace_SelectsSQLite(t *testing.T) {
|
||||
|
||||
func TestNew_PGSelection_AttemptsPGWhenURLSet(t *testing.T) {
|
||||
t.Parallel()
|
||||
// A loopback URL on a closed port fails fast, proving New chose the PG path
|
||||
// rather than silently falling back to SQLite. Port 1 (tcpmux) does not
|
||||
// listen on localhost, so the connection is refused immediately.
|
||||
// 指向已关闭端口的环回 URL 会快速失败,证明 New 选择了 PG 路径
|
||||
// 而不是静默回退到 SQLite。端口 1(tcpmux)在
|
||||
// localhost 上不监听,因此连接立即被拒。
|
||||
idx, err := New(config.DBConfig{
|
||||
SQLitePath: ":memory:",
|
||||
PGURL: "postgres://127.0.0.1:1/mem?sslmode=disable&connect_timeout=1",
|
||||
|
||||
Reference in new issue
Block a user