@@ -40,6 +40,15 @@ const rows = Number(process.env.KNOWLEDGE_SCALE_DOCUMENTS ?? 250_000)
4040const SEED_BATCH_SIZE = 2_000
4141const PAGE_SIZE = 500
4242const DIMENSIONS = 1536
43+ /**
44+ * `embedding` carries no ANN index in the schema — production serves approximate
45+ * retrieval from the `embedding_search` projection, which this fixture does not
46+ * populate. The benchmark still measures ANN behaviour over the dense corpus it
47+ * seeds directly, so it owns this index rather than borrowing a schema one, and
48+ * builds it after the load instead of paying index maintenance on every insert.
49+ */
50+ const BENCHMARK_VECTOR_INDEX = 'embedding_scale_benchmark_hnsw_idx'
51+ const BENCHMARK_VECTOR_INDEX_DEFINITION = `CREATE INDEX IF NOT EXISTS ${ BENCHMARK_VECTOR_INDEX } ON public.embedding USING hnsw (embedding vector_cosine_ops) WITH (m='16', ef_construction='64')`
4352const logger = createLogger ( 'KnowledgeScaleIntegration' )
4453if ( reuseReportFile && statSync ( reuseReportFile ) . size > 16 * 1024 * 1024 )
4554 throw new Error ( 'Retained scale report must be at most 16 MiB' )
@@ -386,7 +395,6 @@ describe.skipIf(!enabled)('knowledge scale: isolated real PostgreSQL, no provide
386395 it . skipIf ( metadataOnly ) (
387396 'stores a bounded dense corpus and measures ACL/tag-filtered vector and hybrid retrieval' ,
388397 async ( ) => {
389- let vectorIndexDefinition : string | undefined
390398 if ( bulkSeed ) {
391399 const other = await db
392400 . select ( { id : embedding . id } )
@@ -397,13 +405,6 @@ describe.skipIf(!enabled)('knowledge scale: isolated real PostgreSQL, no provide
397405 throw new Error (
398406 'Bulk scale setup requires a database containing only its own fixture chunks'
399407 )
400- const [ index ] = await db . execute (
401- sql `SELECT indexdef FROM pg_indexes WHERE schemaname = 'public' AND indexname = 'embedding_vector_hnsw_idx'`
402- )
403- if ( typeof index ?. indexdef !== 'string' )
404- throw new Error ( 'Canonical 1536-dimensional HNSW index is missing' )
405- vectorIndexDefinition = index . indexdef
406- await db . execute ( sql `DROP INDEX embedding_vector_hnsw_idx` )
407408 }
408409 if ( ! reuseReportFile )
409410 await measure ( 'seed.vectors' , async ( ) => {
@@ -420,20 +421,17 @@ describe.skipIf(!enabled)('knowledge scale: isolated real PostgreSQL, no provide
420421 }
421422 }
422423 } )
423- if ( vectorIndexDefinition ) {
424- const definition = vectorIndexDefinition
425- await measure ( 'seed.hnswBuild' , ( ) =>
426- db . transaction ( async ( tx ) => {
427- await tx . execute ( sql `SET LOCAL maintenance_work_mem = '2GB'` )
428- await tx . execute ( sql `SET LOCAL max_parallel_maintenance_workers = 2` )
429- await tx . execute ( sql . raw ( definition ) )
430- } )
431- )
432- const [ restored ] = await db . execute (
433- sql `SELECT indexdef FROM pg_indexes WHERE schemaname = 'public' AND indexname = 'embedding_vector_hnsw_idx'`
434- )
435- expect ( restored . indexdef ) . toBe ( vectorIndexDefinition )
436- }
424+ await measure ( 'seed.hnswBuild' , ( ) =>
425+ db . transaction ( async ( tx ) => {
426+ await tx . execute ( sql `SET LOCAL maintenance_work_mem = '2GB'` )
427+ await tx . execute ( sql `SET LOCAL max_parallel_maintenance_workers = 2` )
428+ await tx . execute ( sql . raw ( BENCHMARK_VECTOR_INDEX_DEFINITION ) )
429+ } )
430+ )
431+ const [ built ] = await db . execute (
432+ sql `SELECT indexdef FROM pg_indexes WHERE schemaname = 'public' AND indexname = ${ BENCHMARK_VECTOR_INDEX } `
433+ )
434+ expect ( built ?. indexdef ) . toEqual ( expect . stringContaining ( 'USING hnsw' ) )
437435 await db . execute ( sql `ANALYZE embedding` )
438436 await db . execute ( sql `ANALYZE document` )
439437 const [ count ] = await db . execute (
0 commit comments