Skip to content

Commit c56b7a4

Browse files
committed
fix(knowledge): split reranker model constants into client-safe module
1 parent 9614a28 commit c56b7a4

4 files changed

Lines changed: 33 additions & 16 deletions

File tree

apps/sim/blocks/blocks/knowledge.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { PackageSearchIcon } from '@/components/icons'
2-
import { DEFAULT_RERANKER_MODEL, SUPPORTED_RERANKER_MODELS } from '@/lib/knowledge/reranker'
2+
import { DEFAULT_RERANKER_MODEL, SUPPORTED_RERANKER_MODELS } from '@/lib/knowledge/reranker-models'
33
import type { BlockConfig } from '@/blocks/types'
44

55
export const KnowledgeBlock: BlockConfig = {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* Client-safe registry of Cohere rerank models supported by the platform.
3+
* Kept free of server imports so it can be imported into UI / block code.
4+
*/
5+
6+
/** Cohere rerank model identifiers we accept. Must match Cohere's model ids exactly. */
7+
export const SUPPORTED_RERANKER_MODELS = [
8+
'rerank-v4.0-pro',
9+
'rerank-v4.0-fast',
10+
'rerank-v3.5',
11+
] as const
12+
export type RerankerModelId = (typeof SUPPORTED_RERANKER_MODELS)[number]
13+
14+
export const DEFAULT_RERANKER_MODEL: RerankerModelId = 'rerank-v4.0-fast'
15+
16+
export function isSupportedRerankerModel(model: string): model is RerankerModelId {
17+
return (SUPPORTED_RERANKER_MODELS as readonly string[]).includes(model)
18+
}

apps/sim/lib/knowledge/reranker.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,24 @@ import { getBYOKKey } from '@/lib/api-key/byok'
33
import { getRotatingApiKey } from '@/lib/core/config/api-keys'
44
import { env } from '@/lib/core/config/env'
55
import { isRetryableError, retryWithExponentialBackoff } from '@/lib/knowledge/documents/utils'
6+
import {
7+
DEFAULT_RERANKER_MODEL,
8+
isSupportedRerankerModel,
9+
type RerankerModelId,
10+
SUPPORTED_RERANKER_MODELS,
11+
} from '@/lib/knowledge/reranker-models'
12+
13+
export {
14+
DEFAULT_RERANKER_MODEL,
15+
isSupportedRerankerModel,
16+
type RerankerModelId,
17+
SUPPORTED_RERANKER_MODELS,
18+
}
619

720
const logger = createLogger('Reranker')
821

922
const RERANK_REQUEST_TIMEOUT_MS = 30_000
1023

11-
/** Cohere rerank model identifiers we accept. Must match Cohere's model ids exactly. */
12-
export const SUPPORTED_RERANKER_MODELS = [
13-
'rerank-v4.0-pro',
14-
'rerank-v4.0-fast',
15-
'rerank-v3.5',
16-
] as const
17-
export type RerankerModelId = (typeof SUPPORTED_RERANKER_MODELS)[number]
18-
19-
export const DEFAULT_RERANKER_MODEL: RerankerModelId = 'rerank-v4.0-fast'
20-
2124
/**
2225
* Cohere bills per "search unit" = one query with up to 100 documents.
2326
* We cap at 100 so each rerank call costs exactly 1 unit and matches
@@ -26,10 +29,6 @@ export const DEFAULT_RERANKER_MODEL: RerankerModelId = 'rerank-v4.0-fast'
2629
*/
2730
const MAX_DOCUMENTS_PER_RERANK = 100
2831

29-
export function isSupportedRerankerModel(model: string): model is RerankerModelId {
30-
return (SUPPORTED_RERANKER_MODELS as readonly string[]).includes(model)
31-
}
32-
3332
export interface RerankItem {
3433
/** Stable identifier so callers can correlate ranked results back to source rows. */
3534
id: string

apps/sim/tools/knowledge/search.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { DEFAULT_RERANKER_MODEL, SUPPORTED_RERANKER_MODELS } from '@/lib/knowledge/reranker'
1+
import { DEFAULT_RERANKER_MODEL, SUPPORTED_RERANKER_MODELS } from '@/lib/knowledge/reranker-models'
22
import type { KnowledgeSearchResponse } from '@/tools/knowledge/types'
33
import { enrichKBTagFiltersSchema } from '@/tools/schema-enrichers'
44
import { parseTagFilters } from '@/tools/shared/tags'

0 commit comments

Comments
 (0)