mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-11-04 07:30:17 +00:00
fix(extension): fall back to chunk when memory is whitespace-only
Graphite review: memory || chunk treated " " as truthy and dropped a valid chunk. Trim both fields before choosing.
This commit is contained in:
parent
4d02f6d79c
commit
c5db753fe3
3 changed files with 18 additions and 8 deletions
|
|
@ -92,12 +92,13 @@ export const HYBRID_RECALL_FIXTURES: HybridRecallFixture[] = [
|
|||
},
|
||||
{
|
||||
id: "empty-and-whitespace-noise",
|
||||
description: "Empty / whitespace hits must not invent prompt lines",
|
||||
expectedTexts: ["Keep this fact"],
|
||||
chunkOnlyTexts: [],
|
||||
description:
|
||||
"Whitespace-only memory must not block a valid chunk; blanks invent no lines",
|
||||
expectedTexts: ["Keep this fact", "Important document text"],
|
||||
chunkOnlyTexts: ["Important document text"],
|
||||
results: [
|
||||
{ memory: "Keep this fact" },
|
||||
{ memory: " " },
|
||||
{ memory: " ", chunk: "Important document text" },
|
||||
{ chunk: "" },
|
||||
{},
|
||||
],
|
||||
|
|
|
|||
|
|
@ -37,6 +37,15 @@ describe("formatSearchHitText", () => {
|
|||
)
|
||||
})
|
||||
|
||||
it("falls back to chunk when memory is only whitespace", () => {
|
||||
expect(
|
||||
formatSearchHitText({
|
||||
memory: " ",
|
||||
chunk: "Important document text",
|
||||
}),
|
||||
).toBe("Important document text")
|
||||
})
|
||||
|
||||
it("returns null for empty hits", () => {
|
||||
expect(formatSearchHitText({})).toBeNull()
|
||||
expect(formatSearchHitText({ memory: " " })).toBeNull()
|
||||
|
|
|
|||
|
|
@ -23,10 +23,10 @@ export function buildSearchMemoriesBody(
|
|||
|
||||
/** Prefer extracted memory text; fall back to document chunk. */
|
||||
export function formatSearchHitText(hit: SearchHit): string | null {
|
||||
const text = hit.memory || hit.chunk
|
||||
if (typeof text !== "string") return null
|
||||
const trimmed = text.trim()
|
||||
return trimmed.length > 0 ? trimmed : null
|
||||
const memory = typeof hit.memory === "string" ? hit.memory.trim() : ""
|
||||
const chunk = typeof hit.chunk === "string" ? hit.chunk.trim() : ""
|
||||
const text = memory || chunk
|
||||
return text.length > 0 ? text : null
|
||||
}
|
||||
|
||||
/** Numbered prompt lines for Included Memories; skips empty hits. */
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue