Skip to content

feat(ui): index documents in the background with an honest time left - #6265

Draft
kovtcharov wants to merge 4 commits into
amd:mainfrom
kovtcharov:kalin/indexing-progress-estimate
Draft

kovtcharov wants to merge 4 commits into
amd:mainfrom
kovtcharov:kalin/indexing-progress-estimate

Conversation

@kovtcharov

Copy link
Copy Markdown
Contributor

Adding seven PDFs blocked for 28 minutes, nothing showed once the library closed, and a chat could start reading a file the library was already reading. Adding a document now returns at once and each one indexes in the background, with one bar and the time left above the chat and in the library. The estimate is measured per phase on this machine, shows nothing until it has enough samples, and says "taking longer than expected" rather than freezing on a number.

Includes the commit from the reuse-indexing PR, which should merge first.

Known limits: a restart shows interrupted work but doesn't resume it, thresholds are untuned against real PDFs, and the Arabic wording needs a native speaker's review. The estimate has only run against recorded progress so far, and the packaged app's sidecar still needs a check for double indexing.

Eval category to watch: rag_quality, because the agent's own index tools now report a running index instead of starting one.

Library

Chat in Arabic

Taking longer than expected

Test plan

  • cd src/gaia/apps/webui && npm test && npm run test:rtl
  • Add several real PDFs in the Agent UI, close the library and watch the line above the chat
  • Cancel a queued document and Retry a failed one

The library indexes an upload's temp copy and chats index the original.
The cache key includes the path, so a first chat read every page again,
images included: 40 minutes on a 790-page library that was already done.

A cache entry for the same bytes and chunking is now reused from any path.
Adding seven PDFs took 28 minutes and a first chat another 30: most adds
blocked until indexed, nothing showed once the library closed, and a chat
read a file the library was already reading, from page one, silently.

Adding a document now returns at once from the library, file browser, drag
and drop, folders and Retry, and each indexes on its own. A line above the
chat shows N of M done, one bar and the time left, and opens the library,
which shows the same plus the file in hand.

The estimate is measured per phase on this machine and covers later phases
and queued files. It shows nothing until there are enough samples, a lower
bound while a phase is unmeasured, and "taking longer than expected" in place
of a frozen number.

A chat leaves documents that are indexing, cancelled or failed out of the
turn and says so; the agent's own index tools report the running index
instead of starting another. Cancel now reaches queued documents, Retry and
automatic re-indexing, and a restart mid-index stays visible.
Each row sized its bar to its status text, so Cancel sat at a different spot on every line. The bar now takes the row and Cancel stays at its end, in either direction.
@github-actions github-actions Bot added documentation Documentation changes rag RAG system changes tests Test changes electron Electron app changes performance Performance-critical changes agents labels Nov 1, 2026
@kovtcharov-amd kovtcharov-amd added the multilingual Language support: translations, right-to-left layout, Arabic and other non-English languages label Nov 6, 2026
rezamuliawijaya pushed a commit to rezamuliawijaya/gaia that referenced this pull request Nov 7, 2026
A document edited after it was indexed kept answering from its old text:
indexing it again said "already indexed" and changed nothing, and only a
new session picked up the edit. Now indexing an edited document
re-indexes it, and an unchanged one still returns at once without
re-embedding.

Open PRs amd#6265 and amd#6286 rework background indexing but don't touch this
already-indexed check, so they don't overlap with this fix.

## Test plan
- [ ] `python -m pytest tests/unit/rag/test_edited_document_reindex.py
tests/unit/rag/test_retrieval_bench_harness.py`
- [ ] In `gaia chat`, index a text file and ask about it; edit the file,
ask the agent to index it again, and the answer reflects the edit
- [ ] Index an unchanged file twice; the second call reports it is
already indexed

<details>
<summary>🔍 Technical details</summary>

- `RAGSDK` keeps `file_content_keys` (the `_content_key` of the indexed
bytes), set on both publish paths and cleared in `remove_document`
(which LRU eviction uses) and the `reindex_document` rollback snapshot.
- A repeat `index_document` hashes the file outside the lock; a mismatch
calls `reindex_document`, which now passes the progress/wait callbacks
through. The hash, not mtime/size, is the check, so a same-size edit
with a restored timestamp is caught (tested).
- The two race re-checks now compare keys: another writer's index of
different bytes is replaced instead of being reported as current.
- A locked file (Windows exclusive open) reports `file_locked` and keeps
its index rather than being dropped.
- `RAGToolsMixin.index_document` short-circuits only when the new
`is_current()` agrees.
- The `replaced_document` retrieval hard case should flip fail→pass; the
gate reports that as information, and the baseline JSON is left for the
next real run.
- Regression hunt: every rag/index/document unit test plus the
flagship's document tests pass (2376 + 382); the one pdfium-thread
failure in the baseline run didn't reproduce.
</details>

Closes amd#4738
kovtcharov-amd added a commit to huong8373tt-beep/gaia that referenced this pull request Nov 7, 2026
A document edited after it was indexed kept answering from its old text:
indexing it again said "already indexed" and changed nothing, and only a
new session picked up the edit. Now indexing an edited document
re-indexes it, and an unchanged one still returns at once without
re-embedding.

Open PRs amd#6265 and amd#6286 rework background indexing but don't touch this
already-indexed check, so they don't overlap with this fix.

## Test plan
- [ ] `python -m pytest tests/unit/rag/test_edited_document_reindex.py
tests/unit/rag/test_retrieval_bench_harness.py`
- [ ] In `gaia chat`, index a text file and ask about it; edit the file,
ask the agent to index it again, and the answer reflects the edit
- [ ] Index an unchanged file twice; the second call reports it is
already indexed

<details>
<summary>🔍 Technical details</summary>

- `RAGSDK` keeps `file_content_keys` (the `_content_key` of the indexed
bytes), set on both publish paths and cleared in `remove_document`
(which LRU eviction uses) and the `reindex_document` rollback snapshot.
- A repeat `index_document` hashes the file outside the lock; a mismatch
calls `reindex_document`, which now passes the progress/wait callbacks
through. The hash, not mtime/size, is the check, so a same-size edit
with a restored timestamp is caught (tested).
- The two race re-checks now compare keys: another writer's index of
different bytes is replaced instead of being reported as current.
- A locked file (Windows exclusive open) reports `file_locked` and keeps
its index rather than being dropped.
- `RAGToolsMixin.index_document` short-circuits only when the new
`is_current()` agrees.
- The `replaced_document` retrieval hard case should flip fail→pass; the
gate reports that as information, and the baseline JSON is left for the
next real run.
- Regression hunt: every rag/index/document unit test plus the
flagship's document tests pass (2376 + 382); the one pdfium-thread
failure in the baseline run didn't reproduce.
</details>

Closes amd#4738
@kovtcharov

Copy link
Copy Markdown
Contributor Author

Left as a draft, nothing pushed: merging main conflicts in 12 files, and resolving them would mean rebuilding parts of this feature rather than merging it.

What is in the way:

  • The agent's index tools. Main rewrote how they track a running index (jobs keyed by the file's real path, a record of indexes that failed after the caller stopped waiting, reuse of a job that just finished). This branch adds its own tracker on top of the old version. The two need to be designed into one, not placed side by side.
  • The chat view. Main moved the attached-documents bar, status-event handling and the stream event types out of the chat view into their own files. This branch edits all three in their old place, including the new notice above the chat.
  • The documents API. Main removed the monitor status route and changed the status route that this branch extends.
  • Smaller overlaps in the library, the file browser, the API client and the visual-test fixtures.

The description's own open items still stand too: the estimate has only run against recorded progress, and the packaged app has not been checked for double indexing. This needs a fresh pass on current main by someone who can run it against real PDFs.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-ui Agent UI changes agents documentation Documentation changes electron Electron app changes enhancement New feature or request multilingual Language support: translations, right-to-left layout, Arabic and other non-English languages 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