Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 7 additions & 15 deletions apps/api/src/services/ab-test-comparison.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Logger } from "winston";
import { parseMarkdown } from "../lib/html-to-markdown";

const AB_LOG_PREFIX = "[FE_AB_COMPARE]";
const MAX_CONTENT_SIZE = 1_000_000; // 1 MB
const VARIANCE_THRESHOLD = 0.05; // 5% allowed variance

export interface FireEngineResponse {
Expand All @@ -20,15 +19,16 @@ function calculateSimilarity(a: string, b: string): number {
if (a === b) return 1;
if (a.length === 0 || b.length === 0) return 0;

const maxLen = Math.max(a.length, b.length);
const minLen = Math.min(a.length, b.length);
const wordsA = new Set(a.toLowerCase().split(/\s+/).filter(Boolean));
const wordsB = new Set(b.toLowerCase().split(/\s+/).filter(Boolean));

let matches = 0;
for (let i = 0; i < minLen; i++) {
if (a[i] === b[i]) matches++;
let intersection = 0;
for (const w of wordsA) {
if (wordsB.has(w)) intersection++;
}

return matches / maxLen;
const union = wordsA.size + wordsB.size - intersection;
return intersection / union;
}

export function scheduleABComparison(
Expand Down Expand Up @@ -57,14 +57,6 @@ export function scheduleABComparison(
return;
}

// Skip comparison if content too large
if (
productionResponse.content.length > MAX_CONTENT_SIZE ||
mirrorResult.response.content.length > MAX_CONTENT_SIZE
) {
return;
}

// Convert HTML to markdown before comparing
const [prodMarkdown, mirrorMarkdown] = await Promise.all([
parseMarkdown(productionResponse.content, { logger: abLogger }),
Expand Down
Loading