fix(mnemopi): preserve empty structured extraction
Short-circuit successfully parsed structured extractor output even when all extraction arrays are empty, so the JSON response body is not stored as a fallback memory. Added coverage for plain and fenced empty extraction JSON. Fixes #4390
This commit is contained in:
@@ -115,9 +115,7 @@ export function parseFacts(rawOutput: string | null | undefined): string[] {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (out.length > 0) {
|
||||
return out.slice(0, 5);
|
||||
}
|
||||
return out.slice(0, 5);
|
||||
}
|
||||
} catch {
|
||||
const matches = [...raw.matchAll(/"([^"]{10,})"/g)].map(m => m[1]).filter((v): v is string => v !== undefined);
|
||||
|
||||
@@ -52,6 +52,13 @@ describe("structured extraction", () => {
|
||||
expect(parseFacts("NO_FACTS")).toEqual([]);
|
||||
});
|
||||
|
||||
it("treats a valid empty structured extraction as no facts", () => {
|
||||
expect(parseFacts('{"facts": [], "instructions": [], "preferences": [], "timelines": [], "kg": []}')).toEqual([]);
|
||||
expect(
|
||||
parseFacts('```json\n{"facts": [], "instructions": [], "preferences": [], "timelines": [], "kg": []}\n```'),
|
||||
).toEqual([]);
|
||||
});
|
||||
|
||||
it("uses deterministic heuristic extraction when no LLM is configured", async () => {
|
||||
process.env.MNEMOPI_LLM_ENABLED = "false";
|
||||
const facts = await extractFactsSafe("My name is Ada. I work at Example Corp and I prefer dark mode.");
|
||||
|
||||
Reference in New Issue
Block a user