processAndInsertEmbeddings() — supabase Function Reference
Architecture documentation for the processAndInsertEmbeddings() function in generate-embeddings.ts from the supabase codebase.
Entity Profile
Dependency Diagram
graph TD e004e86e_d6b3_597d_5a6c_1a898d503de3["processAndInsertEmbeddings()"] b280bae5_b0f6_6775_91cb_d0697bd4d074["generateEmbeddings()"] b280bae5_b0f6_6775_91cb_d0697bd4d074 -->|calls| e004e86e_d6b3_597d_5a6c_1a898d503de3 94c6fd9e_4273_b489_8fb9_0054d6d1c1ce["createBatches()"] e004e86e_d6b3_597d_5a6c_1a898d503de3 -->|calls| 94c6fd9e_4273_b489_8fb9_0054d6d1c1ce b6da1e2f_3534_5430_6fdb_1a60bda504b3["processEmbeddingBatch()"] e004e86e_d6b3_597d_5a6c_1a898d503de3 -->|calls| b6da1e2f_3534_5430_6fdb_1a60bda504b3 6e840ab5_8116_4027_1a88_735f8e359283["insertSectionBatch()"] e004e86e_d6b3_597d_5a6c_1a898d503de3 -->|calls| 6e840ab5_8116_4027_1a88_735f8e359283 cf05d29e_2938_5b91_5b78_aa5880461ee4["updatePageInsertionCounts()"] e004e86e_d6b3_597d_5a6c_1a898d503de3 -->|calls| cf05d29e_2938_5b91_5b78_aa5880461ee4 80a62cf8_e386_06b3_845e_12f65555becb["delay()"] e004e86e_d6b3_597d_5a6c_1a898d503de3 -->|calls| 80a62cf8_e386_06b3_845e_12f65555becb 86b8c4fd_49a3_2d66_414d_91a988e26d4f["computePageResults()"] e004e86e_d6b3_597d_5a6c_1a898d503de3 -->|calls| 86b8c4fd_49a3_2d66_414d_91a988e26d4f style e004e86e_d6b3_597d_5a6c_1a898d503de3 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
apps/docs/scripts/search/generate-embeddings.ts lines 252–316
async function processAndInsertEmbeddings(
openai: OpenAI,
supabaseClient: SupabaseClient,
pageSectionTable: string,
allSections: PageSectionForEmbedding[],
pageInfoMap: Map<number, PageInfo>
): Promise<ProcessingResult> {
const result: ProcessingResult = {
successfulPages: new Set(),
failedPages: new Set(),
totalSectionsProcessed: 0,
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<number, number>()
for (let batchIndex = 0; batchIndex < embeddingBatches.length; batchIndex++) {
const batch = embeddingBatches[batchIndex]
try {
const batchResult = await processEmbeddingBatch(
openai,
batch,
batchIndex,
embeddingBatches.length
)
result.totalSectionsProcessed += batchResult.processedCount
if (batchResult.sectionsWithEmbeddings.length > 0) {
const insertedCount = await insertSectionBatch(
supabaseClient,
pageSectionTable,
batchResult.sectionsWithEmbeddings
)
result.totalSectionsInserted += insertedCount
updatePageInsertionCounts(pageSectionsInserted, batchResult.sectionsWithEmbeddings)
}
// Mark failed section pages
batchResult.failedSectionIndexes.forEach((i) => {
result.failedPages.add(batch[i].pageId)
})
} catch (error) {
console.error(`Batch ${batchIndex + 1} completely failed:`, error)
batch.forEach((section) => result.failedPages.add(section.pageId))
}
if (batchIndex < embeddingBatches.length - 1) {
await delay(CONFIG.OPENAI_BASE_DELAY_MS)
}
}
computePageResults(pageInfoMap, pageSectionsInserted, result)
return result
}
Domain
Subdomains
Calls
Called By
Source
Frequently Asked Questions
What does processAndInsertEmbeddings() do?
processAndInsertEmbeddings() is a function in the supabase codebase.
What does processAndInsertEmbeddings() call?
processAndInsertEmbeddings() calls 6 function(s): computePageResults, createBatches, delay, insertSectionBatch, processEmbeddingBatch, updatePageInsertionCounts.
What calls processAndInsertEmbeddings()?
processAndInsertEmbeddings() is called by 1 function(s): generateEmbeddings.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free