brainy/tests/setup-semantic.ts

34 lines
1.4 KiB
TypeScript
Raw Normal View History

/**
* Tier-2 (semantic) test setup REAL embedding model.
*
* Tier 1 (`tests/integration`, deterministic embedder) verifies every code path fast on
* any machine. Tier 2 (this) loads the REAL `all-MiniLM-L6-v2` model so semantic-relevance
* assertions (recall@k, cross-text nearest-neighbour ranking) are meaningful. It is the
* opt-in tier: slower, needs the model, run via `npm run test:semantic`.
*
* Critically: it does NOT set the deterministic-embedder flag embeddings are real.
*/
beforeAll(async () => {
console.log('🧠 Semantic (Tier 2): REAL embedding model — meaningful relevance/recall')
// Real local model; never the deterministic stub.
process.env.BRAINY_INTEGRATION_TEST = 'true'
process.env.BRAINY_MODELS_PATH = './models'
process.env.BRAINY_ALLOW_REMOTE_MODELS = 'false'
// ONNX runtime memory hygiene for repeated model loads.
process.env.ORT_DISABLE_MEMORY_ARENA = '1'
process.env.ORT_DISABLE_MEMORY_PATTERN = '1'
// Explicitly ensure the deterministic embedder is OFF for this tier.
delete process.env.BRAINY_DETERMINISTIC_EMBEDDINGS
delete (globalThis as { __BRAINY_DETERMINISTIC_EMBED__?: boolean }).__BRAINY_DETERMINISTIC_EMBED__
;(globalThis as { __BRAINY_INTEGRATION_TEST__?: boolean }).__BRAINY_INTEGRATION_TEST__ = true
}, 120000)
afterAll(async () => {
delete process.env.BRAINY_INTEGRATION_TEST
delete (globalThis as { __BRAINY_INTEGRATION_TEST__?: boolean }).__BRAINY_INTEGRATION_TEST__
})