fix G7 E3: crystallize路由路径+GetSkillCandidates通过Rust IPC查LanceDB
- server.go: 修复mux路由路径(去掉"POST "前缀) - skill_crystallize.go: 添加POST方法检查 - models/memory.go: 添加safeTime类型避免空字符串解析报错 - lancedb_ipc.go: GetSkillCandidates改用Rust IPC的lancedb_query - Rust lancedb_ops.rs: 新增query_memories()支持min_recall过滤 - Rust main.rs: 新增lancedb_query IPC handler
This commit is contained in:
@@ -131,6 +131,52 @@ impl LanceDBOps {
|
||||
Ok(records)
|
||||
}
|
||||
|
||||
/// 查询记忆(支持 min_recall_count 过滤),供 GetSkillCandidates 使用
|
||||
pub fn query_memories(&self, min_recall: i64, limit: usize) -> Result<Vec<MemoryRecord>, Box<dyn std::error::Error>> {
|
||||
let db = rt().block_on(lancedb::connect(self.data_dir.to_str().unwrap()).execute())?;
|
||||
let tbl = rt().block_on(db.open_table("memories").execute())?;
|
||||
|
||||
let filter = format!("recall_count >= {} AND is_deleted = false AND tier != 'core'", min_recall);
|
||||
let mut results = Box::pin(rt().block_on(
|
||||
tbl.query()
|
||||
.only_if(&filter)
|
||||
.limit(limit)
|
||||
.execute()
|
||||
)?);
|
||||
|
||||
let mut records = Vec::new();
|
||||
while let Some(Ok(batch)) = rt().block_on(results.next()) {
|
||||
for i in 0..batch.num_rows() {
|
||||
records.push(MemoryRecord {
|
||||
id: col_str(&batch, i, "id"),
|
||||
agent_id: col_str(&batch, i, "agent_id"),
|
||||
namespace: col_str(&batch, i, "namespace"),
|
||||
content: col_str(&batch, i, "content"),
|
||||
category: col_str(&batch, i, "category"),
|
||||
vector: col_vector(&batch, i, "vector"),
|
||||
tier: col_str(&batch, i, "tier"),
|
||||
importance: col_f64(&batch, i, "importance"),
|
||||
quality_score: col_f64(&batch, i, "quality_score"),
|
||||
recall_count: col_i64(&batch, i, "recall_count"),
|
||||
useful_count: col_i64(&batch, i, "useful_count"),
|
||||
not_useful_count: col_i64(&batch, i, "not_useful_count"),
|
||||
freshness: col_str(&batch, i, "freshness"),
|
||||
version: col_i64(&batch, i, "version"),
|
||||
version_history: String::new(),
|
||||
source: col_str(&batch, i, "source"),
|
||||
volatile_flag: col_bool(&batch, i, "volatile_flag"),
|
||||
is_deleted: col_bool(&batch, i, "is_deleted"),
|
||||
depends_on: String::new(),
|
||||
derived_from: String::new(),
|
||||
last_recalled_at: String::new(),
|
||||
created_at: col_str(&batch, i, "created_at"),
|
||||
updated_at: col_str(&batch, i, "updated_at"),
|
||||
});
|
||||
}
|
||||
}
|
||||
Ok(records)
|
||||
}
|
||||
|
||||
pub fn insert_batch(&self, table: &str, records_json: &str) -> Result<usize, Box<dyn std::error::Error>> {
|
||||
let values: serde_json::Value = serde_json::from_str(records_json)?;
|
||||
let records: Vec<serde_json::Value> = values.as_array().ok_or("expected JSON array")?.to_vec();
|
||||
|
||||
@@ -300,6 +300,18 @@ fn handle_client(mut stream: UnixStream, args: &Args, lancedb: LanceDBOps, state
|
||||
}
|
||||
}
|
||||
}
|
||||
"lancedb_query" => {
|
||||
let min_recall = msg["min_recall"].as_i64().unwrap_or(5) as i64;
|
||||
let limit = msg["limit"].as_u64().unwrap_or(20) as usize;
|
||||
eprintln!("[lancedb] query: min_recall={} limit={}", min_recall, limit);
|
||||
match lancedb.query_memories(min_recall, limit) {
|
||||
Ok(r) => {
|
||||
eprintln!("[lancedb] query returned {} records", r.len());
|
||||
send_ok(&mut stream, &serde_json::to_string(&r).unwrap_or_default())
|
||||
}
|
||||
Err(e) => send_error(&mut stream, "lancedb_query", &e.to_string()),
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
let req: ConsolidateRequest = match serde_json::from_value(msg) {
|
||||
Ok(r) => r, Err(e) => {
|
||||
|
||||
Reference in New Issue
Block a user