@wipcomputer/memory-crystal 0.7.18 → 0.7.20

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.
package/dist/cli.js CHANGED
@@ -3,7 +3,7 @@ import {
3
3
  Crystal,
4
4
  createCrystal,
5
5
  resolveConfig
6
- } from "./chunk-MBKCIJHM.js";
6
+ } from "./chunk-FBQWSDPC.js";
7
7
  import {
8
8
  deployBackupScript,
9
9
  ensureLdm,
package/dist/core.js CHANGED
@@ -3,7 +3,7 @@ import {
3
3
  RemoteCrystal,
4
4
  createCrystal,
5
5
  resolveConfig
6
- } from "./chunk-MBKCIJHM.js";
6
+ } from "./chunk-FBQWSDPC.js";
7
7
  export {
8
8
  Crystal,
9
9
  RemoteCrystal,
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  Crystal,
3
3
  resolveConfig
4
- } from "./chunk-MBKCIJHM.js";
4
+ } from "./chunk-FBQWSDPC.js";
5
5
  import {
6
6
  ldmPaths
7
7
  } from "./chunk-EXEZZADG.js";
@@ -6,7 +6,7 @@ import {
6
6
  RemoteCrystal,
7
7
  createCrystal,
8
8
  resolveConfig
9
- } from "./chunk-MBKCIJHM.js";
9
+ } from "./chunk-FBQWSDPC.js";
10
10
  import {
11
11
  resolveStatePath,
12
12
  stateWritePath
package/dist/migrate.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  Crystal,
4
4
  resolveConfig
5
- } from "./chunk-MBKCIJHM.js";
5
+ } from "./chunk-FBQWSDPC.js";
6
6
 
7
7
  // src/migrate.ts
8
8
  import Database from "better-sqlite3";
@@ -5,7 +5,7 @@ import {
5
5
  import {
6
6
  Crystal,
7
7
  resolveConfig
8
- } from "./chunk-MBKCIJHM.js";
8
+ } from "./chunk-FBQWSDPC.js";
9
9
  import {
10
10
  decryptJSON,
11
11
  loadRelayKey
package/dist/openclaw.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  Crystal,
3
3
  resolveConfig
4
- } from "./chunk-MBKCIJHM.js";
4
+ } from "./chunk-FBQWSDPC.js";
5
5
  import {
6
6
  ensureLdm,
7
7
  resolveStatePath,
package/dist/poller.js CHANGED
@@ -14,7 +14,7 @@ import {
14
14
  import {
15
15
  Crystal,
16
16
  resolveConfig
17
- } from "./chunk-MBKCIJHM.js";
17
+ } from "./chunk-FBQWSDPC.js";
18
18
  import {
19
19
  decryptJSON,
20
20
  encryptJSON,
@@ -0,0 +1,73 @@
1
+ import {
2
+ detectProvider,
3
+ expandQuery,
4
+ rerankResults
5
+ } from "./chunk-7IUE7ODU.js";
6
+
7
+ // src/search-pipeline.ts
8
+ var STRONG_SIGNAL_MIN_SCORE = 0.85;
9
+ var STRONG_SIGNAL_MIN_GAP = 0.15;
10
+ var RERANK_CANDIDATE_LIMIT = 40;
11
+ async function deepSearch(crystal, query, options = {}) {
12
+ const limit = options.limit || 5;
13
+ const filter = options.filter;
14
+ const provider = await detectProvider();
15
+ if (provider.provider === "none") {
16
+ return crystal.search(query, limit, filter);
17
+ }
18
+ const db = crystal.sqliteDb;
19
+ if (!db) return crystal.search(query, limit, filter);
20
+ const sinceDate = filter?.since ? crystal.parseSince(filter.since) : void 0;
21
+ const internalFilter = { ...filter, sinceDate };
22
+ const initialFts = crystal.searchFTS(query, 20, internalFilter);
23
+ const topScore = initialFts[0]?.score ?? 0;
24
+ const secondScore = initialFts[1]?.score ?? 0;
25
+ const hasStrongSignal = initialFts.length > 0 && topScore >= STRONG_SIGNAL_MIN_SCORE && topScore - secondScore >= STRONG_SIGNAL_MIN_GAP;
26
+ const expanded = hasStrongSignal ? [] : await expandQuery(query);
27
+ const allResultLists = [];
28
+ if (initialFts.length > 0) allResultLists.push(initialFts);
29
+ const [queryEmbedding] = await crystal.embed([query]);
30
+ const originalVec = crystal.searchVec(queryEmbedding, 30, internalFilter);
31
+ if (originalVec.length > 0) allResultLists.push(originalVec);
32
+ for (const variation of expanded) {
33
+ if (variation.type === "lex") {
34
+ const ftsResults = crystal.searchFTS(variation.text, 20, internalFilter);
35
+ if (ftsResults.length > 0) allResultLists.push(ftsResults);
36
+ } else {
37
+ const [embedding] = await crystal.embed([variation.text]);
38
+ const vecResults = crystal.searchVec(embedding, 20, internalFilter);
39
+ if (vecResults.length > 0) allResultLists.push(vecResults);
40
+ }
41
+ }
42
+ const weights = allResultLists.map((_, i) => i < 2 ? 2 : 1);
43
+ const fused = crystal.reciprocalRankFusion(allResultLists, weights);
44
+ const candidates = fused.slice(0, RERANK_CANDIDATE_LIMIT);
45
+ if (candidates.length === 0) return [];
46
+ const passages = candidates.map((c) => c.text.slice(0, 500));
47
+ const reranked = await rerankResults(query, passages);
48
+ const now = Date.now();
49
+ const blended = reranked.map((r) => {
50
+ const candidate = candidates[r.index];
51
+ if (!candidate) return null;
52
+ const rrfRank = r.index + 1;
53
+ let rrfWeight;
54
+ if (rrfRank <= 3) rrfWeight = 0.75;
55
+ else if (rrfRank <= 10) rrfWeight = 0.6;
56
+ else rrfWeight = 0.4;
57
+ const rrfScore = 1 / rrfRank;
58
+ const blendedScore = rrfWeight * rrfScore + (1 - rrfWeight) * r.score;
59
+ const ageDays = candidate.created_at ? (now - new Date(candidate.created_at).getTime()) / 864e5 : 0;
60
+ const recency = candidate.created_at ? crystal.recencyWeight(ageDays) : 1;
61
+ const finalScore = Math.min(blendedScore * recency * 4, 0.95);
62
+ const freshness = candidate.created_at ? crystal.freshnessLabel(ageDays) : void 0;
63
+ return {
64
+ ...candidate,
65
+ score: finalScore,
66
+ freshness
67
+ };
68
+ }).filter((r) => r !== null);
69
+ return blended.sort((a, b) => b.score - a.score).slice(0, limit);
70
+ }
71
+ export {
72
+ deepSearch
73
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wipcomputer/memory-crystal",
3
- "version": "0.7.18",
3
+ "version": "0.7.20",
4
4
  "description": "Sovereign memory system — local-first with ephemeral encrypted relay. Your memory, your machine, your rules.",
5
5
  "type": "module",
6
6
  "main": "dist/core.js",