fix: increase reranking score threshold

This commit is contained in:
Manoj 2025-09-19 10:31:01 +05:30
parent a0b3128329
commit 963bfcbb78
2 changed files with 3 additions and 1 deletions

View File

@ -89,6 +89,7 @@ const EnvironmentSchema = z.object({
EMBEDDING_MODEL_SIZE: z.string().default("1024"),
OLLAMA_URL: z.string().optional(),
COHERE_API_KEY: z.string().optional(),
COHERE_SCORE_THRESHOLD: z.string().default("0.3"),
});
export type Environment = z.infer<typeof EnvironmentSchema>;

View File

@ -4,6 +4,7 @@ import { type CoreMessage } from "ai";
import { makeModelCall } from "~/lib/model.server";
import { logger } from "../logger.service";
import { CohereClientV2 } from "cohere-ai";
import { env } from "~/env.server";
// Utility function to safely convert BigInt values to Number
function safeNumber(value: any): number {
@ -512,7 +513,7 @@ export async function applyCohereReranking(
cohereScore: result.relevanceScore,
cohereRank: index + 1,
}))
.filter((result) => result.cohereScore >= 0.1);
.filter((result) => result.cohereScore >= Number(env.COHERE_SCORE_THRESHOLD));
const responseTime = Date.now() - startTime;
logger.info(