@xdarkicex/openclaw-memory-libravdb 1.3.21 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/context-engine.ts +12 -2
- package/src/temporal.ts +48 -0
- package/src/types.ts +2 -0
package/package.json
CHANGED
package/src/context-engine.ts
CHANGED
|
@@ -12,7 +12,11 @@ import {
|
|
|
12
12
|
rankSection7VariantCandidates,
|
|
13
13
|
} from "./scoring.js";
|
|
14
14
|
import { buildInjectedMemoryMessageContent, buildMemoryHeader, recentIds } from "./recall-utils.js";
|
|
15
|
-
import {
|
|
15
|
+
import {
|
|
16
|
+
decideTemporalSelectorGuard,
|
|
17
|
+
detectTemporalQuerySignal,
|
|
18
|
+
rankTemporalRecoveryCandidates,
|
|
19
|
+
} from "./temporal.js";
|
|
16
20
|
import type { TemporalRecoveryRankingResult } from "./temporal.js";
|
|
17
21
|
import { countTokens, estimateTokens, fitPromptBudget, fitPromptBudgetFirstFit } from "./tokens.js";
|
|
18
22
|
import type { RpcGetter } from "./plugin-runtime.js";
|
|
@@ -194,6 +198,7 @@ export function buildContextEngineFactory(
|
|
|
194
198
|
} satisfies ContextAssembleResult;
|
|
195
199
|
}
|
|
196
200
|
const temporalQuery = detectTemporalQuerySignal(queryText);
|
|
201
|
+
const temporalSelectorGuard = decideTemporalSelectorGuard(queryText, temporalQuery);
|
|
197
202
|
|
|
198
203
|
const excluded = recentIds(messages, 4);
|
|
199
204
|
const cached = recallCache.take({ userId, queryText });
|
|
@@ -258,6 +263,7 @@ export function buildContextEngineFactory(
|
|
|
258
263
|
excluded,
|
|
259
264
|
queryText,
|
|
260
265
|
temporalQuery,
|
|
266
|
+
temporalSelectorGuard,
|
|
261
267
|
sessionId,
|
|
262
268
|
userId,
|
|
263
269
|
messages,
|
|
@@ -293,6 +299,7 @@ export function buildContextEngineFactory(
|
|
|
293
299
|
excluded,
|
|
294
300
|
queryText,
|
|
295
301
|
temporalQuery,
|
|
302
|
+
temporalSelectorGuard,
|
|
296
303
|
sessionId,
|
|
297
304
|
userId,
|
|
298
305
|
messages,
|
|
@@ -310,6 +317,7 @@ export function buildContextEngineFactory(
|
|
|
310
317
|
excluded: string[];
|
|
311
318
|
queryText: string;
|
|
312
319
|
temporalQuery: ReturnType<typeof detectTemporalQuerySignal>;
|
|
320
|
+
temporalSelectorGuard: ReturnType<typeof decideTemporalSelectorGuard>;
|
|
313
321
|
sessionId: string;
|
|
314
322
|
userId: string;
|
|
315
323
|
messages: Array<{ role: string; content: string }>;
|
|
@@ -608,7 +616,7 @@ export function buildContextEngineFactory(
|
|
|
608
616
|
excludeIds: recoveryExcludeIDs,
|
|
609
617
|
});
|
|
610
618
|
const annotatedUserResults = annotateCollection(rawUserResults.results ?? [], `turns:${userId}`);
|
|
611
|
-
temporalRecoveryResult =
|
|
619
|
+
temporalRecoveryResult = temporalSelectorGuard.shouldApply
|
|
612
620
|
? rankTemporalRecoveryCandidates(annotatedUserResults, {
|
|
613
621
|
queryText,
|
|
614
622
|
maxSelected: 3,
|
|
@@ -709,6 +717,8 @@ export function buildContextEngineFactory(
|
|
|
709
717
|
temporalQueryIndicator: temporalQuery.indicator,
|
|
710
718
|
temporalQueryActive: temporalQuery.active,
|
|
711
719
|
temporalQueryPatterns: temporalQuery.matchedPatterns,
|
|
720
|
+
temporalSelectorApplied: temporalSelectorGuard.shouldApply,
|
|
721
|
+
temporalSelectorReason: temporalSelectorGuard.reason,
|
|
712
722
|
temporalRecoverySlots: temporalRecoveryResult?.slots,
|
|
713
723
|
rawUserRecoveryCandidates: rawUserRecoveryDebug,
|
|
714
724
|
}
|
package/src/temporal.ts
CHANGED
|
@@ -112,6 +112,12 @@ export interface TemporalQuerySignal {
|
|
|
112
112
|
matchedPatterns: string[];
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
+
export interface TemporalSelectorGuardDecision {
|
|
116
|
+
shouldApply: boolean;
|
|
117
|
+
slots: string[];
|
|
118
|
+
reason: string;
|
|
119
|
+
}
|
|
120
|
+
|
|
115
121
|
export interface TemporalRecoveryDebugCandidate {
|
|
116
122
|
id: string;
|
|
117
123
|
text: string;
|
|
@@ -276,6 +282,48 @@ export function rankTemporalRecoveryCandidates(
|
|
|
276
282
|
return { ranked, debug, temporalQuery, slots };
|
|
277
283
|
}
|
|
278
284
|
|
|
285
|
+
export function decideTemporalSelectorGuard(
|
|
286
|
+
queryText: string,
|
|
287
|
+
temporalQuery: TemporalQuerySignal = detectTemporalQuerySignal(queryText),
|
|
288
|
+
): TemporalSelectorGuardDecision {
|
|
289
|
+
const slots = extractTemporalSlots(queryText);
|
|
290
|
+
if (!temporalQuery.active) {
|
|
291
|
+
return {
|
|
292
|
+
shouldApply: false,
|
|
293
|
+
slots,
|
|
294
|
+
reason: "temporal query gate inactive",
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
const strongCompositionalPattern = temporalQuery.matchedPatterns.some((pattern) =>
|
|
299
|
+
pattern === "how many days" ||
|
|
300
|
+
pattern === "how long" ||
|
|
301
|
+
pattern === "before or after" ||
|
|
302
|
+
pattern === "since or between"
|
|
303
|
+
);
|
|
304
|
+
if (!strongCompositionalPattern) {
|
|
305
|
+
return {
|
|
306
|
+
shouldApply: false,
|
|
307
|
+
slots,
|
|
308
|
+
reason: "query lacks strong compositional temporal pattern",
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
if (slots.length !== 2) {
|
|
313
|
+
return {
|
|
314
|
+
shouldApply: false,
|
|
315
|
+
slots,
|
|
316
|
+
reason: "query did not resolve to exactly two temporal slots",
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
return {
|
|
321
|
+
shouldApply: true,
|
|
322
|
+
slots,
|
|
323
|
+
reason: "strong temporal query with two-slot decomposition",
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
|
|
279
327
|
export function resetTemporalCachesForTest(): void {
|
|
280
328
|
temporalAnchorCache.clear();
|
|
281
329
|
}
|
package/src/types.ts
CHANGED
|
@@ -217,6 +217,8 @@ export interface ContextAssembleResult {
|
|
|
217
217
|
temporalQueryIndicator?: number;
|
|
218
218
|
temporalQueryActive?: boolean;
|
|
219
219
|
temporalQueryPatterns?: string[];
|
|
220
|
+
temporalSelectorApplied?: boolean;
|
|
221
|
+
temporalSelectorReason?: string;
|
|
220
222
|
temporalRecoverySlots?: string[];
|
|
221
223
|
};
|
|
222
224
|
}
|