Skip to content

feat(embeddings): activation flow + hybrid default + local backend support (#1217) - #1327

Merged
Sinity merged 1 commit into
masterfrom
feature/feat/embedding-activation-1217
May 18, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/feat/embedding-activation-1217

Conversation

@Sinity

@Sinity Sinity commented May 18, 2026 •

Copy link
Copy Markdown
Owner

Summary

Wires the dormant embedding pipeline (0 messages embedded in production
per #828) into a turnkey polylogue embed onboarding flow, makes
hybrid search the default lane once embeddings exist, and adds
--lexical / --semantic query shortcuts. Closes #1217.

Problem

The Voyage AI embedding pipeline is fully built but dormant. Activating
it today requires the operator to: install sqlite-vec, set
VOYAGE_API_KEY, hand-edit polylogue.toml to flip
embedding_enabled = true, restart the daemon, and watch a
potentially expensive first-embed batch run with no preview. The
acceptance criteria in #1217 ask for a single-command activation with
explicit cost preview, bounded first-embed batching, a clean disable
that preserves existing embeddings, and smoke tests against a stub
provider.

The companion goal — hybrid search as the default once embeddings exist
— is the activation force multiplier: without it, embedding spend
yields no end-user-visible behavior change.

Solution

New polylogue embed group (polylogue/cli/commands/embed.py)

Command Purpose
embed enable (alias activate) Verifies sqlite-vec, captures the Voyage key (flag/env/existing config), prints cost preflight, on confirmation writes [embedding] enabled = true plus the key into the user TOML via a section splicer that preserves comments and unrelated sections. --no-store-key keeps the secret in env only.
embed preflight Read-only token count + Voyage cost estimate using ESTIMATED_TOKENS_PER_MESSAGE and VOYAGE_4_COST_PER_1M_TOKENS; never contacts the provider.
embed backfill Iterates pending conversations with per-conversation cost feedback against embedding_max_cost_usd as a soft cap.
embed disable Flips enabled = false; existing embeddings remain queryable via --similar.
embed status Coverage / freshness snapshot via the existing embedding_status_payload.

Hybrid as the default lane

_maybe_elevate_to_hybrid in polylogue/cli/query.py promotes
retrieval_lane='auto' to 'hybrid' only when all three hold:
there's an FTS query, a vector provider is wired, and
archive_stats.embedded_messages > 0. Otherwise the existing
auto → dialogue path stands. --retrieval-lane dialogue (or the
new --lexical shortcut) is never overridden.

--lexical and --semantic query shortcuts

Added to the root query option group. Desugar at
RootModeRequest.from_params: --lexical forces
retrieval_lane=dialogue (FTS-only), --semantic promotes the
query string into similar_text for vector-only retrieval. No new
spec fields, no parser surface changes downstream.

polylogue status surfaces embedding coverage

The direct-status path includes an Embeddings: line whenever any
messages are embedded so coverage shows up alongside FTS readiness.

Out of scope / deferred

Verification

  • nix develop -c pytest tests/unit/cli/test_embed_activation.py:
    20 passed.
  • nix develop -c pytest tests/unit/cli/ tests/unit/storage/ tests/unit/daemon/ tests/unit/core/test_config.py tests/unit/archive/: 2660 passed, 1 xfailed.
  • nix develop -c devtools verify --quick: exit_code: 0 across
    ruff format, ruff check, mypy, render-all, verify-topology,
    verify-layering, verify-file-budgets, verify-test-ownership,
    verify-closure-matrix, verify-schema-roundtrip, verify-cross-cuts,
    verify-suppressions, verify-manifests, verify-ci-workflows,
    verify-witness-lifecycle, verify-witness-coverage,
    verify-lane-assertions, verify-test-infra-currency, and
    verification-impact check.
  • nix develop -c polylogue embed --help lists the new subcommands;
    nix develop -c polylogue --help surfaces --lexical and
    --semantic plus the new embed entry.

Closes #1217.

Summary by CodeRabbit

  • New Features

    • Added polylogue embed command for activating and managing the embedding pipeline
    • Introduced --lexical and --semantic query options to override search retrieval behavior
    • Hybrid search (FTS + vector) automatically activates when embeddings are enabled and available
    • Enhanced status output to display embedding statistics
  • Documentation

    • Updated CLI reference and architecture docs covering embedding activation workflow

Review Change Stack

Wires the dormant embedding pipeline (zero messages embedded in production
per #828) into a turnkey operator onboarding flow and promotes hybrid
search to the default lane once embeddings exist.

New ``polylogue embed`` group:

- ``enable`` (alias ``activate``): verifies ``sqlite-vec`` is importable,
  resolves the Voyage API key (flag / env / existing config), prints a
  cost preflight, asks for confirmation, and persists
  ``[embedding] enabled = true`` plus the API key into the user
  ``polylogue.toml``. ``--no-store-key`` keeps the secret in env only.
- ``preflight``: read-only token count + Voyage cost estimate using
  ``ESTIMATED_TOKENS_PER_MESSAGE`` and ``VOYAGE_4_COST_PER_1M_TOKENS``;
  never contacts the provider.
- ``backfill``: iterates pending conversations with per-conversation
  cost feedback against ``embedding_max_cost_usd`` as a soft cap.
- ``disable``: flips ``enabled = false`` without dropping existing
  embeddings; previously-embedded messages stay queryable via
  ``--similar``.
- ``status``: coverage / freshness snapshot via the existing
  ``embedding_status_payload``.

Hybrid as default: ``_maybe_elevate_to_hybrid`` in
``polylogue/cli/query.py`` promotes ``retrieval_lane='auto'`` to
``'hybrid'`` only when there's an FTS query, a vector provider is wired,
and ``archive_stats.embedded_messages > 0``. ``--lexical`` /
``--semantic`` are root query-mode shortcuts that desugar at
``RootModeRequest.from_params``: ``--lexical`` forces
``retrieval_lane=dialogue`` (FTS-only), ``--semantic`` promotes the
query string into ``similar_text`` for vector-only retrieval. Existing
``--retrieval-lane`` choices are unchanged.

Surface integration: ``polylogue status`` now includes an
``Embeddings:`` line whenever any messages are embedded so coverage
shows up at a glance.

Tests in ``tests/unit/cli/test_embed_activation.py`` exercise the TOML
splicer, the ``enable``/``preflight``/``disable``/``backfill``
subcommands against a stub provider, the hybrid auto-elevation gating
(provider absent, no embeddings, no FTS terms, explicit lane), and the
``--lexical``/``--semantic`` desugaring.

Docs: ``docs/architecture.md`` Embedding Pipeline section now describes
the activation flow and the hybrid-as-default behavior.

Closes #1217.
@Sinity
Sinity merged commit 9f6978b into master May 18, 2026
1 check passed
@Sinity
Sinity deleted the feature/feat/embedding-activation-1217 branch May 18, 2026 15:49
@coderabbitai

coderabbitai Bot commented May 18, 2026 •

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: bd5fb12e-3b23-4f7a-a907-efcabcfebf3e

📥 Commits

Reviewing files that changed from the base of the PR and between ee22230 and 41ee13f.

📒 Files selected for processing (17)
  • AGENTS.md
  • docs/architecture.md
  • docs/cli-reference.md
  • docs/plans/topology-target.yaml
  • docs/test-quality-workflows.md
  • docs/topology-status.md
  • docs/verification-catalog.md
  • polylogue/cli/click_app.py
  • polylogue/cli/click_command_registration.py
  • polylogue/cli/click_option_groups.py
  • polylogue/cli/commands/embed.py
  • polylogue/cli/commands/status.py
  • polylogue/cli/query.py
  • polylogue/cli/root_request.py
  • tests/unit/cli/__snapshots__/test_terminal_snapshots.ambr
  • tests/unit/cli/test_click_app.py
  • tests/unit/cli/test_embed_activation.py

📝 Walkthrough

Walkthrough

This PR introduces an embedding pipeline activation onboarding flow, enabling users to safely enable embeddings with cost preview and configuration management. It adds a new polylogue embed CLI command group (enable, preflight, backfill, disable, status), automatic retrieval-lane elevation to hybrid search when embeddings are available, and query overrides via --lexical and --semantic flags.

Changes

Embedding Activation Onboarding Flow

Layer / File(s) Summary
CLI Framework: Embed Command Registration and Query Flags
polylogue/cli/click_app.py, polylogue/cli/click_command_registration.py, polylogue/cli/click_option_groups.py
cli function signature adds lexical and semantic boolean parameters. Root command registrations now include the embed subcommand group, and FILTER_OPTION_DECORATORS adds two new query flags: --lexical (FTS-only override) and --semantic (vector-only similarity probe).
Core Embedding Command Implementation
polylogue/cli/commands/embed.py
New 460-line command group with PreflightReport dataclass and subcommands: enable validates sqlite-vec and Voyage key, runs cost preflight, persists config via TOML line-splicing; preflight estimates cost without provider calls; backfill orchestrates embedding of pending conversations with per-item progress and cost-cap enforcement; disable flips enabled flag while preserving stored key; status delegates to embedding coverage stats; activate aliases enable.
Automatic Hybrid Search Elevation and Query Parameter Handling
polylogue/cli/query.py, polylogue/cli/root_request.py
_maybe_elevate_to_hybrid promotes retrieval lane from auto to hybrid when FTS query + vector provider + embeddings all present. RootModeRequest.from_params desugars --lexical to retrieval_lane="dialogue" and --semantic by promoting query terms into similar_text.
Embedding Status Reporting
polylogue/cli/commands/status.py
Fallback status path now imports embedding_status_payload and prints embedded message/conversation counts and coverage percent when total conversations > 0, with graceful error suppression.
Feature Documentation: Architecture, CLI Reference, and Agent Docs
AGENTS.md, docs/architecture.md, docs/cli-reference.md
Documents polylogue embed CLI onboarding commands, how enabling persists [embedding] enabled = true in TOML, backfill cost feedback and overshoot stopping, automatic hybrid elevation rules, --lexical/--semantic overrides, and polylogue status embeddings coverage line.
Comprehensive Test Coverage for Embedding Activation
tests/unit/cli/test_embed_activation.py, tests/unit/cli/__snapshots__/test_terminal_snapshots.ambr, tests/unit/cli/test_click_app.py
New test suite covering TOML splicing behavior, CLI command invocation (enable with/without key storage, preflight, disable, backfill with cost cap), hybrid auto-elevation scenarios (no provider, no embeddings, missing FTS, explicit lane, promotion), and --lexical/--semantic desugaring. Snapshot tests updated for new options and embed command in help output.
Generated Topology and Catalog Updates
docs/plans/topology-target.yaml, docs/topology-status.md, docs/verification-catalog.md, docs/test-quality-workflows.md
Auto-generated metadata reflecting new CLI modules, scenario/exercise counts (+7 scenarios, +7 exercises), and command subjects for embed subcommands (embed, embed activate, embed backfill, embed disable, embed enable, embed preflight, embed status).

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Suggested labels

type:refactor, type:test, area:cli, area:pipeline, area:storage, tool:claude

Poem

🐰 Embeddings wake from slumber deep,
With voyage keys that users keep,
A preflight glance at tokens sworn,
Hybrid search at query's morn,
--lexical for text so true,
--semantic when vectors brew! 🚀

✨ 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 feature/feat/embedding-activation-1217

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 and usage tips.

path.parent.mkdir(parents=True, exist_ok=True)
existing = path.read_text(encoding="utf-8") if path.exists() else ""
updated = _splice_embedding_section(existing, enabled=enabled, voyage_api_key=voyage_api_key)
path.write_text(updated, encoding="utf-8")

@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: 41ee13fa19

ℹ️ 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 polylogue/cli/commands/embed.py Resolved
Comment thread polylogue/cli/root_request.py Resolved
@Sinity

Sinity commented Oct 1, 2026

Copy link
Copy Markdown
Owner Author

Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.

  • 60.F013 / P1: fixed-already at the checked revision: After checking an explicit key and runtime index configuration, credential resolution now reads load_polylogue_config().voyage_api_key at polylogue/cli/commands/embed.py:276. The key saved in the user TOML is therefore included on subsequent activation runs without an environment variable.
  • 60.F055 / P1: fixed-already at the checked revision: polylogue/cli/root_request.py:32 sends from_context through the same normalized constructor as from_params. That constructor invokes desugar_retrieval_flags at line 46, so parsed lexical/semantic flags reach the shared lowering on the real CLI route.

Only the rows listed above are dispositioned. Held findings remain open.

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.

feat(embeddings): activation onboarding flow with key provisioning, batching, cost preflight

2 participants