22 * Resolves memory-search source, sync, and ranking configuration.
33 */
44import { normalizeProviderId } from "@openclaw/model-catalog-core/provider-id" ;
5- import {
6- MAX_TIMER_TIMEOUT_MS ,
7- resolvePositiveTimerTimeoutMs ,
8- } from "@openclaw/normalization-core/number-coercion" ;
95import type { OpenClawConfig , MemorySearchConfig } from "../config/config.js" ;
106import type { SecretInput } from "../config/types.secrets.js" ;
117import {
@@ -22,7 +18,7 @@ import { getMemoryEmbeddingProvider } from "../plugins/memory-embedding-provider
2218import { assertSecretOwnerAvailable } from "../secrets/runtime-degraded-state.js" ;
2319import { runtimeMemorySecretOwnerId } from "../secrets/runtime-memory-secret-owner.js" ;
2420import { resolveOpenClawAgentSqlitePath } from "../state/openclaw-agent-db.paths.js" ;
25- import { clampInt , clampNumber } from "../utils.js" ;
21+ import { clampNumber } from "../utils.js" ;
2622import { resolveAgentConfig } from "./agent-scope.js" ;
2723
2824export type ResolvedMemorySearchConfig = {
@@ -137,34 +133,13 @@ const DEFAULT_SOURCES: Array<"memory" | "sessions"> = ["memory"];
137133const DEFAULT_MEMORY_EMBEDDING_PROVIDER = "openai" ;
138134const DEFAULT_REMOTE_BATCH_POLL_INTERVAL_MS = 2_000 ;
139135const DEFAULT_REMOTE_BATCH_TIMEOUT_MINUTES = 60 ;
140- const MAX_REMOTE_BATCH_TIMEOUT_MINUTES = Math . floor ( MAX_TIMER_TIMEOUT_MS / 60_000 ) ;
141136
142137type ConfiguredMemoryEmbeddingProvider = {
143138 defaultModel ?: string ;
144139 transport ?: "local" | "remote" ;
145140 supportsMultimodalEmbeddings ?: ( params : { model : string } ) => boolean ;
146141} ;
147142
148- function resolveRemoteBatchPollIntervalMs (
149- overrideValue : number | undefined ,
150- defaultValue : number | undefined ,
151- ) : number {
152- return resolvePositiveTimerTimeoutMs (
153- overrideValue ?? defaultValue ,
154- DEFAULT_REMOTE_BATCH_POLL_INTERVAL_MS ,
155- ) ;
156- }
157-
158- function resolveRemoteBatchTimeoutMinutes (
159- overrideValue : number | undefined ,
160- defaultValue : number | undefined ,
161- ) : number {
162- const value = overrideValue ?? defaultValue ;
163- return typeof value === "number" && Number . isFinite ( value ) && value > 0
164- ? clampInt ( value , 1 , MAX_REMOTE_BATCH_TIMEOUT_MINUTES )
165- : DEFAULT_REMOTE_BATCH_TIMEOUT_MINUTES ;
166- }
167-
168143function normalizeSources (
169144 sources : Array < "memory" | "sessions" > | undefined ,
170145 sessionMemoryEnabled : boolean ,
@@ -238,8 +213,8 @@ function mergeConfig(
238213 enabled : overrideRemote ?. batch ?. enabled ?? defaultRemote ?. batch ?. enabled ?? false ,
239214 wait : true ,
240215 concurrency : 2 ,
241- pollIntervalMs : resolveRemoteBatchPollIntervalMs ( undefined , undefined ) ,
242- timeoutMinutes : resolveRemoteBatchTimeoutMinutes ( undefined , undefined ) ,
216+ pollIntervalMs : DEFAULT_REMOTE_BATCH_POLL_INTERVAL_MS ,
217+ timeoutMinutes : DEFAULT_REMOTE_BATCH_TIMEOUT_MINUTES ,
243218 } ;
244219 const remote = includeRemote
245220 ? {
@@ -297,7 +272,7 @@ function mergeConfig(
297272 tokens : DEFAULT_CHUNK_TOKENS ,
298273 overlap : DEFAULT_CHUNK_OVERLAP ,
299274 } ;
300- const sync = resolveSyncConfig ( defaults , overrides ) ;
275+ const sync = resolveSyncConfig ( ) ;
301276 const query = {
302277 maxResults : overrides ?. query ?. maxResults ?? defaults ?. query ?. maxResults ?? DEFAULT_MAX_RESULTS ,
303278 minScore : overrides ?. query ?. minScore ?? defaults ?. query ?. minScore ?? DEFAULT_MIN_SCORE ,
@@ -321,25 +296,7 @@ function mergeConfig(
321296 maxEntries : DEFAULT_CACHE_MAX_ENTRIES ,
322297 } ;
323298
324- const overlap = clampNumber ( chunking . overlap , 0 , Math . max ( 0 , chunking . tokens - 1 ) ) ;
325299 const minScore = clampNumber ( query . minScore , 0 , 1 ) ;
326- const vectorWeight = clampNumber ( hybrid . vectorWeight , 0 , 1 ) ;
327- const textWeight = clampNumber ( hybrid . textWeight , 0 , 1 ) ;
328- const sum = vectorWeight + textWeight ;
329- const normalizedVectorWeight = sum > 0 ? vectorWeight / sum : DEFAULT_HYBRID_VECTOR_WEIGHT ;
330- const normalizedTextWeight = sum > 0 ? textWeight / sum : DEFAULT_HYBRID_TEXT_WEIGHT ;
331- const candidateMultiplier = clampInt ( hybrid . candidateMultiplier , 1 , 20 ) ;
332- const temporalDecayHalfLifeDays = Math . max (
333- 1 ,
334- Math . floor (
335- Number . isFinite ( hybrid . temporalDecay . halfLifeDays )
336- ? hybrid . temporalDecay . halfLifeDays
337- : DEFAULT_TEMPORAL_DECAY_HALF_LIFE_DAYS ,
338- ) ,
339- ) ;
340- const deltaBytes = clampInt ( sync . sessions . deltaBytes , 0 , Number . MAX_SAFE_INTEGER ) ;
341- const deltaMessages = clampInt ( sync . sessions . deltaMessages , 0 , Number . MAX_SAFE_INTEGER ) ;
342- const postCompactionForce = sync . sessions . postCompactionForce ;
343300 return {
344301 enabled,
345302 rememberAcrossConversations,
@@ -360,49 +317,18 @@ function mergeConfig(
360317 outputDimensionality,
361318 local,
362319 store,
363- chunking : { tokens : Math . max ( 1 , chunking . tokens ) , overlap } ,
364- sync : {
365- ...sync ,
366- sessions : {
367- deltaBytes,
368- deltaMessages,
369- postCompactionForce,
370- } ,
371- } ,
320+ chunking,
321+ sync,
372322 query : {
373323 ...query ,
374324 minScore,
375- hybrid : {
376- enabled : hybrid . enabled ,
377- vectorWeight : normalizedVectorWeight ,
378- textWeight : normalizedTextWeight ,
379- candidateMultiplier,
380- mmr : {
381- enabled : hybrid . mmr . enabled ,
382- lambda : Number . isFinite ( hybrid . mmr . lambda )
383- ? Math . max ( 0 , Math . min ( 1 , hybrid . mmr . lambda ) )
384- : DEFAULT_MMR_LAMBDA ,
385- } ,
386- temporalDecay : {
387- enabled : hybrid . temporalDecay . enabled ,
388- halfLifeDays : temporalDecayHalfLifeDays ,
389- } ,
390- } ,
391- } ,
392- cache : {
393- enabled : cache . enabled ,
394- maxEntries :
395- typeof cache . maxEntries === "number" && Number . isFinite ( cache . maxEntries )
396- ? Math . max ( 1 , Math . floor ( cache . maxEntries ) )
397- : undefined ,
325+ hybrid,
398326 } ,
327+ cache,
399328 } ;
400329}
401330
402- function resolveSyncConfig (
403- _defaults : MemorySearchConfig | undefined ,
404- _overrides : MemorySearchConfig | undefined ,
405- ) : ResolvedMemorySearchSyncConfig {
331+ function resolveSyncConfig ( ) : ResolvedMemorySearchSyncConfig {
406332 return {
407333 onSessionStart : true ,
408334 onSearch : true ,
@@ -464,5 +390,5 @@ export function resolveMemorySearchSyncConfig(
464390 if ( ! enabled ) {
465391 return null ;
466392 }
467- return resolveSyncConfig ( defaults , overrides ) ;
393+ return resolveSyncConfig ( ) ;
468394}
0 commit comments