@@ -140,6 +140,15 @@ class Database {
140140 this . inner . upsertEmbedding ( contentHash , embedding , chunkText , model ) ;
141141 }
142142
143+ upsertEmbeddingsBatch ( items : Array < {
144+ contentHash : string ;
145+ embedding : Buffer ;
146+ chunkText : string ;
147+ model : string ;
148+ } > ) : void {
149+ this . inner . upsertEmbeddingsBatch ( items ) ;
150+ }
151+
143152 upsertChunk ( data : {
144153 chunkId : string ;
145154 contentHash : string ;
@@ -153,10 +162,27 @@ class Database {
153162 this . inner . upsertChunk ( data ) ;
154163 }
155164
165+ upsertChunksBatch ( chunks : Array < {
166+ chunkId : string ;
167+ contentHash : string ;
168+ filePath : string ;
169+ startLine : number ;
170+ endLine : number ;
171+ nodeType ?: string ;
172+ name ?: string ;
173+ language : string ;
174+ } > ) : void {
175+ this . inner . upsertChunksBatch ( chunks ) ;
176+ }
177+
156178 addChunksToBranch ( branch : string , chunkIds : string [ ] ) : void {
157179 this . inner . addChunksToBranch ( branch , chunkIds ) ;
158180 }
159181
182+ addChunksToBranchBatch ( branch : string , chunkIds : string [ ] ) : void {
183+ this . inner . addChunksToBranchBatch ( branch , chunkIds ) ;
184+ }
185+
160186 getBranchChunkIds ( branch : string ) : string [ ] {
161187 return this . inner . getBranchChunkIds ( branch ) ;
162188 }
@@ -507,18 +533,19 @@ async function runBenchmarks(): Promise<void> {
507533 // ============================================
508534 console . log ( "\n=== Database Performance (SQLite) ===" ) ;
509535
510- const dbPath = path . join ( tempDir , "benchmark.db" ) ;
511- const db = new Database ( dbPath ) ;
512-
513536 const chunkCounts = [ 100 , 1000 , 5000 , 10000 ] ;
514537
515538 for ( const chunkCount of chunkCounts ) {
539+ const dbPath = path . join ( tempDir , `benchmark-${ chunkCount } .db` ) ;
540+ const db = new Database ( dbPath ) ;
541+ const dbBatch = new Database ( path . join ( tempDir , `benchmark-batch-${ chunkCount } .db` ) ) ;
542+
516543 const embedding = Buffer . from (
517544 new Float32Array ( generateRandomEmbedding ( dimensions ) ) . buffer
518545 ) ;
519546
520547 benchmark (
521- `Insert ${ chunkCount } embeddings` ,
548+ `Insert ${ chunkCount } embeddings (sequential) ` ,
522549 ( ) => {
523550 for ( let i = 0 ; i < chunkCount ; i ++ ) {
524551 db . upsertEmbedding ( `hash-${ chunkCount } -${ i } ` , embedding , `text-${ i } ` , "test-model" ) ;
@@ -528,8 +555,24 @@ async function runBenchmarks(): Promise<void> {
528555 { embeddings : chunkCount }
529556 ) ;
530557
558+ const embeddingBatchItems = Array . from ( { length : chunkCount } , ( _ , i ) => ( {
559+ contentHash : `hash-batch-${ chunkCount } -${ i } ` ,
560+ embedding,
561+ chunkText : `text-${ i } ` ,
562+ model : "test-model" ,
563+ } ) ) ;
564+
531565 benchmark (
532- `Insert ${ chunkCount } chunks` ,
566+ `Insert ${ chunkCount } embeddings (batch)` ,
567+ ( ) => {
568+ dbBatch . upsertEmbeddingsBatch ( embeddingBatchItems ) ;
569+ } ,
570+ 1 ,
571+ { embeddings : chunkCount }
572+ ) ;
573+
574+ benchmark (
575+ `Insert ${ chunkCount } chunks (sequential)` ,
533576 ( ) => {
534577 for ( let i = 0 ; i < chunkCount ; i ++ ) {
535578 db . upsertChunk ( {
@@ -548,19 +591,52 @@ async function runBenchmarks(): Promise<void> {
548591 { chunks : chunkCount }
549592 ) ;
550593
594+ const chunkBatchItems = Array . from ( { length : chunkCount } , ( _ , i ) => ( {
595+ chunkId : `chunk-batch-${ chunkCount } -${ i } ` ,
596+ contentHash : `hash-batch-${ chunkCount } -${ i } ` ,
597+ filePath : `/file${ i % 100 } .ts` ,
598+ startLine : i * 10 ,
599+ endLine : i * 10 + 10 ,
600+ nodeType : "function" ,
601+ name : `func${ i } ` ,
602+ language : "typescript" ,
603+ } ) ) ;
604+
605+ benchmark (
606+ `Insert ${ chunkCount } chunks (batch)` ,
607+ ( ) => {
608+ dbBatch . upsertChunksBatch ( chunkBatchItems ) ;
609+ } ,
610+ 1 ,
611+ { chunks : chunkCount }
612+ ) ;
613+
551614 const chunkIds = Array . from (
552615 { length : chunkCount } ,
553616 ( _ , i ) => `chunk-${ chunkCount } -${ i } `
554617 ) ;
555618 benchmark (
556- `Add ${ chunkCount } chunks to branch` ,
619+ `Add ${ chunkCount } chunks to branch (sequential) ` ,
557620 ( ) => {
558621 db . addChunksToBranch ( `branch-${ chunkCount } ` , chunkIds ) ;
559622 } ,
560623 1 ,
561624 { chunks : chunkCount }
562625 ) ;
563626
627+ const chunkIdsBatch = Array . from (
628+ { length : chunkCount } ,
629+ ( _ , i ) => `chunk-batch-${ chunkCount } -${ i } `
630+ ) ;
631+ benchmark (
632+ `Add ${ chunkCount } chunks to branch (batch)` ,
633+ ( ) => {
634+ dbBatch . addChunksToBranchBatch ( `branch-batch-${ chunkCount } ` , chunkIdsBatch ) ;
635+ } ,
636+ 1 ,
637+ { chunks : chunkCount }
638+ ) ;
639+
564640 benchmark (
565641 `Get branch chunk IDs (${ chunkCount } )` ,
566642 ( ) => {
0 commit comments