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
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type {
UnderstandingRequest,
UnderstandingResult,
} from "@typeagent/memory-service";
import { memoryPerformanceExperiments } from "@typeagent/memory-service";
import { memoryPerformanceExperiments } from "@typeagent/memory-service/performance-experiments";
import {
understandingRequestSchema,
understandingResultSchema,
Expand Down
47 changes: 47 additions & 0 deletions ts/packages/agents/browser/test/viewLifecycle.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License.

import assert from "node:assert/strict";
import { execFileSync } from "node:child_process";
import { once } from "node:events";
import { mkdtemp, rm } from "node:fs/promises";
import { tmpdir } from "node:os";
Expand Down Expand Up @@ -39,6 +40,52 @@ function createContext(folder) {
};
}

test("view routes load experiment configuration without the memory runtime", () => {
const routes = new URL(
"../dist/views/server/features/views/viewRoutes.mjs",
import.meta.url,
);
execFileSync(
process.execPath,
[
"--input-type=module",
"--eval",
`
import assert from "node:assert/strict";
import { registerHooks } from "node:module";
registerHooks({
resolve(specifier, context, nextResolve) {
assert.ok(
![
"@typeagent/memory-service",
"@typeagent/knowpro",
"@typeagent/aiclient",
].includes(specifier),
"View startup must not load " + specifier +
" from " + context.parentURL,
);
return nextResolve(specifier, context);
},
});
const routes = await import(${JSON.stringify(routes.href)});
assert.equal(typeof routes.registerViewRoutes, "function");
const { memoryPerformanceExperiments } = await import(
"@typeagent/memory-service/performance-experiments"
);
assert.deepEqual(
[...memoryPerformanceExperiments("source-preview")],
["source-preview"],
);
assert.throws(
() => memoryPerformanceExperiments("topic-parallel"),
/Unknown memory performance experiment/,
);
`,
],
{ cwd: new URL("..", import.meta.url), timeout: 30_000 },
);
});

test(
"view host readiness shares startup and cleans up after restart",
{ timeout: 20_000 },
Expand Down
10 changes: 6 additions & 4 deletions ts/packages/memory/client/src/viewDetailProtocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import { z } from "zod";
import {
viewDetailMaxChars,
viewDetailPageChars,
type ViewDetailPage,
type ViewDetailPageRequest,
type ViewDetailReadRequest,
type ViewVersion,
} from "@typeagent/memory-service/view-detail";
import type {
ViewDetailPage,
ViewDetailPageRequest,
ViewDetailReadRequest,
ViewVersion,
} from "@typeagent/memory-service";
import { viewReadRequestSchema, viewVersionSchema } from "./viewProtocol.js";

Expand Down
50 changes: 34 additions & 16 deletions ts/packages/memory/service/README.md

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions ts/packages/memory/service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
".": "./dist/index.js",
"./rpc": "./dist/rpcFacade.js",
"./benchmark": "./dist/benchmarkBridge.js",
"./performance-experiments": "./dist/memoryPerformanceExperimentConfig.js",
"./agent-edition-validation": "./dist/agentEditionValidation.js",
"./procedure-markdown": "./dist/procedureMarkdown.js",
"./procedureMarkdown": "./dist/procedureMarkdown.js",
"./view-text": "./dist/viewText.js",
"./view-detail": "./dist/viewDetail.js",
"./view-types": "./dist/viewTypes.js",
"./view-packages": "./dist/viewPackages.js"
},
Expand Down
30 changes: 5 additions & 25 deletions ts/packages/memory/service/src/fileMemoryService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -904,18 +904,9 @@ function configuredTopicCuration(
options: FileMemoryServiceOptions,
decisionTopics: boolean,
curatedTopics: boolean,
parallel: boolean,
): TopicCurationSettings | undefined {
const parallelDefaults =
parallel &&
!decisionTopics &&
curatedTopics &&
!options.viewSynthesisAdapter?.generateTopics;
if (!options.topicCuration && !parallelDefaults) return undefined;
const settings: TopicCurationSettings = {
...(parallelDefaults ? { concurrency: 2 } : {}),
...options.topicCuration,
};
if (!options.topicCuration) return undefined;
const settings = { ...options.topicCuration };
validateTopicCurationSettings(settings);
if (
decisionTopics ||
Expand Down Expand Up @@ -1481,18 +1472,11 @@ function configuredTopicWatermark(
options: FileMemoryServiceOptions,
curated: boolean,
decision: boolean,
settings: TopicCurationSettings | undefined,
): boolean {
if (options.topicWatermark !== true) return false;
if (
!options.topicCurationReuse ||
!curated ||
decision ||
((settings?.concurrency ?? 1) !== 1 &&
settings?.frozenPreparation !== true)
)
if (!options.topicCurationReuse || !curated || decision)
throw new Error(
"Topic watermark requires curation reuse and ordered generative curated topics; parallelism requires frozen preparation",
"Topic watermark requires curation reuse and generative curated topics",
);
return true;
}
Expand Down Expand Up @@ -2035,13 +2019,11 @@ export class FileMemoryService
options,
this.decisionTopics,
this.curatedTopics,
this.experiments.has("topic-parallel"),
);
this.topicWatermark = configuredTopicWatermark(
options,
this.curatedTopics,
this.decisionTopics,
this.topicCuration,
);
this.topicPolicy = topicCurationPolicy(
this.curatedTopics,
Expand Down Expand Up @@ -11862,9 +11844,7 @@ export class FileMemoryService
model: this.topicModelIdentity(),
curationRecipe: this.decisionTopics
? topicDecisionRecipe
: this.curatedTopics
? this.topicPolicy
: "curated-lazy-v6",
: this.topicPolicy,
topicCurationReuse: this.topicCurationReuse,
topicWatermark: this.topicWatermark,
...(this.topicWatermark && state.continuation
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

export const memoryPerformanceExperimentNames = [
"fast-models",
"brief-reader",
"source-preview",
"refinement-fallback",
"translation-cache",
"evidence-leases",
"graph-parallel",
"foreground-priority",
"lazy-collections",
"indexing-parallel",
"synopsis-parallel",
"embedding-parallel",
"synopsis-checkpoint-priority",
"early-required-failure",
"wiki-full-context",
"wiki-stable-evidence",
"wiki-utility-first",
"wiki-coalesced-discovery",
"wiki-grouped-contributions",
"family-frozen-preparation",
] as const;

export type MemoryPerformanceExperiment =
(typeof memoryPerformanceExperimentNames)[number];

export function memoryPerformanceExperiments(
value = process.env.TYPEAGENT_MEMORY_PERF_EXPERIMENTS ?? "",
): ReadonlySet<MemoryPerformanceExperiment> {
const result = new Set<MemoryPerformanceExperiment>();
for (const name of value
.split(",")
.map((item) => item.trim())
.filter(Boolean)) {
const names =
name === "p2"
? memoryPerformanceExperimentNames.slice(0, 5)
: name === "p3"
? memoryPerformanceExperimentNames.slice(5, 9)
: memoryPerformanceExperimentNames.filter(
(item) => item === name,
);
if (!names.length)
throw new Error(`Unknown memory performance experiment: ${name}`);
for (const item of names) result.add(item);
}
if (result.has("indexing-parallel")) {
result.add("synopsis-parallel");
result.add("embedding-parallel");
}
return result;
}
60 changes: 6 additions & 54 deletions ts/packages/memory/service/src/memoryPerformanceExperiments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,12 @@

import { timeSearchStage } from "@typeagent/knowpro";
import type { MaintenanceScheduler } from "./maintenanceScheduler.js";
export const memoryPerformanceExperimentNames = [
"fast-models",
"brief-reader",
"source-preview",
"refinement-fallback",
"translation-cache",
"evidence-leases",
"graph-parallel",
"foreground-priority",
"lazy-collections",
"indexing-parallel",
"topic-parallel",
"synopsis-parallel",
"embedding-parallel",
"synopsis-checkpoint-priority",
"early-required-failure",
"wiki-full-context",
"wiki-stable-evidence",
"wiki-utility-first",
"wiki-coalesced-discovery",
"wiki-grouped-contributions",
"family-frozen-preparation",
] as const;

export type MemoryPerformanceExperiment =
(typeof memoryPerformanceExperimentNames)[number];
import type { MemoryPerformanceExperiment } from "./memoryPerformanceExperimentConfig.js";
export {
memoryPerformanceExperimentNames,
memoryPerformanceExperiments,
type MemoryPerformanceExperiment,
} from "./memoryPerformanceExperimentConfig.js";

export function deferSynopsisForCheckpoint(
scheduler: Pick<MaintenanceScheduler, "deferFamily">,
Expand Down Expand Up @@ -66,34 +46,6 @@ export function resolveInitialReaderModelEndpoint(
);
}

export function memoryPerformanceExperiments(
value = process.env.TYPEAGENT_MEMORY_PERF_EXPERIMENTS ?? "",
): ReadonlySet<MemoryPerformanceExperiment> {
const result = new Set<MemoryPerformanceExperiment>();
for (const name of value
.split(",")
.map((item) => item.trim())
.filter(Boolean)) {
const names =
name === "p2"
? memoryPerformanceExperimentNames.slice(0, 5)
: name === "p3"
? memoryPerformanceExperimentNames.slice(5, 9)
: memoryPerformanceExperimentNames.filter(
(item) => item === name,
);
if (!names.length)
throw new Error(`Unknown memory performance experiment: ${name}`);
for (const item of names) result.add(item);
}
if (result.has("indexing-parallel")) {
result.add("topic-parallel");
result.add("synopsis-parallel");
result.add("embedding-parallel");
}
return result;
}

export async function boundedSupportMap<T, R>(
items: readonly T[],
concurrency: 1 | 2,
Expand Down
7 changes: 4 additions & 3 deletions ts/packages/memory/service/src/topicCapture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { viewHash } from "./viewMerge.js";
import { initialTopicNodes, validateTopicSnapshot } from "./topicSnapshot.js";
import { topicClusterSignature } from "./topicDecision.js";
import { topicMaintenanceSignature } from "./topicClusterMaintenance.js";
import { topicCurationPolicy } from "./topicCurationSettings.js";

export function supportsTopicIndex(
index: CorpusIndex,
Expand Down Expand Up @@ -113,7 +114,7 @@ function reusableTopicPackets(
!previous.curationInputFingerprint ||
previous.corpusId !== options.corpusId ||
previous.recipe !==
`${options.model}:editorial-v1:${options.curationRecipe ?? "curated-lazy-v6"}` ||
`${options.model}:editorial-v1:${options.curationRecipe ?? topicCurationPolicy(true)}` ||
previous.curationSuppressionFingerprint !==
viewHash(options.suppressions) ||
!topicSourceClosurePreserved(
Expand Down Expand Up @@ -171,7 +172,7 @@ function curationDependencyFingerprint(
occurrences,
suppressions: options.suppressions,
model: options.model,
curationRecipe: options.curationRecipe ?? "curated-lazy-v6",
curationRecipe: options.curationRecipe ?? topicCurationPolicy(true),
events: options.influenceEvents ?? [],
});
}
Expand All @@ -188,7 +189,7 @@ function reusableTopicCuration(
!current ||
current.corpusId !== corpusId ||
current.recipe !==
`${model}:editorial-v1:${options.curationRecipe ?? "curated-lazy-v6"}` ||
`${model}:editorial-v1:${options.curationRecipe ?? topicCurationPolicy(true)}` ||
viewHash(current.occurrences) !== viewHash(occurrences) ||
!current.nodes.every((node) => node.authorship === "generated")
)
Expand Down
Loading
Loading