fix(memory): default non-finite lancedb text limits · openclaw/openclaw@27cd187
steipete
·
2026-05-29
·
via Recent Commits to openclaw:main
File tree
extensions/memory-lancedb
| Original file line number | Diff line number | Diff line change |
|---|
@@ -2408,13 +2408,15 @@ describe("memory plugin e2e", () => {
|
2408 | 2408 | const customTooLong = `I always prefer this style. ${"x".repeat(1600)}`; |
2409 | 2409 | expect(shouldCapture(customAllowed, { maxChars: 1500 })).toBe(true); |
2410 | 2410 | expect(shouldCapture(customTooLong, { maxChars: 1500 })).toBe(false); |
| 2411 | +expect(shouldCapture(defaultTooLong, { maxChars: Number.NaN })).toBe(false); |
2411 | 2412 | }); |
2412 | 2413 | |
2413 | 2414 | test("normalizeRecallQuery trims whitespace and bounds embedding input", () => { |
2414 | 2415 | expect(normalizeRecallQuery(" remember the blue mug ", 100)).toBe( |
2415 | 2416 | "remember the blue mug", |
2416 | 2417 | ); |
2417 | 2418 | expect(normalizeRecallQuery(`look up ${"x".repeat(200)}`, 120)).toHaveLength(120); |
| 2419 | +expect(normalizeRecallQuery(`look up ${"x".repeat(2000)}`, Number.NaN)).toHaveLength(1000); |
2418 | 2420 | }); |
2419 | 2421 | |
2420 | 2422 | test("normalizeEmbeddingVector accepts float arrays and base64 float32 responses", () => { |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -139,10 +139,16 @@ export function normalizeRecallQuery(
|
139 | 139 | maxChars: number = DEFAULT_RECALL_MAX_CHARS, |
140 | 140 | ): string { |
141 | 141 | const normalized = text.replace(/\s+/g, " ").trim(); |
142 | | -const limit = Math.max(0, Math.floor(maxChars)); |
| 142 | +const limit = normalizeMaxChars(maxChars, DEFAULT_RECALL_MAX_CHARS); |
143 | 143 | return normalized.length > limit ? truncateUtf16Safe(normalized, limit).trimEnd() : normalized; |
144 | 144 | } |
145 | 145 | |
| 146 | +function normalizeMaxChars(value: number | undefined, fallback: number): number { |
| 147 | +return typeof value === "number" && Number.isFinite(value) |
| 148 | + ? Math.max(0, Math.floor(value)) |
| 149 | + : fallback; |
| 150 | +} |
| 151 | + |
146 | 152 | function messageFingerprint(message: unknown): string { |
147 | 153 | const msgObj = asRecord(message); |
148 | 154 | if (!msgObj) { |
@@ -572,7 +578,7 @@ export function shouldCapture(
|
572 | 578 | text: string, |
573 | 579 | options?: { customTriggers?: string[]; maxChars?: number }, |
574 | 580 | ): boolean { |
575 | | -const maxChars = options?.maxChars ?? DEFAULT_CAPTURE_MAX_CHARS; |
| 581 | +const maxChars = normalizeMaxChars(options?.maxChars, DEFAULT_CAPTURE_MAX_CHARS); |
576 | 582 | if (text.length > maxChars) { |
577 | 583 | return false; |
578 | 584 | } |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。