@melandlabs/memory-store 1.2.3 → 1.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -87,7 +87,7 @@ interface HitSignals {
87
87
  * fetch fallback.
88
88
  */
89
89
  declare function deriveLexicalKeywords(query: string): string[];
90
- type UnifiedMemoryReasoningStrategy = "none" | "rewrite" | "iterative";
90
+ type UnifiedMemoryReasoningStrategy = "none" | "rewrite" | "iterative" | "union";
91
91
  interface UnifiedMemorySearchWarning {
92
92
  source: UnifiedMemorySearchSource;
93
93
  code: string;
package/dist/http.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { M as MemoryStoreConfig } from './config-DfvVZ--0.js';
1
+ import { M as MemoryStoreConfig } from './config-Dw4aXj2a.js';
2
2
  import '@melandlabs/memory-consolidation';
3
3
  import '@melandlabs/contracts/peer';
4
4
  import '@melandlabs/contracts';
package/dist/http.js CHANGED
@@ -462,7 +462,7 @@ function normalizeUnifiedMemoryMergeStrategy(value) {
462
462
  return value === "rrf" ? "rrf" : "similarity";
463
463
  }
464
464
  function normalizeUnifiedMemoryReasoningStrategy(value, defaultStrategy = "none") {
465
- if (value === "rewrite" || value === "iterative") {
465
+ if (value === "rewrite" || value === "iterative" || value === "union") {
466
466
  return value;
467
467
  }
468
468
  return defaultStrategy;
@@ -1156,7 +1156,7 @@ function createUnifiedSearch(deps = {}) {
1156
1156
  return normalizeUnifiedMemoryReasoningStrategy(deps.reasoning?.defaultStrategy, "none");
1157
1157
  }
1158
1158
  async function runMemorySource(input, limit, threshold, warnings, reasoningStrategy = "none", reasoningInfo, peerPeers = []) {
1159
- if (reasoningStrategy === "iterative" && !deps.reasoning?.iterativePlanner) {
1159
+ if ((reasoningStrategy === "iterative" || reasoningStrategy === "union") && !deps.reasoning?.iterativePlanner) {
1160
1160
  warnings.push({
1161
1161
  source: "memory",
1162
1162
  code: "memory_iterative_planner_not_configured",
@@ -1172,7 +1172,8 @@ function createUnifiedSearch(deps = {}) {
1172
1172
  });
1173
1173
  if (reasoningInfo) reasoningInfo.degraded = true;
1174
1174
  }
1175
- if (reasoningStrategy === "iterative" && deps.reasoning?.iterativePlanner) {
1175
+ let unionEvidence = null;
1176
+ if ((reasoningStrategy === "iterative" || reasoningStrategy === "union") && deps.reasoning?.iterativePlanner) {
1176
1177
  const planner = deps.reasoning.iterativePlanner;
1177
1178
  const result = await planner.plan({
1178
1179
  query: input.query,
@@ -1229,14 +1230,17 @@ function createUnifiedSearch(deps = {}) {
1229
1230
  reasoningInfo.degraded = true;
1230
1231
  }
1231
1232
  }
1232
- const semantic2 = result.evidence.map((candidate) => ({
1233
+ const evidence = result.evidence.map((candidate) => ({
1233
1234
  type: "memory",
1234
1235
  id: candidate.id,
1235
1236
  content: candidate.content,
1236
1237
  similarity: candidate.similarity,
1237
- metadata: { ...candidate.metadata, reasoning: "iterative" }
1238
+ metadata: { ...candidate.metadata, reasoning: reasoningStrategy }
1238
1239
  }));
1239
- return { semantic: semantic2, lexical: [] };
1240
+ if (reasoningStrategy === "iterative") {
1241
+ return { semantic: evidence, lexical: [] };
1242
+ }
1243
+ unionEvidence = evidence;
1240
1244
  }
1241
1245
  if (typeof deps.embedQuery !== "function") {
1242
1246
  warnings.push({
@@ -1362,6 +1366,37 @@ function createUnifiedSearch(deps = {}) {
1362
1366
  message: "RRF merge requested but entity search is not configured; falling back to semantic+lexical RRF."
1363
1367
  });
1364
1368
  }
1369
+ if (unionEvidence) {
1370
+ const plannerHits = unionEvidence;
1371
+ const base = mergeByMaxScore([
1372
+ filterByDateRange(semantic, input.dateFrom, input.dateTo),
1373
+ filterByDateRange(lexical, input.dateFrom, input.dateTo)
1374
+ ]);
1375
+ const maxBase = base.length > 0 ? Math.max(...base.map((h) => h.similarity)) : 0;
1376
+ const seen = /* @__PURE__ */ new Set();
1377
+ const merged = [];
1378
+ plannerHits.forEach((hit, i) => {
1379
+ if (seen.has(hit.id)) {
1380
+ return;
1381
+ }
1382
+ seen.add(hit.id);
1383
+ merged.push({
1384
+ ...hit,
1385
+ similarity: maxBase + (plannerHits.length - i) * 1e-6
1386
+ });
1387
+ });
1388
+ for (const hit of base) {
1389
+ if (merged.length >= limit) {
1390
+ break;
1391
+ }
1392
+ if (seen.has(hit.id)) {
1393
+ continue;
1394
+ }
1395
+ seen.add(hit.id);
1396
+ merged.push(hit);
1397
+ }
1398
+ return { semantic: merged.slice(0, limit), lexical: [] };
1399
+ }
1365
1400
  const out = {
1366
1401
  semantic: filterByDateRange(semantic, input.dateFrom, input.dateTo),
1367
1402
  lexical: filterByDateRange(lexical, input.dateFrom, input.dateTo)
@@ -2190,7 +2225,7 @@ async function startHttpServer(options = {}) {
2190
2225
  authToken: typeof body.authToken === "string" ? body.authToken : void 0,
2191
2226
  dateFrom: typeof body.dateFrom === "string" ? body.dateFrom : void 0,
2192
2227
  dateTo: typeof body.dateTo === "string" ? body.dateTo : void 0,
2193
- reasoningStrategy: body.reasoningStrategy === "rewrite" || body.reasoningStrategy === "iterative" ? body.reasoningStrategy : void 0,
2228
+ reasoningStrategy: body.reasoningStrategy === "rewrite" || body.reasoningStrategy === "iterative" || body.reasoningStrategy === "union" ? body.reasoningStrategy : void 0,
2194
2229
  ...wantsSynthesis ? {
2195
2230
  synthesize: {
2196
2231
  ...responseSchema ? { responseSchema } : {}
package/dist/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import * as _melandlabs_memory_consolidation from '@melandlabs/memory-consolidation';
2
2
  import { OwnerScope } from '@melandlabs/memory-consolidation';
3
- import { d as SearchInput, e as SearchOutput, M as MemoryStoreConfig } from './config-DfvVZ--0.js';
4
- export { E as EmbedQueryFn, H as HitChannel, i as HitSignals, I as IterativeRecallCandidate, B as IterativeRecallExecutor, C as IterativeRecallPlanner, D as IterativeRecallPlannerOptions, F as IterativeRecallResult, G as IterativeRecallSearchRequest, J as IterativeRecallSearchResult, K as IterativeRecallStats, L as MemoryStoreDb, a as MemoryStoreEnv, Q as QueryRewriter, N as QueryRewriterInput, O as QueryRewriterOptions, c as SearchEvidence, j as SearchSource, S as SearchTier, k as UnifiedMemoryMergeStrategy, l as UnifiedMemoryRankedList, P as UnifiedMemoryReasoningInfo, m as UnifiedMemoryReasoningStrategy, f as UnifiedMemorySearchInput, g as UnifiedMemorySearchOutput, h as UnifiedMemorySearchResult, n as UnifiedMemorySearchSource, b as UnifiedMemorySearchWarning, R as UnifiedSearchInsightsResult, T as UnifiedSearchKnowledgeResult, V as UnifiedSearchReasoningDeps, W as VectorBackend, o as clampUnifiedMemorySearchLimit, p as clampUnifiedMemorySearchThreshold, X as createIdentityIterativePlanner, Y as createIdentityRewriter, Z as createIterativeRecallPlanner, _ as createUserVoiceRewriter, r as isRawMemorySemanticResult, s as listNameToChannel, t as materializeSignals, u as mergeUnifiedMemorySearchResults, v as mergeUnifiedMemorySearchResultsRrf, x as normalizeUnifiedMemoryReasoningStrategy, y as normalizeUnifiedMemorySearchSources, z as toKnowledgeResult, A as toMemoryResult } from './config-DfvVZ--0.js';
5
- import { U as UnifiedSearch, A as ApplyConsolidateInput, a as ApplyConsolidateOutput } from './unified-search-A8Q3JHwU.js';
6
- export { b as applyReflectedPlan, c as createUnifiedSearch } from './unified-search-A8Q3JHwU.js';
3
+ import { d as SearchInput, e as SearchOutput, M as MemoryStoreConfig } from './config-Dw4aXj2a.js';
4
+ export { E as EmbedQueryFn, H as HitChannel, i as HitSignals, I as IterativeRecallCandidate, B as IterativeRecallExecutor, C as IterativeRecallPlanner, D as IterativeRecallPlannerOptions, F as IterativeRecallResult, G as IterativeRecallSearchRequest, J as IterativeRecallSearchResult, K as IterativeRecallStats, L as MemoryStoreDb, a as MemoryStoreEnv, Q as QueryRewriter, N as QueryRewriterInput, O as QueryRewriterOptions, c as SearchEvidence, j as SearchSource, S as SearchTier, k as UnifiedMemoryMergeStrategy, l as UnifiedMemoryRankedList, P as UnifiedMemoryReasoningInfo, m as UnifiedMemoryReasoningStrategy, f as UnifiedMemorySearchInput, g as UnifiedMemorySearchOutput, h as UnifiedMemorySearchResult, n as UnifiedMemorySearchSource, b as UnifiedMemorySearchWarning, R as UnifiedSearchInsightsResult, T as UnifiedSearchKnowledgeResult, V as UnifiedSearchReasoningDeps, W as VectorBackend, o as clampUnifiedMemorySearchLimit, p as clampUnifiedMemorySearchThreshold, X as createIdentityIterativePlanner, Y as createIdentityRewriter, Z as createIterativeRecallPlanner, _ as createUserVoiceRewriter, r as isRawMemorySemanticResult, s as listNameToChannel, t as materializeSignals, u as mergeUnifiedMemorySearchResults, v as mergeUnifiedMemorySearchResultsRrf, x as normalizeUnifiedMemoryReasoningStrategy, y as normalizeUnifiedMemorySearchSources, z as toKnowledgeResult, A as toMemoryResult } from './config-Dw4aXj2a.js';
5
+ import { U as UnifiedSearch, A as ApplyConsolidateInput, a as ApplyConsolidateOutput } from './unified-search-DfE8ek7W.js';
6
+ export { b as applyReflectedPlan, c as createUnifiedSearch } from './unified-search-DfE8ek7W.js';
7
7
  import { StoreVsaFactInput, StoreVsaFactOutput, VsaRecallInput, VsaRecallOutput, VsaListInput, VsaFactSummary, VsaForgetInput, VsaForgetOutput, VsaFactStorage } from '@melandlabs/contracts';
8
8
  export { DerivedFact, DerivedKind, EntityEdge, EntityKind, StoreVsaFactInput, StoreVsaFactOutput, VsaFact, VsaFactStorage, VsaFactSummary, VsaForgetInput, VsaForgetOutput, VsaListInput, VsaRecallInput, VsaRecallOutput, VsaRecallScore, VsaVocabularyEntry } from '@melandlabs/contracts';
9
9
  import { RawMessageStore, getRawMessageManager } from './storage/raw-message-store.js';
package/dist/index.js CHANGED
@@ -311,7 +311,7 @@ function normalizeUnifiedMemoryMergeStrategy(value) {
311
311
  return value === "rrf" ? "rrf" : "similarity";
312
312
  }
313
313
  function normalizeUnifiedMemoryReasoningStrategy(value, defaultStrategy = "none") {
314
- if (value === "rewrite" || value === "iterative") {
314
+ if (value === "rewrite" || value === "iterative" || value === "union") {
315
315
  return value;
316
316
  }
317
317
  return defaultStrategy;
@@ -1157,7 +1157,7 @@ function createUnifiedSearch(deps = {}) {
1157
1157
  return normalizeUnifiedMemoryReasoningStrategy(deps.reasoning?.defaultStrategy, "none");
1158
1158
  }
1159
1159
  async function runMemorySource(input, limit, threshold, warnings, reasoningStrategy = "none", reasoningInfo, peerPeers = []) {
1160
- if (reasoningStrategy === "iterative" && !deps.reasoning?.iterativePlanner) {
1160
+ if ((reasoningStrategy === "iterative" || reasoningStrategy === "union") && !deps.reasoning?.iterativePlanner) {
1161
1161
  warnings.push({
1162
1162
  source: "memory",
1163
1163
  code: "memory_iterative_planner_not_configured",
@@ -1173,7 +1173,8 @@ function createUnifiedSearch(deps = {}) {
1173
1173
  });
1174
1174
  if (reasoningInfo) reasoningInfo.degraded = true;
1175
1175
  }
1176
- if (reasoningStrategy === "iterative" && deps.reasoning?.iterativePlanner) {
1176
+ let unionEvidence = null;
1177
+ if ((reasoningStrategy === "iterative" || reasoningStrategy === "union") && deps.reasoning?.iterativePlanner) {
1177
1178
  const planner = deps.reasoning.iterativePlanner;
1178
1179
  const result = await planner.plan({
1179
1180
  query: input.query,
@@ -1230,14 +1231,17 @@ function createUnifiedSearch(deps = {}) {
1230
1231
  reasoningInfo.degraded = true;
1231
1232
  }
1232
1233
  }
1233
- const semantic2 = result.evidence.map((candidate) => ({
1234
+ const evidence = result.evidence.map((candidate) => ({
1234
1235
  type: "memory",
1235
1236
  id: candidate.id,
1236
1237
  content: candidate.content,
1237
1238
  similarity: candidate.similarity,
1238
- metadata: { ...candidate.metadata, reasoning: "iterative" }
1239
+ metadata: { ...candidate.metadata, reasoning: reasoningStrategy }
1239
1240
  }));
1240
- return { semantic: semantic2, lexical: [] };
1241
+ if (reasoningStrategy === "iterative") {
1242
+ return { semantic: evidence, lexical: [] };
1243
+ }
1244
+ unionEvidence = evidence;
1241
1245
  }
1242
1246
  if (typeof deps.embedQuery !== "function") {
1243
1247
  warnings.push({
@@ -1363,6 +1367,37 @@ function createUnifiedSearch(deps = {}) {
1363
1367
  message: "RRF merge requested but entity search is not configured; falling back to semantic+lexical RRF."
1364
1368
  });
1365
1369
  }
1370
+ if (unionEvidence) {
1371
+ const plannerHits = unionEvidence;
1372
+ const base = mergeByMaxScore([
1373
+ filterByDateRange(semantic, input.dateFrom, input.dateTo),
1374
+ filterByDateRange(lexical, input.dateFrom, input.dateTo)
1375
+ ]);
1376
+ const maxBase = base.length > 0 ? Math.max(...base.map((h) => h.similarity)) : 0;
1377
+ const seen = /* @__PURE__ */ new Set();
1378
+ const merged = [];
1379
+ plannerHits.forEach((hit, i) => {
1380
+ if (seen.has(hit.id)) {
1381
+ return;
1382
+ }
1383
+ seen.add(hit.id);
1384
+ merged.push({
1385
+ ...hit,
1386
+ similarity: maxBase + (plannerHits.length - i) * 1e-6
1387
+ });
1388
+ });
1389
+ for (const hit of base) {
1390
+ if (merged.length >= limit) {
1391
+ break;
1392
+ }
1393
+ if (seen.has(hit.id)) {
1394
+ continue;
1395
+ }
1396
+ seen.add(hit.id);
1397
+ merged.push(hit);
1398
+ }
1399
+ return { semantic: merged.slice(0, limit), lexical: [] };
1400
+ }
1366
1401
  const out = {
1367
1402
  semantic: filterByDateRange(semantic, input.dateFrom, input.dateTo),
1368
1403
  lexical: filterByDateRange(lexical, input.dateFrom, input.dateTo)
package/dist/mcp.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
- import { M as MemoryStoreConfig } from './config-DfvVZ--0.js';
2
+ import { M as MemoryStoreConfig } from './config-Dw4aXj2a.js';
3
3
  import '@melandlabs/memory-consolidation';
4
4
  import '@melandlabs/contracts/peer';
5
5
  import '@melandlabs/contracts';
package/dist/mcp.js CHANGED
@@ -463,7 +463,7 @@ function normalizeUnifiedMemoryMergeStrategy(value) {
463
463
  return value === "rrf" ? "rrf" : "similarity";
464
464
  }
465
465
  function normalizeUnifiedMemoryReasoningStrategy(value, defaultStrategy = "none") {
466
- if (value === "rewrite" || value === "iterative") {
466
+ if (value === "rewrite" || value === "iterative" || value === "union") {
467
467
  return value;
468
468
  }
469
469
  return defaultStrategy;
@@ -1157,7 +1157,7 @@ function createUnifiedSearch(deps = {}) {
1157
1157
  return normalizeUnifiedMemoryReasoningStrategy(deps.reasoning?.defaultStrategy, "none");
1158
1158
  }
1159
1159
  async function runMemorySource(input, limit, threshold, warnings, reasoningStrategy = "none", reasoningInfo, peerPeers = []) {
1160
- if (reasoningStrategy === "iterative" && !deps.reasoning?.iterativePlanner) {
1160
+ if ((reasoningStrategy === "iterative" || reasoningStrategy === "union") && !deps.reasoning?.iterativePlanner) {
1161
1161
  warnings.push({
1162
1162
  source: "memory",
1163
1163
  code: "memory_iterative_planner_not_configured",
@@ -1173,7 +1173,8 @@ function createUnifiedSearch(deps = {}) {
1173
1173
  });
1174
1174
  if (reasoningInfo) reasoningInfo.degraded = true;
1175
1175
  }
1176
- if (reasoningStrategy === "iterative" && deps.reasoning?.iterativePlanner) {
1176
+ let unionEvidence = null;
1177
+ if ((reasoningStrategy === "iterative" || reasoningStrategy === "union") && deps.reasoning?.iterativePlanner) {
1177
1178
  const planner = deps.reasoning.iterativePlanner;
1178
1179
  const result = await planner.plan({
1179
1180
  query: input.query,
@@ -1230,14 +1231,17 @@ function createUnifiedSearch(deps = {}) {
1230
1231
  reasoningInfo.degraded = true;
1231
1232
  }
1232
1233
  }
1233
- const semantic2 = result.evidence.map((candidate) => ({
1234
+ const evidence = result.evidence.map((candidate) => ({
1234
1235
  type: "memory",
1235
1236
  id: candidate.id,
1236
1237
  content: candidate.content,
1237
1238
  similarity: candidate.similarity,
1238
- metadata: { ...candidate.metadata, reasoning: "iterative" }
1239
+ metadata: { ...candidate.metadata, reasoning: reasoningStrategy }
1239
1240
  }));
1240
- return { semantic: semantic2, lexical: [] };
1241
+ if (reasoningStrategy === "iterative") {
1242
+ return { semantic: evidence, lexical: [] };
1243
+ }
1244
+ unionEvidence = evidence;
1241
1245
  }
1242
1246
  if (typeof deps.embedQuery !== "function") {
1243
1247
  warnings.push({
@@ -1363,6 +1367,37 @@ function createUnifiedSearch(deps = {}) {
1363
1367
  message: "RRF merge requested but entity search is not configured; falling back to semantic+lexical RRF."
1364
1368
  });
1365
1369
  }
1370
+ if (unionEvidence) {
1371
+ const plannerHits = unionEvidence;
1372
+ const base = mergeByMaxScore([
1373
+ filterByDateRange(semantic, input.dateFrom, input.dateTo),
1374
+ filterByDateRange(lexical, input.dateFrom, input.dateTo)
1375
+ ]);
1376
+ const maxBase = base.length > 0 ? Math.max(...base.map((h) => h.similarity)) : 0;
1377
+ const seen = /* @__PURE__ */ new Set();
1378
+ const merged = [];
1379
+ plannerHits.forEach((hit, i) => {
1380
+ if (seen.has(hit.id)) {
1381
+ return;
1382
+ }
1383
+ seen.add(hit.id);
1384
+ merged.push({
1385
+ ...hit,
1386
+ similarity: maxBase + (plannerHits.length - i) * 1e-6
1387
+ });
1388
+ });
1389
+ for (const hit of base) {
1390
+ if (merged.length >= limit) {
1391
+ break;
1392
+ }
1393
+ if (seen.has(hit.id)) {
1394
+ continue;
1395
+ }
1396
+ seen.add(hit.id);
1397
+ merged.push(hit);
1398
+ }
1399
+ return { semantic: merged.slice(0, limit), lexical: [] };
1400
+ }
1366
1401
  const out = {
1367
1402
  semantic: filterByDateRange(semantic, input.dateFrom, input.dateTo),
1368
1403
  lexical: filterByDateRange(lexical, input.dateFrom, input.dateTo)
@@ -2165,8 +2200,8 @@ async function startMcpServer(options = {}) {
2165
2200
  tiers: z.array(z.enum(["summary", "raw", "insight", "knowledge"])).optional().describe(
2166
2201
  "Per-tier evidence scope for synthesis. Default: ['summary','raw','insight','knowledge']. Ignored when `synthesize` is falsy."
2167
2202
  ),
2168
- reasoningStrategy: z.enum(["none", "rewrite", "iterative"]).optional().describe(
2169
- "LLM reasoning strategy. `rewrite` rephrases the query before embedding; `iterative` runs a planner that searches, notes evidence, and searches again. Requires `unified.reasoning.{queryRewriter,iterativePlanner}` to be wired into the server."
2203
+ reasoningStrategy: z.enum(["none", "rewrite", "iterative", "union"]).optional().describe(
2204
+ "LLM reasoning strategy. `rewrite` rephrases the query before embedding; `iterative` runs a planner that searches, notes evidence, and searches again; `union` merges the planner's evidence with the baseline top-k hits (evidence first, deduped, capped at limit). Requires `unified.reasoning.{queryRewriter,iterativePlanner}` to be wired into the server."
2170
2205
  ),
2171
2206
  synthesize: z.union([z.boolean(), z.object({ responseSchema: z.record(z.string(), z.unknown()).optional() })]).optional().describe(
2172
2207
  "Opt-in LLM synthesis. `true` returns `{ answer, evidence, results, warnings }`. `synthesize.responseSchema` extracts `answer` from a JSON payload."
@@ -2243,7 +2278,7 @@ async function startMcpServer(options = {}) {
2243
2278
  documentIds: a.documentIds,
2244
2279
  authToken: a.authToken,
2245
2280
  includeArchivedInsights: a.includeArchivedInsights,
2246
- reasoningStrategy: a.reasoningStrategy === "rewrite" || a.reasoningStrategy === "iterative" ? a.reasoningStrategy : void 0,
2281
+ reasoningStrategy: a.reasoningStrategy === "rewrite" || a.reasoningStrategy === "iterative" || a.reasoningStrategy === "union" ? a.reasoningStrategy : void 0,
2247
2282
  ...a.tiers ? { tiers: a.tiers } : {},
2248
2283
  ...wantsSynthesis ? {
2249
2284
  synthesize: {
@@ -1,7 +1,7 @@
1
1
  import { DerivedFact } from '@melandlabs/contracts/derived-fact';
2
2
  import { FactType } from '@melandlabs/contracts/fact-type';
3
3
  import { Peer } from '@melandlabs/contracts/peer';
4
- import { U as UnifiedSearchDeps } from '../config-DfvVZ--0.js';
4
+ import { U as UnifiedSearchDeps } from '../config-Dw4aXj2a.js';
5
5
  import '@melandlabs/memory-consolidation';
6
6
  import '@melandlabs/contracts';
7
7
  import '@melandlabs/contracts/entity-edge';
@@ -1,5 +1,5 @@
1
1
  import { EntityEdge } from '@melandlabs/contracts/entity-edge';
2
- import { U as UnifiedSearchDeps } from '../config-DfvVZ--0.js';
2
+ import { U as UnifiedSearchDeps } from '../config-Dw4aXj2a.js';
3
3
  import '@melandlabs/memory-consolidation';
4
4
  import '@melandlabs/contracts/peer';
5
5
  import '@melandlabs/contracts';
@@ -1,5 +1,5 @@
1
- export { H as HitChannel, i as HitSignals, c as SearchEvidence, d as SearchInput, e as SearchOutput, j as SearchSource, S as SearchTier, k as UnifiedMemoryMergeStrategy, l as UnifiedMemoryRankedList, m as UnifiedMemoryReasoningStrategy, f as UnifiedMemorySearchInput, g as UnifiedMemorySearchOutput, h as UnifiedMemorySearchResult, n as UnifiedMemorySearchSource, b as UnifiedMemorySearchWarning, o as clampUnifiedMemorySearchLimit, p as clampUnifiedMemorySearchThreshold, q as deriveLexicalKeywords, r as isRawMemorySemanticResult, s as listNameToChannel, t as materializeSignals, u as mergeUnifiedMemorySearchResults, v as mergeUnifiedMemorySearchResultsRrf, w as normalizeUnifiedMemoryMergeStrategy, x as normalizeUnifiedMemoryReasoningStrategy, y as normalizeUnifiedMemorySearchSources, z as toKnowledgeResult, A as toMemoryResult } from '../config-DfvVZ--0.js';
2
- export { U as UnifiedSearch, c as createUnifiedSearch } from '../unified-search-A8Q3JHwU.js';
1
+ export { H as HitChannel, i as HitSignals, c as SearchEvidence, d as SearchInput, e as SearchOutput, j as SearchSource, S as SearchTier, k as UnifiedMemoryMergeStrategy, l as UnifiedMemoryRankedList, m as UnifiedMemoryReasoningStrategy, f as UnifiedMemorySearchInput, g as UnifiedMemorySearchOutput, h as UnifiedMemorySearchResult, n as UnifiedMemorySearchSource, b as UnifiedMemorySearchWarning, o as clampUnifiedMemorySearchLimit, p as clampUnifiedMemorySearchThreshold, q as deriveLexicalKeywords, r as isRawMemorySemanticResult, s as listNameToChannel, t as materializeSignals, u as mergeUnifiedMemorySearchResults, v as mergeUnifiedMemorySearchResultsRrf, w as normalizeUnifiedMemoryMergeStrategy, x as normalizeUnifiedMemoryReasoningStrategy, y as normalizeUnifiedMemorySearchSources, z as toKnowledgeResult, A as toMemoryResult } from '../config-Dw4aXj2a.js';
2
+ export { U as UnifiedSearch, c as createUnifiedSearch } from '../unified-search-DfE8ek7W.js';
3
3
  import '@melandlabs/memory-consolidation';
4
4
  import '@melandlabs/contracts/peer';
5
5
  import '@melandlabs/contracts';
@@ -300,7 +300,7 @@ function normalizeUnifiedMemoryMergeStrategy(value) {
300
300
  return value === "rrf" ? "rrf" : "similarity";
301
301
  }
302
302
  function normalizeUnifiedMemoryReasoningStrategy(value, defaultStrategy = "none") {
303
- if (value === "rewrite" || value === "iterative") {
303
+ if (value === "rewrite" || value === "iterative" || value === "union") {
304
304
  return value;
305
305
  }
306
306
  return defaultStrategy;
@@ -1146,7 +1146,7 @@ function createUnifiedSearch(deps = {}) {
1146
1146
  return normalizeUnifiedMemoryReasoningStrategy(deps.reasoning?.defaultStrategy, "none");
1147
1147
  }
1148
1148
  async function runMemorySource(input, limit, threshold, warnings, reasoningStrategy = "none", reasoningInfo, peerPeers = []) {
1149
- if (reasoningStrategy === "iterative" && !deps.reasoning?.iterativePlanner) {
1149
+ if ((reasoningStrategy === "iterative" || reasoningStrategy === "union") && !deps.reasoning?.iterativePlanner) {
1150
1150
  warnings.push({
1151
1151
  source: "memory",
1152
1152
  code: "memory_iterative_planner_not_configured",
@@ -1162,7 +1162,8 @@ function createUnifiedSearch(deps = {}) {
1162
1162
  });
1163
1163
  if (reasoningInfo) reasoningInfo.degraded = true;
1164
1164
  }
1165
- if (reasoningStrategy === "iterative" && deps.reasoning?.iterativePlanner) {
1165
+ let unionEvidence = null;
1166
+ if ((reasoningStrategy === "iterative" || reasoningStrategy === "union") && deps.reasoning?.iterativePlanner) {
1166
1167
  const planner = deps.reasoning.iterativePlanner;
1167
1168
  const result = await planner.plan({
1168
1169
  query: input.query,
@@ -1219,14 +1220,17 @@ function createUnifiedSearch(deps = {}) {
1219
1220
  reasoningInfo.degraded = true;
1220
1221
  }
1221
1222
  }
1222
- const semantic2 = result.evidence.map((candidate) => ({
1223
+ const evidence = result.evidence.map((candidate) => ({
1223
1224
  type: "memory",
1224
1225
  id: candidate.id,
1225
1226
  content: candidate.content,
1226
1227
  similarity: candidate.similarity,
1227
- metadata: { ...candidate.metadata, reasoning: "iterative" }
1228
+ metadata: { ...candidate.metadata, reasoning: reasoningStrategy }
1228
1229
  }));
1229
- return { semantic: semantic2, lexical: [] };
1230
+ if (reasoningStrategy === "iterative") {
1231
+ return { semantic: evidence, lexical: [] };
1232
+ }
1233
+ unionEvidence = evidence;
1230
1234
  }
1231
1235
  if (typeof deps.embedQuery !== "function") {
1232
1236
  warnings.push({
@@ -1352,6 +1356,37 @@ function createUnifiedSearch(deps = {}) {
1352
1356
  message: "RRF merge requested but entity search is not configured; falling back to semantic+lexical RRF."
1353
1357
  });
1354
1358
  }
1359
+ if (unionEvidence) {
1360
+ const plannerHits = unionEvidence;
1361
+ const base = mergeByMaxScore([
1362
+ filterByDateRange(semantic, input.dateFrom, input.dateTo),
1363
+ filterByDateRange(lexical, input.dateFrom, input.dateTo)
1364
+ ]);
1365
+ const maxBase = base.length > 0 ? Math.max(...base.map((h) => h.similarity)) : 0;
1366
+ const seen = /* @__PURE__ */ new Set();
1367
+ const merged = [];
1368
+ plannerHits.forEach((hit, i) => {
1369
+ if (seen.has(hit.id)) {
1370
+ return;
1371
+ }
1372
+ seen.add(hit.id);
1373
+ merged.push({
1374
+ ...hit,
1375
+ similarity: maxBase + (plannerHits.length - i) * 1e-6
1376
+ });
1377
+ });
1378
+ for (const hit of base) {
1379
+ if (merged.length >= limit) {
1380
+ break;
1381
+ }
1382
+ if (seen.has(hit.id)) {
1383
+ continue;
1384
+ }
1385
+ seen.add(hit.id);
1386
+ merged.push(hit);
1387
+ }
1388
+ return { semantic: merged.slice(0, limit), lexical: [] };
1389
+ }
1355
1390
  const out = {
1356
1391
  semantic: filterByDateRange(semantic, input.dateFrom, input.dateTo),
1357
1392
  lexical: filterByDateRange(lexical, input.dateFrom, input.dateTo)
@@ -463,7 +463,7 @@ function normalizeUnifiedMemoryMergeStrategy(value) {
463
463
  return value === "rrf" ? "rrf" : "similarity";
464
464
  }
465
465
  function normalizeUnifiedMemoryReasoningStrategy(value, defaultStrategy = "none") {
466
- if (value === "rewrite" || value === "iterative") {
466
+ if (value === "rewrite" || value === "iterative" || value === "union") {
467
467
  return value;
468
468
  }
469
469
  return defaultStrategy;
@@ -1157,7 +1157,7 @@ function createUnifiedSearch(deps = {}) {
1157
1157
  return normalizeUnifiedMemoryReasoningStrategy(deps.reasoning?.defaultStrategy, "none");
1158
1158
  }
1159
1159
  async function runMemorySource(input, limit, threshold, warnings, reasoningStrategy = "none", reasoningInfo, peerPeers = []) {
1160
- if (reasoningStrategy === "iterative" && !deps.reasoning?.iterativePlanner) {
1160
+ if ((reasoningStrategy === "iterative" || reasoningStrategy === "union") && !deps.reasoning?.iterativePlanner) {
1161
1161
  warnings.push({
1162
1162
  source: "memory",
1163
1163
  code: "memory_iterative_planner_not_configured",
@@ -1173,7 +1173,8 @@ function createUnifiedSearch(deps = {}) {
1173
1173
  });
1174
1174
  if (reasoningInfo) reasoningInfo.degraded = true;
1175
1175
  }
1176
- if (reasoningStrategy === "iterative" && deps.reasoning?.iterativePlanner) {
1176
+ let unionEvidence = null;
1177
+ if ((reasoningStrategy === "iterative" || reasoningStrategy === "union") && deps.reasoning?.iterativePlanner) {
1177
1178
  const planner = deps.reasoning.iterativePlanner;
1178
1179
  const result = await planner.plan({
1179
1180
  query: input.query,
@@ -1230,14 +1231,17 @@ function createUnifiedSearch(deps = {}) {
1230
1231
  reasoningInfo.degraded = true;
1231
1232
  }
1232
1233
  }
1233
- const semantic2 = result.evidence.map((candidate) => ({
1234
+ const evidence = result.evidence.map((candidate) => ({
1234
1235
  type: "memory",
1235
1236
  id: candidate.id,
1236
1237
  content: candidate.content,
1237
1238
  similarity: candidate.similarity,
1238
- metadata: { ...candidate.metadata, reasoning: "iterative" }
1239
+ metadata: { ...candidate.metadata, reasoning: reasoningStrategy }
1239
1240
  }));
1240
- return { semantic: semantic2, lexical: [] };
1241
+ if (reasoningStrategy === "iterative") {
1242
+ return { semantic: evidence, lexical: [] };
1243
+ }
1244
+ unionEvidence = evidence;
1241
1245
  }
1242
1246
  if (typeof deps.embedQuery !== "function") {
1243
1247
  warnings.push({
@@ -1363,6 +1367,37 @@ function createUnifiedSearch(deps = {}) {
1363
1367
  message: "RRF merge requested but entity search is not configured; falling back to semantic+lexical RRF."
1364
1368
  });
1365
1369
  }
1370
+ if (unionEvidence) {
1371
+ const plannerHits = unionEvidence;
1372
+ const base = mergeByMaxScore([
1373
+ filterByDateRange(semantic, input.dateFrom, input.dateTo),
1374
+ filterByDateRange(lexical, input.dateFrom, input.dateTo)
1375
+ ]);
1376
+ const maxBase = base.length > 0 ? Math.max(...base.map((h) => h.similarity)) : 0;
1377
+ const seen = /* @__PURE__ */ new Set();
1378
+ const merged = [];
1379
+ plannerHits.forEach((hit, i) => {
1380
+ if (seen.has(hit.id)) {
1381
+ return;
1382
+ }
1383
+ seen.add(hit.id);
1384
+ merged.push({
1385
+ ...hit,
1386
+ similarity: maxBase + (plannerHits.length - i) * 1e-6
1387
+ });
1388
+ });
1389
+ for (const hit of base) {
1390
+ if (merged.length >= limit) {
1391
+ break;
1392
+ }
1393
+ if (seen.has(hit.id)) {
1394
+ continue;
1395
+ }
1396
+ seen.add(hit.id);
1397
+ merged.push(hit);
1398
+ }
1399
+ return { semantic: merged.slice(0, limit), lexical: [] };
1400
+ }
1366
1401
  const out = {
1367
1402
  semantic: filterByDateRange(semantic, input.dateFrom, input.dateTo),
1368
1403
  lexical: filterByDateRange(lexical, input.dateFrom, input.dateTo)
@@ -2191,7 +2226,7 @@ async function startHttpServer(options = {}) {
2191
2226
  authToken: typeof body.authToken === "string" ? body.authToken : void 0,
2192
2227
  dateFrom: typeof body.dateFrom === "string" ? body.dateFrom : void 0,
2193
2228
  dateTo: typeof body.dateTo === "string" ? body.dateTo : void 0,
2194
- reasoningStrategy: body.reasoningStrategy === "rewrite" || body.reasoningStrategy === "iterative" ? body.reasoningStrategy : void 0,
2229
+ reasoningStrategy: body.reasoningStrategy === "rewrite" || body.reasoningStrategy === "iterative" || body.reasoningStrategy === "union" ? body.reasoningStrategy : void 0,
2195
2230
  ...wantsSynthesis ? {
2196
2231
  synthesize: {
2197
2232
  ...responseSchema ? { responseSchema } : {}
@@ -464,7 +464,7 @@ function normalizeUnifiedMemoryMergeStrategy(value) {
464
464
  return value === "rrf" ? "rrf" : "similarity";
465
465
  }
466
466
  function normalizeUnifiedMemoryReasoningStrategy(value, defaultStrategy = "none") {
467
- if (value === "rewrite" || value === "iterative") {
467
+ if (value === "rewrite" || value === "iterative" || value === "union") {
468
468
  return value;
469
469
  }
470
470
  return defaultStrategy;
@@ -1158,7 +1158,7 @@ function createUnifiedSearch(deps = {}) {
1158
1158
  return normalizeUnifiedMemoryReasoningStrategy(deps.reasoning?.defaultStrategy, "none");
1159
1159
  }
1160
1160
  async function runMemorySource(input, limit, threshold, warnings, reasoningStrategy = "none", reasoningInfo, peerPeers = []) {
1161
- if (reasoningStrategy === "iterative" && !deps.reasoning?.iterativePlanner) {
1161
+ if ((reasoningStrategy === "iterative" || reasoningStrategy === "union") && !deps.reasoning?.iterativePlanner) {
1162
1162
  warnings.push({
1163
1163
  source: "memory",
1164
1164
  code: "memory_iterative_planner_not_configured",
@@ -1174,7 +1174,8 @@ function createUnifiedSearch(deps = {}) {
1174
1174
  });
1175
1175
  if (reasoningInfo) reasoningInfo.degraded = true;
1176
1176
  }
1177
- if (reasoningStrategy === "iterative" && deps.reasoning?.iterativePlanner) {
1177
+ let unionEvidence = null;
1178
+ if ((reasoningStrategy === "iterative" || reasoningStrategy === "union") && deps.reasoning?.iterativePlanner) {
1178
1179
  const planner = deps.reasoning.iterativePlanner;
1179
1180
  const result = await planner.plan({
1180
1181
  query: input.query,
@@ -1231,14 +1232,17 @@ function createUnifiedSearch(deps = {}) {
1231
1232
  reasoningInfo.degraded = true;
1232
1233
  }
1233
1234
  }
1234
- const semantic2 = result.evidence.map((candidate) => ({
1235
+ const evidence = result.evidence.map((candidate) => ({
1235
1236
  type: "memory",
1236
1237
  id: candidate.id,
1237
1238
  content: candidate.content,
1238
1239
  similarity: candidate.similarity,
1239
- metadata: { ...candidate.metadata, reasoning: "iterative" }
1240
+ metadata: { ...candidate.metadata, reasoning: reasoningStrategy }
1240
1241
  }));
1241
- return { semantic: semantic2, lexical: [] };
1242
+ if (reasoningStrategy === "iterative") {
1243
+ return { semantic: evidence, lexical: [] };
1244
+ }
1245
+ unionEvidence = evidence;
1242
1246
  }
1243
1247
  if (typeof deps.embedQuery !== "function") {
1244
1248
  warnings.push({
@@ -1364,6 +1368,37 @@ function createUnifiedSearch(deps = {}) {
1364
1368
  message: "RRF merge requested but entity search is not configured; falling back to semantic+lexical RRF."
1365
1369
  });
1366
1370
  }
1371
+ if (unionEvidence) {
1372
+ const plannerHits = unionEvidence;
1373
+ const base = mergeByMaxScore([
1374
+ filterByDateRange(semantic, input.dateFrom, input.dateTo),
1375
+ filterByDateRange(lexical, input.dateFrom, input.dateTo)
1376
+ ]);
1377
+ const maxBase = base.length > 0 ? Math.max(...base.map((h) => h.similarity)) : 0;
1378
+ const seen = /* @__PURE__ */ new Set();
1379
+ const merged = [];
1380
+ plannerHits.forEach((hit, i) => {
1381
+ if (seen.has(hit.id)) {
1382
+ return;
1383
+ }
1384
+ seen.add(hit.id);
1385
+ merged.push({
1386
+ ...hit,
1387
+ similarity: maxBase + (plannerHits.length - i) * 1e-6
1388
+ });
1389
+ });
1390
+ for (const hit of base) {
1391
+ if (merged.length >= limit) {
1392
+ break;
1393
+ }
1394
+ if (seen.has(hit.id)) {
1395
+ continue;
1396
+ }
1397
+ seen.add(hit.id);
1398
+ merged.push(hit);
1399
+ }
1400
+ return { semantic: merged.slice(0, limit), lexical: [] };
1401
+ }
1367
1402
  const out = {
1368
1403
  semantic: filterByDateRange(semantic, input.dateFrom, input.dateTo),
1369
1404
  lexical: filterByDateRange(lexical, input.dateFrom, input.dateTo)
@@ -2166,8 +2201,8 @@ async function startMcpServer(options = {}) {
2166
2201
  tiers: z.array(z.enum(["summary", "raw", "insight", "knowledge"])).optional().describe(
2167
2202
  "Per-tier evidence scope for synthesis. Default: ['summary','raw','insight','knowledge']. Ignored when `synthesize` is falsy."
2168
2203
  ),
2169
- reasoningStrategy: z.enum(["none", "rewrite", "iterative"]).optional().describe(
2170
- "LLM reasoning strategy. `rewrite` rephrases the query before embedding; `iterative` runs a planner that searches, notes evidence, and searches again. Requires `unified.reasoning.{queryRewriter,iterativePlanner}` to be wired into the server."
2204
+ reasoningStrategy: z.enum(["none", "rewrite", "iterative", "union"]).optional().describe(
2205
+ "LLM reasoning strategy. `rewrite` rephrases the query before embedding; `iterative` runs a planner that searches, notes evidence, and searches again; `union` merges the planner's evidence with the baseline top-k hits (evidence first, deduped, capped at limit). Requires `unified.reasoning.{queryRewriter,iterativePlanner}` to be wired into the server."
2171
2206
  ),
2172
2207
  synthesize: z.union([z.boolean(), z.object({ responseSchema: z.record(z.string(), z.unknown()).optional() })]).optional().describe(
2173
2208
  "Opt-in LLM synthesis. `true` returns `{ answer, evidence, results, warnings }`. `synthesize.responseSchema` extracts `answer` from a JSON payload."
@@ -2244,7 +2279,7 @@ async function startMcpServer(options = {}) {
2244
2279
  documentIds: a.documentIds,
2245
2280
  authToken: a.authToken,
2246
2281
  includeArchivedInsights: a.includeArchivedInsights,
2247
- reasoningStrategy: a.reasoningStrategy === "rewrite" || a.reasoningStrategy === "iterative" ? a.reasoningStrategy : void 0,
2282
+ reasoningStrategy: a.reasoningStrategy === "rewrite" || a.reasoningStrategy === "iterative" || a.reasoningStrategy === "union" ? a.reasoningStrategy : void 0,
2248
2283
  ...a.tiers ? { tiers: a.tiers } : {},
2249
2284
  ...wantsSynthesis ? {
2250
2285
  synthesize: {
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { U as UnifiedSearchDeps } from '../config-DfvVZ--0.js';
2
+ import { U as UnifiedSearchDeps } from '../config-Dw4aXj2a.js';
3
3
  import '@melandlabs/memory-consolidation';
4
4
  import '@melandlabs/contracts/peer';
5
5
  import '@melandlabs/contracts';
@@ -1,4 +1,4 @@
1
- import { a as MemoryStoreEnv } from '../config-DfvVZ--0.js';
1
+ import { a as MemoryStoreEnv } from '../config-Dw4aXj2a.js';
2
2
  import '@melandlabs/memory-consolidation';
3
3
  import '@melandlabs/contracts/peer';
4
4
  import '@melandlabs/contracts';
@@ -1,5 +1,5 @@
1
1
  import { RawMessageStorageManager } from '@melandlabs/indexeddb';
2
- import { a as MemoryStoreEnv, M as MemoryStoreConfig } from '../config-DfvVZ--0.js';
2
+ import { a as MemoryStoreEnv, M as MemoryStoreConfig } from '../config-Dw4aXj2a.js';
3
3
  import '@melandlabs/memory-consolidation';
4
4
  import '@melandlabs/contracts/peer';
5
5
  import '@melandlabs/contracts';
@@ -1,5 +1,5 @@
1
1
  import { SQLiteRawMessageManager } from '@melandlabs/sqlite';
2
- import { a as MemoryStoreEnv } from '../config-DfvVZ--0.js';
2
+ import { a as MemoryStoreEnv } from '../config-Dw4aXj2a.js';
3
3
  import '@melandlabs/memory-consolidation';
4
4
  import '@melandlabs/contracts/peer';
5
5
  import '@melandlabs/contracts';
@@ -1,5 +1,5 @@
1
1
  import { VectorSearchResult } from '@melandlabs/rag/vector-service';
2
- import { a as MemoryStoreEnv } from '../config-DfvVZ--0.js';
2
+ import { a as MemoryStoreEnv } from '../config-Dw4aXj2a.js';
3
3
  import '@melandlabs/memory-consolidation';
4
4
  import '@melandlabs/contracts/peer';
5
5
  import '@melandlabs/contracts';
@@ -1,4 +1,4 @@
1
- import { S as SearchTier, b as UnifiedMemorySearchWarning, c as SearchEvidence, U as UnifiedSearchDeps, d as SearchInput, e as SearchOutput, f as UnifiedMemorySearchInput, g as UnifiedMemorySearchOutput, h as UnifiedMemorySearchResult } from './config-DfvVZ--0.js';
1
+ import { S as SearchTier, b as UnifiedMemorySearchWarning, c as SearchEvidence, U as UnifiedSearchDeps, d as SearchInput, e as SearchOutput, f as UnifiedMemorySearchInput, g as UnifiedMemorySearchOutput, h as UnifiedMemorySearchResult } from './config-Dw4aXj2a.js';
2
2
  import { MemoryStorageAdapter } from '@melandlabs/ai/memory';
3
3
  import { Peer } from '@melandlabs/contracts/peer';
4
4
  import { OwnerScope, MemoryConsolidationPlan, ReflectApplyClusterKeyFn, MemoryStorageAdapterLike, MemoryGraphStoreWithOperationHistory, MemoryGraphUpdateResult } from '@melandlabs/memory-consolidation';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@melandlabs/memory-store",
3
- "version": "1.2.3",
3
+ "version": "1.2.5",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist",
@@ -60,15 +60,15 @@
60
60
  "@modelcontextprotocol/sdk": "^1.25.3",
61
61
  "hono": "^4.6.14",
62
62
  "zod": "^4.3.6",
63
- "@melandlabs/contracts": "0.7.0",
64
- "@melandlabs/ai": "0.10.1",
65
63
  "@melandlabs/env-config": "0.4.0",
66
- "@melandlabs/okf": "0.3.1",
64
+ "@melandlabs/contracts": "0.7.0",
67
65
  "@melandlabs/memory-consolidation": "0.5.2",
66
+ "@melandlabs/okf": "0.3.1",
67
+ "@melandlabs/shared": "0.4.0",
68
+ "@melandlabs/ai": "0.10.3",
68
69
  "@melandlabs/rag": "0.3.0",
69
70
  "@melandlabs/sqlite": "0.5.2",
70
- "@melandlabs/vsa": "0.3.0",
71
- "@melandlabs/shared": "0.4.0"
71
+ "@melandlabs/vsa": "0.3.0"
72
72
  },
73
73
  "peerDependencies": {
74
74
  "@melandlabs/ai-rag": "0.2.9",