Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .changeset/38377-retire-split-algorithm-version.md
Original file line number Diff line number Diff line change
@@ -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

<!-- adr-0087: not-required (runtime-export-retired @objectstack/service-knowledge#SPLIT_ALGORITHM_VERSION) the retired operand is a numeric constant of the package's published entry that no runtime code reads; no packages/spec schema, no registered node type, no ADR-0087 conversion surface and no stored shape names it, so there is nothing for `objectstack migrate meta` to rewrite, and a host still importing it is told by its own compiler -->

**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.
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, unknown> = {}): KnowledgeSource =>
({
Expand All @@ -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',
Expand All @@ -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(
Expand All @@ -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.
Expand Down
1 change: 0 additions & 1 deletion packages/services/service-knowledge/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion packages/services/service-knowledge/src/split/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 5 additions & 13 deletions packages/services/service-knowledge/src/split/splitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<Record<KnowledgeSplitStrategy, number>> = 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,
});

Expand Down
Loading