@@ -305,17 +305,27 @@ class FernScribe {
305305
306306 async queryTurbopuffer ( query , opts = { } ) {
307307 if ( ! query || query . trimStart ( ) . length === 0 ) {
308+ < << << << HEAD
308309 console . log ( 'π§ Empty query provided to Turbopuffer' ) ;
310+ = === ===
311+ >>> >>> > origin / main
309312 return [ ] ;
310313 }
311314
312315 try {
316+ < << << << HEAD
313317 console . log ( 'π§ Querying Turbopuffer with options:' , JSON . stringify ( opts , null , 2 ) ) ;
314318
315319 // Create embedding for the query
316320 const embeddingResponse = await this . createEmbedding ( query ) ;
317321 if ( ! embeddingResponse ) {
318322 console . error ( 'π§ Failed to create embedding for query' ) ;
323+ = === ===
324+ // Create embedding for the query
325+ const embeddingResponse = await this . createEmbedding ( query ) ;
326+ if ( ! embeddingResponse ) {
327+ console . error ( 'Failed to create embedding for query' ) ;
328+ > >>> >>> origin / main
319329 return [ ] ;
320330 }
321331
@@ -327,18 +337,22 @@ class FernScribe {
327337 ...( opts . urlsToIgnore && { urls_to_ignore : opts . urlsToIgnore } )
328338 } ;
329339
340+ < << << << HEAD
330341 console . log ( 'π§ Turbopuffer request body (without embedding):' , {
331342 ...requestBody ,
332343 query_embedding : `[${ embeddingResponse . length } dimensions]`
333344 } ) ;
334345
346+ = === ===
347+ >>> >>> > origin / main
335348 const response = await fetch ( this . turbopufferEndpoint , {
336349 method : 'POST' ,
337350 headers : {
338351 'Authorization' : `Bearer ${ this . turbopufferApiKey } ` ,
339352 'Content-Type' : 'application/json'
340353 } ,
341354 body : JSON . stringify ( requestBody )
355+ << < << << HEAD
342356 } ) ;
343357
344358 if ( ! response . ok ) {
@@ -379,14 +393,52 @@ class FernScribe {
379393 const errorText = await response . text ( ) ;
380394 console . error ( 'π§ Embedding API error details:' , errorText ) ;
381395 throw new Error ( `Embedding API error: ${ response . status } ` ) ;
396+ = === ===
397+ } ) ;
398+
399+ if ( ! response . ok ) {
400+ throw new Error ( `Turbopuffer API error: ${ response . status } ` ) ;
401+ > >>> >>> origin / main
382402 }
383403
384404 const data = await response . json ( ) ;
385405 console . log ( 'π§ Embedding created successfully, dimensions:' , data . data [ 0 ] ?. embedding ?. length ) ;
386406 return data . data [ 0 ] ?. embedding ;
387407 } catch ( error ) {
408+ < << << << HEAD
388409 console . error ( 'π§ Embedding creation failed:' , error ) ;
389410 return null ;
411+ = === ===
412+ console . error ( 'Turbopuffer query failed:' , error ) ;
413+ return [ ] ;
414+ > >>> >>> origin / main
415+ }
416+ }
417+
418+ async createEmbedding ( text ) {
419+ try {
420+ // Using OpenAI's embedding model
421+ const response = await fetch ( 'https://api.openai.com/v1/embeddings' , {
422+ method : 'POST' ,
423+ headers : {
424+ 'Authorization' : `Bearer ${ process . env . OPENAI_API_KEY } ` ,
425+ 'Content-Type' : 'application/json'
426+ } ,
427+ body : JSON . stringify ( {
428+ model : 'text-embedding-3-small' ,
429+ input : text
430+ } )
431+ } ) ;
432+
433+ if ( ! response . ok ) {
434+ throw new Error ( `Embedding API error: ${ response . status } ` ) ;
435+ }
436+
437+ const data = await response . json ( ) ;
438+ return data . data [ 0 ] ?. embedding ;
439+ } catch ( error ) {
440+ console . error ( 'Embedding creation failed:' , error ) ;
441+ return null ;
390442 }
391443 }
392444
@@ -621,11 +673,14 @@ ${context.additionalContext ? `**Additional Context:** ${context.additionalConte
621673 context . additionalContext ? `\n\nAdditional Context:\n${ context . additionalContext } ` : ''
622674 ] . filter ( Boolean ) . join ( '\n' ) ;
623675
676+ < << << << HEAD
624677 // Debug logging
625678 console . log ( 'π Enhanced query length:' , enhancedQuery . length ) ;
626679 console . log ( 'π Enhanced query preview:' , enhancedQuery . substring ( 0 , 500 ) + '...' ) ;
627680 console . log ( 'π Namespace:' , process . env . TURBOPUFFER_NAMESPACE || 'default' ) ;
628681
682+ = === ===
683+ >>> >>> > origin / main
629684 // Query TurboBuffer for relevant files
630685 console . log ( 'π Querying TurboBuffer for relevant files...' ) ;
631686 const searchResultURLs = new Set ( ) ;
@@ -636,11 +691,14 @@ ${context.additionalContext ? `**Additional Context:** ${context.additionalConte
636691 topK : 3
637692 } ) ;
638693
694+ < << << << HEAD
639695 console . log ( 'π Turbopuffer results count:' , turbopufferResults . length ) ;
640696 if ( turbopufferResults . length > 0 ) {
641697 console . log ( 'π First result preview:' , JSON . stringify ( turbopufferResults [ 0 ] , null , 2 ) ) ;
642698 }
643699
700+ = === ===
701+ >>> >>> > origin / main
644702 // Deduplicate results by URL (following the original logic)
645703 for ( const result of turbopufferResults ) {
646704 const url = result . attributes ?. url ||
0 commit comments