Skip to content

feat: add neural Mneme indexing and associative think#8

Open
georgeantonopoulos wants to merge 10 commits into
mainfrom
experiment/neural-think
Open

feat: add neural Mneme indexing and associative think#8
georgeantonopoulos wants to merge 10 commits into
mainfrom
experiment/neural-think

Conversation

@georgeantonopoulos

@georgeantonopoulos georgeantonopoulos commented Jul 18, 2026

Copy link
Copy Markdown
Owner

Summary

Adds an experimental neural interface for Mneme:

perception -> latent neuron activation -> synapse propagation -> thought context -> feedback

The existing relational model remains intact as auditable storage. This PR adds a smaller agent-facing path for local indexing and associative thought.

What changed

  • add incremental local latent indexing with Ollama embeddings
  • add a deterministic signed feature-hash provider for offline tests
  • add mneme index and mneme think CLI commands
  • spread activation through active synapses only
  • prevent candidate, killed, and zero-weight synapses from becoming factual thought paths
  • preserve provenance, truth policy, contract identity, and activation reasons in the generated context packet
  • detect changed or mixed embedding widths instead of silently truncating cosine comparisons
  • exclude extraction scaffolding from latent seed selection while retaining it for graph traversal
  • document rollout, freshness checks, evaluation, and retrieval pitfalls
  • accept description/expected_by as compatible prediction fields while keeping canonical prediction output
  • tighten Mneme-only memory-interface guidance

Test plan

  • pytest -q with the declared dev dependencies - 316 passed
  • mneme run-once --vault ./examples/vault --db /tmp/mneme_smoke.sqlite --out /tmp/mneme_smoke_out - passed against the bundled example vault
  • mneme contract check --db /tmp/mneme_smoke.sqlite - passed with zero failures and zero warnings
  • python scripts/privacy_scan.py - passed
  • git diff --check origin/main...HEAD - passed

Mneme contract checklist

  • Active semantic edges require explicit evidence and validation.
  • Candidate edges remain tentative in retrieval, surface, and thoughts.
  • Killed edges cannot be resurrected by ingest, update, promote, or remember.
  • Feedback weakens by default and kills only false relationships.
  • Old open loops require fresh source evidence before being treated as live.
  • Agent-facing neural outputs include truth_policy and contract metadata.

Privacy checklist

  • No real vault content
  • No generated databases/cards from private notes
  • No secrets, tokens, or credentials
  • No private names, emails, paths, IDs, or project-specific examples
  • All branch commits use the generic noreply author and committer identity

Scope

This is an experimental vertical slice, not a replacement of the existing world model. Latent similarity remains an associative lead rather than factual evidence, and the source must be checked before making a factual claim.

Summary by CodeRabbit

  • New Features

    • Added mneme index to build a local semantic memory index.
    • Added mneme think for semantic retrieval, controlled association, temporal decay, and source-backed evidence.
    • Added offline deterministic retrieval support alongside local embedding-based retrieval.
    • Added compatibility handling for legacy prediction fields.
  • Documentation

    • Added guidance for neural retrieval, live-vault evaluation, entity retrieval, and hook safety.
    • Updated operating rules, provenance requirements, and verification procedures.
  • Bug Fixes

    • Improved hook cleanup and prevention of leaked reminder text.
    • Improved prediction normalization and repeatability.
  • Tests

    • Expanded coverage for retrieval, indexing, temporal behavior, evidence, CLI validation, hooks, and predictions.

@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds a latent neuron index with hash or Ollama embeddings, introduces mneme index and mneme think, updates neural operating guidance and hook reminders, adds neural tests, and normalizes legacy prediction payload fields for stable replay.

Changes

Neural Think Workflow

Layer / File(s) Summary
Neural experiment contracts
NEURAL_EXPERIMENT.md, skills/mneme/references/neural-think-experiment.md, skills/mneme/references/person-entity-retrieval.md
Defines latent indexing, activation propagation, provenance requirements, evaluation criteria, and entity retrieval behavior.
Latent index and activation engine
src/mneme/neural.py
Adds SQLite latent-neuron storage, hash and Ollama embeddings, incremental indexing, temporal decay, similarity seeding, active-synapse propagation, provenance, and context formatting.
CLI wiring and neural validation
src/mneme/cli.py, tests/test_neural.py, tests/test_cli_contracts.py
Adds index and think commands with configuration and activation options, then tests indexing updates, propagation, structured output, evidence hydration, temporal decay, and argument validation.
Operating guidance and hook integration
skills/mneme/SKILL.md, skills/mneme/references/hermes-live-vault-evaluation.md, skills/mneme/references/hook-directive-order.md, scripts/mneme_senses_context_hook.py, tests/test_hook_directive_order.py
Updates neural workflow, vault, temporal evaluation, provenance, hook-injection, reminder, and leak-marker guidance.

Prediction Compatibility

Layer / File(s) Summary
Prediction payload normalization
src/mneme/world_model/predictions.py, tests/test_world_model_predictions.py
Maps description and expected_by to canonical prediction fields and generates stable identifiers from normalized values.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Operator
  participant MnemeCLI
  participant build_latent_index
  participant SQLite
  participant neural_think
  Operator->>MnemeCLI: run mneme index
  MnemeCLI->>build_latent_index: build latent index
  build_latent_index->>SQLite: read neurons and edges
  build_latent_index->>SQLite: upsert latent vectors
  Operator->>MnemeCLI: run mneme think with prompt
  MnemeCLI->>neural_think: submit prompt
  neural_think->>SQLite: load vectors and active edges
  neural_think->>neural_think: rank seeds and spread activation
  neural_think-->>MnemeCLI: return activations, provenance, and context
  MnemeCLI-->>Operator: print JSON result
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 1.41% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed Short, clear, and accurately summarizes the neural Mneme indexing and associative think changes.
Description check ✅ Passed Includes all required template sections and filled-in checks, with test plan, contract, and privacy items completed.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch experiment/neural-think

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5698647f95

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/mneme/neural.py Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@scripts/mneme_senses_context_hook.py`:
- Line 68: Update the production _strip_injected_context marker list to
recognize and remove COMPACT_MEMORY_REMINDER, preferably using a stable prefix
so quoted variants are stripped; add an end-to-end regression test for
scripts/mneme_senses_context_hook.py confirming the reminder is not reprocessed
as user content.

In `@src/mneme/cli.py`:
- Around line 324-336: Add argparse-level positive integer validation for
--batch-size, --dimensions, --seeds, --limit, and --max-neurons in the neural
command definitions, rejecting zero and negative values. Add non-negative
validation for --hops, allowing zero while rejecting negatives, and ensure
invalid values fail during argument parsing.

In `@src/mneme/neural.py`:
- Around line 143-145: The public neural APIs currently overwrite caller-owned
SQLite connection configuration. In build_latent_index at
src/mneme/neural.py:143-145 and think at src/mneme/neural.py:243-245, capture
the existing conn.row_factory before assigning sqlite3.Row, then restore the
original value before returning or closing the caller-provided connection;
preserve the current behavior for connections created from paths.
- Around line 103-110: The neural pipeline must ignore active edges with zero
effective strength or confidence in both stages. In _neuron_rows, filter the
active edge join so zero-weight edges are excluded from embedded neuron text; in
the later propagation logic at src/mneme/neural.py lines 292-293, default only
NULL weights and preserve explicit zero values.
- Around line 164-169: Update the incremental-index identity check around the
latent_neurons lookup to include the hash dimensions alongside content_hash,
provider, and model. Select the stored dimensions and require it to match the
current dimensions before continuing; a mismatch must proceed through rebuilding
so vectors are regenerated at the requested size.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e7c09379-fd66-4ee4-a4c7-c1be40a482c1

📥 Commits

Reviewing files that changed from the base of the PR and between 77703f5 and 5698647.

📒 Files selected for processing (13)
  • NEURAL_EXPERIMENT.md
  • scripts/mneme_senses_context_hook.py
  • skills/mneme/SKILL.md
  • skills/mneme/references/hermes-live-vault-evaluation.md
  • skills/mneme/references/hook-directive-order.md
  • skills/mneme/references/neural-think-experiment.md
  • skills/mneme/references/person-entity-retrieval.md
  • src/mneme/cli.py
  • src/mneme/neural.py
  • src/mneme/world_model/predictions.py
  • tests/test_hook_directive_order.py
  • tests/test_neural.py
  • tests/test_world_model_predictions.py

Comment thread scripts/mneme_senses_context_hook.py
Comment thread src/mneme/cli.py Outdated
Comment thread src/mneme/neural.py
Comment thread src/mneme/neural.py
Comment thread src/mneme/neural.py
@georgeantonopoulos

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 355c1884cc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/mneme/neural.py
noreply added 2 commits July 18, 2026 21:15
Validate that stored latent vectors use one consistent width and that the live query embedding matches it before cosine ranking. If an Ollama model tag changes width, fail clearly with the mneme index --rebuild recovery path instead of silently truncating vectors.

Add a regression test that simulates an Ollama model changing from three dimensions to two. Verified with 36 focused tests, 316 full-suite tests, the privacy scan, the example-vault smoke run, and the Mneme contract check.
Attach the existing Mneme agent-brain contract name and version to think results, and mark each activated neuron as provenance_not_fact so associative leads cannot be mistaken for verified facts.

Add contract assertions to the neural propagation test. Verified with 7 focused tests, 316 full-suite tests, and the repository privacy scan.
@georgeantonopoulos
georgeantonopoulos force-pushed the experiment/neural-think branch from 830bdff to 9d7e1f1 Compare July 18, 2026 18:16

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/mneme/neural.py (1)

596-604: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

signals["latent"]["cosine"] reports the decayed score, not the raw cosine.

decayed_score_by_id holds cosine * temporal_decay (Line 544), so labeling it cosine misrepresents the similarity signal in the activation reason payload consumers use for evaluation — especially since the lexical sibling already separates raw_score, calibrated_score, and the decayed score. Consider renaming this field (e.g. decayed_cosine/score) or emitting the pre-decay cosine alongside temporal_decay for parity. Confirm no doc/contract in NEURAL_EXPERIMENT.md depends on the current key.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/mneme/neural.py` around lines 596 - 604, The latent signal currently
labels the decayed value from decayed_score_by_id as cosine. Update the signal
payload construction near the in_latent branch to distinguish the decayed value,
preferably by renaming the key to decayed_cosine or score, and preserve
compatibility with any documented contract such as NEURAL_EXPERIMENT.md before
changing the field name.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/mneme/neural.py`:
- Around line 596-604: The latent signal currently labels the decayed value from
decayed_score_by_id as cosine. Update the signal payload construction near the
in_latent branch to distinguish the decayed value, preferably by renaming the
key to decayed_cosine or score, and preserve compatibility with any documented
contract such as NEURAL_EXPERIMENT.md before changing the field name.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 180f1c3d-2bda-4ffe-9d05-5d9e34551e92

📥 Commits

Reviewing files that changed from the base of the PR and between 5698647 and 8bbe713.

📒 Files selected for processing (8)
  • NEURAL_EXPERIMENT.md
  • scripts/mneme_senses_context_hook.py
  • skills/mneme/references/neural-think-experiment.md
  • src/mneme/cli.py
  • src/mneme/neural.py
  • tests/test_cli_contracts.py
  • tests/test_hook_directive_order.py
  • tests/test_neural.py
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/mneme/cli.py
  • NEURAL_EXPERIMENT.md
  • scripts/mneme_senses_context_hook.py

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.

2 participants