mirror of
https://github.com/abhigyanpatwari/GitNexus.git
synced 2026-11-30 23:47:58 +00:00
Some checks are pending
CodeQL / Analyze (javascript-typescript) (push) Waiting to run
CodeQL / Analyze (python) (push) Waiting to run
Gitleaks / gitleaks (push) Waiting to run
Publish / Classify release event (push) Waiting to run
Publish / RC guard (marker + release-PR skip) (push) Blocked by required conditions
Publish / ci (push) Blocked by required conditions
Publish / Publish to npm (push) Blocked by required conditions
Publish / Build & Push RC Docker images (push) Blocked by required conditions
Scorecard / Scorecard analysis (push) Waiting to run
Trivy Image Scan / Trivy (gitnexus-cli) (push) Waiting to run
Trivy Image Scan / Trivy (gitnexus-web) (push) Waiting to run
* feat(embeddings): select the local model with GITNEXUS_EMBEDDING_MODEL_ID The in-process embedder always loaded Snowflake/snowflake-arctic-embed-xs. GITNEXUS_EMBEDDING_MODEL_ID now names another transformers.js model, and a custom model takes its vector width from GITNEXUS_EMBEDDING_DIMS, the value the vector column is already created with. - A custom model joins the embedding content hash, so switching models re-embeds every node instead of reusing vectors from the previous model. Default-model hashes are unchanged. - A custom model whose vectors have another width stops the run on the first sub-batch with the value to set, printed without a stack dump. - Unset, every path behaves as before: the default model keeps 384 dimensions and no width check, whatever GITNEXUS_EMBEDDING_DIMS says. Refs #628 * fix(embeddings): document safe model switches Require forced embedding generation when switching local models: unchanged source can otherwise retain vectors from the old model. Verify replacement and reuse through real analysis and LadybugDB. Refs #3802 * test(embeddings): isolate model config cases Preserve inherited model IDs and verify one error message with no stack output. Correct the MCP comment for custom local dimensions. Refs #3802 --------- Co-authored-by: Gergő Magyar <gergomagyar@icloud.com> Co-authored-by: Gergo Magyar <gergomagyar0@gmail.com>
62 lines
2.3 KiB
TypeScript
62 lines
2.3 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
|
import { resolveEmbeddingConfig } from '../../src/core/embeddings/config.js';
|
|
import { DEFAULT_EMBEDDING_CONFIG } from '../../src/core/embeddings/types.js';
|
|
|
|
const OLD_ENV = { ...process.env };
|
|
|
|
beforeEach(() => {
|
|
delete process.env.GITNEXUS_EMBEDDING_MODEL_ID;
|
|
});
|
|
|
|
afterEach(() => {
|
|
process.env = { ...OLD_ENV };
|
|
});
|
|
|
|
describe('resolveEmbeddingConfig', () => {
|
|
it('applies env overrides for local resource controls', () => {
|
|
process.env.GITNEXUS_EMBEDDING_THREADS = '3';
|
|
process.env.GITNEXUS_EMBEDDING_BATCH_SIZE = '7';
|
|
process.env.GITNEXUS_EMBEDDING_SUB_BATCH_SIZE = '5';
|
|
process.env.GITNEXUS_EMBEDDING_DEVICE = 'cpu';
|
|
|
|
const config = resolveEmbeddingConfig();
|
|
|
|
expect(config.threads).toBe(3);
|
|
expect(config.batchSize).toBe(7);
|
|
expect(config.subBatchSize).toBe(5);
|
|
expect(config.device).toBe('cpu');
|
|
});
|
|
|
|
it('reads the local model id from GITNEXUS_EMBEDDING_MODEL_ID over explicit config', () => {
|
|
process.env.GITNEXUS_EMBEDDING_MODEL_ID = ' Xenova/bge-base-en-v1.5 ';
|
|
expect(resolveEmbeddingConfig({ modelId: 'other/model' }).modelId).toBe(
|
|
'Xenova/bge-base-en-v1.5',
|
|
);
|
|
});
|
|
|
|
it('keeps the explicit or default model id when GITNEXUS_EMBEDDING_MODEL_ID is unset or blank', () => {
|
|
expect(resolveEmbeddingConfig().modelId).toBe(DEFAULT_EMBEDDING_CONFIG.modelId);
|
|
process.env.GITNEXUS_EMBEDDING_MODEL_ID = ' ';
|
|
expect(resolveEmbeddingConfig().modelId).toBe(DEFAULT_EMBEDDING_CONFIG.modelId);
|
|
expect(resolveEmbeddingConfig({ modelId: 'other/model' }).modelId).toBe('other/model');
|
|
});
|
|
|
|
it('rejects invalid numeric env values', () => {
|
|
process.env.GITNEXUS_EMBEDDING_THREADS = '0';
|
|
|
|
expect(() => resolveEmbeddingConfig()).toThrow('GITNEXUS_EMBEDDING_THREADS');
|
|
});
|
|
|
|
it('resolves the final generated input budget from env over explicit config', () => {
|
|
process.env.GITNEXUS_EMBEDDING_MAX_INPUT_CHARS = '2048';
|
|
expect(resolveEmbeddingConfig({ maxInputChars: 8192 }).maxInputChars).toBe(2048);
|
|
});
|
|
|
|
it.each(['1', '0', '-1', '2.5', 'Infinity', '9007199254740992'])(
|
|
'rejects invalid final input budget %s',
|
|
(value) => {
|
|
process.env.GITNEXUS_EMBEDDING_MAX_INPUT_CHARS = value;
|
|
expect(() => resolveEmbeddingConfig()).toThrow('GITNEXUS_EMBEDDING_MAX_INPUT_CHARS');
|
|
},
|
|
);
|
|
});
|