mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-18 10:07:27 +00:00
Memory: fix MMR tie-break and temporal timestamp dedupe
This commit is contained in:
committed by
Peter Steinberger
parent
33cf27a52a
commit
65ad9a4262
@@ -163,7 +163,7 @@ export function mmrRerank<T extends MMRItem>(items: T[], config: Partial<MMRConf
|
||||
// Use original score as tiebreaker (higher is better)
|
||||
if (
|
||||
mmrScore > bestMMRScore ||
|
||||
(mmrScore === bestMMRScore && (bestItem === null || candidate.score > bestItem.score))
|
||||
(mmrScore === bestMMRScore && candidate.score > (bestItem?.score ?? -Infinity))
|
||||
) {
|
||||
bestMMRScore = mmrScore;
|
||||
bestItem = candidate;
|
||||
|
||||
@@ -132,21 +132,22 @@ export async function applyTemporalDecayToHybridResults<
|
||||
}
|
||||
|
||||
const nowMs = params.nowMs ?? Date.now();
|
||||
const timestampCache = new Map<string, Date | null>();
|
||||
const timestampPromiseCache = new Map<string, Promise<Date | null>>();
|
||||
|
||||
return Promise.all(
|
||||
params.results.map(async (entry) => {
|
||||
const cacheKey = `${entry.source}:${entry.path}`;
|
||||
if (!timestampCache.has(cacheKey)) {
|
||||
const timestamp = await extractTimestamp({
|
||||
let timestampPromise = timestampPromiseCache.get(cacheKey);
|
||||
if (!timestampPromise) {
|
||||
timestampPromise = extractTimestamp({
|
||||
filePath: entry.path,
|
||||
source: entry.source,
|
||||
workspaceDir: params.workspaceDir,
|
||||
});
|
||||
timestampCache.set(cacheKey, timestamp);
|
||||
timestampPromiseCache.set(cacheKey, timestampPromise);
|
||||
}
|
||||
|
||||
const timestamp = timestampCache.get(cacheKey) ?? null;
|
||||
const timestamp = await timestampPromise;
|
||||
if (!timestamp) {
|
||||
return entry;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user