Repository navigation
fix(rag): resolve the exact indexed file instead of the first substring hit - #4613
Conversation
…ng hit Asking about report.pdf could answer from q3_report.pdf: query_specific_file, summarize_document and dump_document substring-matched the request against the index and silently took whichever match came first (from an unordered set). Files now resolve by exact path, then exact filename / trailing path components, then substring. If more than one indexed file still matches, the tool returns an "Ambiguous filename" error with a candidates list so the model retries with a full path instead of guessing.
|
Verdict: Approve with suggestions Before this PR, asking about Two things to close out before or soon after merge:
Real-world evidenceN/A: the evidence bundle wasn't produced for this run. The change is internal to the RAG tools, and its only user-visible effect needs real inference (the strix-halo lane). The verdict rests on static review alone. I couldn't run the new tests here either, because pytest isn't installed in the review environment. 🔍 Technical detailsIssues 🟡 LLM-facing tool results changed, eval not run ( 🟢 No test for 🟢 Redundant second ambiguity check ( Edge cases I checked (all fine)
Strengths
|
The ambiguity check after the not-found branch already covers the auto-index path, so the inner copy went.
|
The RAG eval still needs a run on AMD hardware before this ships in a release: the model now gets an "ambiguous file" error with candidates where it used to get a silent first match, and that can't be scored locally. 🔍 Technical details
|
File tools now all check the same allowed-folders rule. Before, `read_file` and `write_file` checked a path against the session's allowed folders (asking the user when it was outside), but several neighbouring tools did not: folder browsing and directory search, recent files, document and code indexing, folder watching, `list_files`, and the paths screenshots, transcripts, speech and exports are saved to. Now every one goes through the same check and the same approval prompt, so a chat scoped to its documents behaves the same whichever tool the model picks. - **One rule, not a second one.** Tools call the existing `PathValidator.validate_read` / `validate_write` through a thin helper. The validator now expands `~` before resolving symlinks and `..`, so it judges the path the tool actually opens. - **Approving a folder now covers document indexing too.** The chat agent's RAG SDK kept a separate validator, so a folder approved in the chat was still refused at indexing time. It now shares the agent's. - **Wider on purpose, and documented:** name search over the common document folders (it returns paths only, and opening one is checked), GAIA's own output folders, and `capture_skill`, which asks the user on every call. <details> <summary>🔍 Technical details</summary> - Helper: `gaia.agents.tools.path_access` (`read_access_error`, `write_access_error`, `readable_entry`). Folder walks call `readable_entry` per file, which never prompts. - Model-visible changes: refusal text from these tools is now the validator's standard message, `list_recent_files` reports `locations_not_searched`, and `search_directory` with no root searches the allowed folders instead of the whole home folder. No tool docstrings changed. - Overlap with amd#4642: both PRs add the same `~` expansion to `browse_directory`, `get_file_info`, `analyze_data_file` and `search_file_content`, with identical lines, so either merge order applies cleanly. Merging amd#4642 first is the simplest order. - Nearby open PRs: amd#4613 and amd#4648 (`rag_tools.py`), amd#4644 (`code_index_tools.py`), amd#4626 (`filesystem_tools.py`), and amd#4647 (flagship CHANGELOG). Their hunks don't overlap these, but whichever lands second may need a trivial rebase. </details> ## Test plan - [x] `pytest tests/unit/test_file_tools_allowed_folders.py hub/agents/chat/python/tests/test_chat_file_tools_allowed_folders.py`: 66 tests. For each tool, a path outside the allowed folders (direct, through `..`, and through a symlink) goes through the approval prompt and is refused, and a path inside still works. 41 of them fail on main. The ChatAgent tests live in the chat package, so the chat-agent lane runs them; the core unit lane has no `gaia_agent_chat`. - [x] Existing file, RAG, audio, screenshot, code-index, security and chat-agent unit tests pass. The two local failures (`test_persisted_grants_are_not_unioned_into_a_host_scope`, `test_backups_directory_is_owner_only`) also fail on main on this machine. - [x] black, isort, flake8 and pylint are clean on the changed files. - [ ] Follow-up after the core release that ships `path_access`: raise the chat and flagship `amd-gaia` floors to it, as the chat CHANGELOG records. - [ ] CI eval re-run, since refusal text and the default search scope are model-visible: `gaia_files`, `gaia_core`, `gaia_data`, `tool_selection`. --------- Co-authored-by: Kalin Ovtcharov <[email protected]> Co-authored-by: Kalin Ovtcharov <[email protected]>
Asking about
report.pdfwithq3_report.pdfalso indexed could answer from the wrong document, with no sign anything was off — the per-file tools took the first substring match from an unordered set. Now an exact path or filename match wins, and when a request still matches several indexed files the tool returns an "Ambiguous filename" error listing the candidates, so the model retries with a full path instead of guessing. Applies to per-file query, summarize, and dump.Test plan
pytest tests/unit/test_rag_file_resolution.py— exact match beats substring, true ambiguity returns the error with candidates, a single substring match still resolves (12 tests)pyteston everytests/unitfile importingrag_tools— 475 passed, 15 skippedgaia eval agent --category rag_qualityon AMD hardware — required because this changes tool results the LLM sees; not run (no AMD hardware available)