diff --git a/.changeset/38377-retire-split-algorithm-version.md b/.changeset/38377-retire-split-algorithm-version.md new file mode 100644 index 00000000000..6aa53e77b76 --- /dev/null +++ b/.changeset/38377-retire-split-algorithm-version.md @@ -0,0 +1,24 @@ +--- +'@objectstack/service-knowledge': patch +--- + +refactor(service-knowledge)!: `SPLIT_ALGORITHM_VERSION` is retired — the index fingerprint reads the split version per strategy + +Clause-②: no (narrowing) +Metadata-protocol: none + + + +**BREAKING** for a host that imports `SPLIT_ALGORITHM_VERSION` from `@objectstack/service-knowledge`. It leaves at once, with no alias. The index fingerprint (ADR-0161 K7) stopped reading it when the split version became per strategy: each strategy (`whole`, `recursive`, `markdown`) carries its own version inside the splitter, and the fingerprint reads the version of the source's resolved strategy. The constant changed nothing a host could observe, and bumping it rebuilt nothing. + +This retirement replaces the earlier note in this same release that `SPLIT_ALGORITHM_VERSION` keeps its name and its value: it is removed. + +No fingerprint changes and no index is rebuilt when this lands. + +## What leaves, and what to write instead + +| FROM | TO | +|:--|:--| +| `SPLIT_ALGORITHM_VERSION` | delete the import from `@objectstack/service-knowledge`; to tell whether a stored index is current, compare its fingerprint with `computeIndexFingerprint` or `indexExpectation`, which read the per-strategy version | + +What to do: delete the import where a host has one. Nothing else. diff --git a/packages/services/service-knowledge/src/__tests__/index-fingerprint.test.ts b/packages/services/service-knowledge/src/__tests__/index-fingerprint.test.ts index c27d4f710ea..9061a06536f 100644 --- a/packages/services/service-knowledge/src/__tests__/index-fingerprint.test.ts +++ b/packages/services/service-knowledge/src/__tests__/index-fingerprint.test.ts @@ -16,7 +16,9 @@ import { computeIndexFingerprint, computeRecipeHash, } from '../knowledge-index-fingerprint.js'; -import { SPLIT_ALGORITHM_VERSION, SPLIT_ALGORITHM_VERSION_BY_STRATEGY, resolveSplit } from '../split/index.js'; +import * as splitBarrel from '../split/index.js'; +import { SPLIT_ALGORITHM_VERSION_BY_STRATEGY, resolveSplit } from '../split/index.js'; +import * as packageEntry from '../index.js'; const source = (extra: Record = {}): KnowledgeSource => ({ @@ -35,7 +37,8 @@ const split = splitFor('markdown'); * The fingerprint of `source()` under `embedding`, per resolved strategy. * `whole`, `recursive` and no split stand as they did under one global split * version; `markdown` is at its version 2 (a heading with no body is a - * passage of its own), and {@link MARKDOWN_V1} is the value it moved from. + * passage of its own, and a section that fits the bounds is one passage + * whatever `minChars` is), and {@link MARKDOWN_V1} is the value it moved from. */ const PINNED = { whole: 'fp1:02171c5bcf94ff5d951de321a1a7206b059e684e094d329c9674309d7e472ce3', @@ -50,7 +53,7 @@ const MARKDOWN_V1 = 'fp1:1455ed0d278a0e58b26ccc2d423298c29d65162125032d76453847f describe('index fingerprint (ADR-0161 K7)', () => { it('is pinned for a fixed input', () => { - expect([INDEX_FINGERPRINT_VERSION, SPLIT_ALGORITHM_VERSION, ASSEMBLY_RULE_VERSION]).toEqual(['fp1', 1, 1]); + expect([INDEX_FINGERPRINT_VERSION, ASSEMBLY_RULE_VERSION]).toEqual(['fp1', 1]); expect(SPLIT_ALGORITHM_VERSION_BY_STRATEGY).toEqual({ whole: 1, recursive: 1, markdown: 2 }); expect(Object.isFrozen(SPLIT_ALGORITHM_VERSION_BY_STRATEGY)).toBe(true); expect(computeIndexFingerprint({ source: source(), embedding, split })).toBe( @@ -59,6 +62,15 @@ describe('index fingerprint (ADR-0161 K7)', () => { expect(computeIndexFingerprint({ source: source(), embedding, split })).toMatchInlineSnapshot(`"fp1:08c130e59628942ccc73bee1ac654a37fb09b6368e3807467998bb2cf0ac9727"`); }); + // The one global split version is retired, at once and with no alias: the + // per-strategy table above is the only split version the fingerprint reads, + // so neither the split barrel nor the package entry publishes another. + it('publishes no global split version beside the per-strategy table', () => { + expect(splitBarrel).not.toHaveProperty('SPLIT_ALGORITHM_VERSION'); + expect(packageEntry).not.toHaveProperty('SPLIT_ALGORITHM_VERSION'); + expect(packageEntry).toHaveProperty('INDEX_FINGERPRINT_VERSION', 'fp1'); + }); + // The values the fingerprint had while one global split version was read: // the per-strategy table starts every strategy at that version, so no // stored index reads as built under another fingerprint when it lands. diff --git a/packages/services/service-knowledge/src/index.ts b/packages/services/service-knowledge/src/index.ts index 1c8be1df600..b8fc4a96ee8 100644 --- a/packages/services/service-knowledge/src/index.ts +++ b/packages/services/service-knowledge/src/index.ts @@ -20,7 +20,6 @@ export { indexExpectation, } from './knowledge-index-fingerprint.js'; export type { IndexFingerprintInput, RecipeHashInput } from './knowledge-index-fingerprint.js'; -export { SPLIT_ALGORITHM_VERSION } from './split/index.js'; export { SEARCH_KNOWLEDGE_DEFAULT_TOP_K, SEARCH_KNOWLEDGE_MAX_TOP_K, diff --git a/packages/services/service-knowledge/src/split/index.ts b/packages/services/service-knowledge/src/split/index.ts index 7d7653bd7a6..ee1cd5e7129 100644 --- a/packages/services/service-knowledge/src/split/index.ts +++ b/packages/services/service-knowledge/src/split/index.ts @@ -3,7 +3,6 @@ export { DEFAULT_SPLIT_MAX_CHARS, DEFAULT_SPLIT_MIN_CHARS, - SPLIT_ALGORITHM_VERSION, SPLIT_ALGORITHM_VERSION_BY_STRATEGY, SPLIT_TOKEN_BUDGET_SHARE, resolveSplit, diff --git a/packages/services/service-knowledge/src/split/splitter.ts b/packages/services/service-knowledge/src/split/splitter.ts index d98c3e8d43a..767759405ee 100644 --- a/packages/services/service-knowledge/src/split/splitter.ts +++ b/packages/services/service-knowledge/src/split/splitter.ts @@ -57,16 +57,6 @@ export const DEFAULT_SPLIT_MIN_CHARS = 200; /** The share of the embedder's input limit a passage may fill, by `estimateTokens`. */ export const SPLIT_TOKEN_BUDGET_SHARE = 0.8; -/** - * The version every split strategy started at (ADR-0161 K7). The index - * fingerprint no longer reads it: each strategy carries its own version, in - * the splitter's per-strategy table (not published), so a change to one - * strategy's passages rebuilds only the sources that resolve to that strategy. - * Kept, at its value, because the package publishes it; bumping it rebuilds - * nothing. - */ -export const SPLIT_ALGORITHM_VERSION = 1; - /** * The version of this splitter's algorithm, per strategy. The index * fingerprint's split algorithm version (ADR-0161 K7) is the entry for the @@ -80,15 +70,17 @@ export const SPLIT_ALGORITHM_VERSION = 1; * * A change shared by several strategies (`markdown` cuts each section as * `recursive` does) bumps every strategy whose passages it changes. Every - * entry started at {@link SPLIT_ALGORITHM_VERSION}, so introducing this table - * changed no fingerprint. Typed over every strategy, so a new strategy cannot - * reach the fingerprint without a version. + * entry started at 1, the one split version the fingerprint read before this + * table, so introducing it changed no fingerprint. Typed over every strategy, + * so a new strategy cannot reach the fingerprint without a version. */ export const SPLIT_ALGORITHM_VERSION_BY_STRATEGY: Readonly> = Object.freeze({ whole: 1, recursive: 1, // 2: a heading with no text and no descendant after it is a passage of its // own, under its own path; it was carried into the next section as a line. + // And a section that fits the bounds is one passage, whatever `minChars` + // is; it was cut as `recursive` cuts and its pieces merged up to `minChars`. markdown: 2, });