-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmemory_write.py
More file actions
97 lines (89 loc) · 2.87 KB
/
Copy pathmemory_write.py
File metadata and controls
97 lines (89 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
from __future__ import annotations
"""
Helpers to write episodic memories for Azurro's Memory Vault.
"""
from typing import Any
from memory_embeddings import embed_text
from memory_db import insert_memory_item
def build_episode_text(
entry: dict,
window_name: str,
colour: str,
narrative: str,
placed: bool,
result: str | None = None,
) -> str:
"""
Turn an entry + Sentry decision into a compact narrative string for embedding.
"""
name = entry.get("name") or "?"
league = entry.get("league") or ""
score = entry.get("score") or "? - ?"
target = entry.get("target_line") or "?"
odds = entry.get("odds")
shots = entry.get("total_shots")
corners = entry.get("total_corners")
fouls = entry.get("fouls")
preds = entry.get("predictions_text") or ""
parts: list[str] = []
parts.append(f"Match: {name} ({league})")
parts.append(f"Window: {window_name}")
parts.append(f"Score: {score}, Line: {target}, Odds: {odds}")
parts.append(f"Stats: shots={shots}, corners={corners}, fouls={fouls}")
if preds:
parts.append(f"Predictions: {preds}")
parts.append(f"Sentry colour: {colour}")
if narrative:
parts.append(f"Sentry narrative: {narrative}")
parts.append(f"Action: {'PLACED' if placed else 'SKIPPED'}")
if result:
parts.append(f"Result: {result}")
return " | ".join(str(p) for p in parts if p)
def write_episode_memory(
entry: dict,
*,
window_name: str,
colour: str,
narrative: str,
placed: bool,
source: str = "hunter",
result: str | None = None,
importance: float = 0.5,
) -> None:
"""
Embed and insert one episodic memory row for this candidate.
"""
text = build_episode_text(entry, window_name, colour, narrative, placed, result)
emb = embed_text(text)
fixture_id = entry.get("fixture_id")
try:
fixture_id_int: int | None = int(fixture_id) if fixture_id is not None else None
except (TypeError, ValueError):
fixture_id_int = None
azuro_game_id = entry.get("azuro_game_id") or None
league = entry.get("league") or None
features: dict[str, Any] = {
"score": entry.get("score"),
"target_line": entry.get("target_line"),
"odds": entry.get("odds"),
"shots": entry.get("total_shots"),
"corners": entry.get("total_corners"),
"fouls": entry.get("fouls"),
"window_name": window_name,
"colour": colour,
"placed": placed,
"result": result,
}
insert_memory_item(
kind="bet" if placed else "skip",
source=source,
text=text,
embedding=emb,
fixture_id=fixture_id_int,
azuro_game_id=azuro_game_id,
league=league,
window_name=window_name,
features=features,
importance=importance,
tags=[window_name, league] if league else [window_name],
)