$ show CortexReach/memory-lancedb-pro
This is a production-grade long-term memory plugin for the OpenClaw AI agent platform, built as a TypeScript/ESM module. It provides a complete memory lifecycle: LLM-powered extraction from conversation transcripts (6-category classification with L0/L1/L2 layering), hybrid vector+BM25 retrieval with cross-encoder reranking, Weibull decay-based importance scoring, tier management (core/working/peripheral), and multi-scope isolation (global, agent, user, project). The plugin integrates deeply into OpenClaw via lifecycle hooks, agent tools, CLI commands, and a dreaming engine for periodic consolidation. It stores all data in LanceDB and supports multiple embedding providers, LLM backends, and OAuth flows. The codebase is large and complex, with extensive test coverage (100+ tests) and many edge-case handlers, but exhibits significant technical debt in a single massive index.ts file and multiple fallback/legacy migration paths. It is not a research project; it is a highly functional, actively maintained plugin with a clear engineering focus on correctness, resilience, and performance.
The LLM identified 4 files worth highlighting for reuse:
Implements a Weibull stretched-exponential decay function for scoring memory importance based on recency, frequency, and intrinsic importance. Exported as a factory function `createDecayEngine(options)` that returns a `scoreMemory` function. Configurable half-life, tier-specific beta, and frequency/intrinsic components. Completely self-contained with no internal imports, making it reusable as a generic decay scoring utility for any application needing time-decay ranking.
Provides `expandQuery(query, source)` which appends technical synonyms to a user query for improved BM25 retrieval. Uses a static map of Chinese terms to English equivalents (e.g., 'ĺ´Šćş' â 'ĺ´Šćş crash error') and avoids false positives via substring checks. Gated by `source` parameter to only apply to manual recall, not auto-recall. Highly reusable as a standalone utility for expanding search queries with domain-specific synonyms.
Implements a `TraceCollector` class that instruments each stage of a retrieval pipeline with start/end counts, duration, and drop IDs. Exposes `getLastDiagnostics()` returning a structured JSON object with stage-by-stage counts, drop summary, and failure stage. Designed as a pass-through collector that can be injected into any multi-stage pipeline (not just retrieval). No internal imports, making it a reusable pattern for observability in any data processing flow.
Provides `parseSmartMetadata()`, `buildSmartMetadata()`, and `stringifySmartMetadata()` for converting between raw metadata strings and structured objects, supporting both camelCase and snake_case field names, legacy compatibility, clamping, and lifecycle-aware boolean checks (`isMemoryExpired`, `isMemoryActiveAt`). Self-contained with no internal imports beyond standard types. Can be extracted as a generic metadata handling utility for any system that stores structured metadata in a JSON string column.