Skip to content

Commit 488ef20

Browse files
committed
fix kb config as sot
1 parent b9fc3c2 commit 488ef20

File tree

6 files changed

+26
-40
lines changed

6 files changed

+26
-40
lines changed

apps/sim/app/api/knowledge/[id]/documents/route.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,25 @@ const CreateDocumentSchema = z.object({
3939
})
4040

4141
/**
42-
* Schema for bulk document creation with processing options
42+
* Schema for bulk document creation with processing options.
43+
* Chunking fields are optional — the server falls back to the KB's stored chunkingConfig.
4344
*
4445
* Processing options units:
4546
* - chunkSize: tokens (1 token ≈ 4 characters)
4647
* - minCharactersPerChunk: characters
47-
* - chunkOverlap: characters
48+
* - chunkOverlap: tokens (1 token ≈ 4 characters)
4849
*/
4950
const BulkCreateDocumentsSchema = z.object({
5051
documents: z.array(CreateDocumentSchema),
5152
processingOptions: z.object({
5253
/** Maximum chunk size in tokens (1 token ≈ 4 characters) */
53-
chunkSize: z.number().min(100).max(4000),
54+
chunkSize: z.number().min(100).max(4000).optional(),
5455
/** Minimum chunk size in characters */
55-
minCharactersPerChunk: z.number().min(1).max(2000),
56-
recipe: z.string(),
57-
lang: z.string(),
58-
/** Overlap between chunks in characters */
59-
chunkOverlap: z.number().min(0).max(500),
56+
minCharactersPerChunk: z.number().min(1).max(2000).optional(),
57+
recipe: z.string().optional(),
58+
lang: z.string().optional(),
59+
/** Overlap between chunks in tokens (1 token ≈ 4 characters) */
60+
chunkOverlap: z.number().min(0).max(500).optional(),
6061
}),
6162
bulk: z.literal(true),
6263
})

apps/sim/app/api/knowledge/[id]/documents/upsert/route.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ const UpsertDocumentSchema = z.object({
2626
mimeType: z.string().min(1, 'MIME type is required'),
2727
documentTagsData: z.string().optional(),
2828
processingOptions: z.object({
29-
chunkSize: z.number().min(100).max(4000),
30-
minCharactersPerChunk: z.number().min(1).max(2000),
31-
recipe: z.string(),
32-
lang: z.string(),
33-
chunkOverlap: z.number().min(0).max(500),
29+
chunkSize: z.number().min(100).max(4000).optional(),
30+
minCharactersPerChunk: z.number().min(1).max(2000).optional(),
31+
recipe: z.string().optional(),
32+
lang: z.string().optional(),
33+
chunkOverlap: z.number().min(0).max(500).optional(),
3434
}),
3535
workflowId: z.string().optional(),
3636
})

apps/sim/app/api/v1/knowledge/[id]/documents/route.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,6 @@ export async function POST(request: NextRequest, { params }: DocumentsRouteParam
187187
requestId
188188
)
189189

190-
const chunkingConfig = result.kb.chunkingConfig ?? { maxSize: 1024, minSize: 100, overlap: 200 }
191-
192190
const documentData: DocumentData = {
193191
documentId: newDocument.id,
194192
filename: file.name,
@@ -197,18 +195,7 @@ export async function POST(request: NextRequest, { params }: DocumentsRouteParam
197195
mimeType: contentType,
198196
}
199197

200-
processDocumentsWithQueue(
201-
[documentData],
202-
knowledgeBaseId,
203-
{
204-
chunkSize: chunkingConfig.maxSize,
205-
minCharactersPerChunk: chunkingConfig.minSize,
206-
chunkOverlap: chunkingConfig.overlap,
207-
recipe: 'default',
208-
lang: 'en',
209-
},
210-
requestId
211-
).catch(() => {
198+
processDocumentsWithQueue([documentData], knowledgeBaseId, {}, requestId).catch(() => {
212199
// Processing errors are logged internally
213200
})
214201

apps/sim/app/workspace/[workspaceId]/knowledge/[id]/components/add-documents-modal/add-documents-modal.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,6 @@ export function AddDocumentsModal({
195195

196196
try {
197197
await uploadFiles([fileToRetry], knowledgeBaseId, {
198-
chunkSize: chunkingConfig?.maxSize || 1024,
199-
minCharactersPerChunk: chunkingConfig?.minSize || 1,
200-
chunkOverlap: chunkingConfig?.overlap || 200,
201198
recipe: 'default',
202199
})
203200
removeFile(index)
@@ -217,9 +214,6 @@ export function AddDocumentsModal({
217214

218215
try {
219216
await uploadFiles(files, knowledgeBaseId, {
220-
chunkSize: chunkingConfig?.maxSize || 1024,
221-
minCharactersPerChunk: chunkingConfig?.minSize || 1,
222-
chunkOverlap: chunkingConfig?.overlap || 200,
223217
recipe: 'default',
224218
})
225219
logger.info(`Successfully uploaded ${files.length} files`)

apps/sim/app/workspace/[workspaceId]/knowledge/hooks/use-knowledge-upload.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,10 +1011,14 @@ export function useKnowledgeUpload(options: UseKnowledgeUploadOptions = {}) {
10111011
...file,
10121012
})),
10131013
processingOptions: {
1014-
chunkSize: processingOptions.chunkSize || 1024,
1015-
minCharactersPerChunk: processingOptions.minCharactersPerChunk || 1,
1016-
chunkOverlap: processingOptions.chunkOverlap || 200,
1017-
recipe: processingOptions.recipe || 'default',
1014+
...(processingOptions.chunkSize != null && { chunkSize: processingOptions.chunkSize }),
1015+
...(processingOptions.minCharactersPerChunk != null && {
1016+
minCharactersPerChunk: processingOptions.minCharactersPerChunk,
1017+
}),
1018+
...(processingOptions.chunkOverlap != null && {
1019+
chunkOverlap: processingOptions.chunkOverlap,
1020+
}),
1021+
recipe: processingOptions.recipe ?? 'default',
10181022
lang: 'en',
10191023
},
10201024
bulk: true,

apps/sim/lib/knowledge/documents/service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -464,9 +464,9 @@ export async function processDocumentAsync(
464464
docData.fileUrl,
465465
docData.filename,
466466
docData.mimeType,
467-
processingOptions.chunkSize ?? kbConfig.maxSize,
468-
processingOptions.chunkOverlap ?? kbConfig.overlap,
469-
processingOptions.minCharactersPerChunk ?? kbConfig.minSize,
467+
kbConfig.maxSize,
468+
kbConfig.overlap,
469+
kbConfig.minSize,
470470
kb[0].userId,
471471
kb[0].workspaceId
472472
)

0 commit comments

Comments
 (0)