-
Notifications
You must be signed in to change notification settings - Fork 6
membench: add 50 free-form synthesis questions draft #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bunny-bot-openclaw
wants to merge
2
commits into
main
Choose a base branch
from
feat/membench-questions-draft
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
| Memory consolidation, cross-linking, garbage collection, and core memory promotion | ||
| """ | ||
|
|
||
| import re | ||
| import sqlite3 | ||
| import json | ||
| import math | ||
|
|
@@ -30,6 +31,58 @@ class SleepEvent: | |
| event_type: str # "cross_link", "dedup", "dream", "gc_decay", "core_promotion", "core_demotion" | ||
| details: dict | ||
|
|
||
| # Temporal anchor detection — used to guard cluster merge against losing | ||
| # date/weekday/relative-time information during LLM synthesis. | ||
| _MONTHS = ( | ||
| "january|february|march|april|may|june|july|august|" | ||
| "september|october|november|december|" | ||
| "jan|feb|mar|apr|jun|jul|aug|sep|sept|oct|nov|dec" | ||
| ) | ||
| _WEEKDAYS = "monday|tuesday|wednesday|thursday|friday|saturday|sunday" | ||
| _RELATIVE = ( | ||
| r"yesterday|today|tonight|tomorrow|" | ||
| r"(?:last|next|this|past|coming)\s+(?:week|month|year|" | ||
| + _WEEKDAYS + r")|" | ||
| r"(?:\d+|one|two|three|four|five|six|seven|eight|nine|ten|" | ||
| r"eleven|twelve|few|several|couple\s+of)\s+" | ||
| r"(?:minute|hour|day|week|month|year)s?\s+ago|" | ||
| r"in\s+(?:\d+|one|two|three|four|five|six|seven|eight|nine|ten)\s+" | ||
| r"(?:minute|hour|day|week|month|year)s?" | ||
| ) | ||
| _TEMPORAL_PATTERNS = [ | ||
| re.compile(r"\b\d{4}-\d{2}-\d{2}\b"), # ISO date | ||
| re.compile(r"\b\d{1,2}/\d{1,2}/\d{2,4}\b"), # 3/5/2026 | ||
| re.compile(rf"\b(?:{_MONTHS})\b\.?\s*\d{{1,2}}(?:,\s*\d{{4}})?", re.IGNORECASE), | ||
| re.compile(rf"\b\d{{1,2}}\s+(?:{_MONTHS})\b", re.IGNORECASE), | ||
| re.compile(rf"\b(?:{_MONTHS})\s+\d{{4}}\b", re.IGNORECASE), | ||
| re.compile(rf"\b(?:{_WEEKDAYS})\b", re.IGNORECASE), | ||
| re.compile(r"\b(?:19|20)\d{2}\b"), # bare year | ||
| re.compile(rf"\b(?:{_RELATIVE})\b", re.IGNORECASE), | ||
| ] | ||
|
|
||
|
|
||
| def _collect_temporal_anchors(snippets: List[str]) -> List[str]: | ||
| """Return distinct lowercase temporal anchor strings found across snippets.""" | ||
| seen: Set[str] = set() | ||
| for s in snippets or (): | ||
| if not s: | ||
| continue | ||
| for pat in _TEMPORAL_PATTERNS: | ||
| for m in pat.findall(s): | ||
| tok = m.lower().strip() | ||
| if tok: | ||
| seen.add(tok) | ||
| return list(seen) | ||
|
|
||
|
|
||
| def _has_any_anchor(text: str, anchors: List[str]) -> bool: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Observation: Substring matching ( |
||
| """True if `text` (case-insensitive) contains at least one anchor string.""" | ||
| if not text or not anchors: | ||
| return False | ||
| low = text.lower() | ||
| return any(a in low for a in anchors) | ||
|
|
||
|
|
||
| @dataclass | ||
| class CrossLinkCandidate: | ||
| node1_id: str | ||
|
|
@@ -396,11 +449,19 @@ def _synthesize_cluster_content( | |
|
|
||
| With model_fn, asks the LLM for a single-line synthesis. Falls back to | ||
| the longest member's content on None or failure (degraded but not blank). | ||
|
|
||
| Temporal-anchor preservation: any date, weekday, month, year, or relative | ||
| time phrase ("last Tuesday", "in March", "two weeks ago") that appears in | ||
| a source snippet must survive into the merged statement. If the LLM | ||
| synthesis drops every temporal anchor present in the inputs, fall back to | ||
| the longest source rather than emit a temporally bleached merge. | ||
| """ | ||
| longest = max(cluster_contents, key=lambda s: len(s or "")) if cluster_contents else "" | ||
| if model_fn is None: | ||
| return longest | ||
|
|
||
| source_anchors = _collect_temporal_anchors(cluster_contents) | ||
|
|
||
| snippet_block = "\n\n".join( | ||
| f"SNIPPET {i+1} ({t}):\n{c}" | ||
| for i, (c, t) in enumerate(zip(cluster_contents, cluster_types)) | ||
|
|
@@ -412,6 +473,10 @@ def _synthesize_cluster_content( | |
| "express. Preserve the strongest, most specific phrasing. Do not " | ||
| "average or hedge. If they disagree on detail, keep the version that " | ||
| "is most concrete.\n\n" | ||
| "Critical: preserve every temporal anchor (specific dates, weekdays, " | ||
| "months, years, relative times like 'last Tuesday' or 'two weeks ago') " | ||
| "that appears in any snippet. Temporal context is load-bearing — " | ||
| "never drop it for brevity.\n\n" | ||
| "Rules: no preamble, no headers, no markdown. Output only the " | ||
| "consolidated statement, on a single line.\n\n" | ||
| f"{snippet_block}\n" | ||
|
|
@@ -421,6 +486,12 @@ def _synthesize_cluster_content( | |
| if response: | ||
| candidate = response.strip().splitlines()[0].strip() | ||
| if len(candidate) >= 10: | ||
| if source_anchors and not _has_any_anchor(candidate, source_anchors): | ||
| logger.warning( | ||
| "Cluster synthesis dropped all temporal anchors; " | ||
| "falling back to longest source to preserve them." | ||
| ) | ||
| return longest | ||
| return candidate | ||
| except Exception as e: | ||
| logger.warning(f"Cluster LLM synthesis failed, falling back: {e}") | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Observation:
\b(?:19|20)\d{2}\bwill capture any 4-digit sequence starting with 19/20 — "page 2024", "section 1984" — as temporal anchors. In thought-graph snippets this is unlikely to cause problems, but if the guard triggers false fallbacks in practice, a negative lookahead for non-temporal contexts could be added.