@@ -8,13 +8,11 @@ import {
88 handleRouteError ,
99 defaultOptionsHandler ,
1010} from "~/utils/supabase/apiUtils" ;
11+ import { processAndInsertBatch } from "~/utils/supabase/dbUtils" ;
1112import {
12- processAndInsertBatch ,
13+ type ContentEmbeddingVecTables ,
14+ type ContentEmbeddingVecTablesInsert ,
1315 KNOWN_EMBEDDING_TABLES ,
14- } from "~/utils/supabase/dbUtils" ;
15- import {
16- type ApiInputEmbeddingItem ,
17- type ApiOutputEmbeddingRecord ,
1816 embeddingInputProcessing ,
1917 embeddingOutputProcessing ,
2018} from "~/utils/supabase/validators" ;
@@ -23,12 +21,12 @@ const DEFAULT_MODEL = "openai_text_embedding_3_small_1536";
2321
2422const batchInsertEmbeddingsProcess = async (
2523 supabase : Awaited < ReturnType < typeof createClient > > ,
26- embeddingItems : ApiInputEmbeddingItem [ ] ,
27- ) : Promise < PostgrestResponse < ApiOutputEmbeddingRecord > > => {
24+ embeddingItems : ContentEmbeddingVecTablesInsert [ ] ,
25+ ) : Promise < PostgrestResponse < ContentEmbeddingVecTables > > => {
2826 // groupBy is node21 only, we are using 20. Group by model, by hand.
2927 // Note: This means that later index values may be totally wrong.
3028 // Note2: The key is a ModelName, but I cannot use an enum as a key.
31- const byModel : { [ key : string ] : ApiInputEmbeddingItem [ ] } = { } ;
29+ const byModel : { [ key : string ] : ContentEmbeddingVecTablesInsert [ ] } = { } ;
3230 try {
3331 embeddingItems . reduce ( ( acc , item ) => {
3432 const model = item ?. model || DEFAULT_MODEL ;
@@ -45,7 +43,7 @@ const batchInsertEmbeddingsProcess = async (
4543 throw error ;
4644 }
4745
48- const globalResults : ApiOutputEmbeddingRecord [ ] = [ ] ;
46+ const globalResults : ContentEmbeddingVecTables [ ] = [ ] ;
4947 const partialErrors : string [ ] = [ ] ;
5048 let created = false ,
5149 count = 0 ,
@@ -55,15 +53,11 @@ const batchInsertEmbeddingsProcess = async (
5553 if ( embeddingItemsSet === undefined ) continue ;
5654 const tableData = KNOWN_EMBEDDING_TABLES [ modelName ] ;
5755 if ( tableData === undefined ) continue ;
58- const results = await processAndInsertBatch <
59- // any ContentEmbedding table for type checking purposes only
60- "ContentEmbedding_openai_text_embedding_3_small_1536" ,
61- ApiInputEmbeddingItem ,
62- ApiOutputEmbeddingRecord
63- > ( {
56+ const { tableName } = tableData ;
57+ const results = await processAndInsertBatch ( {
6458 supabase,
6559 items : embeddingItemsSet ,
66- tableName : tableData . tableName ,
60+ tableName,
6761 inputProcessor : embeddingInputProcessing ,
6862 outputProcessor : embeddingOutputProcessing ,
6963 } ) ;
@@ -108,7 +102,7 @@ export const POST = async (request: NextRequest): Promise<NextResponse> => {
108102 const supabase = await createClient ( ) ;
109103
110104 try {
111- const body : ApiInputEmbeddingItem [ ] = await request . json ( ) ;
105+ const body = ( await request . json ( ) ) as ContentEmbeddingVecTablesInsert [ ] ;
112106 if ( ! Array . isArray ( body ) ) {
113107 return createApiResponse (
114108 request ,
0 commit comments