@inupedia/spotlight-memory 0.2.5 → 0.2.7

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.
Files changed (43) hide show
  1. package/dist/node/exactStore.d.ts +9 -3
  2. package/dist/node/exactStore.d.ts.map +1 -1
  3. package/dist/node/exactStore.js +20 -4
  4. package/dist/node/gate.d.ts +5 -1
  5. package/dist/node/gate.d.ts.map +1 -1
  6. package/dist/node/gate.js +37 -29
  7. package/dist/node/index.d.ts +19 -12
  8. package/dist/node/index.d.ts.map +1 -1
  9. package/dist/node/index.js +93 -40
  10. package/dist/node/memoryBackends.d.ts +6 -0
  11. package/dist/node/memoryBackends.d.ts.map +1 -1
  12. package/dist/node/memoryBackends.js +19 -0
  13. package/dist/node/memoryEntryScope.d.ts +19 -0
  14. package/dist/node/memoryEntryScope.d.ts.map +1 -0
  15. package/dist/node/memoryEntryScope.js +28 -0
  16. package/dist/node/memoryLog.d.ts +2 -0
  17. package/dist/node/memoryLog.d.ts.map +1 -0
  18. package/dist/node/memoryLog.js +7 -0
  19. package/dist/node/memoryStoreTypes.d.ts +15 -0
  20. package/dist/node/memoryStoreTypes.d.ts.map +1 -0
  21. package/dist/node/memoryStoreTypes.js +1 -0
  22. package/dist/node/meta.d.ts +6 -2
  23. package/dist/node/meta.d.ts.map +1 -1
  24. package/dist/node/meta.js +9 -3
  25. package/dist/node/milvusClient.d.ts +1 -1
  26. package/dist/node/milvusClient.d.ts.map +1 -1
  27. package/dist/node/milvusClient.js +1 -1
  28. package/dist/node/milvusExpr.d.ts +16 -0
  29. package/dist/node/milvusExpr.d.ts.map +1 -0
  30. package/dist/node/milvusExpr.js +30 -0
  31. package/dist/node/milvusSemanticStore.d.ts +13 -8
  32. package/dist/node/milvusSemanticStore.d.ts.map +1 -1
  33. package/dist/node/milvusSemanticStore.js +200 -55
  34. package/dist/node/paths.d.ts +6 -2
  35. package/dist/node/paths.d.ts.map +1 -1
  36. package/dist/node/paths.js +2 -1
  37. package/dist/node/redisExactStore.d.ts +4 -3
  38. package/dist/node/redisExactStore.d.ts.map +1 -1
  39. package/dist/node/redisExactStore.js +72 -11
  40. package/dist/node/semanticStore.d.ts +7 -6
  41. package/dist/node/semanticStore.d.ts.map +1 -1
  42. package/dist/node/semanticStore.js +14 -5
  43. package/package.json +2 -2
@@ -20,9 +20,15 @@ export declare class ExactMemoryStore {
20
20
  hasExact(cacheKey: string): Promise<boolean>;
21
21
  putExact(cacheKey: string, entry: SpotlightMemoryEntry): Promise<void>;
22
22
  touch(entryId: string): Promise<void>;
23
- listEntries(limit?: number): SpotlightMemoryEntry[];
24
- deleteEntry(entryId: string): boolean;
25
- deleteAll(projectId: string): number;
23
+ listEntries(limit?: number): Promise<SpotlightMemoryEntry[]>;
24
+ listEntriesSync(limit?: number): SpotlightMemoryEntry[];
25
+ deleteEntry(entryId: string): Promise<boolean>;
26
+ deleteEntrySync(entryId: string): boolean;
27
+ deleteAll(projectId: string): Promise<number>;
28
+ deleteAllSync(projectId: string): number;
29
+ count(): Promise<number>;
30
+ /** @deprecated use async count() */
31
+ countSync(): number;
26
32
  private rewriteEntriesFile;
27
33
  }
28
34
  //# sourceMappingURL=exactStore.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"exactStore.d.ts","sourceRoot":"","sources":["../../src/node/exactStore.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACzE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAIlD,MAAM,WAAW,uBAAuB;IACtC,KAAK,EAAE,eAAe,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,uEAAuE;AACvE,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAkB;IACxC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,KAAK,CAAkB;IAC/B,OAAO,CAAC,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CAAC,YAAY;IAyBpB,OAAO,CAAC,YAAY;IASpB,OAAO,CAAC,WAAW;IASnB,OAAO,CAAC,QAAQ;IAcV,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC;IAQhE,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAI5C,QAAQ,CACZ,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,oBAAoB,GAC1B,OAAO,CAAC,IAAI,CAAC;IAQV,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAOrC,WAAW,CAAC,KAAK,SAAK,GAAG,OAAO,CAAC,oBAAoB,EAAE,CAAC;IAI9D,eAAe,CAAC,KAAK,SAAK,GAAG,oBAAoB,EAAE;IAQ7C,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAIpD,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAYnC,SAAS,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAInD,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM;IAWlC,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC;IAI9B,oCAAoC;IACpC,SAAS,IAAI,MAAM;IAInB,OAAO,CAAC,kBAAkB;CAS3B"}
@@ -84,13 +84,19 @@ export class ExactMemoryStore {
84
84
  entry.hitCount += 1;
85
85
  entry.lastHitAt = Date.now();
86
86
  }
87
- listEntries(limit = 50) {
87
+ async listEntries(limit = 50) {
88
+ return this.listEntriesSync(limit);
89
+ }
90
+ listEntriesSync(limit = 50) {
88
91
  const safeLimit = Number.isFinite(limit) && limit > 0 ? Math.min(500, Math.floor(limit)) : 50;
89
92
  return [...this.entries.values()]
90
93
  .sort((a, b) => b.createdAt - a.createdAt)
91
94
  .slice(0, safeLimit);
92
95
  }
93
- deleteEntry(entryId) {
96
+ async deleteEntry(entryId) {
97
+ return this.deleteEntrySync(entryId);
98
+ }
99
+ deleteEntrySync(entryId) {
94
100
  if (!this.entries.has(entryId))
95
101
  return false;
96
102
  this.entries.delete(entryId);
@@ -103,17 +109,27 @@ export class ExactMemoryStore {
103
109
  this.rewriteEntriesFile();
104
110
  return true;
105
111
  }
106
- deleteAll(projectId) {
112
+ async deleteAll(projectId) {
113
+ return this.deleteAllSync(projectId);
114
+ }
115
+ deleteAllSync(projectId) {
107
116
  const ids = [...this.entries.values()]
108
117
  .filter((entry) => entry.projectId === projectId)
109
118
  .map((entry) => entry.id);
110
119
  let removed = 0;
111
120
  for (const entryId of ids) {
112
- if (this.deleteEntry(entryId))
121
+ if (this.deleteEntrySync(entryId))
113
122
  removed += 1;
114
123
  }
115
124
  return removed;
116
125
  }
126
+ async count() {
127
+ return this.entries.size;
128
+ }
129
+ /** @deprecated use async count() */
130
+ countSync() {
131
+ return this.entries.size;
132
+ }
117
133
  rewriteEntriesFile() {
118
134
  mkdirSync(this.paths.exactDir, { recursive: true });
119
135
  const lines = [...this.entries.values()].map((entry) => JSON.stringify(entry));
@@ -1,7 +1,11 @@
1
1
  import { type SpotlightMemoryGateResult, type SpotlightMemoryLookupInput, type SpotlightMemoryWriteInput, type SpotlightMemoryWriteResult } from "@inupedia/spotlight-protocol";
2
+ import type { MemoryEntryScope } from "./memoryEntryScope.js";
2
3
  export interface MemoryStoreReader {
3
4
  getExact(cacheKey: string): Promise<import("@inupedia/spotlight-protocol").SpotlightMemoryEntry | null>;
4
- findSemantic(projectId: string, questionNorm: string, limit?: number): Promise<Array<{
5
+ findSemantic(projectId: string, questionNorm: string, limit?: number, lookupScopes?: Array<{
6
+ scope: MemoryEntryScope;
7
+ sessionId?: string;
8
+ }>): Promise<Array<{
5
9
  entry: import("@inupedia/spotlight-protocol").SpotlightMemoryEntry;
6
10
  score: number;
7
11
  }>>;
@@ -1 +1 @@
1
- {"version":3,"file":"gate.d.ts","sourceRoot":"","sources":["../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Q,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAC9C;AAED,MAAM,WAAW,gBAAgB;IAC/B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED,MAAM,WAAW,UAAU;IACzB,MAAM,CAAC,KAAK,EAAE,0BAA0B,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAAC;IAC9E,KAAK,CAAC,KAAK,EAAE,yBAAyB,GAAG,OAAO,CAAC,0BAA0B,CAAC,CAAC;CAC9E;AAqDD,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,iBAAiB,EACzB,MAAM,EAAE,iBAAiB,EACzB,MAAM,GAAE,gBAAqB,GAC5B,UAAU,CAyJZ"}
package/dist/node/gate.js CHANGED
@@ -18,16 +18,12 @@ function resolveLookupScopes(input) {
18
18
  return [{ scope: "project" }];
19
19
  return [{ scope: "session", sessionId }, { scope: "project" }];
20
20
  }
21
- function entryMatchesLookupScope(entry, scopes) {
22
- const scopedEntry = entry;
23
- const entryScope = scopedEntry.scope ?? "project";
24
- return scopes.some((scope) => {
25
- if (scope.scope !== entryScope)
26
- return false;
27
- if (entryScope === "session")
28
- return scopedEntry.sessionId === scope.sessionId;
29
- return true;
30
- });
21
+ function pickViableSemanticHit(candidates, params) {
22
+ const viable = candidates
23
+ .filter((candidate) => candidate.score >= params.threshold)
24
+ .filter((candidate) => !isMemoryEntryStale(candidate.entry, params.invalidation))
25
+ .filter((candidate) => isMemoryKindAllowedForRead(candidate.entry.kind));
26
+ return viable[0] ?? null;
31
27
  }
32
28
  export function createMemoryGate(reader, writer, config = {}) {
33
29
  const enabled = config.enabled ?? true;
@@ -57,7 +53,7 @@ export function createMemoryGate(reader, writer, config = {}) {
57
53
  const exact = await reader.getExact(cacheKey);
58
54
  if (exact) {
59
55
  if (isMemoryEntryStale(exact, input.invalidation)) {
60
- return finishMiss("stale");
56
+ continue;
61
57
  }
62
58
  if (!isMemoryKindAllowedForRead(exact.kind)) {
63
59
  return finishMiss("kind_blocked");
@@ -75,27 +71,39 @@ export function createMemoryGate(reader, writer, config = {}) {
75
71
  }
76
72
  }
77
73
  if (!input.exactOnly && semanticEnabled) {
78
- const semantic = (await reader.findSemantic(input.projectId, questionNorm, 20)).filter((candidate) => entryMatchesLookupScope(candidate.entry, lookupScopes));
79
- const top = semantic.find((c) => c.score >= semanticThreshold);
80
- if (top) {
81
- if (isMemoryEntryStale(top.entry, input.invalidation)) {
82
- return finishMiss("stale");
74
+ let bestScore = 0;
75
+ let sawStaleAboveThreshold = false;
76
+ for (const scope of lookupScopes) {
77
+ const semantic = await reader.findSemantic(input.projectId, questionNorm, 20, [scope]);
78
+ const top = pickViableSemanticHit(semantic, {
79
+ threshold: semanticThreshold,
80
+ invalidation: input.invalidation,
81
+ });
82
+ if (top) {
83
+ await reader.touch(top.entry.id);
84
+ return {
85
+ hit: true,
86
+ result: {
87
+ source: "semantic",
88
+ entry: top.entry,
89
+ confidence: top.score,
90
+ lookupLatencyMs: performance.now() - started,
91
+ },
92
+ };
83
93
  }
84
- if (!isMemoryKindAllowedForRead(top.entry.kind)) {
85
- return finishMiss("kind_blocked");
94
+ for (const candidate of semantic) {
95
+ if (candidate.score > bestScore)
96
+ bestScore = candidate.score;
97
+ if (candidate.score >= semanticThreshold &&
98
+ isMemoryEntryStale(candidate.entry, input.invalidation)) {
99
+ sawStaleAboveThreshold = true;
100
+ }
86
101
  }
87
- await reader.touch(top.entry.id);
88
- return {
89
- hit: true,
90
- result: {
91
- source: "semantic",
92
- entry: top.entry,
93
- confidence: top.score,
94
- lookupLatencyMs: performance.now() - started,
95
- },
96
- };
97
102
  }
98
- if (semantic.length && semantic[0].score < semanticThreshold) {
103
+ if (sawStaleAboveThreshold) {
104
+ return finishMiss("stale");
105
+ }
106
+ if (bestScore > 0 && bestScore < semanticThreshold) {
99
107
  return finishMiss("below_threshold");
100
108
  }
101
109
  }
@@ -1,26 +1,30 @@
1
1
  import type { SpotlightMemoryEntry } from "@inupedia/spotlight-protocol";
2
2
  import type { MemoryGate } from "./gate.js";
3
3
  import { type MemoryGateConfig } from "./gate.js";
4
+ import { type ExactMemoryBackend, type SemanticMemoryBackend } from "./memoryBackends.js";
4
5
  import { type PackMemoryPaths } from "./paths.js";
6
+ import type { SemanticLookupOptions, SemanticWriteResult } from "./memoryStoreTypes.js";
5
7
  export interface SemanticMemoryStoreLike {
6
- findSimilar(projectId: string, questionNorm: string, limit?: number): Promise<Array<{
8
+ findSimilar(projectId: string, questionNorm: string, limit?: number, options?: SemanticLookupOptions): Promise<Array<{
7
9
  entry: SpotlightMemoryEntry;
8
10
  score: number;
9
11
  }>>;
10
- putWithOptionalEmbedding(entry: SpotlightMemoryEntry): Promise<void>;
12
+ putWithOptionalEmbedding(entry: SpotlightMemoryEntry): Promise<SemanticWriteResult>;
11
13
  touch(entryId: string): void | Promise<void>;
12
- count(projectId?: string): number;
13
- deleteEntry(entryId: string): boolean;
14
- deleteAll(projectId: string): number;
14
+ count(projectId?: string): number | Promise<number>;
15
+ listEntries(limit?: number): SpotlightMemoryEntry[] | Promise<SpotlightMemoryEntry[]>;
16
+ deleteEntry(entryId: string): boolean | Promise<boolean>;
17
+ deleteAll(projectId: string): number | Promise<number>;
15
18
  }
16
19
  export interface ExactMemoryStoreLike {
17
20
  getExact(cacheKey: string): Promise<SpotlightMemoryEntry | null>;
18
21
  putExact(cacheKey: string, entry: SpotlightMemoryEntry): Promise<void>;
19
22
  hasExact(cacheKey: string): Promise<boolean>;
20
23
  touch(entryId: string): Promise<void>;
21
- listEntries(limit?: number): SpotlightMemoryEntry[];
22
- deleteEntry(entryId: string): boolean;
23
- deleteAll(projectId: string): number;
24
+ listEntries(limit?: number): SpotlightMemoryEntry[] | Promise<SpotlightMemoryEntry[]>;
25
+ deleteEntry(entryId: string): boolean | Promise<boolean>;
26
+ deleteAll(projectId: string): number | Promise<number>;
27
+ count?(projectId?: string): number | Promise<number>;
24
28
  }
25
29
  export interface PackMemoryStores {
26
30
  paths: PackMemoryPaths;
@@ -28,8 +32,9 @@ export interface PackMemoryStores {
28
32
  semantic: SemanticMemoryStoreLike;
29
33
  gate: MemoryGate;
30
34
  backends: {
31
- exact: "file" | "redis";
32
- semantic: "sqlite" | "milvus";
35
+ exact: ExactMemoryBackend;
36
+ semantic: SemanticMemoryBackend;
37
+ countsAvailable: boolean;
33
38
  };
34
39
  }
35
40
  export declare function createPackMemoryStores(params: {
@@ -41,9 +46,9 @@ export declare function createPackMemoryStores(params: {
41
46
  }): PackMemoryStores;
42
47
  export { ExactMemoryStore } from "./exactStore.js";
43
48
  export { SemanticMemoryStore } from "./semanticStore.js";
44
- export { MilvusSemanticMemoryStore } from "./milvusSemanticStore.js";
49
+ export { MilvusSemanticMemoryStore, isMilvusEmbeddingReady, validateMilvusEmbedding, } from "./milvusSemanticStore.js";
45
50
  export { RedisExactMemoryStore } from "./redisExactStore.js";
46
- export { resolveExactMemoryBackend, resolveSemanticMemoryBackend, } from "./memoryBackends.js";
51
+ export { resolveExactMemoryBackend, resolveSemanticMemoryBackend, resolveEffectiveSemanticMemoryBackend, isRemoteMemoryBackend, } from "./memoryBackends.js";
47
52
  export { buildCacheKey, createMemoryEntryId, } from "./cacheKey.js";
48
53
  export { createMemoryGate, type MemoryGate, type MemoryGateConfig, type MemoryStoreReader, type MemoryStoreWriter, } from "./gate.js";
49
54
  export { defaultPackMemoryMeta, resolvePackMemoryDir, type PackMemoryMeta, type PackMemoryPaths, } from "./paths.js";
@@ -51,5 +56,7 @@ export { readPackMemoryMeta, refreshPackMemoryMeta, writePackMemoryMeta, } from
51
56
  export { type EmbeddingProvider, resolveEmbeddingProviderFromEnv, } from "./embeddingProvider.js";
52
57
  export { getSpotlightRedisClient, isSpotlightRedisConfigured, spotlightRedisKey, } from "./redisClient.js";
53
58
  export { getSpotlightMilvusClient, isSpotlightMilvusConfigured, resolveSpotlightMilvusDb, SPOTLIGHT_MILVUS_SEMANTIC_COLLECTION, } from "./milvusClient.js";
59
+ export type { SemanticLookupOptions, SemanticWriteResult, } from "./memoryStoreTypes.js";
60
+ export { resolveMemoryEntryScopeFields, entryMatchesLookupScopes, isMemoryEntryExpired, } from "./memoryEntryScope.js";
54
61
  export { FILE_MEMORY_ENTRYPOINT, appendSpotlightFileMemory, buildSpotlightFileMemoryPrompt, ensureSpotlightFileMemoryEntrypoints, isSpotlightFileMemoryPath, loadSpotlightFileMemories, resolveAgentMemoryDir, resolveAgentMemoryEntrypoint, resolveSpotlightFileMemoryPaths, type BuildSpotlightFileMemoryPromptOptions, type LoadSpotlightFileMemoryOptions, type ResolveSpotlightFileMemoryPathsOptions, type SpotlightFileMemoryInfo, type SpotlightFileMemoryPaths, type SpotlightFileMemoryScope, } from "./fileMemory.js";
55
62
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACzE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAoB,KAAK,gBAAgB,EAAE,MAAM,WAAW,CAAC;AASpE,OAAO,EAAwB,KAAK,eAAe,EAAE,MAAM,YAAY,CAAC;AAIxE,MAAM,WAAW,uBAAuB;IACtC,WAAW,CACT,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,MAAM,EACpB,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC,KAAK,CAAC;QAAE,KAAK,EAAE,oBAAoB,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC,CAAC;IAClE,wBAAwB,CAAC,KAAK,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACrE,KAAK,CAAC,OAA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sBAAsB,EACtB,yBAAyB,EACzB,8BAA8B,EAC9B,oCAAoC,EACpC,yBAAyB,EACzB,yBAAyB,EACzB,qBAAqB,EACrB,4BAA4B,EAC5B,+BAA+B,EAC/B,KAAK,qCAAqC,EAC1C,KAAK,8BAA8B,EACnC,KAAK,sCAAsC,EAC3C,KAAK,uBAAuB,EAC5B,KAAK,wBAAwB,EAC7B,KAAK,wBAAwB,GAC9B,MAAM,iBAAiB,CAAC"}
@@ -1,15 +1,42 @@
1
1
  import { createMemoryGate } from "./gate.js";
2
2
  import { ExactMemoryStore } from "./exactStore.js";
3
3
  import { refreshPackMemoryMeta } from "./meta.js";
4
- import { resolveExactMemoryBackend, resolveSemanticMemoryBackend, } from "./memoryBackends.js";
4
+ import { isRemoteMemoryBackend, resolveEffectiveSemanticMemoryBackend, resolveExactMemoryBackend, } from "./memoryBackends.js";
5
5
  import { MilvusSemanticMemoryStore } from "./milvusSemanticStore.js";
6
6
  import { resolvePackMemoryDir } from "./paths.js";
7
7
  import { RedisExactMemoryStore } from "./redisExactStore.js";
8
8
  import { SemanticMemoryStore } from "./semanticStore.js";
9
- function createCompositeMemoryStores(paths, exact, semantic, projectId) {
9
+ import { logMemoryEvent } from "./memoryLog.js";
10
+ async function resolveStoreCount(store, projectId) {
11
+ if (!store.count)
12
+ return 0;
13
+ return Promise.resolve(store.count(projectId));
14
+ }
15
+ async function refreshLocalMetaIfAvailable(params) {
16
+ if (!params.backends.countsAvailable) {
17
+ refreshPackMemoryMeta({
18
+ paths: params.paths,
19
+ exactBackend: params.backends.exact,
20
+ semanticBackend: params.backends.semantic,
21
+ countsAvailable: false,
22
+ });
23
+ return;
24
+ }
25
+ refreshPackMemoryMeta({
26
+ paths: params.paths,
27
+ exactCount: (await Promise.resolve(params.exact.listEntries(Number.MAX_SAFE_INTEGER))).length,
28
+ semanticCount: await resolveStoreCount(params.semantic, params.projectId),
29
+ exactBackend: params.backends.exact,
30
+ semanticBackend: params.backends.semantic,
31
+ countsAvailable: true,
32
+ });
33
+ }
34
+ function createCompositeMemoryStores(paths, exact, semantic, projectId, backends) {
10
35
  const reader = {
11
36
  getExact: (cacheKey) => exact.getExact(cacheKey),
12
- findSemantic: (pid, questionNorm, limit) => semantic.findSimilar(pid, questionNorm, limit),
37
+ findSemantic: (pid, questionNorm, limit, lookupScopes) => semantic.findSimilar(pid, questionNorm, limit, {
38
+ scopes: lookupScopes,
39
+ }),
13
40
  touch: async (entryId) => {
14
41
  await exact.touch(entryId);
15
42
  await semantic.touch(entryId);
@@ -18,11 +45,23 @@ function createCompositeMemoryStores(paths, exact, semantic, projectId) {
18
45
  const writer = {
19
46
  putExact: (cacheKey, entry) => exact.putExact(cacheKey, entry),
20
47
  putSemantic: async (entry) => {
21
- await semantic.putWithOptionalEmbedding(entry);
22
- refreshPackMemoryMeta({
48
+ const result = await semantic.putWithOptionalEmbedding(entry);
49
+ if (!result.written) {
50
+ logMemoryEvent("semantic_write_skipped", {
51
+ projectId: entry.projectId,
52
+ entryId: entry.id,
53
+ reason: result.skippedReason,
54
+ exactBackend: backends.exact,
55
+ semanticBackend: backends.semantic,
56
+ });
57
+ return;
58
+ }
59
+ await refreshLocalMetaIfAvailable({
23
60
  paths,
24
- exactCount: exact.listEntries(Number.MAX_SAFE_INTEGER).length,
25
- semanticCount: semantic.count(projectId),
61
+ exact,
62
+ semantic,
63
+ projectId,
64
+ backends,
26
65
  });
27
66
  },
28
67
  hasExact: (cacheKey) => exact.hasExact(cacheKey),
@@ -32,69 +71,82 @@ function createCompositeMemoryStores(paths, exact, semantic, projectId) {
32
71
  function createExactStore(params) {
33
72
  const backend = resolveExactMemoryBackend();
34
73
  if (backend === "redis" && RedisExactMemoryStore.isAvailable()) {
35
- return new RedisExactMemoryStore({
36
- projectId: params.projectId,
37
- tenantId: params.tenantId,
38
- lruMax: params.lruMax,
39
- });
74
+ return {
75
+ backend: "redis",
76
+ store: new RedisExactMemoryStore({
77
+ projectId: params.projectId,
78
+ tenantId: params.tenantId,
79
+ lruMax: params.lruMax,
80
+ }),
81
+ };
40
82
  }
41
- return new ExactMemoryStore({
42
- paths: params.paths,
43
- lruMax: params.lruMax,
44
- });
83
+ return {
84
+ backend: "file",
85
+ store: new ExactMemoryStore({
86
+ paths: params.paths,
87
+ lruMax: params.lruMax,
88
+ }),
89
+ };
45
90
  }
46
91
  function createSemanticStore(params) {
47
- const backend = resolveSemanticMemoryBackend();
92
+ const backend = resolveEffectiveSemanticMemoryBackend();
48
93
  if (backend === "milvus" && MilvusSemanticMemoryStore.isAvailable()) {
49
- return new MilvusSemanticMemoryStore({
50
- projectId: params.projectId,
51
- tenantId: params.tenantId,
52
- });
94
+ return {
95
+ backend: "milvus",
96
+ store: new MilvusSemanticMemoryStore({
97
+ projectId: params.projectId,
98
+ tenantId: params.tenantId,
99
+ }),
100
+ };
53
101
  }
54
- return new SemanticMemoryStore({ paths: params.paths });
102
+ return {
103
+ backend: "sqlite",
104
+ store: new SemanticMemoryStore({ paths: params.paths }),
105
+ };
55
106
  }
56
107
  export function createPackMemoryStores(params) {
57
108
  const paths = resolvePackMemoryDir(params.packsRoot, params.projectId);
58
- const exactBackend = resolveExactMemoryBackend();
59
- const semanticBackend = resolveSemanticMemoryBackend();
60
- const exact = createExactStore({
109
+ const { store: exact, backend: exactBackend } = createExactStore({
61
110
  paths,
62
111
  projectId: params.projectId,
63
112
  tenantId: params.tenantId,
64
113
  lruMax: params.lruMax,
65
114
  });
66
- const semantic = createSemanticStore({
115
+ const { store: semantic, backend: semanticBackend } = createSemanticStore({
67
116
  paths,
68
117
  projectId: params.projectId,
69
118
  tenantId: params.tenantId,
70
119
  });
71
- const { reader, writer } = createCompositeMemoryStores(paths, exact, semantic, params.projectId);
120
+ const backends = {
121
+ exact: exactBackend,
122
+ semantic: semanticBackend,
123
+ countsAvailable: !isRemoteMemoryBackend({
124
+ exact: exactBackend,
125
+ semantic: semanticBackend,
126
+ }),
127
+ };
128
+ const { reader, writer } = createCompositeMemoryStores(paths, exact, semantic, params.projectId, backends);
72
129
  const gate = createMemoryGate(reader, writer, params.gateConfig);
73
- refreshPackMemoryMeta({
130
+ void refreshLocalMetaIfAvailable({
74
131
  paths,
75
- exactCount: exact.listEntries(Number.MAX_SAFE_INTEGER).length,
76
- semanticCount: semantic.count(params.projectId),
132
+ exact,
133
+ semantic,
134
+ projectId: params.projectId,
135
+ backends,
77
136
  });
78
137
  return {
79
138
  paths,
80
139
  exact,
81
140
  semantic,
82
141
  gate,
83
- backends: {
84
- exact: exactBackend === "redis" && RedisExactMemoryStore.isAvailable()
85
- ? "redis"
86
- : "file",
87
- semantic: semanticBackend === "milvus" && MilvusSemanticMemoryStore.isAvailable()
88
- ? "milvus"
89
- : "sqlite",
90
- },
142
+ backends,
91
143
  };
92
144
  }
93
145
  export { ExactMemoryStore } from "./exactStore.js";
94
146
  export { SemanticMemoryStore } from "./semanticStore.js";
95
- export { MilvusSemanticMemoryStore } from "./milvusSemanticStore.js";
147
+ export { MilvusSemanticMemoryStore, isMilvusEmbeddingReady, validateMilvusEmbedding, } from "./milvusSemanticStore.js";
96
148
  export { RedisExactMemoryStore } from "./redisExactStore.js";
97
- export { resolveExactMemoryBackend, resolveSemanticMemoryBackend, } from "./memoryBackends.js";
149
+ export { resolveExactMemoryBackend, resolveSemanticMemoryBackend, resolveEffectiveSemanticMemoryBackend, isRemoteMemoryBackend, } from "./memoryBackends.js";
98
150
  export { buildCacheKey, createMemoryEntryId, } from "./cacheKey.js";
99
151
  export { createMemoryGate, } from "./gate.js";
100
152
  export { defaultPackMemoryMeta, resolvePackMemoryDir, } from "./paths.js";
@@ -102,4 +154,5 @@ export { readPackMemoryMeta, refreshPackMemoryMeta, writePackMemoryMeta, } from
102
154
  export { resolveEmbeddingProviderFromEnv, } from "./embeddingProvider.js";
103
155
  export { getSpotlightRedisClient, isSpotlightRedisConfigured, spotlightRedisKey, } from "./redisClient.js";
104
156
  export { getSpotlightMilvusClient, isSpotlightMilvusConfigured, resolveSpotlightMilvusDb, SPOTLIGHT_MILVUS_SEMANTIC_COLLECTION, } from "./milvusClient.js";
157
+ export { resolveMemoryEntryScopeFields, entryMatchesLookupScopes, isMemoryEntryExpired, } from "./memoryEntryScope.js";
105
158
  export { FILE_MEMORY_ENTRYPOINT, appendSpotlightFileMemory, buildSpotlightFileMemoryPrompt, ensureSpotlightFileMemoryEntrypoints, isSpotlightFileMemoryPath, loadSpotlightFileMemories, resolveAgentMemoryDir, resolveAgentMemoryEntrypoint, resolveSpotlightFileMemoryPaths, } from "./fileMemory.js";
@@ -2,4 +2,10 @@ export type SemanticMemoryBackend = "sqlite" | "milvus";
2
2
  export type ExactMemoryBackend = "file" | "redis";
3
3
  export declare function resolveSemanticMemoryBackend(): SemanticMemoryBackend;
4
4
  export declare function resolveExactMemoryBackend(): ExactMemoryBackend;
5
+ /** Milvus semantic requires a working embedding provider; otherwise fall back to SQLite. */
6
+ export declare function resolveEffectiveSemanticMemoryBackend(): SemanticMemoryBackend;
7
+ export declare function isRemoteMemoryBackend(params: {
8
+ exact: ExactMemoryBackend;
9
+ semantic: SemanticMemoryBackend;
10
+ }): boolean;
5
11
  //# sourceMappingURL=memoryBackends.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"memoryBackends.d.ts","sourceRoot":"","sources":["../../src/node/memoryBackends.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,qBAAqB,GAAG,QAAQ,GAAG,QAAQ,CAAC;AACxD,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,OAAO,CAAC;AAElD,wBAAgB,4BAA4B,IAAI,qBAAqB,CAMpE;AAED,wBAAgB,yBAAyB,IAAI,kBAAkB,CAM9D"}
1
+ {"version":3,"file":"memoryBackends.d.ts","sourceRoot":"","sources":["../../src/node/memoryBackends.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,qBAAqB,GAAG,QAAQ,GAAG,QAAQ,CAAC;AACxD,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,OAAO,CAAC;AAElD,wBAAgB,4BAA4B,IAAI,qBAAqB,CAMpE;AAED,wBAAgB,yBAAyB,IAAI,kBAAkB,CAM9D;AAED,4FAA4F;AAC5F,wBAAgB,qCAAqC,IAAI,qBAAqB,CAO7E;AAED,wBAAgB,qBAAqB,CAAC,MAAM,EAAE;IAC5C,KAAK,EAAE,kBAAkB,CAAC;IAC1B,QAAQ,EAAE,qBAAqB,CAAC;CACjC,GAAG,OAAO,CAEV"}
@@ -1,3 +1,6 @@
1
+ import { MilvusSemanticMemoryStore } from "./milvusSemanticStore.js";
2
+ import { resolveEmbeddingProviderFromEnv } from "./embeddingProvider.js";
3
+ import { isSpotlightMilvusConfigured } from "./milvusClient.js";
1
4
  export function resolveSemanticMemoryBackend() {
2
5
  const raw = process.env.SPOTLIGHT_MEMORY_SEMANTIC_BACKEND?.trim().toLowerCase();
3
6
  if (raw === "sqlite" || raw === "file")
@@ -18,3 +21,19 @@ export function resolveExactMemoryBackend() {
18
21
  return "redis";
19
22
  return "file";
20
23
  }
24
+ /** Milvus semantic requires a working embedding provider; otherwise fall back to SQLite. */
25
+ export function resolveEffectiveSemanticMemoryBackend() {
26
+ const requested = resolveSemanticMemoryBackend();
27
+ if (requested !== "milvus")
28
+ return "sqlite";
29
+ if (!isSpotlightMilvusConfigured())
30
+ return "sqlite";
31
+ if (!MilvusSemanticMemoryStore.isAvailable())
32
+ return "sqlite";
33
+ if (!resolveEmbeddingProviderFromEnv())
34
+ return "sqlite";
35
+ return "milvus";
36
+ }
37
+ export function isRemoteMemoryBackend(params) {
38
+ return params.exact !== "file" || params.semantic !== "sqlite";
39
+ }
@@ -0,0 +1,19 @@
1
+ import type { SpotlightMemoryEntry } from "@inupedia/spotlight-protocol";
2
+ export type MemoryEntryScope = "project" | "session";
3
+ export type ScopedMemoryEntry = SpotlightMemoryEntry & {
4
+ scope?: MemoryEntryScope;
5
+ sessionId?: string;
6
+ };
7
+ export declare function resolveMemoryEntryScopeFields(entry: SpotlightMemoryEntry): {
8
+ scope: MemoryEntryScope;
9
+ sessionId: string;
10
+ kind: string;
11
+ createdAt: number;
12
+ expiresAt: number;
13
+ };
14
+ export declare function entryMatchesLookupScopes(entry: SpotlightMemoryEntry, scopes: Array<{
15
+ scope: MemoryEntryScope;
16
+ sessionId?: string;
17
+ }>): boolean;
18
+ export declare function isMemoryEntryExpired(entry: SpotlightMemoryEntry, now?: number): boolean;
19
+ //# sourceMappingURL=memoryEntryScope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memoryEntryScope.d.ts","sourceRoot":"","sources":["../../src/node/memoryEntryScope.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAEzE,MAAM,MAAM,gBAAgB,GAAG,SAAS,GAAG,SAAS,CAAC;AAErD,MAAM,MAAM,iBAAiB,GAAG,oBAAoB,GAAG;IACrD,KAAK,CAAC,EAAE,gBAAgB,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,oBAAoB,GAAG;IAC1E,KAAK,EAAE,gBAAgB,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB,CAeA;AAED,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,oBAAoB,EAC3B,MAAM,EAAE,KAAK,CAAC;IAAE,KAAK,EAAE,gBAAgB,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,GAC7D,OAAO,CAST;AAED,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,oBAAoB,EAC3B,GAAG,SAAa,GACf,OAAO,CAET"}
@@ -0,0 +1,28 @@
1
+ export function resolveMemoryEntryScopeFields(entry) {
2
+ const scoped = entry;
3
+ const scope = scoped.scope === "session" ? "session" : "project";
4
+ const sessionId = scope === "session" ? (scoped.sessionId?.trim() ?? "") : "";
5
+ const createdAt = entry.createdAt;
6
+ const ttlSec = entry.ttlSec > 0 ? entry.ttlSec : 86_400;
7
+ return {
8
+ scope,
9
+ sessionId,
10
+ kind: entry.kind,
11
+ createdAt,
12
+ expiresAt: createdAt + ttlSec * 1000,
13
+ };
14
+ }
15
+ export function entryMatchesLookupScopes(entry, scopes) {
16
+ const { scope, sessionId } = resolveMemoryEntryScopeFields(entry);
17
+ return scopes.some((candidate) => {
18
+ if (candidate.scope !== scope)
19
+ return false;
20
+ if (scope === "session") {
21
+ return Boolean(candidate.sessionId?.trim()) && sessionId === candidate.sessionId?.trim();
22
+ }
23
+ return true;
24
+ });
25
+ }
26
+ export function isMemoryEntryExpired(entry, now = Date.now()) {
27
+ return resolveMemoryEntryScopeFields(entry).expiresAt <= now;
28
+ }
@@ -0,0 +1,2 @@
1
+ export declare function logMemoryEvent(event: string, data: Record<string, unknown>): void;
2
+ //# sourceMappingURL=memoryLog.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memoryLog.d.ts","sourceRoot":"","sources":["../../src/node/memoryLog.ts"],"names":[],"mappings":"AAAA,wBAAgB,cAAc,CAC5B,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC5B,IAAI,CAQN"}
@@ -0,0 +1,7 @@
1
+ export function logMemoryEvent(event, data) {
2
+ console.info(JSON.stringify({
3
+ event,
4
+ ...data,
5
+ at: Date.now(),
6
+ }));
7
+ }
@@ -0,0 +1,15 @@
1
+ import type { MemoryEntryScope } from "./memoryEntryScope.js";
2
+ export interface SemanticLookupOptions {
3
+ scopes?: Array<{
4
+ scope: MemoryEntryScope;
5
+ sessionId?: string;
6
+ }>;
7
+ now?: number;
8
+ }
9
+ export type SemanticWriteResult = {
10
+ written: true;
11
+ } | {
12
+ written: false;
13
+ skippedReason: string;
14
+ };
15
+ //# sourceMappingURL=memoryStoreTypes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memoryStoreTypes.d.ts","sourceRoot":"","sources":["../../src/node/memoryStoreTypes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAE9D,MAAM,WAAW,qBAAqB;IACpC,MAAM,CAAC,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,gBAAgB,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAChE,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,MAAM,mBAAmB,GAC3B;IAAE,OAAO,EAAE,IAAI,CAAA;CAAE,GACjB;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,aAAa,EAAE,MAAM,CAAA;CAAE,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -1,9 +1,13 @@
1
+ import type { ExactMemoryBackend, SemanticMemoryBackend } from "./memoryBackends.js";
1
2
  import { type PackMemoryMeta, type PackMemoryPaths } from "./paths.js";
2
3
  export declare function readPackMemoryMeta(paths: PackMemoryPaths): PackMemoryMeta;
3
4
  export declare function writePackMemoryMeta(paths: PackMemoryPaths, meta: PackMemoryMeta): void;
4
5
  export declare function refreshPackMemoryMeta(params: {
5
6
  paths: PackMemoryPaths;
6
- exactCount: number;
7
- semanticCount: number;
7
+ exactCount?: number;
8
+ semanticCount?: number;
9
+ exactBackend?: ExactMemoryBackend;
10
+ semanticBackend?: SemanticMemoryBackend;
11
+ countsAvailable?: boolean;
8
12
  }): PackMemoryMeta;
9
13
  //# sourceMappingURL=meta.d.ts.map