Skip to content

Commit 3fcd053

Browse files
waleedlatif1claude
andcommitted
fix(knowledge): address PR feedback on Cohere reranker controls
- Drop required:true on apiKey field — server has BYOK→env→rotation fallback chain, so self-hosted users with COHERE_API_KEY env should not be blocked - Drop .min(1) on rerankerApiKey contract field so empty strings coerce to undefined via the transform (matches the existing query field pattern) - Log a warning when rerankerInputCount is clamped up to topK so users notice their setting was overridden Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent ef97b7b commit 3fcd053

3 files changed

Lines changed: 8 additions & 4 deletions

File tree

apps/sim/app/api/knowledge/search/route.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,15 @@ export const POST = withRouteHandler(async (request: NextRequest) => {
251251
* Cap at 100 to bound Cohere request cost (1 search unit = ≤100 docs). When the caller
252252
* supplies `rerankerInputCount`, honor it but never let it drop below `topK`
253253
* (which would defeat the purpose) or exceed 100 (which would split into >1 search units). */
254+
const rawInputCount = validatedData.rerankerInputCount
255+
if (useReranker && rawInputCount !== undefined && rawInputCount < validatedData.topK) {
256+
logger.warn(
257+
`[${requestId}] rerankerInputCount (${rawInputCount}) is below topK (${validatedData.topK}); raising to topK`
258+
)
259+
}
254260
const candidateTopK = useReranker
255-
? validatedData.rerankerInputCount !== undefined
256-
? Math.min(100, Math.max(validatedData.topK, validatedData.rerankerInputCount))
261+
? rawInputCount !== undefined
262+
? Math.min(100, Math.max(validatedData.topK, rawInputCount))
257263
: Math.min(100, validatedData.topK * 4)
258264
: validatedData.topK
259265

apps/sim/blocks/blocks/knowledge.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ export const KnowledgeBlock: BlockConfig = {
125125
placeholder: 'Enter your Cohere API key',
126126
password: true,
127127
connectionDroppable: false,
128-
required: true,
129128
condition: getCohereRerankerApiKeyCondition(),
130129
},
131130

apps/sim/lib/api/contracts/knowledge/search.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ export const knowledgeSearchBodySchema = z
5151
.transform((val) => val ?? undefined),
5252
rerankerApiKey: z
5353
.string()
54-
.min(1, 'rerankerApiKey cannot be empty')
5554
.optional()
5655
.nullable()
5756
.transform((val) => val || undefined),

0 commit comments

Comments
 (0)