Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ the end of this file for historical context.

### Fixes

- Notes with newline-separated preferences or facts now keep each claim in
stored summaries without splitting wrapped lines into separate statements.
- Embedded project-scoped writes. `longmemory_ingest` with a `project_id`,
`longmemory_remember_decision` and connector imports go through
`applyImportPlan`, which stored every node without a semantic vector, so
Expand Down
10 changes: 9 additions & 1 deletion src/core/engine/claim_extractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,15 @@ export function extract_claims(text: string): ExtractedClaim[] {
const prose = text.split(/\r?\n/).filter((line) => !line.trim().startsWith('|')).join('\n');
const protected_text = prose.replace(/[\p{L}\p{N}.!#$%&'*+/=?^_`{|}~-]+@[\p{L}\p{N}-]+(?:\.[\p{L}\p{N}-]+)+/gu, (email) => email.replaceAll('.', '<period>').replaceAll('!', '<exclaim>').replaceAll('?', '<question>'))
.replace(/(?<=\d)\.(?=\d)/g, '<period>').replace(/\b(Dr|Mr|Mrs|Ms|Prof|[A-Z])\./g, '$1<period>');
const statements = protected_text.split(/[.!?]+/)
const lines = protected_text.split(/\n+/).reduce<string[]>((joined, line) => {
const candidate = line.replace(/^\s*(?:[-*+]|\d+[.)])\s+/, '').replace(/^\s*(?:user|assistant|system|tool|function):\s*/i, '').trim();
const starts_claim = [preference, moved_location, location, copula, first_person, contact, mode_change].some((pattern) => pattern.test(candidate));
if (!joined.length || starts_claim || /^\s*(?:[-*+]|\d+[.)])\s+/.test(line)) joined.push(line);
else joined[joined.length - 1] += ` ${line.trim()}`;
return joined;
}, []);
const statements = lines
.flatMap((line) => line.split(/[.!?]+/))
.flatMap((item) => item.split(/,\s*(?=(?:please\s+)?(?:ping|contact|message|reach)\s+me\b)/i))
.map((item) => item.replaceAll('<period>', '.').replaceAll('<exclaim>', '!').replaceAll('<question>', '?').replace(/^\s*(?:user|assistant|system|tool|function):\s*/i, '').trim()).filter(Boolean);
const prose_claims = statements.map((statement): ExtractedClaim => {
Expand Down
7 changes: 7 additions & 0 deletions tools/check-recall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import assert from 'node:assert/strict';
import { createMemory } from '../src/index.js';
import { extract_claims } from '../src/core/engine/claim_extractor.js';

async function main() {
const memory = createMemory({ store: 'memory', embedding_dimension: 2 });
Expand All @@ -40,6 +41,12 @@ async function main() {
assert.ok(worlds.some((world) => world.id === 'release-check' || world.name === 'release-check'), 'the ingested world should be listed');

await memory.close();
assert.deepEqual(extract_claims('I prefer dark mode\nI prefer light mode').map((claim) => claim.object), ['dark mode', 'light mode']);
assert.deepEqual(extract_claims('I prefer dark mode because it reduces eye\nstrain.').map((claim) => claim.object), ['dark mode because it reduces eye strain']);
assert.deepEqual(extract_claims('- I prefer dark mode\n- Alice is in Paris').map((claim) => [claim.predicate, claim.object]), [
['prefers', 'dark mode'],
['located_in', 'paris'],
]);
const preferences = createMemory({ store: 'memory', embedding_dimension: 2 });
try {
const at = Date.now() - 1000;
Expand Down