From fd308c6bad93469774480c9643385960a9d0b643 Mon Sep 17 00:00:00 2001 From: Charis <26616127+charislam@users.noreply.github.com> Date: Wed, 17 Sep 2025 11:20:43 -0400 Subject: [PATCH] fix: search and sync scripts (#38756) * fix: search script * fix: sync script --- .../globalSearch/globalSearchModel.ts | 2 +- .../scripts/search/generate-embeddings.ts | 34 +++++++++---------- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/apps/docs/resources/globalSearch/globalSearchModel.ts b/apps/docs/resources/globalSearch/globalSearchModel.ts index 8b46f5d8707..731d0271e2c 100644 --- a/apps/docs/resources/globalSearch/globalSearchModel.ts +++ b/apps/docs/resources/globalSearch/globalSearchModel.ts @@ -4,7 +4,7 @@ import { Result } from '~/features/helpers.fn' import { openAI } from '~/lib/openAi' import { supabase, type DatabaseCorrected } from '~/lib/supabase' -import { isFeatureEnabled } from 'common/enabled-features' +import { isFeatureEnabled } from '../../../../packages/common/enabled-features' import { GuideModel } from '../guide/guideModel' import { DB_METADATA_TAG_PLATFORM_CLI, diff --git a/apps/docs/scripts/search/generate-embeddings.ts b/apps/docs/scripts/search/generate-embeddings.ts index a5abac64019..81263f113a5 100644 --- a/apps/docs/scripts/search/generate-embeddings.ts +++ b/apps/docs/scripts/search/generate-embeddings.ts @@ -178,12 +178,14 @@ async function prepareSections( return } - if (existingPage && debug) { - console.log( - !shouldRefresh - ? `[${path}] Docs have changed, removing old page sections and their embeddings` - : `[${path}] Refresh flag set, removing old page sections and their embeddings` - ) + if (existingPage) { + if (debug) { + console.log( + !shouldRefresh + ? `[${path}] Docs have changed, removing old page sections and their embeddings` + : `[${path}] Refresh flag set, removing old page sections and their embeddings` + ) + } const { error: deletePageSectionError } = await supabaseClient .from(pageSectionTable) @@ -254,18 +256,6 @@ async function processAndInsertEmbeddings( allSections: PageSectionForEmbedding[], pageInfoMap: Map ): Promise { - if (allSections.length === 0) { - return { - successfulPages: new Set(), - failedPages: new Set(), - totalSectionsProcessed: 0, - totalSectionsInserted: 0, - } - } - - console.log(`Processing ${allSections.length} sections with embeddings + insertion`) - - const embeddingBatches = createBatches(allSections, CONFIG.OPENAI_BATCH_SIZE) const result: ProcessingResult = { successfulPages: new Set(), failedPages: new Set(), @@ -273,6 +263,14 @@ async function processAndInsertEmbeddings( totalSectionsInserted: 0, } + if (allSections.length === 0) { + return result + } + + console.log(`Processing ${allSections.length} sections with embeddings + insertion`) + + const embeddingBatches = createBatches(allSections, CONFIG.OPENAI_BATCH_SIZE) + // Track sections inserted per page const pageSectionsInserted = new Map()