Skip to content

Commit 14f81b1

Browse files
fern-supportKapil GowruKapil Gowru
authored
Scribe issue turbopuffer (#217)
Co-authored-by: Kapil Gowru <[email protected]> Co-authored-by: Kapil Gowru <[email protected]>
1 parent 41f6bc1 commit 14f81b1

File tree

1 file changed

+57
-2
lines changed

1 file changed

+57
-2
lines changed

β€Ž.github/scripts/fern-scribe.jsβ€Ž

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,14 +305,17 @@ class FernScribe {
305305

306306
async queryTurbopuffer(query, opts = {}) {
307307
if (!query || query.trimStart().length === 0) {
308+
console.log('πŸ”§ Empty query provided to Turbopuffer');
308309
return [];
309310
}
310311

311312
try {
313+
console.log('πŸ”§ Querying Turbopuffer with options:', JSON.stringify(opts, null, 2));
314+
312315
// Create embedding for the query
313316
const embeddingResponse = await this.createEmbedding(query);
314317
if (!embeddingResponse) {
315-
console.error('Failed to create embedding for query');
318+
console.error('πŸ”§ Failed to create embedding for query');
316319
return [];
317320
}
318321

@@ -324,6 +327,11 @@ class FernScribe {
324327
...(opts.urlsToIgnore && { urls_to_ignore: opts.urlsToIgnore })
325328
};
326329

330+
console.log('πŸ”§ Turbopuffer request body (without embedding):', {
331+
...requestBody,
332+
query_embedding: `[${embeddingResponse.length} dimensions]`
333+
});
334+
327335
const response = await fetch(this.turbopufferEndpoint, {
328336
method: 'POST',
329337
headers: {
@@ -334,17 +342,54 @@ class FernScribe {
334342
});
335343

336344
if (!response.ok) {
345+
const errorText = await response.text();
346+
console.error('πŸ”§ Turbopuffer API error details:', errorText);
337347
throw new Error(`Turbopuffer API error: ${response.status}`);
338348
}
339349

340350
const data = await response.json();
351+
console.log('πŸ”§ Turbopuffer response structure:', Object.keys(data));
352+
console.log('πŸ”§ Turbopuffer results count:', data.results?.length || 0);
353+
341354
return data.results || [];
342355
} catch (error) {
343-
console.error('Turbopuffer query failed:', error);
356+
console.error('πŸ”§ Turbopuffer query failed:', error);
344357
return [];
345358
}
346359
}
347360

361+
async createEmbedding(text) {
362+
try {
363+
console.log('πŸ”§ Creating embedding for text of length:', text.length);
364+
365+
// Using OpenAI's embedding model
366+
const response = await fetch('https://api.openai.com/v1/embeddings', {
367+
method: 'POST',
368+
headers: {
369+
'Authorization': `Bearer ${process.env.OPENAI_API_KEY}`,
370+
'Content-Type': 'application/json'
371+
},
372+
body: JSON.stringify({
373+
model: 'text-embedding-3-small',
374+
input: text
375+
})
376+
});
377+
378+
if (!response.ok) {
379+
const errorText = await response.text();
380+
console.error('πŸ”§ Embedding API error details:', errorText);
381+
throw new Error(`Embedding API error: ${response.status}`);
382+
}
383+
384+
const data = await response.json();
385+
console.log('πŸ”§ Embedding created successfully, dimensions:', data.data[0]?.embedding?.length);
386+
return data.data[0]?.embedding;
387+
} catch (error) {
388+
console.error('πŸ”§ Embedding creation failed:', error);
389+
return null;
390+
}
391+
}
392+
348393
async createEmbedding(text) {
349394
try {
350395
// Using OpenAI's embedding model
@@ -603,6 +648,11 @@ ${context.additionalContext ? `**Additional Context:** ${context.additionalConte
603648
context.additionalContext ? `\n\nAdditional Context:\n${context.additionalContext}` : ''
604649
].filter(Boolean).join('\n');
605650

651+
// Debug logging
652+
console.log('πŸ” Enhanced query length:', enhancedQuery.length);
653+
console.log('πŸ” Enhanced query preview:', enhancedQuery.substring(0, 500) + '...');
654+
console.log('πŸ” Namespace:', process.env.TURBOPUFFER_NAMESPACE || 'default');
655+
606656
// Query TurboBuffer for relevant files
607657
console.log('πŸ” Querying TurboBuffer for relevant files...');
608658
const searchResultURLs = new Set();
@@ -613,6 +663,11 @@ ${context.additionalContext ? `**Additional Context:** ${context.additionalConte
613663
topK: 3
614664
});
615665

666+
console.log('πŸ” Turbopuffer results count:', turbopufferResults.length);
667+
if (turbopufferResults.length > 0) {
668+
console.log('πŸ” First result preview:', JSON.stringify(turbopufferResults[0], null, 2));
669+
}
670+
616671
// Deduplicate results by URL (following the original logic)
617672
for (const result of turbopufferResults) {
618673
const url = result.attributes?.url ||

0 commit comments

Comments
Β (0)