Skip to content

Commit f1ca929

Browse files
Copilotdevlux76
andcommitted
fix(#93): apply Williams-bound budgets consistently
- FullNeighborRecalc now derives maxNeighbors from computeNeighborMaxDegree instead of using a fixed default of 16 - Query.ts uses getResidentCount() as proxy for corpus size to avoid scanning all pages on the hot path for computeSubgraphBounds Closes #93 Co-authored-by: devlux76 <[email protected]>
1 parent 546e078 commit f1ca929

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

lib/cortex/Query.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,16 +191,16 @@ export async function query(
191191

192192
// --- Subgraph expansion ---
193193
// Use dynamic Williams-derived bounds unless the caller has pinned an
194-
// explicit maxHops value. Only load all pages when we actually need to
195-
// compute bounds — skip the full-page scan on the hot path when maxHops is
196-
// already known.
194+
// explicit maxHops value. Prefer the hotpath resident count as an efficient
195+
// proxy for corpus size to avoid scanning all pages on the hot path.
197196
const topPageIds = topPages.map((p) => p.pageId);
198197
let effectiveMaxHops: number;
199198
if (options.maxHops !== undefined) {
200199
effectiveMaxHops = options.maxHops;
201200
} else {
202-
const allPages = await metadataStore.getAllPages();
203-
effectiveMaxHops = computeSubgraphBounds(allPages.length).maxHops;
201+
const residentCount = await metadataStore.getResidentCount();
202+
const graphMass = residentCount > 0 ? residentCount : combinedPageIds.size;
203+
effectiveMaxHops = computeSubgraphBounds(Math.max(1, graphMass)).maxHops;
204204
}
205205
const subgraph = await metadataStore.getInducedNeighborSubgraph(topPageIds, effectiveMaxHops);
206206

lib/daydreamer/FullNeighborRecalc.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// ---------------------------------------------------------------------------
1515

1616
import type { Hash, MetadataStore, SemanticNeighbor, Page, VectorStore } from "../core/types";
17-
import { computeCapacity, DEFAULT_HOTPATH_POLICY, type HotpathPolicy } from "../core/HotpathPolicy";
17+
import { computeCapacity, computeNeighborMaxDegree, DEFAULT_HOTPATH_POLICY, type HotpathPolicy } from "../core/HotpathPolicy";
1818
import { batchComputeSalience, runPromotionSweep } from "../core/SalienceEngine";
1919

2020
// Minimum pair budget per idle recalc cycle.
@@ -31,7 +31,8 @@ export interface FullNeighborRecalcOptions {
3131
metadataStore: MetadataStore;
3232
vectorStore: VectorStore;
3333
policy?: HotpathPolicy;
34-
/** Maximum semantic neighbors stored per page. Default: 16. */
34+
/** Maximum semantic neighbors stored per page.
35+
* When omitted, uses Williams-derived `computeNeighborMaxDegree(graphMass)`. */
3536
maxNeighbors?: number;
3637
/** Current timestamp (ms since epoch). Defaults to Date.now(). */
3738
now?: number;
@@ -84,7 +85,6 @@ export async function runFullNeighborRecalc(
8485
metadataStore,
8586
vectorStore,
8687
policy = DEFAULT_HOTPATH_POLICY,
87-
maxNeighbors = 16,
8888
now = Date.now(),
8989
} = options;
9090

@@ -110,6 +110,9 @@ export async function runFullNeighborRecalc(
110110
const totalGraphMass = (await metadataStore.getAllPages()).length;
111111
const pairBudget = Math.max(MIN_RECALC_PAIR_BUDGET, computeCapacity(totalGraphMass, policy.c));
112112

113+
// Derive max neighbor degree from Williams bounds if not explicitly provided.
114+
const maxNeighbors = options.maxNeighbors ?? computeNeighborMaxDegree(totalGraphMass, policy.c);
115+
113116
let totalVolumesProcessed = 0;
114117
let totalPagesProcessed = 0;
115118
let totalPairsComputed = 0;

0 commit comments

Comments
 (0)