Skip to content

feat(quality): pre-write memory quality gate foundation - #748

Open
andreyt2002-droid wants to merge 1 commit into
zilliztech:mainfrom
andreyt2002-droid:feat/prewrite-memory-quality-filter
Open

andreyt2002-droid wants to merge 1 commit into
zilliztech:mainfrom
andreyt2002-droid:feat/prewrite-memory-quality-filter

Conversation

@andreyt2002-droid

Copy link
Copy Markdown
Contributor

Summary

Foundation for the pre-write memory quality filter (Proposal 002): a deterministic, fail-open way for capture integrations to score a pending journal section before appending it, so meta-memory noise, ultra-short notes, and near-duplicates stop diluting recall.

  • src/memsearch/quality.py — pure score_section() (no I/O, no LLM, no shared state). Penalties: meta-memory vocabulary (−25), agent-verbosity boilerplate (−10), below min_content_length after normalization (−30), token repetition ratio > 0.6 (−20), near-duplicate of a recent section (shingle Jaccard > 0.8, −40). Returns write / degrade / reject with score and reasons. Normalization is UTF-8 replacement-safe for lone surrogates so verdicts never crash on console-captured text.
  • [quality_filter] config section (enabled, min_content_length, degrade_threshold, reject_threshold) — global-only by design: project .memsearch.toml stays restricted to low-risk indexing keys and cannot change capture automation policy.
  • memsearch quality CLI — side-effect free: reads the candidate from stdin plus repeatable --recent-file journals (current + prior day covers the 48h duplicate window), emits a stable JSON verdict; never writes a journal or opens Milvus. Designed so plugins call it via direct argv/stdin without a shell.
  • Fail-open contract is documented: an unavailable/malformed/timeout verdict must preserve existing capture behavior, so the gate cannot lose valid captures.
  • Docs: docs/cli.md (command + config keys), docs/home/configuration.md (section explaining thresholds and global-only placement).

Testing

  • tests/test_quality.py — each penalty rule, exact threshold boundaries, Jaccard strictly > 0.8, disabled filter preserves writes, surrogate/anchor normalization, invalid threshold order rejected.
  • tests/test_cli_quality.py — JSON verdict stability, --recent-file duplicate detection, empty-stdin error goes to stderr with nonzero exit.
  • tests/test_config.py — defaults and project-config cannot alter quality policy.
  • Windows: new quality tests 11/11; CLI+quality regression set 50/50; Ruff check/format clean; mkdocs build --strict passes.
  • Ubuntu (isolated worktree at this commit): same suites 60 passed, 0 failed.

Scope / follow-up

Core + CLI only — deliberately no plugins/ wiring in this PR to keep it independent of the open Windows-runtime PR #721. DSH integration (post-summary gate before writeCapture(), quality:<score> anchor tag for degraded writes) follows as a small separate PR on top of merged #721.

Deterministic, side-effect-free scoring for captured memory sections:

- src/memsearch/quality.py: pure UTF-8-safe score_section() with
  meta-memory, boilerplate, length, repetition, and near-duplicate
  (shingle Jaccard) penalties returning write/degrade/reject.
- [quality_filter] global-only config section (project .memsearch.toml
  cannot change capture automation policy).
- `memsearch quality` CLI: reads a candidate from stdin plus
  repeatable --recent-file journals, emits a stable JSON verdict,
  never touches journals or Milvus.
- Focused unit/CLI/config tests; docs for the command and config.

Foundation for Proposal 002; DSH wiring follows separately after zilliztech#721.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant