project-nomad/admin/app/services
Chris Sherwood b080a27ff2 fix(AI): truncate-and-retry oversized embed chunks; stop 30x retry storm (#881)
Dense source content produces chunks that exceed the embedding model's
context window (nomic-embed-text:v1.5 defaults to 2048 tokens). Two paths
hit this even after the prior pre-cap:

  - Older Ollama (e.g. 0.18.1, #944) ignores the num_ctx=8192 we send on
    /api/embed, so it stays at the model's 2048 default.
  - The OpenAI-compat /v1/embeddings fallback didn't pass num_ctx/truncate
    at all, so any Ollama drops to 2048 whenever it lands on the fallback.

When a chunk overflowed, the 400 was swallowed and the chunk was silently
dropped from Qdrant. Worse, the failure propagated to EmbedFileJob, which
re-embeds the entire file on each of its 30 BullMQ attempts — the "endless
queue loop" / "api/embed for weeks" / pegged GPU reported in #944/#959.

Fix:
  - OllamaService.embed(): on a context-length error, retry once with an
    aggressive 2048-safe cap (EMBED_CONTEXT_SAFE_CHARS = 2000) so the chunk
    is embedded (start-of-chunk) instead of dropped. Native-path context
    errors now bubble to this retry instead of falling through to the
    smaller-context fallback. Split the native+fallback attempt into
    _embedWithFallback().
  - Pass truncate/num_ctx on the /v1/embeddings fallback too (Ollama's
    OpenAI-compat shim forwards them).
  - EmbedFileJob: classify "input length exceeds context length" as an
    UnrecoverableError so one permanently-oversized chunk can't trigger 30
    full-file re-embeds.
  - Add OllamaService.isContextLengthError() shared by both.

Graceful degradation: a truncated chunk loses its tail but is kept in the
index, which is strictly better than today's silent drop + retry storm.

Refs #881. Supersedes the #369/#670 symptom closures that never fixed the
fallback path.
2026-06-08 09:42:00 -07:00
..
app_auto_update_service.ts feat(supply-depot): opt-in automatic updates for installed apps 2026-06-07 15:56:42 -07:00
auto_update_service.ts feat(supply-depot): opt-in automatic updates for installed apps 2026-06-07 15:56:42 -07:00
benchmark_service.ts fix(AI): vendor-aware AMD HSA override + benchmark discrete-GPU detection 2026-05-20 10:16:00 -07:00
chat_service.ts fix(AI): qwen2.5 loading on every chat message (#649) 2026-04-21 14:26:28 -07:00
collection_manifest_service.ts fix(content): show selected tier on cards while downloads are in flight 2026-05-20 10:16:00 -07:00
collection_update_service.ts feat(content-updates): show size, surface downloads in Active Downloads 2026-05-20 10:16:00 -07:00
container_registry_service.ts feat(system): add opt-in automatic updates for the core NOMAD app 2026-06-07 15:52:56 -07:00
countries_service.ts feat(Maps): regional map downloads via go-pmtiles extract (#780) 2026-05-20 10:16:00 -07:00
custom_app_guard.ts feat: supply depot 2026-06-06 11:08:52 -07:00
docker_service.ts fix(storage): match default prefix too when relocating child-app binds 2026-06-07 14:56:05 -07:00
docs_service.ts feat(supply-depot): per-app onboarding docs, install fixes, and in-app Docs links 2026-06-06 11:08:52 -07:00
download_service.ts feat(Maps): regional map downloads via go-pmtiles extract (#780) 2026-05-20 10:16:00 -07:00
kiwix_library_service.ts feat(zim): add "Rescan Library" button for sideloaded ZIM files 2026-06-06 11:04:53 -07:00
map_service.ts fix: minor type guarding fixes after axios bump 2026-06-07 21:18:42 +00:00
ollama_service.ts fix(AI): truncate-and-retry oversized embed chunks; stop 30x retry storm (#881) 2026-06-08 09:42:00 -07:00
queue_service.ts fix(queue): singleton QueueService to stop ioredis connection leak 2026-05-20 10:16:00 -07:00
rag_service.ts perf(KB): swap Qdrant full-scroll for facet on source enumeration (#928) 2026-06-06 10:55:20 -07:00
system_service.ts feat(supply-depot): opt-in automatic updates for installed apps 2026-06-07 15:56:42 -07:00
system_update_service.ts feat(system): add opt-in automatic updates for the core NOMAD app 2026-06-07 15:52:56 -07:00
zim_extraction_service.ts fix(RAG): report ZIM ingestion progress in overall-file frame 2026-05-20 10:16:00 -07:00
zim_service.ts feat(zim): add "Rescan Library" button for sideloaded ZIM files 2026-06-06 11:04:53 -07:00