Skip to content

Studio: decode escaped spreadsheet text during RAG indexing - #16712

Merged
oobabooga merged 2 commits into
unslothai:mainfrom
DimitriChrysafis:studio-xlsx-indexed-text
Nov 6, 2026
Merged

oobabooga merged 2 commits into
unslothai:mainfrom
DimitriChrysafis:studio-xlsx-indexed-text

Conversation

@DimitriChrysafis

Copy link
Copy Markdown
Contributor

What was broken

Spreadsheet previews decode Excel's _xHHHH_ text escapes after #16592, but RAG ingestion uses a separate reader and still indexes the encoded strings. Stored text differs from the preview, and lexical searches can miss the decoded cell contents.

This is the backend follow-up noted in the merge comment on #16592.

Repro

  1. On main at 91be10960, put Zebra_x006D_arker in an XLSX shared string, inline string or cached formula result.
  2. Upload it for RAG indexing. Ingestion completes, but the stored text still contains the escape.
  3. Search for zebramarker. There are no lexical matches.

Fix

Decode each text run before joining it, preserving quoted underscores and literal uppercase _X sequences. Combine UTF-16 surrogate pairs after joining runs, and replace unmatched surrogate units so the result remains valid UTF-8 for indexing. Cached formula strings use the same decoder. Number and error cells are unchanged.

Test

Nineteen regression cases fail before the fix; all 21 selected cases pass afterward. Coverage includes shared, inline and cached strings, rich-run boundaries, phonetic hints, quoted escapes, supplementary Unicode, and Strict OOXML. Upload-to-FTS tests cover .xlsx, .xlsm, .xltx and .xltm, using stub embeddings with the real ingestion and SQLite paths.

From studio/backend:

$ python -m pytest -q --tb=short --timeout=330 tests/test_rag_office_formats.py
161 passed in 4.57s
$ python -m pytest -q --tb=short -n 4 --dist loadgroup --timeout=330 tests/test_rag_office_formats.py tests/test_rag_parsing.py tests/test_rag_ingestion.py tests/test_rag_retrieval.py
333 passed, 1 skipped in 7.94s

The skip is the opt-in real-embedder test. Separately checked 16 exact string round trips through XlsxWriter-generated shared-string and inline-string workbooks, including control characters and escape-looking literals.

All seven repository checks and the pinned pre-commit formatter pass. No schema or dependency changes.

@oobabooga

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-06T07:23:32.322764Z 7c45e20 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: 6c3d3e18b7

ℹ️ 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".

@oobabooga

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: 7c45e20086

ℹ️ 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".

@oobabooga

Copy link
Copy Markdown
Member

Thanks @DimitriChrysafis. This is the backend counterpart of #16592: the knowledge base reader (_xlsx_text in office_formats.py) still stored Excel's _xHHHH_ escapes as text, so indexed spreadsheets didn't match the preview and searches could miss those cells. It now decodes them with the same rule as decodeXstring, plus a fix for emoji, which Python handles differently from JS.

I checked that the two decoders agree on 20,000 random inputs, and an XlsxWriter round trip that main got wrong on 6 of 13 strings now comes back exact. Mirror CI is clear at 0e8ed36ef2: 48 checks passed, and the one failure is an FP8 LoRA test that also fails on main, fixed since in #16855.

@oobabooga
oobabooga merged commit 7ac3ea5 into unslothai:main Nov 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants