Skip to content

The embed phase copies vectors from embed_reuse_from - #1710

Merged
zlareb1 merged 4 commits into
ClickHouse:mainfrom
VanshajPoonia:issues/1681-embed-reuse-phase-embed
Nov 30, 2026
Merged

zlareb1 merged 4 commits into
ClickHouse:mainfrom
VanshajPoonia:issues/1681-embed-reuse-phase-embed

Conversation

@VanshajPoonia

@VanshajPoonia VanshajPoonia commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Closes: #1681

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in a release)

Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):

loom code backfill --phase embed and the code_embed_recovery worker now copy vectors from a namespace's embed_reuse_from for chunks whose path, content hash and context text match, as an inline --embed index already did, and embed only the rest.

Why

embed_reuse.reusable_vectors had one caller, _embed_new_chunks, which runs only when the index embeds inline. A branch namespace indexed with --phase index and then embedded with --phase embed sent every chunk to the embedder, although the guide recommends both the split and embed_reuse_from for a branch.

Scope and risk

  • _embed_rows in server/code/workers/embed_recovery.py, which both the backfill embed phase and code_embed_recovery use, resolves embed_reuse_from once per (org, namespace) group (code chunks only, never the summaries table). Before each embed call it looks up reusable vectors per path with the existing reusable_vectors and its key: the same path, content hash and stored context_text under the same embedding_model. Matched stubs get the copied vector and the rest go to the embedder as before.
  • A lookup that fails or finds nothing changes nothing: reusable_vectors already returns {} on any error. A stub without a path, hash, context text or model is embedded as before.
  • When the org's model calls are off mid-pass, copied vectors still land, because copying calls no model. The stubs that needed the embedder stay as they are with no attempt spent, as before.
  • CodeEmbedRecoveryResult.reused counts copied vectors. The backfill embed phase prints it and records it as embed_reused, the name the inline index uses.
  • The fake repo config in test_code_embed_recovery_republishes.py gains embed_reuse_from = "", which every real RepoConfig has.

Compatibility, rollout and rollback

  • Wire: none.
  • Operator steps: none. A namespace with embed_reuse_from now reuses vectors in the embed phase with no flag.
  • Rollback: revert. Copied vectors are ordinary chunk vectors of the same model, so nothing needs cleaning up.

Tests

  • pytest tests/unit/test_code_embed_recovery_reuse.py: 3 new cases. Two stubs that match the source copy its vectors and a third with the same content but a different context text is embedded, with one lookup for the path. A namespace without embed_reuse_from embeds everything and looks nothing up. A switched-off org still writes the copied vector and leaves the other stub untouched. All 3 fail without the change.
  • test_code_embed_recovery_republishes.py and test_code_embed_recovery_empty_text.py pass (19 with the new file).
  • Every tests/unit/test_code_*.py file was run with and without the change on this machine. The failure sets are the same (local gaps such as numpy and clickhouse-local), apart from two timing-based parser cases that flip between runs.
  • ruff, mypy on the two changed modules, the function-length gate, Prettier 3.9.9 on the guide, test_public_copy.py and test_doc_links.py pass. No run against a live ClickHouse and embedder.

AI assistance in the code (leave one; writing this description with AI is fine):

  • AI-generated (an agent wrote most of the diff): Claude Code wrote the diff and ran the checks above.

  • I can explain every line of this diff and how it interacts with the rest of Loom.

Checklist

  • Local format, lint, type checks and focused tests pass. The full make test-unit and applicable integration results are reported by CI; a full local run is not required before pushing.
  • Docs under docs/ describe the system as it now is, and this description names any operator steps and wire changes.
  • Commits are signed off (git commit -s), as CONTRIBUTING.md asks.

Note

Medium Risk
Touches shared embed recovery used by backfill and background workers; behavior change is limited to namespaces with embed_reuse_from and falls back to full embed when lookup fails.

Overview
Fixes a gap where branch namespaces indexed with --phase index and then --phase embed (or healed by code_embed_recovery) sent every chunk to the embedder even when embed_reuse_from pointed at a main namespace with identical chunks. Those paths now match inline --embed ingest: before each embed batch, stubs whose path, content hash, and stored context_text match a live embedded chunk in the source namespace copy that vector; only unmatched stubs call the embedder.

CodeEmbedRecoveryResult gains a reused counter; backfill’s embed phase prints it and records embed_reused in pass counters. When model calls are switched off mid-pass, copied vectors still land and stubs that still need embedding are left untouched.

Docs under docs/operations/code-index-operations.md describe reuse for --phase embed and branch indexing. Unit tests cover match vs mismatch, namespaces without reuse, and switched-off orgs.

Reviewed by Cursor Bugbot for commit dff2452. Bugbot is set up for automated code reviews on this repo. Configure here.

Only the inline ingest looked up reusable vectors, so a branch namespace indexed with --phase index and embedded with --phase embed (or by code_embed_recovery) embedded every chunk. _embed_rows now copies the vector of every code chunk stub whose path, content hash and stored context text match a live, embedded chunk in the namespace's embed_reuse_from, and embeds only the rest. A switched-off org still gets its copied vectors; its other stubs stay as they are.

Signed-off-by: Vanshaj Poonia <vanshajtheunique@gmail.com>
Signed-off-by: Vanshaj Poonia <vanshajtheunique@gmail.com>
Signed-off-by: Vanshaj Poonia <vanshajtheunique@gmail.com>
@vercel

vercel Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
loom-docs Ready Ready Preview Nov 28, 2026 2:56pm UTC
loom-telemetry Ready Ready Preview Nov 28, 2026 2:56pm UTC

Request Review

@cla-assistant

cla-assistant Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@zlareb1 zlareb1 self-assigned this Nov 28, 2026

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No blocking findings. The backfill and worker share the reuse path. It reads vectors by organization, source namespace, path, and model, and checks the stored context text before copying. Unmatched chunks still use the existing embed path.

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The format job fails on the adoption page with the same formatter output on clean main. The pinned Biome check passes with the tracked repair. Failed job · Repair #1706

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The hosted worker suite found four failures in the existing polling tests. Update the shared configuration fixture before merging. Failed unit job

Comment thread server/code/workers/embed_recovery.py Resolved
The embed phase reads embed_reuse_from from the namespace's repo config, and the cer fixture's stand-in config had only org and namespace, so four polling tests raised AttributeError.

Signed-off-by: Vanshaj Poonia <vanshajtheunique@gmail.com>

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The polling fixture now supplies the reuse setting. That keeps the existing scan, watermark, and poison tests on their intended paths when the worker looks up the namespace configuration. No blocking findings on this head.

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The rename report integration test fails at the same assertion on this head and on clean main. The tagged fixture describes a naming claim, so the planner returns about_naming. The same test passes with the fixture repair. PR job · Main job · Repair #1719

@zlareb1
zlareb1 merged commit abeae58 into ClickHouse:main Nov 30, 2026
75 of 80 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.

embed_reuse_from has no effect when a namespace is embedded with backfill --phase embed

2 participants