@@ -113,25 +113,46 @@ export class RagAiSearchNode extends ExecutableNode {
113113 // Create multi-tenant folder filter
114114 const folderPrefix = `${ organizationId } /${ datasetId } /` ;
115115
116- // Prepare AutoRAG search parameters
117- const searchParams = {
116+ // Prepare AutoRAG search parameters - only include defined values
117+ const searchParams : any = {
118118 query : query . trim ( ) ,
119- model : model || "@cf/meta/llama-3.3-70b-instruct-sd" ,
120- rewrite_query : Boolean ( rewriteQuery ) ,
121- max_num_results : Math . min ( Math . max ( Number ( maxResults ) || 10 , 1 ) , 50 ) ,
122- ranking_options : {
123- score_threshold : Math . min (
124- Math . max ( Number ( scoreThreshold ) || 0.3 , 0 ) ,
125- 1
126- ) ,
127- } ,
128- stream : false , // Keep simple for now
129- filters : {
119+ } ;
120+
121+ // Only set model if provided
122+ if ( model && typeof model === "string" ) {
123+ searchParams . model = model ;
124+ }
125+
126+ // Only set rewrite_query if explicitly provided
127+ if ( rewriteQuery !== undefined ) {
128+ searchParams . rewrite_query = Boolean ( rewriteQuery ) ;
129+ }
130+
131+ // Only set max_num_results if provided and valid
132+ if ( maxResults !== undefined && ! isNaN ( Number ( maxResults ) ) ) {
133+ const numResults = Math . min ( Math . max ( Number ( maxResults ) , 1 ) , 50 ) ;
134+ searchParams . max_num_results = numResults ;
135+ }
136+
137+ // Only set ranking_options if scoreThreshold is provided and valid
138+ if ( scoreThreshold !== undefined && ! isNaN ( Number ( scoreThreshold ) ) ) {
139+ const threshold = Math . min ( Math . max ( Number ( scoreThreshold ) , 0 ) , 1 ) ;
140+ searchParams . ranking_options = {
141+ score_threshold : threshold ,
142+ } ;
143+ }
144+
145+ // Always set stream to false for simplicity
146+ searchParams . stream = false ;
147+
148+ // Only set filters if we have a valid folder prefix
149+ if ( folderPrefix ) {
150+ searchParams . filters = {
130151 type : "eq" as const ,
131152 key : "folder" ,
132153 value : folderPrefix ,
133- } ,
134- } ;
154+ } ;
155+ }
135156
136157 // Execute AutoRAG search
137158 const autoragInstance = context . env . AI . autorag (
0 commit comments