refactor(memory): extract F2 recall path (#23)
This commit is contained in:
@@ -361,34 +361,21 @@ def search_cmd(
|
||||
from rich.table import Table
|
||||
|
||||
from tht.cli.vector_cmd import make_embedder, open_searcher, require_vector_cfg
|
||||
from tht.memory import REUSABLE_TYPES, decided_memory_ids, load_registry
|
||||
from tht.memory import load_registry, recall_memories
|
||||
|
||||
cfg = _load_config_or_exit(config)
|
||||
require_vector_cfg(cfg)
|
||||
excluded: set[str] = set()
|
||||
if session is not None:
|
||||
excluded = decided_memory_ids(load_snapshot_or_exit(cfg, session).decisions)
|
||||
decisions = load_snapshot_or_exit(cfg, session).decisions if session is not None else []
|
||||
searcher = open_searcher(cfg)
|
||||
embedder = make_embedder(cfg.embeddings)
|
||||
hits = searcher.search(embedder.embed_query(question), top_n=top, kinds=["memory"])
|
||||
by_id = {r.id: r for r in load_registry(registry_path(cfg))}
|
||||
|
||||
results = []
|
||||
for h in hits:
|
||||
rec = by_id.get(h.ref)
|
||||
if rec is None:
|
||||
continue # indice piu' avanti del registro: ignora
|
||||
if rec.type not in REUSABLE_TYPES:
|
||||
continue # record legacy non-concept: non e' una memory riusabile
|
||||
if rec.id in excluded:
|
||||
continue # gia' decisa in questa sessione: non riproporla
|
||||
results.append({
|
||||
"id": rec.id, "type": rec.type, "subject": rec.subject,
|
||||
"detail": rec.detail, "rationale": rec.rationale,
|
||||
"question_context": rec.question_context,
|
||||
"tables": rec.tables, "concepts": rec.concepts,
|
||||
"session_id": rec.session_id, "score": round(h.similarity, 4),
|
||||
})
|
||||
results = recall_memories(
|
||||
question,
|
||||
records=load_registry(registry_path(cfg)),
|
||||
decisions=decisions,
|
||||
searcher=searcher,
|
||||
embedder=embedder,
|
||||
top=top,
|
||||
)
|
||||
|
||||
if json_out:
|
||||
typer.echo(json.dumps(results, ensure_ascii=False, indent=2))
|
||||
|
||||
Reference in New Issue
Block a user