@@ -13,8 +13,8 @@ import {
1313 KNOWN_EMBEDDING_TABLES ,
1414} from "~/utils/supabase/dbUtils" ;
1515import {
16- ApiInputEmbeddingItem ,
17- ApiOutputEmbeddingRecord ,
16+ type ContentEmbeddingVecTablesInsert ,
17+ type ContentEmbeddingVecTables ,
1818 embeddingInputProcessing ,
1919 embeddingOutputProcessing ,
2020} from "~/utils/supabase/validators" ;
@@ -23,19 +23,19 @@ const DEFAULT_MODEL = "openai_text_embedding_3_small_1536";
2323
2424const batchInsertEmbeddingsProcess = async (
2525 supabase : Awaited < ReturnType < typeof createClient > > ,
26- embeddingItems : ApiInputEmbeddingItem [ ] ,
27- ) : Promise < PostgrestResponse < ApiOutputEmbeddingRecord > > => {
26+ embeddingItems : ContentEmbeddingVecTablesInsert [ ] ,
27+ ) : Promise < PostgrestResponse < ContentEmbeddingVecTables > > => {
2828 // groupBy is node21 only, we are using 20. Group by model, by hand.
2929 // Note: This means that later index values may be totally wrong.
3030 // Note2: The key is a ModelName, but I cannot use an enum as a key.
31- const byModel : { [ key : string ] : ApiInputEmbeddingItem [ ] } = { } ;
31+ const byModel : { [ key : string ] : ContentEmbeddingVecTablesInsert [ ] } = { } ;
3232 try {
3333 embeddingItems . reduce ( ( acc , item ) => {
3434 const model = item ?. model || DEFAULT_MODEL ;
3535 if ( acc [ model ] === undefined ) {
3636 acc [ model ] = [ ] ;
3737 }
38- acc [ model ] ! . push ( item ) ;
38+ acc [ model ] . push ( item ) ;
3939 return acc ;
4040 } , byModel ) ;
4141 } catch ( error ) {
@@ -45,7 +45,7 @@ const batchInsertEmbeddingsProcess = async (
4545 throw error ;
4646 }
4747
48- const globalResults : ApiOutputEmbeddingRecord [ ] = [ ] ;
48+ const globalResults : ContentEmbeddingVecTables [ ] = [ ] ;
4949 const partialErrors : string [ ] = [ ] ;
5050 let created = false ,
5151 count = 0 ,
@@ -55,15 +55,11 @@ const batchInsertEmbeddingsProcess = async (
5555 if ( embeddingItemsSet === undefined ) continue ;
5656 const tableData = KNOWN_EMBEDDING_TABLES [ modelName ] ;
5757 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- > ( {
58+ const { tableName } = tableData ;
59+ const results = await processAndInsertBatch ( {
6460 supabase,
6561 items : embeddingItemsSet ,
66- tableName : tableData . tableName ,
62+ tableName,
6763 inputProcessor : embeddingInputProcessing ,
6864 outputProcessor : embeddingOutputProcessing ,
6965 } ) ;
@@ -81,6 +77,7 @@ const batchInsertEmbeddingsProcess = async (
8177 return {
8278 data : globalResults ,
8379 error : null ,
80+ success : true ,
8481 status : has_400 ? 400 : 500 ,
8582 count,
8683 statusText : partialErrors . join ( "; " ) ,
@@ -89,6 +86,7 @@ const batchInsertEmbeddingsProcess = async (
8986 return {
9087 data : globalResults ,
9188 error : null ,
89+ success : true ,
9290 status : created ? 201 : 200 ,
9391 count,
9492 statusText : created ? "created" : "success" ,
@@ -106,7 +104,7 @@ export const POST = async (request: NextRequest): Promise<NextResponse> => {
106104 const supabase = await createClient ( ) ;
107105
108106 try {
109- const body : ApiInputEmbeddingItem [ ] = await request . json ( ) ;
107+ const body = ( await request . json ( ) ) as ContentEmbeddingVecTablesInsert [ ] ;
110108 if ( ! Array . isArray ( body ) ) {
111109 return createApiResponse (
112110 request ,
0 commit comments