Skip to content

fix(rag): drop unnecessary sentence-transformers hard dependency - #1979

Merged
kovtcharov-amd merged 3 commits into
mainfrom
fix/rag-drop-sentence-transformers-dep
Jul 9, 2026
Merged

kovtcharov-amd merged 3 commits into
mainfrom
fix/rag-drop-sentence-transformers-dep

Conversation

@kovtcharov-amd

Copy link
Copy Markdown
Collaborator

Why this matters

RAG embeds through Lemonade, yet the RAG SDK hard-required sentence-transformers to import — a heavy, fragile dependency (torch/torchcodec) it never actually uses. On any machine where sentence-transformers failed to import (e.g. broken torchcodec/FFmpeg native libs), every RAG document-indexing call silently produced 0 chunks even though the Lemonade EmbeddingGemma embedder was loaded and ready — a hard-to-diagnose "RAG returns nothing" failure. After this change, RAG initializes and indexes normally regardless of sentence-transformers health; the library is now only what it should be — an optional dependency of the memory cross-encoder reranker (which already degrades gracefully).

This also closes the test gap that let it through: the RAG dependency-guard test previously encoded the wrong behavior (it required sentence-transformers), and the Test RAG CI workflow didn't run tests/unit/rag/ at all — so nothing exercised the guard.

Test plan

  • pytest tests/test_rag.py tests/unit/rag/ — green (115 tests; previously 28 errors from obsolete ST mocks)
  • New regression guard: RAG initializes with sentence-transformers forcibly unavailable (tests/unit/rag/test_dependency_guard.py)
  • End-to-end: index a document + retrieve with ST blocked → EmbeddingGemma 768-dim embeddings, correct answer
  • black --check / flake8 clean on changed files
  • CI Test RAG now runs tests/unit/rag/ (path filter + test command updated)

Notes

  • Bundles a small pre-existing fix: test_pptx_extraction.py::test_table_extraction was env-dependent (failed when LibreOffice was installed, since the PPTX→PDF path flattens tables); it now forces the pure-python markdown path so the assertion is deterministic.

RAG embeds via Lemonade, but RAGSDK._check_dependencies() required
sentence-transformers to import — a heavy, fragile dep (torch/torchcodec) it
never uses. On any box where sentence-transformers failed to import (e.g.
broken torchcodec/FFmpeg native libs), every RAG indexing call produced 0
chunks even though the Lemonade EmbeddingGemma embedder was loaded and ready.

Remove the import and the requirement, stop eagerly importing it at UI-server
boot, and drop it from the "rag" extra (kept in "ui" for the optional memory
cross-encoder reranker, which already degrades gracefully).

Closes the test gap that let this through: the dependency-guard test encoded
the wrong behavior (required ST), and the Test RAG workflow never ran
tests/unit/rag/. Adds a regression guard (RAG must init with ST absent/broken)
and wires tests/unit/rag/ into CI. Also fixes a pre-existing env-dependent
pptx table test (forces the pure-python markdown path deterministically).
@github-actions github-actions Bot added dependencies Dependency updates devops DevOps/infrastructure changes rag RAG system changes tests Test changes performance Performance-critical changes labels Jul 9, 2026
@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Verdict: Approve with suggestions — safe to merge; the two items below are optional cleanups, not blockers.

This PR removes sentence-transformers as a hard RAG dependency. RAG actually embeds through Lemonade, so importing the heavy torch/torchcodec stack at RAG import time was dead weight — and when that native stack was broken it took down all RAG indexing (0 chunks) even though the embedder was healthy. The fix is correct and the reasoning holds up: RAG embeds via the Lemonade client, and the memory cross-encoder reranker (the library's only real user) already degrades gracefully when it's absent, so dropping it from the rag extra doesn't silently break anything. It also closes the test gap that let this through — the dependency-guard test now encodes the right behavior and CI's Test RAG job actually runs tests/unit/rag/.

Nothing blocking. Two small leftovers from the removal are worth tidying while you're here.

🔍 Technical details

Verified claims

  • RAG embedding path is Lemonade, not sentence-transformers: src/gaia/rag/sdk.py:581,613 call self.embedder.embeddings(...); sdk.py:519 sets self.embedder = self.llm_client. ✅
  • Reranker degrades gracefully: src/gaia/agents/base/memory.py:263-290 (_get_cross_encoder) returns None on ImportError/load failure and caches the miss. Removing ST from [rag] is safe; it's retained in [ui]. ✅
  • Test dict key mock_dependencies["lemonade"] exists in every yielded fixture (tests/test_rag.py:80,212,938,1258). ✅

🟢 Minor — stale hint in the broken-dep error message (src/gaia/rag/sdk.py:251)
The only remaining broken-load candidate is faiss (arch mismatch / illegal instruction). The torchcodec/FFmpeg example only ever applied to the now-removed sentence-transformers, so it now points users at the wrong cause.

                    "reinstalling won't help until the underlying error is fixed "
                    "(e.g. an arch-mismatched faiss build):\n"

🟢 Minor — single-element loop reads as leftover scaffolding (src/gaia/rag/sdk.py:234-235)
for pkg, label in (("faiss", "faiss"),): with an inner if pkg == "faiss" is an awkward remnant of the old two-item loop. Since only faiss remains, it can flatten to a plain block — clearer intent, same behavior. Optional.

Strengths

  • Fix is backed by a real regression test that asserts the absence of the ST import (test_rag_does_not_import_sentence_transformers) plus a guard that the dependency check never fails on a broken ST — exactly the failure mode being fixed.
  • Doc/comment updates land consistently across setup.py, sdk.py, and server.py, all naming why ST isn't a RAG dep.
  • The path-filter + test-command change to test_rag.yml closes the "guard existed but nothing ran it" gap in the same PR.
  • Bundled pptx test fix correctly forces the pure-python markdown path so the table assertion is deterministic regardless of LibreOffice presence.

Ovtcharov added 2 commits July 9, 2026 13:02
Address PR review: flatten the now single-element broken-dependency loop to a
plain faiss block, and correct the broken-load hint — the torchcodec/FFmpeg
example only ever applied to the removed sentence-transformers, so it now points
users at the wrong cause; faiss (arch mismatch) is the only remaining candidate.
@kovtcharov-amd

Copy link
Copy Markdown
Collaborator Author

Addressed both suggestions in 8cf2752:

  • Corrected the broken-load hint — it now names an arch-mismatched faiss build instead of the stale torchcodec/FFmpeg example (which only applied to the removed sentence-transformers).
  • Flattened the single-element for pkg, label in (("faiss", "faiss"),) loop to a plain if faiss is None: block.

Also merged latest main (no conflicts). Dependency-guard tests pass (5), black/flake8 clean.

@kovtcharov-amd
kovtcharov-amd enabled auto-merge July 9, 2026 20:30
@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Jul 9, 2026
Merged via the queue into main with commit 638487a Jul 9, 2026
56 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the fix/rag-drop-sentence-transformers-dep branch July 9, 2026 20:30
pull Bot pushed a commit to bhardwajRahul/gaia that referenced this pull request Aug 17, 2026
Release notes had grown into long blocks of prose with a marketing-toned
paragraph on top. They now generate as short bullets grouped by section,
with a word cap on the narrative part. Nothing informational is lost —
every PR link, contributor credit, and changelog entry is preserved; the
prose around them is cut.

Two generators write `docs/releases/<tag>.mdx` and they had drifted
apart. The `gaia-release` skill told the model GAIA's notes "read dry"
and to make them "engaging"; the `release-notes` job in `claude.yml`
asked for "comprehensive" notes with an `## Overview` paragraph and
emoji headings. Fixing one alone would have been overwritten by the
other on the next tag, so both now share one spec.

Closes amd#2961

## What it looks like now

Regenerated from the last two releases — same facts, same PR numbers,
new template. Narrative words (the capped part, excluding
bug-fix/contributor/changelog lists):

| Release | Published | Regenerated | Cap |
|---|---|---|---|
| v0.22.0 (minor) | 1705 | **538** | 600 |
| v0.23.0 (minor) | 1119 | **280** | 600 |

<details>
<summary>Example 1 — v0.23.0 regenerated</summary>

```markdown
---
title: "v0.23.0"
description: "Install and run agents from the terminal, add capabilities as skills, and connect a Microsoft account without a secret."
---

# GAIA v0.23.0 Release Notes

Agents are now installable from the terminal, and the confirmation gate that pauses an agent before a consequential action works everywhere, not just in the Agent UI.

## Breaking Changes

- **`GAIA_MICROSOFT_TENANT` is gone** — the Microsoft connector split into Personal and Work/School, each with its own tenant. Drop the variable and pick the matching connector. (PR [amd#2729](amd#2729))

## What's New

- **Install and run agents from the terminal** — `gaia hub list`, `gaia hub install <agent> --trust`, `gaia hub uninstall <agent>`. `--trust` is required for an unverified agent. (PRs [amd#2484](amd#2484), [amd#2530](amd#2530), [amd#2708](amd#2708))
- **Every agent asks before it acts** — the confirmation gate for sending mail, writing files, and running commands now fires from the terminal, the local API, and MCP tool calls, not only the Agent UI. Set `GAIA_AUTO_APPROVE_TOOLS=1` to opt out. (PRs [amd#2475](amd#2475), [amd#2544](amd#2544), [amd#2846](amd#2846), [amd#2854](amd#2854))
- **Safer by default** — the MCP bridge binds to localhost and enforces `--auth-token`; the local API refuses credentialed cross-origin requests from non-allow-listed sites; MCP servers launch without a shell; agents cannot write to `~/.gaia` or pass crafted SQL to the database agent. (PRs [amd#2246](amd#2246), [amd#2238](amd#2238), [amd#2344](amd#2344), [amd#2844](amd#2844), [amd#2847](amd#2847), [amd#2860](amd#2860))
- **Add capabilities as skills** — `gaia skill create|import|list|info` gives an agent a new capability from a folder and a manifest. Skills are signed with trust tiers, audited before publish, and opt-in. (PRs [amd#2669](amd#2669), [amd#2692](amd#2692), [amd#2702](amd#2702), [amd#2693](amd#2693))
- **Connect a Microsoft account without a secret** — Personal and Work/School are separate connectors with device-code sign-in. (PRs [amd#2718](amd#2718), [amd#2364](amd#2364))
- **Lemonade Server 11.5.0.**

## Bug Fixes

- **Triage paginates large inboxes and reports truncation** (PR [amd#2646](amd#2646)) — mail past a hidden limit is no longer dropped without saying so.
- **Thread messages come back sorted and numbered** (PR [amd#2570](amd#2570)) — "reply to 3" hits the message shown at position 3.
- **The inbox pre-scan reports uncertainty as uncertainty** (PR [amd#2587](amd#2587)).
- **An email conversation survives its turns** (PR [amd#2837](amd#2837)) — a follow-up keeps session context.
- **A bare reconnect keeps existing grants** (PR [amd#2733](amd#2733)).
- **Restore from Trash anytime** (PR [amd#2542](amd#2542)) — no time window on undo.
- **Sender priority no longer overrides content classification** (PR [amd#2774](amd#2774)).
- **The agent survives an OpenMP double-init** (PR [amd#2508](amd#2508)).
- **Large tool results truncate to valid JSON** (PR [amd#2645](amd#2645)).
- **A missing model surfaces as a real 404** (PR [amd#2245](amd#2245)).
- **GPU is detected on all platforms and `default_device` is honoured** (PR [amd#2244](amd#2244)).
- **A sidecar that is alive but not serving is detected** (PR [amd#2707](amd#2707)).
- **The model-slot lease is held across inference** (PR [amd#2394](amd#2394)) — a second agent can't evict the model mid-generation.
- **A browser that never launched is surfaced** (PR [amd#2507](amd#2507)).
- **Stop aborts in-flight streaming** (PR [amd#2166](amd#2166)).

## Known Issues

- **The email agent is beta and CLI-first** — treat its output as a draft to review.
- **A full inbox triage can time out on larger mailboxes.**
- **Email autonomy is experimental** and not wired up in the packaged sidecar.

## Contributors

- [@handle](https://github.com/handle) — <contribution> (PR [#NNN](https://github.com/amd/gaia/pull/NNN))
  <!-- generated from the commit log; v0.23.0's list is unchanged from the published notes -->


## Full Changelog

**N commits** since v0.22.0:

- `<sha>` — <subject>

Full Changelog: [v0.22.0...v0.23.0](amd/gaia@v0.22.0...v0.23.0)
```
</details>

<details>
<summary>Example 2 — v0.22.0 regenerated (the largest recent
release)</summary>

```markdown
---
title: "v0.22.0"
description: "The email agent tracks follow-ups and action items, drafts in your voice, and runs as its own process. Plus a cron scheduler and Word document support in RAG."
---

# GAIA v0.22.0 Release Notes

A large release built around the email agent, which now tracks what you're waiting on instead of forgetting it after triage.

## Breaking Changes

- **Triage returns a reply scaffold, not an empty draft** — `POST /v1/email/triage` and `/triage/batch` now return a `DraftScaffold` without `body`. Code reading `result.draft.body` gets a missing key instead of `""`; use `POST /v1/email/draft` for composed prose. (PR [amd#1984](amd#1984))
- **RoutingAgent and DocumentQAAgent moved to standalone packages** — install `gaia-agent-routing` and `gaia-agent-docqa`. The old imports fail; there is no deprecation shim. (PR [amd#1455](amd#1455))

## What's New

- **An inbox agent that keeps track** — `gaia email` scans Sent folders across every connected mailbox and flags threads still waiting on a reply past a window you set (default 3 days). Detection only; it never nudges anyone for you. (PRs [amd#1922](amd#1922), [amd#1917](amd#1917), [amd#1919](amd#1919), [amd#1918](amd#1918))
- **Drafts in your own voice** — the agent derives greeting, sign-off, length, and formality from your Sent history and composes against that. Only the derived characteristics are stored, never old mail content. (PR [amd#1925](amd#1925))
- **Attachments work end to end** — triage surfaces each attachment's name, type, and size, and drafting and sending accept real attachments as Gmail multipart MIME or Outlook Graph attachments. (PRs [amd#1921](amd#1921), [amd#1883](amd#1883))
- **Email runs as its own process in the Agent UI (beta)** — install it from the Agent Hub panel and the UI talks to it over HTTP, instead of loading the email stack into the UI process. (PRs [amd#1884](amd#1884), [amd#1910](amd#1910), [amd#2100](amd#2100), [amd#2101](amd#2101), [amd#2105](amd#2105))
- **Run prompts on a cron from the terminal** — `gaia schedule add --name digest --cron "0 9 * * *" --prompt "summarize my inbox" --sink stdout`, then `gaia schedule daemon`. Schedules live in a hand-editable `~/.gaia/schedules.toml`; sinks are `stdout`, `file:<path>`, `notification`, or `telegram`. (PR [amd#1371](amd#1371))
- **Agents learn from work they repeat** — after enough successes on the same shape of goal, an agent distills the tool sequence into a reusable procedure and recalls it next time. Runs inside the existing memory pass; nothing to install. (PR [amd#1794](amd#1794))
- **Pick your model once** — `gaia config set default_model <id>` persists across `gaia chat`, `gaia llm`, and `gaia prompt`. An explicit `--model` still wins for a one-off. (PR [amd#1863](amd#1863))
- **RAG reads Word documents** — `.docx` files index like PDF and PPTX, including table cells, nested tables, content controls, hyperlinks, and textboxes, so filled-in form values get indexed. (PR [amd#1866](amd#1866))
- **A new default embedder** — the previous default cannot be loaded by current llama.cpp builds, which broke indexing, code search, and memory embedding on an up-to-date Lemonade. The default is now EmbeddingGemma 300M at the same 768 dimensions. (PRs [amd#1952](amd#1952), [amd#1761](amd#1761), [amd#1748](amd#1748))
- **The Agent Hub shows what an agent is worth** — an agent's page now carries its eval scorecard with a score badge and a code-derived capability matrix. (PRs [amd#1985](amd#1985), [amd#2020](amd#2020), [amd#2066](amd#2066))
- **Lemonade Server 10.10.0** — adds an audio-generation endpoint, lets Windows reuse system ROCm, and inhibits suspend during inference. Two upstream breaking changes are Linux-specific. (PR [amd#1969](amd#1969))

## Bug Fixes

- **`gaia init` said a working Lemonade wasn't installed** (PR [amd#1940](amd#1940)) — modern Lemonade (10.7+) dropped the `lemonade-server` CLI that GAIA probed for.
- **Installing the email agent from the Hub failed on every platform** (PR [amd#2086](amd#2086)).
- **Bulk triage broke on any real inbox** (PR [amd#2088](amd#2088)) — 60 emails overflowed the 16K context window; the result envelope is now condensed.
- **RAG silently indexed nothing** (PR [amd#1979](amd#1979)) — a failed `sentence-transformers` import made every indexing call a no-op.
- **Email bodies were truncated at 4,000 characters with no override** (PR [amd#2036](amd#2036)) — MFA codes and precise replies lost content past the cutoff.
- **Long threads overflowed the model's context** (PR [amd#2076](amd#2076)).
- **A disabled device was treated as usable** (PR [amd#2081](amd#2081)) — a device reporting `available: false`, such as an unpowered NPU, was misread as ready.
- **A newly connected mailbox was skipped** (PR [amd#1808](amd#1808)) — mailboxes connected mid-session were not picked up.
- **JSON with a `}` inside a string was dropped** (PR [amd#1824](amd#1824)).
- **Outlook users were told to reconnect Google** (PR [amd#1757](amd#1757)) — `AGENT_NOT_GRANTED` named the wrong provider.
- **The Agent UI hard-crashed on a recoverable GPU crash** (PR [amd#1799](amd#1799)) — it now falls back to software rendering.
- **A user-edited memory could be silently downgraded and then wiped** (PR [amd#1958](amd#1958)).
- **The builder agent ignored an agent name you had already given** (PR [amd#1981](amd#1981)).
- **The landing and hub pages scrolled sideways on phones** (PR [amd#1959](amd#1959)).

## Known Issues

- **Inbox pre-scan needs a single mailbox for now** — with both Gmail and Outlook connected, an Agent UI pre-scan errors. Disconnect one in Settings → Connectors; triage itself still spans every mailbox. ([amd#2127](amd#2127))
- **Spam detection under-flags over the REST API** — `/v1/email/triage` uses a narrow sender check rather than the model's reading. The agent's own inbox scanning is unaffected. ([amd#2124](amd#2124))
- **The email agent is beta** — treat its output as a draft to review. It never sends without your confirmation.

## Contributors

- [@alexey-tyurin](https://github.com/alexey-tyurin) — skill auto-synthesis / procedural memory (PR [amd#1794](amd#1794))
- [@TravisHaa](https://github.com/TravisHaa) — the `gaia schedule` CLI and cron-based dispatch (PR [amd#1371](amd#1371))
- [@Rohithmatham12](https://github.com/Rohithmatham12) — refresh resolved email backends before multi-mailbox triage (PR [amd#1808](amd#1808))
- [@Osamaali313](https://github.com/Osamaali313) — fix `extract_json_from_text` dropping JSON containing `}` (PR [amd#1824](amd#1824))
- [@eeee2345](https://github.com/eeee2345) — offline model-endpoint guard-proxy integration guide (PR [amd#1809](amd#1809))
- [@somo9909](https://github.com/somo9909) — prerequisites section for the memory guide (PR [amd#1665](amd#1665))

## Full Changelog

**N commits** since v0.21.2:

- `<sha>` — <subject>

Full Changelog: [v0.21.2...v0.22.0](amd/gaia@v0.21.2...v0.22.0)
```
</details>

<details>
<summary>What changed in the templates</summary>

- The narrative overview paragraph and the `**Why upgrade:**` block are
gone — the latter restated `What's New` verbatim.
- `What's New` entries are bullets, not `###` prose blocks.
- Tone guidance is no longer restated in the skill; it points at
CLAUDE.md § How You Communicate.
- The skill's embedded example now shows the old prose block as **bad**
and the bullet form as **good**.
- Emoji removed from the CI prompt (it asked for 🚀 / 🎯 / 🐛 headings
against the skill's own no-emoji rule).
- Both generators now emit the same sections in the same order, so the
file's shape no longer depends on which one ran.
- The cap excludes `Bug Fixes` / `Known Issues` / `Contributors` / `Full
Changelog`. Those are reference lists sized by how many fixes shipped —
capping them would hide work. This was caught by regenerating v0.22.0,
which overflowed a whole-file cap purely on its 14 bug-fix bullets.

**Follow-up, not in this PR:** the cap lives in prompt text, so it is
advisory. Making it a hard check in `util/validate_release_notes.py`
would enforce it in CI.
</details>

## Test plan

- [ ] `python util/validate_release_notes.py <regenerated sample> --tag
v0.23.0` exits 0 — passes unmodified, no validator changes in this PR
- [ ] `awk '/^## (Bug Fixes|Known Issues|Contributors|Full
Changelog)/{exit} {print}' <file> | wc -w` is under 350 (patch) / 600
(minor-major)
- [ ] `.github/workflows/claude.yml` parses as valid YAML and its
release-notes prompt contains no emoji
- [ ] `.claude/skills/gaia-release/SKILL.md` is under 500 lines (498)
- [ ] Both generators list the same sections in the same order
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Dependency updates devops DevOps/infrastructure changes performance Performance-critical changes rag RAG system changes tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants