@@ -23,47 +23,49 @@ describe("Server Mode - Batch Operations", () => {
2323 } ) ;
2424
2525 test ( "add large batch of items" , async ( ) => {
26+ // User-side batching: caller invokes add() multiple times with small batches; SDK does not split.
2627 const collectionName = generateCollectionName ( "test_large_batch" ) ;
2728 const collection = await client . createCollection ( {
2829 name : collectionName ,
2930 configuration : { dimension : 3 , distance : "l2" } ,
3031 embeddingFunction : null ,
3132 } ) ;
3233
33- const batchSize = 100 ;
34- const ids = Array . from ( { length : batchSize } , ( _ , i ) => `id_${ i } ` ) ;
35- const embeddings = Array . from ( { length : batchSize } , ( _ , i ) => [
34+ const totalCount = 100 ;
35+ const perBatch = 30 ;
36+ const ids = Array . from ( { length : totalCount } , ( _ , i ) => `id_${ i } ` ) ;
37+ const embeddings = Array . from ( { length : totalCount } , ( _ , i ) => [
3638 i * 0.1 ,
3739 i * 0.2 ,
3840 i * 0.3 ,
3941 ] ) ;
4042 const documents = Array . from (
41- { length : batchSize } ,
43+ { length : totalCount } ,
4244 ( _ , i ) => `Document ${ i } `
4345 ) ;
44- const metadatas = Array . from ( { length : batchSize } , ( _ , i ) => ( {
46+ const metadatas = Array . from ( { length : totalCount } , ( _ , i ) => ( {
4547 index : i ,
4648 batch : "large" ,
4749 } ) ) ;
4850
49- await collection . add ( {
50- ids,
51- embeddings,
52- documents,
53- metadatas,
54- } ) ;
51+ for ( let offset = 0 ; offset < totalCount ; offset += perBatch ) {
52+ const end = Math . min ( offset + perBatch , totalCount ) ;
53+ await collection . add ( {
54+ ids : ids . slice ( offset , end ) ,
55+ embeddings : embeddings . slice ( offset , end ) ,
56+ documents : documents . slice ( offset , end ) ,
57+ metadatas : metadatas . slice ( offset , end ) ,
58+ } ) ;
59+ }
5560
56- // Verify all items were added
5761 const results = await collection . get ( { ids : ids . slice ( 0 , 10 ) } ) ;
5862 expect ( results . ids . length ) . toBe ( 10 ) ;
5963
60- // Verify count
6164 const count = await client . countCollection ( ) ;
62- // Should have at least our batch
6365 expect ( count ) . toBeGreaterThanOrEqual ( 1 ) ;
6466
6567 await client . deleteCollection ( collectionName ) ;
66- } , 60000 ) ;
68+ } ) ;
6769
6870 test ( "get large batch of items" , async ( ) => {
6971 const collectionName = generateCollectionName ( "test_large_get" ) ;
0 commit comments