om-memory-system 6.1.0-next.237 → 6.1.1

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.
@@ -32,14 +32,17 @@ async function findActiveRow(id) {
32
32
  return null;
33
33
  }
34
34
  /**
35
- * Looks a memorisation up by exact ID in the active space, then in the linked spaces. Only
36
- * rows of the given project are returned, the same rule as text recall and list.
35
+ * Looks a memorisation up by exact ID in the active space, then in the linked spaces. A
36
+ * project tag narrows the lookup to that project; `null` matches any project, the rule
37
+ * recall and bulk delete use.
37
38
  * The caller snapshots `linked` from CONFIG, so this module never imports it.
38
39
  */
39
40
  export async function getMemorisationById(id, containerTag, linked) {
40
41
  const row = await findActiveRow(id);
41
- if (row?.container_tag === containerTag && row.type === "memorisation")
42
+ if (row?.type === "memorisation" &&
43
+ (containerTag === null || row.container_tag === containerTag)) {
42
44
  return toStored(row);
45
+ }
43
46
  const found = await readLinkedMemory(id, activeOwner(), linked, containerTag);
44
47
  return found?.row.type === "memorisation" ? toStored(found.row, found.name) : null;
45
48
  }
@@ -94,9 +97,10 @@ export async function listMemorisationsByTags(containerTag, tags, scope, limit)
94
97
  return { success: true, memories };
95
98
  }
96
99
  /**
97
- * Deletes one memorisation of this project from the active space. A row of another project,
98
- * or no row, is "not-found". A row of another type is kept ("not-memorisation"). A row that
99
- * lives only in a linked, read-only space is "linked" and is never touched.
100
+ * Deletes one memorisation from the active space. A project tag narrows the delete to that
101
+ * project; `null` matches any project, the rule bulk delete uses. No row is "not-found".
102
+ * A row of another type is kept ("not-memorisation"). A row that lives only in a linked,
103
+ * read-only space is "linked" and is never touched.
100
104
  */
101
105
  export async function deleteMemorisation(id, containerTag, linked) {
102
106
  await memoryClient.ensureStorageReady();
@@ -107,7 +111,7 @@ export async function deleteMemorisation(id, containerTag, linked) {
107
111
  for (const shard of shards) {
108
112
  const db = await tursoConnectionManager.getConnection(shard.dbPath);
109
113
  const row = await tursoVectorSearch.getMemoryById(db, id);
110
- if (!row || row.container_tag !== containerTag)
114
+ if (!row || (containerTag !== null && row.container_tag !== containerTag))
111
115
  continue;
112
116
  if (row.type !== "memorisation")
113
117
  return "not-memorisation";
@@ -32,6 +32,12 @@ export declare class RerankError extends Error {
32
32
  * and the caller falls back.
33
33
  */
34
34
  export declare function rerankSettingsFrom(config: RerankerConfigSlice): RerankerSettings | undefined;
35
+ /**
36
+ * Reranker settings for one read. An override decides for that read alone:
37
+ * `false` never reranks; `true` reranks whenever the server URL and model are
38
+ * set, even with the general switch off. No override keeps the general rule.
39
+ */
40
+ export declare function rerankSettingsFor(config: RerankerConfigSlice, override?: boolean): RerankerSettings | undefined;
35
41
  /**
36
42
  * Ask the reranker to order the documents. Throws RerankError on any
37
43
  * failure; the caller falls back to the threshold result. A reply is valid
@@ -59,6 +59,18 @@ export function rerankSettingsFrom(config) {
59
59
  timeoutMs: config.rerankerTimeoutMs ?? RERANKER_TIMEOUT_DEFAULT_MS,
60
60
  };
61
61
  }
62
+ /**
63
+ * Reranker settings for one read. An override decides for that read alone:
64
+ * `false` never reranks; `true` reranks whenever the server URL and model are
65
+ * set, even with the general switch off. No override keeps the general rule.
66
+ */
67
+ export function rerankSettingsFor(config, override) {
68
+ if (override === false)
69
+ return undefined;
70
+ if (override === true)
71
+ return rerankSettingsFrom({ ...config, rerankerEnabled: true });
72
+ return rerankSettingsFrom(config);
73
+ }
62
74
  /**
63
75
  * Ask the reranker to order the documents. Throws RerankError on any
64
76
  * failure; the caller falls back to the threshold result. A reply is valid
@@ -24,6 +24,8 @@ export interface RerankedSearchOptions {
24
24
  maxMemories: number;
25
25
  similarityThreshold: number;
26
26
  kind?: MemoryKind;
27
+ /** Drop reranked candidates below `similarityThreshold` before the limit (memorisation recall). */
28
+ thresholdAfterRerank?: boolean;
27
29
  }
28
30
  export interface RerankedSearchDeps {
29
31
  search: SearchAcrossShards;
@@ -15,7 +15,10 @@ export async function rerankedSearch(options, settings, deps) {
15
15
  return { results: [], warnings, reranked: false };
16
16
  try {
17
17
  const { ordered } = await rerankDocuments(settings, options.queryText, candidates, deps.fetchImpl);
18
- return { results: ordered.slice(0, options.maxMemories), warnings, reranked: true };
18
+ const kept = options.thresholdAfterRerank
19
+ ? ordered.filter((result) => result.similarity >= options.similarityThreshold)
20
+ : ordered;
21
+ return { results: kept.slice(0, options.maxMemories), warnings, reranked: true };
19
22
  }
20
23
  catch (error) {
21
24
  // Metadata only: the code, the elapsed time, and the candidate count.
@@ -45,6 +45,7 @@ const editable = [
45
45
  "memorisationRepeat",
46
46
  "memorisationMaxSize",
47
47
  "memorisationSizeUnit",
48
+ "memorisationRerank",
48
49
  ...MEMORY_LIMIT_SETTINGS,
49
50
  ];
50
51
  /**
@@ -79,6 +80,7 @@ const globalOnly = [
79
80
  "memorisationRepeat",
80
81
  "memorisationMaxSize",
81
82
  "memorisationSizeUnit",
83
+ "memorisationRerank",
82
84
  ];
83
85
  function readSettingsFile(path) {
84
86
  if (!path)
@@ -33,7 +33,7 @@ export async function routeModules(path, method, url, req, ctx) {
33
33
  });
34
34
  if (spaces !== undefined)
35
35
  return spaces;
36
- const memorisations = await routeMemorisations(path, method, url, ctx.cwd, { defaultScope: config.memory.defaultScope, linked: linkedSettingsFrom(config) }, readBody);
36
+ const memorisations = await routeMemorisations(path, method, url, { linked: linkedSettingsFrom(config), rerank: config.memorisationRerank === true }, readBody);
37
37
  if (memorisations !== undefined)
38
38
  return memorisations;
39
39
  return routeChat(path, method, readBody, config);