mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 04:01:23 +00:00
fix: MMR default disabled, tie-break null guard, correct docs URL
- DEFAULT_MMR_CONFIG.enabled = false (opt-in, was incorrectly true) - Tie-break: handle bestItem === null so first candidate always wins - CHANGELOG URL: docs.clawd.bot → docs.openclaw.ai - Tests updated to pass enabled: true explicitly where needed
This commit is contained in:
committed by
Peter Steinberger
parent
6b3e0710f4
commit
33cf27a52a
@@ -148,7 +148,7 @@ describe("mmrRerank", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("lambda=0 maximizes diversity", () => {
|
it("lambda=0 maximizes diversity", () => {
|
||||||
const result = mmrRerank(diverseItems, { lambda: 0 });
|
const result = mmrRerank(diverseItems, { enabled: true, lambda: 0 });
|
||||||
// First item is still highest score (no penalty yet)
|
// First item is still highest score (no penalty yet)
|
||||||
expect(result[0].id).toBe("1");
|
expect(result[0].id).toBe("1");
|
||||||
// Second should be most different from first
|
// Second should be most different from first
|
||||||
@@ -161,7 +161,7 @@ describe("mmrRerank", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("clamps lambda < 0 to 0", () => {
|
it("clamps lambda < 0 to 0", () => {
|
||||||
const result = mmrRerank(diverseItems, { lambda: -0.5 });
|
const result = mmrRerank(diverseItems, { enabled: true, lambda: -0.5 });
|
||||||
expect(result[0].id).toBe("1");
|
expect(result[0].id).toBe("1");
|
||||||
expect(result[1].id).toBe("3");
|
expect(result[1].id).toBe("3");
|
||||||
});
|
});
|
||||||
@@ -176,7 +176,7 @@ describe("mmrRerank", () => {
|
|||||||
{ id: "4", score: 0.85, content: "machine learning algorithms" },
|
{ id: "4", score: 0.85, content: "machine learning algorithms" },
|
||||||
];
|
];
|
||||||
|
|
||||||
const result = mmrRerank(items, { lambda: 0.5 });
|
const result = mmrRerank(items, { enabled: true, lambda: 0.5 });
|
||||||
|
|
||||||
// First is always highest score
|
// First is always highest score
|
||||||
expect(result[0].id).toBe("1");
|
expect(result[0].id).toBe("1");
|
||||||
@@ -191,7 +191,7 @@ describe("mmrRerank", () => {
|
|||||||
{ id: "3", score: 0.8, content: "different stuff" },
|
{ id: "3", score: 0.8, content: "different stuff" },
|
||||||
];
|
];
|
||||||
|
|
||||||
const result = mmrRerank(items, { lambda: 0.5 });
|
const result = mmrRerank(items, { enabled: true, lambda: 0.5 });
|
||||||
expect(result[0].id).toBe("1");
|
expect(result[0].id).toBe("1");
|
||||||
// Second should be different, not identical duplicate
|
// Second should be different, not identical duplicate
|
||||||
expect(result[1].id).toBe("3");
|
expect(result[1].id).toBe("3");
|
||||||
@@ -344,7 +344,7 @@ describe("applyMMRToHybridResults", () => {
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const reranked = applyMMRToHybridResults(results, { lambda: 0.5 });
|
const reranked = applyMMRToHybridResults(results, { enabled: true, lambda: 0.5 });
|
||||||
|
|
||||||
// First stays the same (highest score)
|
// First stays the same (highest score)
|
||||||
expect(reranked[0].path).toBe("/a.ts");
|
expect(reranked[0].path).toBe("/a.ts");
|
||||||
@@ -365,7 +365,7 @@ describe("applyMMRToHybridResults", () => {
|
|||||||
|
|
||||||
describe("DEFAULT_MMR_CONFIG", () => {
|
describe("DEFAULT_MMR_CONFIG", () => {
|
||||||
it("has expected default values", () => {
|
it("has expected default values", () => {
|
||||||
expect(DEFAULT_MMR_CONFIG.enabled).toBe(true);
|
expect(DEFAULT_MMR_CONFIG.enabled).toBe(false);
|
||||||
expect(DEFAULT_MMR_CONFIG.lambda).toBe(0.7);
|
expect(DEFAULT_MMR_CONFIG.lambda).toBe(0.7);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -14,14 +14,14 @@ export type MMRItem = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export type MMRConfig = {
|
export type MMRConfig = {
|
||||||
/** Enable/disable MMR re-ranking. Default: true */
|
/** Enable/disable MMR re-ranking. Default: false (opt-in) */
|
||||||
enabled: boolean;
|
enabled: boolean;
|
||||||
/** Lambda parameter: 0 = max diversity, 1 = max relevance. Default: 0.7 */
|
/** Lambda parameter: 0 = max diversity, 1 = max relevance. Default: 0.7 */
|
||||||
lambda: number;
|
lambda: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const DEFAULT_MMR_CONFIG: MMRConfig = {
|
export const DEFAULT_MMR_CONFIG: MMRConfig = {
|
||||||
enabled: true,
|
enabled: false,
|
||||||
lambda: 0.7,
|
lambda: 0.7,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -163,7 +163,7 @@ export function mmrRerank<T extends MMRItem>(items: T[], config: Partial<MMRConf
|
|||||||
// Use original score as tiebreaker (higher is better)
|
// Use original score as tiebreaker (higher is better)
|
||||||
if (
|
if (
|
||||||
mmrScore > bestMMRScore ||
|
mmrScore > bestMMRScore ||
|
||||||
(mmrScore === bestMMRScore && bestItem && candidate.score > bestItem.score)
|
(mmrScore === bestMMRScore && (bestItem === null || candidate.score > bestItem.score))
|
||||||
) {
|
) {
|
||||||
bestMMRScore = mmrScore;
|
bestMMRScore = mmrScore;
|
||||||
bestItem = candidate;
|
bestItem = candidate;
|
||||||
|
|||||||
Reference in New Issue
Block a user