Skip to content

Add optional embedding reranker#13

Merged
Da7-Tech merged 2 commits into
Da7-Tech:mainfrom
therealclvn:codex/pluggable-embed-backend
Jul 14, 2026
Merged

Add optional embedding reranker#13
Da7-Tech merged 2 commits into
Da7-Tech:mainfrom
therealclvn:codex/pluggable-embed-backend

Conversation

@therealclvn

@therealclvn therealclvn commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Closes #1.

Summary

  • add an optional MIND_EMBED_CMD command-backed embedder for recall head re-ranking
  • keep the default path offline, deterministic, stdlib-only, and behaviorally unchanged
  • execute a trusted local command directly as argv, never through a shell
  • fall back to HashEmbed on missing commands, timeouts, non-zero exits, oversized output, invalid or zero vectors, or dimension mismatch
  • keep fallback comparisons entirely in the hash-vector space; external and fallback vectors are never mixed
  • retry transient per-text failures after a short cache window instead of poisoning that text for the process lifetime
  • update the benchmark to always report the offline column and, when configured, an embedded re-rank column
  • document the hook and MIND_EMBED_TIMEOUT

Maintainer audit corrections

The initial implementation had two correctness/resource defects:

  1. If the command succeeded for one text and failed for another, equal vector dimensions could cause cosine similarity between unrelated embedding spaces. The cache now records vector provenance, and any partial failure falls back to HashEmbed.similarity() for both texts.
  2. Command stdout was captured into memory before the one-megabyte check. Output now goes to a temporary file, so an accidental flood does not consume the Python heap; oversized output is rejected before parsing.

The audit also added:

  • short-lived caching for failed command results, followed by retry
  • zero-vector rejection
  • regression tests for mixed-space fallback, transient recovery, oversized output, and zero vectors
  • a clean rebase onto the merged LongMemEval benchmark work

Behavior and trust boundary

MIND_EMBED_CMD is explicit operator configuration for a trusted local executable. It is parsed with shlex and passed to subprocess without shell=True. The command receives one text on stdin and must print a JSON vector or whitespace/comma-separated floats.

Only the recall head re-ranker uses it. Dream clustering, fuzzy fallback, pattern separation, storage, persistence, graph mutation, and the default offline recall path continue to use the deterministic built-in embedder.

Verification

  • python3 -m unittest discover -s tests — 278 passed after rebasing onto current main
  • python3 bench/bench.py
  • env MIND_EMBED_CMD='/bin/echo 1 0' python3 bench/bench.py
  • python3 bench/multilang.py
  • python3 bench/discrim.py
  • python3 bench/soak.py
  • python3 bench/fuzz.py --quick
  • python3 bench/longmemeval.py --data tests/fixtures/longmemeval_tiny.json --limit 2
  • python3 -m compileall mind.py bench/bench.py bench/longmemeval.py tests/test_mind.py tests/test_longmemeval_bench.py
  • git diff --check

Manual security/privacy review found no shell execution, secret persistence, network calls, or personal data in the added code or maintainer commit metadata.

@therealclvn therealclvn force-pushed the codex/pluggable-embed-backend branch from d78b5fa to 1bc3854 Compare July 12, 2026 21:51
@Da7-Tech Da7-Tech force-pushed the codex/pluggable-embed-backend branch from 1bc3854 to 00c7572 Compare July 14, 2026 01:24
@Da7-Tech

Copy link
Copy Markdown
Owner

Maintainer audit revision pushed as 00c7572 and rebased onto current main after #14 merged.

The critical fixes are provenance-aware fallback (no external/hash vector-space mixing), transient-failure retry, zero-vector rejection, and temporary-file stdout capture before the one-megabyte parse limit. Documentation now states the trusted-command boundary and timeout control.

All 278 tests plus the benchmark, multilingual, discrimination, soak, fuzz, embedded-command, and LongMemEval smoke paths pass locally. Waiting for the refreshed nine-job matrix before merge.

@Da7-Tech Da7-Tech merged commit aaf2695 into Da7-Tech:main Jul 14, 2026
9 checks passed
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.

Pluggable semantic backend (optional embeddings) behind the same recall API

2 participants