mem-os-python 1.6.27__py3-none-any.whl
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.
- mem_os_python-1.6.27.dist-info/METADATA +1032 -0
- mem_os_python-1.6.27.dist-info/RECORD +253 -0
- mem_os_python-1.6.27.dist-info/WHEEL +4 -0
- mem_os_python-1.6.27.dist-info/entry_points.txt +2 -0
- mem_os_python-1.6.27.dist-info/licenses/LICENSE +21 -0
- memos/__init__.py +16 -0
- memos/_js/adapters/anthropic.d.ts +279 -0
- memos/_js/adapters/anthropic.d.ts.map +1 -0
- memos/_js/adapters/anthropic.js +348 -0
- memos/_js/adapters/anthropic.js.map +1 -0
- memos/_js/adapters/base.d.ts +10 -0
- memos/_js/adapters/base.d.ts.map +1 -0
- memos/_js/adapters/base.js +2 -0
- memos/_js/adapters/base.js.map +1 -0
- memos/_js/adapters/openai.d.ts +264 -0
- memos/_js/adapters/openai.d.ts.map +1 -0
- memos/_js/adapters/openai.js +342 -0
- memos/_js/adapters/openai.js.map +1 -0
- memos/_js/apps/explorer.d.ts +244 -0
- memos/_js/apps/explorer.d.ts.map +1 -0
- memos/_js/apps/explorer.js +738 -0
- memos/_js/apps/explorer.js.map +1 -0
- memos/_js/citations.d.ts +65 -0
- memos/_js/citations.d.ts.map +1 -0
- memos/_js/citations.js +143 -0
- memos/_js/citations.js.map +1 -0
- memos/_js/cli-browse.d.ts +3 -0
- memos/_js/cli-browse.d.ts.map +1 -0
- memos/_js/cli-browse.js +129 -0
- memos/_js/cli-browse.js.map +1 -0
- memos/_js/cli-completion.d.ts +31 -0
- memos/_js/cli-completion.d.ts.map +1 -0
- memos/_js/cli-completion.js +340 -0
- memos/_js/cli-completion.js.map +1 -0
- memos/_js/cli-help.d.ts +18 -0
- memos/_js/cli-help.d.ts.map +1 -0
- memos/_js/cli-help.js +357 -0
- memos/_js/cli-help.js.map +1 -0
- memos/_js/cli.d.ts +28 -0
- memos/_js/cli.d.ts.map +1 -0
- memos/_js/cli.js +2880 -0
- memos/_js/cli.js.map +1 -0
- memos/_js/compression.d.ts +25 -0
- memos/_js/compression.d.ts.map +1 -0
- memos/_js/compression.js +319 -0
- memos/_js/compression.js.map +1 -0
- memos/_js/confidence-machine.d.ts +99 -0
- memos/_js/confidence-machine.d.ts.map +1 -0
- memos/_js/confidence-machine.js +222 -0
- memos/_js/confidence-machine.js.map +1 -0
- memos/_js/context-pack.d.ts +506 -0
- memos/_js/context-pack.d.ts.map +1 -0
- memos/_js/context-pack.js +1435 -0
- memos/_js/context-pack.js.map +1 -0
- memos/_js/contradictions.d.ts +160 -0
- memos/_js/contradictions.d.ts.map +1 -0
- memos/_js/contradictions.js +255 -0
- memos/_js/contradictions.js.map +1 -0
- memos/_js/dashboard.d.ts +30 -0
- memos/_js/dashboard.d.ts.map +1 -0
- memos/_js/dashboard.js +302 -0
- memos/_js/dashboard.js.map +1 -0
- memos/_js/ebbinghaus.d.ts +29 -0
- memos/_js/ebbinghaus.d.ts.map +1 -0
- memos/_js/ebbinghaus.js +32 -0
- memos/_js/ebbinghaus.js.map +1 -0
- memos/_js/embedding-queue.d.ts +190 -0
- memos/_js/embedding-queue.d.ts.map +1 -0
- memos/_js/embedding-queue.js +316 -0
- memos/_js/embedding-queue.js.map +1 -0
- memos/_js/embeddings.d.ts +187 -0
- memos/_js/embeddings.d.ts.map +1 -0
- memos/_js/embeddings.js +633 -0
- memos/_js/embeddings.js.map +1 -0
- memos/_js/entity-extraction.d.ts +54 -0
- memos/_js/entity-extraction.d.ts.map +1 -0
- memos/_js/entity-extraction.js +325 -0
- memos/_js/entity-extraction.js.map +1 -0
- memos/_js/entity-index.d.ts +93 -0
- memos/_js/entity-index.d.ts.map +1 -0
- memos/_js/entity-index.js +165 -0
- memos/_js/entity-index.js.map +1 -0
- memos/_js/event-memory.d.ts +147 -0
- memos/_js/event-memory.d.ts.map +1 -0
- memos/_js/event-memory.js +290 -0
- memos/_js/event-memory.js.map +1 -0
- memos/_js/external-import.d.ts +98 -0
- memos/_js/external-import.d.ts.map +1 -0
- memos/_js/external-import.js +669 -0
- memos/_js/external-import.js.map +1 -0
- memos/_js/fidelity.d.ts +367 -0
- memos/_js/fidelity.d.ts.map +1 -0
- memos/_js/fidelity.js +911 -0
- memos/_js/fidelity.js.map +1 -0
- memos/_js/graph-expansion.d.ts +119 -0
- memos/_js/graph-expansion.d.ts.map +1 -0
- memos/_js/graph-expansion.js +213 -0
- memos/_js/graph-expansion.js.map +1 -0
- memos/_js/graph-mermaid.d.ts +13 -0
- memos/_js/graph-mermaid.d.ts.map +1 -0
- memos/_js/graph-mermaid.js +32 -0
- memos/_js/graph-mermaid.js.map +1 -0
- memos/_js/graph.d.ts +170 -0
- memos/_js/graph.d.ts.map +1 -0
- memos/_js/graph.js +482 -0
- memos/_js/graph.js.map +1 -0
- memos/_js/harness.d.ts +63 -0
- memos/_js/harness.d.ts.map +1 -0
- memos/_js/harness.js +93 -0
- memos/_js/harness.js.map +1 -0
- memos/_js/importance.d.ts +118 -0
- memos/_js/importance.d.ts.map +1 -0
- memos/_js/importance.js +144 -0
- memos/_js/importance.js.map +1 -0
- memos/_js/index.d.ts +51 -0
- memos/_js/index.d.ts.map +1 -0
- memos/_js/index.js +53 -0
- memos/_js/index.js.map +1 -0
- memos/_js/mcp.d.ts +58 -0
- memos/_js/mcp.d.ts.map +1 -0
- memos/_js/mcp.js +1853 -0
- memos/_js/mcp.js.map +1 -0
- memos/_js/memory.d.ts +1762 -0
- memos/_js/memory.d.ts.map +1 -0
- memos/_js/memory.js +6283 -0
- memos/_js/memory.js.map +1 -0
- memos/_js/procedural.d.ts +74 -0
- memos/_js/procedural.d.ts.map +1 -0
- memos/_js/procedural.js +125 -0
- memos/_js/procedural.js.map +1 -0
- memos/_js/project-config.d.ts +68 -0
- memos/_js/project-config.d.ts.map +1 -0
- memos/_js/project-config.js +59 -0
- memos/_js/project-config.js.map +1 -0
- memos/_js/proof-of-forgetting.d.ts +57 -0
- memos/_js/proof-of-forgetting.d.ts.map +1 -0
- memos/_js/proof-of-forgetting.js +80 -0
- memos/_js/proof-of-forgetting.js.map +1 -0
- memos/_js/provenance.d.ts +122 -0
- memos/_js/provenance.d.ts.map +1 -0
- memos/_js/provenance.js +182 -0
- memos/_js/provenance.js.map +1 -0
- memos/_js/quarantine-commands.d.ts +23 -0
- memos/_js/quarantine-commands.d.ts.map +1 -0
- memos/_js/quarantine-commands.js +42 -0
- memos/_js/quarantine-commands.js.map +1 -0
- memos/_js/quarantine.d.ts +120 -0
- memos/_js/quarantine.d.ts.map +1 -0
- memos/_js/quarantine.js +873 -0
- memos/_js/quarantine.js.map +1 -0
- memos/_js/redact.d.ts +12 -0
- memos/_js/redact.d.ts.map +1 -0
- memos/_js/redact.js +26 -0
- memos/_js/redact.js.map +1 -0
- memos/_js/repl.d.ts +57 -0
- memos/_js/repl.d.ts.map +1 -0
- memos/_js/repl.js +295 -0
- memos/_js/repl.js.map +1 -0
- memos/_js/rerank-local.d.ts +61 -0
- memos/_js/rerank-local.d.ts.map +1 -0
- memos/_js/rerank-local.js +210 -0
- memos/_js/rerank-local.js.map +1 -0
- memos/_js/retain-filter.d.ts +98 -0
- memos/_js/retain-filter.d.ts.map +1 -0
- memos/_js/retain-filter.js +232 -0
- memos/_js/retain-filter.js.map +1 -0
- memos/_js/retrieval.d.ts +265 -0
- memos/_js/retrieval.d.ts.map +1 -0
- memos/_js/retrieval.js +1018 -0
- memos/_js/retrieval.js.map +1 -0
- memos/_js/revert.d.ts +77 -0
- memos/_js/revert.d.ts.map +1 -0
- memos/_js/revert.js +252 -0
- memos/_js/revert.js.map +1 -0
- memos/_js/scope.d.ts +30 -0
- memos/_js/scope.d.ts.map +1 -0
- memos/_js/scope.js +71 -0
- memos/_js/scope.js.map +1 -0
- memos/_js/semantic-screen.d.ts +152 -0
- memos/_js/semantic-screen.d.ts.map +1 -0
- memos/_js/semantic-screen.js +290 -0
- memos/_js/semantic-screen.js.map +1 -0
- memos/_js/session-hooks.d.ts +127 -0
- memos/_js/session-hooks.d.ts.map +1 -0
- memos/_js/session-hooks.js +482 -0
- memos/_js/session-hooks.js.map +1 -0
- memos/_js/storage/sqlite.d.ts +427 -0
- memos/_js/storage/sqlite.d.ts.map +1 -0
- memos/_js/storage/sqlite.js +2428 -0
- memos/_js/storage/sqlite.js.map +1 -0
- memos/_js/sync.d.ts +213 -0
- memos/_js/sync.d.ts.map +1 -0
- memos/_js/sync.js +389 -0
- memos/_js/sync.js.map +1 -0
- memos/_js/tamper-log.d.ts +98 -0
- memos/_js/tamper-log.d.ts.map +1 -0
- memos/_js/tamper-log.js +327 -0
- memos/_js/tamper-log.js.map +1 -0
- memos/_js/temporal.d.ts +92 -0
- memos/_js/temporal.d.ts.map +1 -0
- memos/_js/temporal.js +536 -0
- memos/_js/temporal.js.map +1 -0
- memos/_js/time-travel.d.ts +38 -0
- memos/_js/time-travel.d.ts.map +1 -0
- memos/_js/time-travel.js +46 -0
- memos/_js/time-travel.js.map +1 -0
- memos/_js/timestamp-format.d.ts +18 -0
- memos/_js/timestamp-format.d.ts.map +1 -0
- memos/_js/timestamp-format.js +52 -0
- memos/_js/timestamp-format.js.map +1 -0
- memos/_js/triple-extraction.d.ts +31 -0
- memos/_js/triple-extraction.d.ts.map +1 -0
- memos/_js/triple-extraction.js +116 -0
- memos/_js/triple-extraction.js.map +1 -0
- memos/_js/types.d.ts +2474 -0
- memos/_js/types.d.ts.map +1 -0
- memos/_js/types.js +20 -0
- memos/_js/types.js.map +1 -0
- memos/_js/updater.d.ts +95 -0
- memos/_js/updater.d.ts.map +1 -0
- memos/_js/updater.js +268 -0
- memos/_js/updater.js.map +1 -0
- memos/_js/version.d.ts +17 -0
- memos/_js/version.d.ts.map +1 -0
- memos/_js/version.js +34 -0
- memos/_js/version.js.map +1 -0
- memos/_js/vision/clip-query-cache.d.ts +58 -0
- memos/_js/vision/clip-query-cache.d.ts.map +1 -0
- memos/_js/vision/clip-query-cache.js +79 -0
- memos/_js/vision/clip-query-cache.js.map +1 -0
- memos/_js/vision/clip.d.ts +113 -0
- memos/_js/vision/clip.d.ts.map +1 -0
- memos/_js/vision/clip.js +224 -0
- memos/_js/vision/clip.js.map +1 -0
- memos/_js/vision/fake-clip.d.ts +55 -0
- memos/_js/vision/fake-clip.d.ts.map +1 -0
- memos/_js/vision/fake-clip.js +122 -0
- memos/_js/vision/fake-clip.js.map +1 -0
- memos/_js/vision/index.d.ts +15 -0
- memos/_js/vision/index.d.ts.map +1 -0
- memos/_js/vision/index.js +13 -0
- memos/_js/vision/index.js.map +1 -0
- memos/_js/vision/store.d.ts +137 -0
- memos/_js/vision/store.d.ts.map +1 -0
- memos/_js/vision/store.js +383 -0
- memos/_js/vision/store.js.map +1 -0
- memos/adapters/__init__.py +0 -0
- memos/adapters/crewai.py +385 -0
- memos/adapters/langchain.py +301 -0
- memos/adapters/ollama.py +396 -0
- memos/server/__init__.py +0 -0
- memos/server/main.py +547 -0
- memos/server/routes.py +360 -0
memos/_js/retrieval.d.ts
ADDED
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retrieval fusion — hybrid search result merging.
|
|
3
|
+
*
|
|
4
|
+
* Two fusion algorithms (see `FusionOptions.fusionMode`):
|
|
5
|
+
*
|
|
6
|
+
* - RRF (weighted Reciprocal Rank Fusion): each leg votes by RANK
|
|
7
|
+
* (`weight / (K + rank)`), robust to score outliers that would
|
|
8
|
+
* otherwise dominate a weighted sum. K=60 is the standard constant
|
|
9
|
+
* from the RRF paper (Cormack et al., 2009).
|
|
10
|
+
* - Convex combination (default since round 4): min-max normalize each
|
|
11
|
+
* leg's native scores to [0,1], then take the weighted sum. A dominant
|
|
12
|
+
* absolute score (near-exact embedding match, runaway bm25 hit) keeps
|
|
13
|
+
* its magnitude instead of being flattened to a rank vote. A Sept 2026
|
|
14
|
+
* TOIS analysis found convex combination beats RRF in- and
|
|
15
|
+
* out-of-domain; Weaviate made the same switch.
|
|
16
|
+
*
|
|
17
|
+
* The keyword leg carries the larger weight by default (0.8 vs 0.2):
|
|
18
|
+
* exact term matches are highly reliable for factoid memory queries,
|
|
19
|
+
* while embeddings rescue paraphrases that share no vocabulary.
|
|
20
|
+
*/
|
|
21
|
+
import type { FusionOptions, ScoredMemory } from "./types.js";
|
|
22
|
+
export type { FusionOptions } from "./types.js";
|
|
23
|
+
/** Default RRF constant (Cormack et al., 2009). */
|
|
24
|
+
export declare const DEFAULT_RRF_K = 60;
|
|
25
|
+
/**
|
|
26
|
+
* Default fusion algorithm (round 4). `"convex"` min-max normalizes each
|
|
27
|
+
* leg's native scores and takes the weighted sum; `"rrf"` restores the
|
|
28
|
+
* legacy rank-vote behavior.
|
|
29
|
+
*/
|
|
30
|
+
export declare const DEFAULT_FUSION_MODE: "convex";
|
|
31
|
+
/**
|
|
32
|
+
* Temporal markers that switch on the recency multiplier for a query
|
|
33
|
+
* (round 4 adaptive weighting). Deliberately narrow: generic nouns like
|
|
34
|
+
* "week" alone don't trigger it, only explicit temporal constructions.
|
|
35
|
+
*/
|
|
36
|
+
export declare const TEMPORAL_QUERY_RE: RegExp;
|
|
37
|
+
/** Default strength of the temporal-query recency multiplier (≤5%). */
|
|
38
|
+
export declare const DEFAULT_TEMPORAL_RECENCY_STRENGTH = 0.05;
|
|
39
|
+
/**
|
|
40
|
+
* Tokenize for PRF: lowercase alphanumeric tokens, stopwords and
|
|
41
|
+
* short tokens dropped.
|
|
42
|
+
*/
|
|
43
|
+
export declare function prfTokenize(text: string): string[];
|
|
44
|
+
/**
|
|
45
|
+
* RM3-lite pseudo-relevance feedback term harvesting (round 4).
|
|
46
|
+
*
|
|
47
|
+
* Pure function: given the top semantic-leg hits for a query, harvest
|
|
48
|
+
* up to `maxTerms` recurring content terms that are NOT already in the
|
|
49
|
+
* query, ranked by frequency across the hits. The caller re-probes FTS5
|
|
50
|
+
* with these terms as a second keyword pass whose results are UNIONED
|
|
51
|
+
* into the keyword leg — expansion can only add recall, never remove
|
|
52
|
+
* candidates.
|
|
53
|
+
*
|
|
54
|
+
* Deterministic: no model, no sampling — same hits always yield the
|
|
55
|
+
* same terms. Gated by the caller to short queries (≤3 terms), where
|
|
56
|
+
* vocabulary mismatch hurts most.
|
|
57
|
+
*
|
|
58
|
+
* @param hits — Top semantic-leg results (best first); callers pass ~5.
|
|
59
|
+
* @param queryTerms — Tokenized query terms (from `prfTokenize`).
|
|
60
|
+
* @param maxTerms — Cap on harvested terms. Default 3.
|
|
61
|
+
*/
|
|
62
|
+
export declare function harvestPrfTerms(hits: ScoredMemory[], queryTerms: string[], maxTerms?: number): string[];
|
|
63
|
+
/**
|
|
64
|
+
* Merge an expansion keyword pass into the primary keyword leg (union
|
|
65
|
+
* semantics). Candidates already in the primary leg keep their original
|
|
66
|
+
* score; expansion-only candidates append after.
|
|
67
|
+
*
|
|
68
|
+
* The expansion query is a different query (harvested terms only), so its
|
|
69
|
+
* bm25 scores are NOT comparable to the primary query's: an expansion hit
|
|
70
|
+
* matching three harvested terms will outscore a primary hit on raw bm25
|
|
71
|
+
* even though the primary query is the user's actual intent. To keep PRF
|
|
72
|
+
* a pure recall booster (never a re-ranker), expansion-only candidates are
|
|
73
|
+
* demoted below every primary hit (FTS5 bm25: lower/more-negative is
|
|
74
|
+
* better, so they take worst-primary + 1); they tie among themselves and
|
|
75
|
+
* order deterministically by node id thereafter.
|
|
76
|
+
*/
|
|
77
|
+
export declare function mergeKeywordLegs(primary: ScoredMemory[], expansion: ScoredMemory[]): ScoredMemory[];
|
|
78
|
+
/**
|
|
79
|
+
* Stable ordering for scored memories: descending score, node id as the
|
|
80
|
+
* final tiebreak. The id tiebreak keeps serialized output byte-identical
|
|
81
|
+
* for identical result sets — without it, equal scores surface
|
|
82
|
+
* input/iteration-order noise, which breaks LLM prompt-cache prefixes
|
|
83
|
+
* (providers only discount cached input when the prefix is byte-stable).
|
|
84
|
+
*/
|
|
85
|
+
export declare function compareScoredMemories(a: ScoredMemory, b: ScoredMemory): number;
|
|
86
|
+
/** Default weight for the keyword (FTS5) leg. */
|
|
87
|
+
export declare const DEFAULT_KEYWORD_WEIGHT = 0.8;
|
|
88
|
+
/** Default weight for the semantic (embedding) leg. */
|
|
89
|
+
export declare const DEFAULT_SEMANTIC_WEIGHT = 0.2;
|
|
90
|
+
/**
|
|
91
|
+
* Default strength of the entity-overlap boost — the third retrieval
|
|
92
|
+
* signal (semantic + keyword + entity match). Applied as a post-fusion
|
|
93
|
+
* multiplier `score *= 1 + entityWeight * overlap`, so it nudges rather
|
|
94
|
+
* than dominates; only active when `queryEntities` is non-empty.
|
|
95
|
+
*/
|
|
96
|
+
export declare const DEFAULT_ENTITY_WEIGHT = 0.15;
|
|
97
|
+
/**
|
|
98
|
+
* ── item2: entity leg ── default weight of the entity-inverted-index RRF
|
|
99
|
+
* leg (`entityResults`). Deliberately subordinate to the semantic leg:
|
|
100
|
+
* rank-1 in the entity leg scores `0.1 / (rrfK + 1)`, below a
|
|
101
|
+
* semantic-only rank-1 (`0.2 / (rrfK + 1)`). The extractor is lexical,
|
|
102
|
+
* so on dialogue-heavy corpora a 0.5 weight let entity-matched
|
|
103
|
+
* near-duplicates outrank genuine semantic hits — measured as a LoCoMo
|
|
104
|
+
* nDCG regression at 0.5, neutral at 0.1. The leg's job is recall
|
|
105
|
+
* (surfacing entity-matched memories the other legs missed), not
|
|
106
|
+
* re-ranking.
|
|
107
|
+
*/
|
|
108
|
+
export declare const DEFAULT_ENTITY_LEG_WEIGHT = 0.1;
|
|
109
|
+
/**
|
|
110
|
+
* Default weight of the CLIP image leg (Track B of image memory).
|
|
111
|
+
*
|
|
112
|
+
* Same role as the entity leg — a RECALL leg that surfaces candidates
|
|
113
|
+
* the text legs could not match, not a re-ranking signal — so it sits
|
|
114
|
+
* just below the semantic leg's 0.2, at the entity leg's level. The
|
|
115
|
+
* leg is inert whenever it has no results (no CLIP configured, no image
|
|
116
|
+
* embeddings stored), so this default never moves a text-only store's
|
|
117
|
+
* ranking by a single bit.
|
|
118
|
+
*/
|
|
119
|
+
export declare const DEFAULT_IMAGE_LEG_WEIGHT = 0.1;
|
|
120
|
+
/**
|
|
121
|
+
* Lower bound of the trust multiplier. A memory with trustScore 0 is
|
|
122
|
+
* multiplied by `trustFloor`; trustScore 1 by 1.0. Kept gentle (0.7)
|
|
123
|
+
* so trust nudges ranking without dominating pure relevance.
|
|
124
|
+
*/
|
|
125
|
+
export declare const DEFAULT_TRUST_FLOOR = 0.7;
|
|
126
|
+
/**
|
|
127
|
+
* Weight of the confidence multiplier applied AFTER fusion. The
|
|
128
|
+
* confidence state machine (`src/confidence-machine.ts`) tracks how
|
|
129
|
+
* consistently a memory has been reinforced vs contradicted over time;
|
|
130
|
+
* `confidenceWeight()` combines that with trust via a geometric mean
|
|
131
|
+
* and heavily suppresses memories below the confidence floor (e.g.
|
|
132
|
+
* superseded or contradicted facts). Applied as
|
|
133
|
+
* `score *= floor + weight * (combinedWeight - floor)` — gentle by
|
|
134
|
+
* default so relevance ordering dominates unless evidence says
|
|
135
|
+
* otherwise. Set to `0` to disable confidence-aware ranking.
|
|
136
|
+
*/
|
|
137
|
+
export declare const DEFAULT_CONFIDENCE_WEIGHT = 0.35;
|
|
138
|
+
/**
|
|
139
|
+
* Half-life for the recency tie-break, in milliseconds. Among fused
|
|
140
|
+
* candidates whose scores are within `RECENCY_EPSILON` of each other,
|
|
141
|
+
* the newer memory wins; the boost decays with an exponential half-life
|
|
142
|
+
* (default 30 days) so it only ever re-orders near-ties, never overrides
|
|
143
|
+
* a clear relevance gap. This lifts "Knowledge Update" / "Temporal
|
|
144
|
+
* Reasoning" style queries where two versions of a fact both match but
|
|
145
|
+
* only the current one should surface first. Set to `0` to disable.
|
|
146
|
+
*/
|
|
147
|
+
export declare const DEFAULT_RECENCY_HALF_LIFE_MS: number;
|
|
148
|
+
/**
|
|
149
|
+
* Score window in which candidates are considered TIED for recency
|
|
150
|
+
* tie-breaking. This is a float-noise window (~1e-9), NOT a fuzzy band:
|
|
151
|
+
* adjacent RRF ranks differ by ~w/(K+i)² ≈ 2e-4, three orders of
|
|
152
|
+
* magnitude above this threshold, so genuine rank separation always
|
|
153
|
+
* holds and recency only arbitrates candidates whose fused contributions
|
|
154
|
+
* are mathematically indistinguishable (e.g. rank-1 in the keyword leg
|
|
155
|
+
* vs rank-1 in the semantic leg under equal weights, or duplicate
|
|
156
|
+
* facts ingested twice).
|
|
157
|
+
*/
|
|
158
|
+
export declare const RECENCY_EPSILON = 1e-9;
|
|
159
|
+
/**
|
|
160
|
+
* Fuse two (optionally three) ranked retrieval lists into one, then apply
|
|
161
|
+
* trust weighting.
|
|
162
|
+
*
|
|
163
|
+
* All legs are expected to be pre-ranked best-first (as returned by FTS5
|
|
164
|
+
* bm25, cosine-similarity search, and the entity-inverted-index lookup).
|
|
165
|
+
* Candidates appearing in multiple legs accumulate each leg's RRF
|
|
166
|
+
* contribution.
|
|
167
|
+
*
|
|
168
|
+
* @param keywordResults — Ranked keyword/FTS5 leg (best first).
|
|
169
|
+
* @param semanticResults — Ranked semantic/embedding leg (best first).
|
|
170
|
+
* @param options — Tunable weights; see {@link FusionOptions}.
|
|
171
|
+
* @param entityResults — Ranked entity-inverted-index leg (best first).
|
|
172
|
+
* Optional third RRF leg: memories sharing entities with the query that
|
|
173
|
+
* the keyword/semantic legs missed still enter the candidate pool.
|
|
174
|
+
* @returns Fused list sorted by descending hybrid score, with a `scores`
|
|
175
|
+
* breakdown (`keyword`, `semantic`, `entityLeg`, `hybrid`, plus `entity`
|
|
176
|
+
* when the entity-overlap boost fires) on each entry.
|
|
177
|
+
*/
|
|
178
|
+
export declare function fuseResults(keywordResults: ScoredMemory[], semanticResults: ScoredMemory[], options?: FusionOptions, entityResults?: ScoredMemory[], imageResults?: ScoredMemory[]): ScoredMemory[];
|
|
179
|
+
/**
|
|
180
|
+
* Default tail-trim threshold: a candidate is kept when its fused score
|
|
181
|
+
* is at least this fraction of the top score. Deliberately low — it
|
|
182
|
+
* exists to cut the long tail of "matched one stopword" rows, not to
|
|
183
|
+
* make fine-grained relevance decisions.
|
|
184
|
+
*/
|
|
185
|
+
export declare const DEFAULT_RELEVANCE_RATIO = 0.15;
|
|
186
|
+
/**
|
|
187
|
+
* Default abstention floor on the semantic leg's cosine similarity.
|
|
188
|
+
*
|
|
189
|
+
* 0.3 is not arbitrary: `SEMANTIC_FUSION_THRESHOLD` and the fusion
|
|
190
|
+
* comments already treat ~0.3 as the point where a real embedder's
|
|
191
|
+
* paraphrase matches begin. Below it, a hit is coincidence.
|
|
192
|
+
*
|
|
193
|
+
* This is OPT-IN (`filter.abstainBelowSimilarity`) because the floor is
|
|
194
|
+
* embedder-dependent — a 256-d hash embedder and a 1024-d transformer
|
|
195
|
+
* do not share a cosine scale. Calibrate per embedder before enabling.
|
|
196
|
+
*/
|
|
197
|
+
export declare const DEFAULT_ABSTAIN_SIMILARITY = 0.3;
|
|
198
|
+
export interface RelevanceGateOptions {
|
|
199
|
+
/**
|
|
200
|
+
* Abstain (return nothing) when no candidate reaches this cosine
|
|
201
|
+
* similarity AND nothing matched the query literally. `undefined`
|
|
202
|
+
* disables abstention. See {@link DEFAULT_ABSTAIN_SIMILARITY}.
|
|
203
|
+
*/
|
|
204
|
+
abstainBelowSimilarity?: number;
|
|
205
|
+
/**
|
|
206
|
+
* Keep only candidates scoring at least `topScore * relevanceRatio`.
|
|
207
|
+
* `undefined` or `0` disables trimming.
|
|
208
|
+
*/
|
|
209
|
+
relevanceRatio?: number;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* True when any candidate literally contains a query term.
|
|
213
|
+
*
|
|
214
|
+
* Guards abstention against its main failure mode: a bullseye exact-term
|
|
215
|
+
* hit (a rare proper noun, a product name) can score a low cosine when
|
|
216
|
+
* the embedder barely knows the word. Abstaining there would throw away
|
|
217
|
+
* a perfect answer, so a literal match always wins over the cosine test.
|
|
218
|
+
*/
|
|
219
|
+
export declare function hasExactTermMatch(query: string, results: ScoredMemory[]): boolean;
|
|
220
|
+
/**
|
|
221
|
+
* Decide whether retrieval found anything worth returning at all.
|
|
222
|
+
*
|
|
223
|
+
* Conservative by construction — three independent escape hatches, each
|
|
224
|
+
* of which suppresses abstention:
|
|
225
|
+
*
|
|
226
|
+
* - no floor configured, or no results at all → never abstain;
|
|
227
|
+
* - no candidate carries a semantic score (keyword-only retrieval, or no
|
|
228
|
+
* embedding provider) → cannot judge similarity, so never abstain;
|
|
229
|
+
* - any candidate reaches the cosine floor → clearly relevant, return.
|
|
230
|
+
*
|
|
231
|
+
* Only when every candidate is below the floor do we abstain, and even
|
|
232
|
+
* then a literal term match rescues the result set.
|
|
233
|
+
*
|
|
234
|
+
* **Reads `scores.semanticRaw`, never `scores.semantic`.** Convex fusion
|
|
235
|
+
* (the default mode) min-max-normalizes each leg, so `scores.semantic`
|
|
236
|
+
* holds a fusion weight whose top candidate is always exactly `1` —
|
|
237
|
+
* comparing that against an absolute floor can never fail, which made
|
|
238
|
+
* abstention dead code on the default path. `semanticRaw` carries the
|
|
239
|
+
* unnormalized cosine on the embedder's own scale. The fallback to
|
|
240
|
+
* `scores.semantic` is for hand-built results and custom fusion paths
|
|
241
|
+
* that predate the raw field; those already store a raw value in
|
|
242
|
+
* `semantic` (see `rrfFuse`).
|
|
243
|
+
*/
|
|
244
|
+
export declare function shouldAbstain(results: ScoredMemory[], query: string, options?: RelevanceGateOptions): boolean;
|
|
245
|
+
/**
|
|
246
|
+
* Apply abstention and tail trimming to a fused, best-first result list.
|
|
247
|
+
*
|
|
248
|
+
* Pure and dependency-free (like {@link fuseResults}) so it can be unit
|
|
249
|
+
* tested without storage, embeddings, or a MemOS instance.
|
|
250
|
+
*/
|
|
251
|
+
export declare function applyRelevanceGate(results: ScoredMemory[], query: string, options?: RelevanceGateOptions): ScoredMemory[];
|
|
252
|
+
/**
|
|
253
|
+
* Build an expanded query by harvesting distinctive terms from the top
|
|
254
|
+
* `maxDocs` candidates of a first retrieval pass.
|
|
255
|
+
*
|
|
256
|
+
* Scores terms by DOCUMENT FREQUENCY across the top candidates rather
|
|
257
|
+
* than raw term frequency, so one long memory cannot dominate the
|
|
258
|
+
* expansion. Returns `""` when nothing was harvested, which callers
|
|
259
|
+
* treat as "skip the second pass".
|
|
260
|
+
*/
|
|
261
|
+
export declare function expandQueryWithPseudoRelevance(query: string, results: ScoredMemory[], options?: {
|
|
262
|
+
maxDocs?: number;
|
|
263
|
+
maxTerms?: number;
|
|
264
|
+
}): string;
|
|
265
|
+
//# sourceMappingURL=retrieval.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retrieval.d.ts","sourceRoot":"","sources":["../src/retrieval.ts"],"names":[],"mappings":"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"}
|