[PR #538] [MERGED] Fix llama.cpp embedding response parsing #4660

Closed
opened 2026-10-22 04:09:34 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/538
Author: @cha1latte
Created: 5/7/2026
Status: ✅ Merged
Merged: 5/7/2026
Merged by: @cha1latte

Base: main ← Head: fix/issue-534-llama-cpp-embeddings


📝 Commits (1)

  • 899e5ba Fix llama.cpp embedding response parsing

📊 Changes

2 files changed (+32 additions, -2 deletions)

View changed files

📝 packages/server/src/services/llm/base-provider.ts (+16 -2)
➕ packages/server/test/embedding-response.test.ts (+16 -0)

📄 Description

Linked issue

Closes #534

Why this change

  • Lorebook Vectorize can call OpenAI-compatible embedding endpoints served by llama.cpp. llama.cpp's /embeddings response can be a top-level array of { embedding } items, while Marinara only accepted the OpenAI /v1/embeddings { data: [...] } wrapper and crashed with Cannot read properties of undefined (reading 'map').

What changed

  • Normalized embedding responses in the shared provider path so both OpenAI { data: [{ embedding }] } responses and llama.cpp [{ embedding }] responses are accepted.
  • Added focused server tests for OpenAI-shaped responses, llama.cpp-shaped responses, and malformed provider responses.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Manual verification notes

  • Reproduced the issue before the fix with pnpm --dir packages/server exec tsx ..\..\scratch\issue-534-embed-repro.ts against a local mock llama.cpp-style /embeddings endpoint. Before the fix it returned {"ok":false,"error":"Cannot read properties of undefined (reading 'map')"}.
  • Re-ran the same scratch repro after the fix. It returned {"ok":true,"embeddings":[[0.1,0.2,0.3]]}.
  • Ran pnpm --dir packages/server exec tsx --test test\embedding-response.test.ts: 3 tests passed, covering OpenAI wrapper responses, llama.cpp top-level array responses, and malformed response error paths.
  • Ran pnpm check: passed.
  • Container/Podman runtime was not rebuilt locally; the core claim is covered by the provider-level repro and baseline build.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Version/release files updated (only if this PR includes a version bump)

UI evidence (if applicable)

N/A - backend/provider response parsing fix; no visible UI state changed.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/538 **Author:** [@cha1latte](https://github.com/cha1latte) **Created:** 5/7/2026 **Status:** ✅ Merged **Merged:** 5/7/2026 **Merged by:** [@cha1latte](https://github.com/cha1latte) **Base:** `main` ← **Head:** `fix/issue-534-llama-cpp-embeddings` --- ### 📝 Commits (1) - [`899e5ba`](https://github.com/Pasta-Devs/Marinara-Engine/commit/899e5ba41967e8bd3030e08988e2e5c6b2b70513) Fix llama.cpp embedding response parsing ### 📊 Changes **2 files changed** (+32 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `packages/server/src/services/llm/base-provider.ts` (+16 -2) ➕ `packages/server/test/embedding-response.test.ts` (+16 -0) </details> ### 📄 Description ## Linked issue <!-- Every PR should reference a feature request or issue report. If there isn't one yet, open one first to gather opinions: --> <!-- https://github.com/Pasta-Devs/Marinara-Engine/issues/new/choose --> Closes #534 ## Why this change <!-- What user problem, bug, or goal does this solve? --> - Lorebook Vectorize can call OpenAI-compatible embedding endpoints served by llama.cpp. llama.cpp's `/embeddings` response can be a top-level array of `{ embedding }` items, while Marinara only accepted the OpenAI `/v1/embeddings` `{ data: [...] }` wrapper and crashed with `Cannot read properties of undefined (reading 'map')`. ## What changed <!-- List the key changes in this PR --> - Normalized embedding responses in the shared provider path so both OpenAI `{ data: [{ embedding }] }` responses and llama.cpp `[{ embedding }]` responses are accepted. - Added focused server tests for OpenAI-shaped responses, llama.cpp-shaped responses, and malformed provider responses. ## Validation <!-- Required: include commands run and/or manual checks performed --> - [x] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [ ] Ran the app, clicked through the changes manually - [x] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [ ] Above manual verification completed (describe below) - [x] Read and followed `CONTRIBUTING.md` ### Manual verification notes <!-- Describe exactly what you tested in a real browser/app, step by step. --> <!-- ⚠️ If an AI agent filled out or ticked these boxes for you, treat them --> <!-- as a TO-DO LIST, not as proof the work is done. Verify each item yourself --> <!-- before submitting. If you haven't verified it, untick the box. --> - Reproduced the issue before the fix with `pnpm --dir packages/server exec tsx ..\..\scratch\issue-534-embed-repro.ts` against a local mock llama.cpp-style `/embeddings` endpoint. Before the fix it returned `{"ok":false,"error":"Cannot read properties of undefined (reading 'map')"}`. - Re-ran the same scratch repro after the fix. It returned `{"ok":true,"embeddings":[[0.1,0.2,0.3]]}`. - Ran `pnpm --dir packages/server exec tsx --test test\embedding-response.test.ts`: 3 tests passed, covering OpenAI wrapper responses, llama.cpp top-level array responses, and malformed response error paths. - Ran `pnpm check`: passed. - Container/Podman runtime was not rebuilt locally; the core claim is covered by the provider-level repro and baseline build. ## Docs and release impact - [x] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Version/release files updated (only if this PR includes a version bump) ## UI evidence (if applicable) N/A - backend/provider response parsing fix; no visible UI state changed. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:09:34 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#4660
No description provided.