File tree Expand file tree Collapse file tree
[id]/documents/[documentId]/chunks Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -245,7 +245,7 @@ export const POST = withRouteHandler(
245245 completion : 0 ,
246246 total : newChunk . tokenCount ,
247247 } ,
248- model : chunkEmbeddingModel ,
248+ model : accessCheck . knowledgeBase . embeddingModel ,
249249 pricing : cost . pricing ,
250250 } ,
251251 }
Original file line number Diff line number Diff line change @@ -264,10 +264,6 @@ export const POST = withRouteHandler(async (request: NextRequest) => {
264264 }
265265 const queryEmbeddingModel = embeddingModels [ 0 ]
266266
267- const queryEmbeddingPromise = hasQuery
268- ? generateSearchEmbedding ( validatedData . query ! , queryEmbeddingModel , workspaceId )
269- : Promise . resolve ( null )
270-
271267 // Check if any requested knowledge bases were not accessible
272268 const inaccessibleKbIds = knowledgeBaseIds . filter ( ( id ) => ! accessibleKbIds . includes ( id ) )
273269
@@ -278,6 +274,10 @@ export const POST = withRouteHandler(async (request: NextRequest) => {
278274 )
279275 }
280276
277+ const queryEmbeddingPromise = hasQuery
278+ ? generateSearchEmbedding ( validatedData . query ! , queryEmbeddingModel , workspaceId )
279+ : Promise . resolve ( null )
280+
281281 if ( workflowId ) {
282282 const authorization = await authorizeWorkflowByWorkspacePermission ( {
283283 workflowId,
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ import {
1414 handleVectorOnlySearch ,
1515 type SearchResult ,
1616} from '@/app/api/knowledge/search/utils'
17- import { checkKnowledgeBaseAccess } from '@/app/api/knowledge/utils'
17+ import { checkKnowledgeBaseAccess , type KnowledgeBaseAccessResult } from '@/app/api/knowledge/utils'
1818import {
1919 authenticateRequest ,
2020 handleError ,
@@ -84,13 +84,12 @@ export const POST = withRouteHandler(async (request: NextRequest) => {
8484 const accessChecks = await Promise . all (
8585 knowledgeBaseIds . map ( ( kbId ) => checkKnowledgeBaseAccess ( kbId , userId ) )
8686 )
87- const accessibleKbs = knowledgeBaseIds
88- . map ( ( _ , idx ) => accessChecks [ idx ] )
87+ const accessibleKbs = accessChecks
8988 . filter (
90- ( ac ) : ac is NonNullable < typeof ac > =>
91- Boolean ( ac ? .hasAccess ) && ac ? .knowledgeBase ? .workspaceId === workspaceId
89+ ( ac ) : ac is KnowledgeBaseAccessResult =>
90+ ac . hasAccess === true && ac . knowledgeBase . workspaceId === workspaceId
9291 )
93- . map ( ( ac ) => ac . knowledgeBase ! )
92+ . map ( ( ac ) => ac . knowledgeBase )
9493 const accessibleKbIds = accessibleKbs . map ( ( kb ) => kb . id )
9594
9695 if ( accessibleKbIds . length === 0 ) {
You can’t perform that action at this time.
0 commit comments