Skip to content

fix(memory): format Nemotron embeddings and refresh aliased vectors - #184142

Merged
steipete merged 6 commits into
mainfrom
fix/doc-prefixes
Oct 26, 2026
Merged

steipete merged 6 commits into
mainfrom
fix/doc-prefixes

Conversation

@steipete

@steipete steipete commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes missing query/document task prefixes for Nemotron embedding models and stale vectors after an Ollama embedding alias changes its backing model. Fixes #182842. Thanks @ajmtrz for the report and retrieval measurements.

User Impact

Recognizable Nemotron-3-Embed and Nemotron-3.5-Embed models receive "query: " and "passage: " prefixes. Aliased models can set memory.search.inputFormat: { query: "query: ", document: "passage: " }. Whitespace is preserved; empty strings select raw text. A nonempty queryInstruction still wins for queries. Explicit document formatting also replaces Gemini's default template in synchronous and asynchronous requests.

Built-in format upgrades rebuild affected indexes once. Explicit document-prefix changes and changed Ollama digests invalidate both the index and embedding cache; use openclaw memory index --force when configuration identity reports a mismatch. Query-only changes preserve document vectors. Compatible digestless Ollama indexes adopt the first observed digest while preserving cached vectors. The old index cannot establish whether an alias was retargeted before that first observation; reset memory first if it was.

Ollama checks its advertised digest when the embedding provider opens, so an already-open provider must reopen after alias retargeting. Embedding-only endpoints without /api/tags remain supported; use memory reset after changing an alias on those endpoints. Global --force cache behavior is unchanged.

Why This Change Was Made

The shared formatter owns both roles, and its revisioned identity isolates document-format changes. Native Ollama adds its resolved model digest to that identity. The existing atomic provider-key migration adopts compatible legacy cache rows; alias cache reads require matching published metadata so leftover or unpublished legacy vectors cannot contaminate a later digest. No new schema or persistence owner was introduced.

NVIDIA documents the exact prefixes in the Nemotron-3 model card and Nemotron-3.5 saved prompts. Matching stays narrow because other Nemotron families have different contracts.

Production: +250/-61 lines; tests: +527/-92; docs/generated: +67/-12; one obsolete mock-baseline line removed. Necessary growth supplies paired config, identity/format plumbing, bounded authenticated digest lookup, and safe legacy-cache adoption. Formatting stays in the existing embedding-policy owner; the oversized embedding-ops module shrinks.

Evidence

  • The original built CLI sent raw known-model text and retained stale vectors after alias A→B plus memory index --force. Regressions failed before repair. The published-upgrade follow-up also reproduced one unnecessary ordinary-document request and three stale-cache paths before repair.
  • Upgrade/identity suites pass 61 tests (199.32s); existing compatible-index/provider-bridge consumers pass 3 tests (143.68s); native HTTP transport passes 5 tests (247.29s). These include zero-work cache reuse, later digest invalidation, orphan-cache exclusion, and mixed/newer-version guards. Earlier unchanged-scope validation includes 65 Gemini tests (59.65s) and 37 config tests (215.80s). Wall times include compiled-worker preparation.
  • Extension production/test types, scoped lint, all ten baseline ratchets, config docs, plugin inventory, and diff checks pass. Prompt snapshots were regenerated with no diff (0 token change).
  • Fresh independent Codex review through P2 on 1db10d3ce63bb9ec01ac7e1e74b1034fa770839e: scoped-clean. Full build passes (791.60s elapsed, including artifact-lock waiting; active phases 544.4s).
  • The unchanged Gemini transport fix has 12 built-CLI checks (116.23s): synchronous and asynchronous indexing each transition unset→raw→custom with exact request bytes and changed identity. A real Ollama control also passed nomic index/search and same-alias bge retarget at 32 dimensions (three commands, 30.60s); the changed digest replaced the stored vector and retrieved the expected memory.

Upgrade proof

On macOS, installed published [email protected] into an isolated npm prefix, HOME, state, and config; indexed/searched a synthetic MEMORY.md; then manually replaced the package in that same prefix with the validated tarball built from 1db10d3ce63bb9ec01ac7e1e74b1034fa770839e. This was a local npm package replacement, not an automatic update. Both restored states matched every published memory table before the candidate first opened them. The ordinary case used real Ollama nomic-embed-text:latest; the Nemotron name used a deterministic Ollama-compatible endpoint with different vectors for raw, automatic, and explicit document formats.

The upgrade proof exposed and now covers the ordinary-model cache migration bug fixed in the follow-up: the earlier candidate sent one unnecessary unchanged document request. The repaired candidate preserves its vector bytes and cache timestamps, adopts the digest key atomically, and retires the legacy namespace.

Case First search Repeat search Document embedding requests Result
Real nomic 12.583s 8.705s 0, then 0 Same chunk/vector bytes and cache timestamps; repeat leaves all memory tables unchanged
Synthetic Nemotron 7.872s 8.790s 1, then 0 Format revision 0→1; stored vector changes; repeat leaves all memory tables unchanged

A literal zero index rewrite is not possible against this stable baseline: main already changed chunking revision 5→6 in #168867. Both cases undergo that inherited one-time chunking rebuild. This PR adds zero document re-embeddings for the ordinary model; it preserves the old cache/vector bytes through that rebuild.

Captured identity and request excerpts (synthetic text; local paths omitted):

nomic:    3503f69d17ca39d924ded77fd085439fbff22fcd36140844ce2d114d32e077bf
       -> 8c85a5ba445b70f9d185b11ba500260a37ff13e779422d6391e68fd6b65295bc
Nemotron: b1a6a728712ed01f5ff1a529f5cde53d40650769841e0d4b4fd2b490529d9e1c
       -> f96eb9c4804d8cef17069188e6b3eb7aa28940b0419596255b02badc769eb433

Nemotron document: "passage: # Synthetic upgrade memory\nThe celadon orchard observations are stored in the amber notebook.\n"
Nemotron query: "query: Where are the celadon orchard observations stored?"
retrieved path: "MEMORY.md"

Explicit override replay passed all six index/search commands in 37.184s. {query: "lookup: ", document: "record: "} sends those exact bytes and embeds once. Changing only the query to "find: " preserves the provider key, cache bytes/timestamps, and makes zero document requests. The raw pair sends the original unprefixed bytes under a distinct key and embeds once. Retrieval succeeds in every case.

Both published-state Doctor migrations completed successfully in parallel (82.888s each). Final config validation passes. Final Doctor output on each state is {"ok":true,"checksRun":41,"checksSkipped":30,"findings":[]} (19.257s/19.268s); versioned SQLite stores have no pending migrations or schema mismatch, and Doctor leaves every memory table unchanged. The isolated diagnostic config declares its existing local Qwen model and disables the unused legacy browser relay, removing unrelated discovery/legacy-relay warnings. No operator state or Gateway was used.

The candidate tarball passed the canonical integrity/import-graph check and the installed build reports the exact head above. Manual replacement took 137.688s plus a 1.356s allowlisted dependency rebuild. Exact Nemotron quality remains untested; this verifies its input contract, persisted-vector replacement, retrieval, and upgrade behavior using synthetic vectors, with real nomic as the ordinary-model control.

@clawsweeper

clawsweeper Bot commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation extensions: memory-core Extension: memory-core agents Agent runtime and tooling extensions: ollama size: L labels Oct 26, 2026
@steipete
steipete marked this pull request as ready for review October 26, 2026 03:13
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-26T08:03:41.795623Z 1db10d3 New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 26, 2026
@clawsweeper

clawsweeper Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Adds Nemotron embedding prefixes, paired formatting overrides, and Ollama digest-aware vector identity with compatible legacy-cache adoption.

Example: Index “remember this” and search “find this” using nvidia/Nemotron-3-Embed-8B-BF16.

  • Before: The embedding endpoint receives raw document and query text.
  • After: It receives “passage: remember this” and “query: find this”, and legacy raw vectors rebuild once.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Focused owner-based repair with shipped-CLI proof, stable-state upgrade coverage, and no actionable correctness or security findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): Supplied installed-CLI evidence exercises exact-head indexing/search, real Ollama alias retargeting, Gemini synchronous/asynchronous overrides, and published-v2026.10.7 state upgrades; synthetic Nemotron vectors prove request formatting and persisted-vector replacement, while model-quality gains remain explicitly unclaimed.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Memory search embeds Nemotron text without its retrieval prefixes and can reuse vectors from an alias’s previous backing model.
Reason: The report demonstrates an owned retrieval problem, and the maintainer-authored direction settles the paired override and digest-adoption tradeoffs.

Merge readiness

✅ Ready for maintainer review

This PR addresses a current memory-retrieval defect and has no actionable findings; the earlier upgrade-proof blocker is resolved, while exact-head CI remains pending.

Priority: P2
Reviewed head: 1db10d3ce63bb9ec01ac7e1e74b1034fa770839e

Before merge

None.

Findings

None.

Agent review details

How this fits together

Memory Core converts memory documents and search queries into provider requests, then stores and retrieves vectors through its existing database publication owner.

flowchart LR
  A[Memory documents and queries] --> B[Resolved memory settings]
  B --> C[Shared input formatter]
  C --> D[Embedding provider transport]
  D --> E[Embedding vectors]
  F[Ollama model digest] --> G[Index and cache identity]
  G --> H[Database publication owner]
  E --> H
Loading

Technical review

Best possible solution:

Keep formatting, digest-aware identity, and compatible cache adoption within the existing formatter and atomic publication owners.

Do we have a high-confidence way to reproduce the issue?

Current-main source establishes raw Nemotron inputs and digestless Ollama identity, matching the affected-release report and supplied before-fix CLI reproduction; no target code was executed during this review.

Is this the best way to solve the issue?

The patch extends existing formatting and publication owners, preserves query-only cache reuse, and covers the earlier Gemini override and upgrade concerns without unnecessary parallel machinery.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 4d560fde03f9.

Provenance checked

  • Shared model formatting and revisioned identity keeps the original intent (58108ee: Correct EmbeddingGemma retrieval prefixes and automatically rebuild raw indexes while separating cache identities.)
  • Explicit query-instruction precedence keeps the original intent (281dd43: Support instruction-sensitive models behind generic aliases without changing document embeddings or index identity.)
  • Ollama endpoint and semantic-header identity changes intended behavior with a stated reason (9405f2c: Prevent vector reuse across distinct endpoints while preserving the shipped default endpoint identity.)
  • Legacy provider-key promotion keeps the original intent (491bfc2: Atomically promote compatible legacy metadata and cached vectors so credential rotation does not strand an accepted index.)
  • Alias cache reads changes intended behavior with a stated reason (1ec7b42: Move embedding-cache work to the worker-owned publication path; this PR explains narrowing alias reads to published metadata to exclude stale legacy vectors.)
  • Gemini document templates changes intended behavior with a stated reason (e30279f: Supply stable Gemini Embedding 2 task instructions across synchronous and asynchronous requests; explicit document overrides now deliberately suppress that default template.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source +189, Tests +435, Docs +55, Generated 0, Other -1. Total +678 across 33 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 17 250 61 +189
Tests 11 527 92 +435
Docs 2 64 9 +55
Config 0 0 0 0
Generated 2 3 3 0
Other 1 0 1 -1
Total 33 844 166 +678

Review metrics

Metric Value Why it matters
Production versus tests Production +250/-61; tests +527/-92 Growth supplies paired formatting, digest-aware identity, compatible cache adoption, and distinct transport/upgrade regressions without a new persistence owner.
Configuration and provider contract 1 optional paired config object; 2 optional provider-call fields inputFormat requires literal query/document strings; documentFormatApplied is added to direct-call and asynchronous-batch options.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #182842
Summary: This PR implements the reported Nemotron formatting and Ollama alias-cache repair.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.

Label justifications:

  • P2: The repair addresses bounded retrieval degradation and stale vector reuse in configured embedding workflows.
  • merge-risk: 🚨 compatibility: The PR extends the provider formatting contract and changes persisted vector identity; the maintainer-approved adoption policy and supplied stable-upgrade evidence cover the intended transition.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (2 earlier review cycles)
  • reviewed 2026-10-26T03:30:56.174Z sha 8e41398 :: blocked before merge. :: [P2] Honor explicit document prefixes in the Gemini adapter
  • reviewed 2026-10-26T03:56:07.561Z sha 0ec1c08 :: blocked before merge. :: none

Reviewed October 26, 2026, 3:31 AM ET / 07:31 UTC (Revision 3).

@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Oct 26, 2026
@clawsweeper clawsweeper Bot removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 26, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 26, 2026
@steipete
steipete merged commit b676db0 into main Oct 26, 2026
137 of 140 checks passed
@steipete
steipete deleted the fix/doc-prefixes branch October 26, 2026 17:44
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 27, 2026
…penclaw#184142)

* test(memory): define paired embedding prefix contract

* fix(memory): format Nemotron inputs and refresh aliased vectors

* test(memory): narrow the embedding fixture provider

* fix(memory): honor explicit document formats in Gemini

* fix(memory): distinguish explicit raw document identity

* fix(memory): preserve vectors when adopting Ollama digests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation extensions: google extensions: memory-core Extension: memory-core extensions: ollama merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: L status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Nemotron embedding task prefixes (query:/passage:) and a config override for aliased embedding models

1 participant