Files
memoryweave/go/cmd/fix_timestamps/main.go
T
xiaowei 2a350cf781 fix(distill): max_tokens 800→1200 — Agnes推理token预算不足
Agnes 2.0-flash是推理模型,推理token占大量预算。
800仍不够→JSON截断(parse error: unexpected end of JSON input)。
1200确保推理+正文都够用。
2026-08-20 01:13:06 +08:00

110 lines
2.8 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// fix_timestamps — 修复 LanceDB 中 epoch-0 时间戳的记忆
// 用法: go run cmd/fix_timestamps/main.go
package main
import (
"encoding/binary"
"encoding/json"
"fmt"
"log"
"net"
"os"
"time"
)
const socketPath = "/tmp/zhiyi-ipc.sock"
type MemoryRecord struct {
ID string `json:"id"`
Content string `json:"content"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
}
// 发 IPC 请求
func ipcCall(req interface{}) ([]byte, error) {
conn, err := net.DialTimeout("unix", socketPath, 5*time.Second)
if err != nil {
return nil, fmt.Errorf("dial: %w", err)
}
defer conn.Close()
data, _ := json.Marshal(req)
buf := make([]byte, 4)
binary.BigEndian.PutUint32(buf, uint32(len(data)))
if _, err := conn.Write(buf); err != nil {
return nil, err
}
if _, err := conn.Write(data); err != nil {
return nil, err
}
respLenBuf := make([]byte, 4)
if _, err := conn.Read(respLenBuf); err != nil {
return nil, err
}
n := binary.BigEndian.Uint32(respLenBuf)
resp := make([]byte, n)
conn.Read(resp)
return resp, nil
}
// 批量更新字段
func ipcUpdate(id, field, value string) error {
req := map[string]interface{}{
"cmd": "lancedb_update",
"id": id,
"table": "memories",
"fields": []map[string]interface{}{
{"column": field, "value": value},
},
}
_, err := ipcCall(req)
return err
}
func main() {
log.SetFlags(0)
log.SetOutput(os.Stderr)
epochThreshold := time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC)
// 查所有记忆(min_recall=0 包含所有 tier)
req := map[string]interface{}{
"cmd": "lancedb_query",
"min_recall": 0,
"limit": 5000,
}
resp, err := ipcCall(req)
if err != nil {
log.Fatalf("查询失败: %v", err)
}
var memories []MemoryRecord
if err := json.Unmarshal(resp, &memories); err != nil {
log.Fatalf("解析失败: %v\n内容: %s", err, string(resp))
}
log.Printf("查到 %d 条记忆,开始检查时间戳...\n", len(memories))
fixed := 0
for _, m := range memories {
t, err := time.Parse(time.RFC3339, m.CreatedAt)
if err != nil || t.Before(epochThreshold) || t.Year() < 2024 {
// 用确定性派生时间(避免所有epoch-0都用同一时间)
// 基于 ID 哈希分配 2024-2026 之间的不同日期
offsetDays := int(len(m.ID)%(365*2)) // 0-729天
newTime := time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC).AddDate(0, 0, offsetDays)
ts := newTime.Format(time.RFC3339)
if err := ipcUpdate(m.ID, "created_at", ts); err != nil {
log.Printf(" ⚠️ 更新失败 id=%s: %v", m.ID, err)
} else {
fixed++
log.Printf(" ✅ 修复 id=%s created_at=%s → %s", m.ID, m.CreatedAt, ts)
}
time.Sleep(50 * time.Millisecond) // 限速
}
}
log.Printf("\n完成: 修复 %d/%d 条记忆时间戳\n", fixed, len(memories))
}