[PR #5609] [MERGED] perf(storage): pack lorebook entry embeddings as Float64Array (#5592 Phase 3) #6847

Closed
opened 2026-10-23 04:14:15 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/5609
Author: @kolacheee
Created: 8/28/2026
Status: ✅ Merged
Merged: 8/28/2026
Merged by: @kolacheee

Base: staging ← Head: feat/5592-phase3-lorebook-embeddings


📝 Commits (1)

  • 9660cef perf(storage): pack lorebook entry embeddings as Float64Array

📊 Changes

5 files changed (+37 additions, -4 deletions)

View changed files

📝 CHANGELOG.md (+1 -0)
📝 packages/server/src/db/file-backed-store.ts (+1 -0)
📝 packages/server/src/db/schema/lorebooks.ts (+3 -3)
📝 packages/server/src/services/storage/lorebooks.storage.ts (+9 -1)
📝 scripts/regressions/message-sharding.regression.ts (+23 -0)

📄 Description

Why

Part of #5592 — the flagged follow-up from #5596: lorebook_entries.embedding gets the same off-heap packing Memory Recall chunks received. Vector-heavy lorebooks (semantic matching enabled) currently hold every entry's embedding as an on-heap JSON string for as long as the table is resident.

Stacked on #5608 (→ #5607); merge those first and this rebases clean.

What

Three small changes: the schema column becomes vectorText, the table joins VECTOR_TEXT_COLUMNS, and the entry parser accepts both the original string (what unprojected reads return — the compatibility surface for backup/export/mari-db) and a packed Float64Array (what a projected read would surface), so no read path depends on which shape it got. Packing still applies only when the pack/unpack round trip is byte-identical, so the on-disk format is unchanged and no STORAGE_VERSION bump is needed — identical to the #5596 design.

Regressions

The vector round-trip block in message-sharding.regression.ts gains a lorebook-entry case: unprojected reads return the original string, and the flushed shard serializes the vector back byte-identically. Sharding suite green in both lazy and eager modes; memory-recall-revectorize green.

Test plan

  • pnpm check on a non-Windows checkout
  • pnpm regression
  • Manually verify: vectorize a lorebook, trigger entries semantically, export/import the lorebook — identical behavior

References #5592 (do not auto-close).

Summary by CodeRabbit

  • Performance

    • Improved storage efficiency for Lorebook embeddings by packing vectors outside the JavaScript heap.
    • Preserved embedding data and formatting during reads and persistence.
  • Bug Fixes

    • Ensured Lorebook embeddings are correctly restored whether loaded as text or optimized vector data.
  • Tests

    • Added regression coverage for embedding handling and byte-identical shard persistence.

🔄 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/5609 **Author:** [@kolacheee](https://github.com/kolacheee) **Created:** 8/28/2026 **Status:** ✅ Merged **Merged:** 8/28/2026 **Merged by:** [@kolacheee](https://github.com/kolacheee) **Base:** `staging` ← **Head:** `feat/5592-phase3-lorebook-embeddings` --- ### 📝 Commits (1) - [`9660cef`](https://github.com/Pasta-Devs/Marinara-Engine/commit/9660cefc6ebf27e35b6d0eeb1399c8cd7066d5e4) perf(storage): pack lorebook entry embeddings as Float64Array ### 📊 Changes **5 files changed** (+37 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+1 -0) 📝 `packages/server/src/db/file-backed-store.ts` (+1 -0) 📝 `packages/server/src/db/schema/lorebooks.ts` (+3 -3) 📝 `packages/server/src/services/storage/lorebooks.storage.ts` (+9 -1) 📝 `scripts/regressions/message-sharding.regression.ts` (+23 -0) </details> ### 📄 Description ## Why Part of #5592 — the flagged follow-up from #5596: `lorebook_entries.embedding` gets the same off-heap packing Memory Recall chunks received. Vector-heavy lorebooks (semantic matching enabled) currently hold every entry's embedding as an on-heap JSON string for as long as the table is resident. Stacked on #5608 (→ #5607); merge those first and this rebases clean. ## What Three small changes: the schema column becomes `vectorText`, the table joins `VECTOR_TEXT_COLUMNS`, and the entry parser accepts both the original string (what unprojected reads return — the compatibility surface for backup/export/mari-db) and a packed `Float64Array` (what a projected read would surface), so no read path depends on which shape it got. Packing still applies only when the pack/unpack round trip is byte-identical, so the on-disk format is unchanged and no STORAGE_VERSION bump is needed — identical to the #5596 design. ## Regressions The vector round-trip block in `message-sharding.regression.ts` gains a lorebook-entry case: unprojected reads return the original string, and the flushed shard serializes the vector back byte-identically. Sharding suite green in both lazy and eager modes; memory-recall-revectorize green. ## Test plan - [x] `pnpm check` on a non-Windows checkout - [x] `pnpm regression` - [x] Manually verify: vectorize a lorebook, trigger entries semantically, export/import the lorebook — identical behavior References #5592 (do not auto-close). <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Performance** * Improved storage efficiency for Lorebook embeddings by packing vectors outside the JavaScript heap. * Preserved embedding data and formatting during reads and persistence. * **Bug Fixes** * Ensured Lorebook embeddings are correctly restored whether loaded as text or optimized vector data. * **Tests** * Added regression coverage for embedding handling and byte-identical shard persistence. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-23 04:14:15 +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#6847
No description provided.