fix(rag): skip hidden and junk directories when indexing#5633
Open
StressTestor wants to merge 1 commit into
Open
fix(rag): skip hidden and junk directories when indexing#5633StressTestor wants to merge 1 commit into
StressTestor wants to merge 1 commit into
Conversation
index_personal_documents walked the whole tree with no pruning, so pointing RAG at a real-world folder silently swept in .obsidian/ plugin JS, .git/ internals, node_modules/, and __pycache__/ — multiplying indexing time and polluting retrieval with junk chunks. Prune hidden directories and well-known junk directories from the walk, and skip hidden files. The explicitly passed root is exempt, so a user who deliberately indexes a hidden directory still gets its contents.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
index_personal_documentswalks the target directory with no pruning, andDEFAULT_FILE_EXTENSIONSincludes.js,.json,.css,.html. Point RAG at a real-world folder and it indexes tool internals: an Obsidian vault's.obsidian/(2.6MB of minified plugin JS in the reporter's case), a repo's.git/,node_modules/,__pycache__/. Indexing time multiplies and retrieval fills with junk chunks.This PR prunes hidden directories and a small junk list (
node_modules,__pycache__,venv) from the walk in place, and skips hidden files. The explicitly passed root is exempt, so a user who deliberately indexes a hidden directory still gets its contents. Plus 3 hermetic regression tests (sameVectorRAG.__new__pattern astest_rag_remove_directory_scope.py); all 3 fail ondevwithout the fix.Target branch
dev, notmain.Linked Issue
Fixes #5559
Type of Change
Checklist
devuvicorn app:app+ a local ChromaDB atlocalhost:8100) and verified the change works end-to-end.How to Test
python -m pytest tests/test_rag_index_hidden_dirs.py: 3 tests covering hidden dirs, hidden files, junk dirs, and the explicit-hidden-root exemption. They fail ondevwithout the fix.End-to-end (what i ran): start ChromaDB and the app, then create a directory under
data/personal_docs/containing real content plus junk dirs:POST /api/personal/add_directorywith that path. Response on this branch:indexed_count: 2, failed_count: 0.Confirm in the vector store that only the two real files landed. Querying the
odysseus_rag_fastembedcollection's metadatas after the call returns exactlynotes/meeting.mdandreadme.mdas sources, none of the junk paths. Ondevthe same tree also embeds the.obsidian/,.git/,node_modules/,__pycache__/, andvenv/files.Also ran: full
python -m pytest(4673 passed, 3 skipped; the 5 failures are the docker-socket tests, which fail identically on cleandevon this machine, macOS with no docker socket) andpython -m compileall app.py core routes src services scripts tests.Scope notes
include_hiddenas optional; adding it means plumbing a flag through the route,PersonalDocsManager,RAGManager, and the UI, so i left it out to keep this small. Can follow up if wanted.dist/,build/,target/could join it, but those names collide with legitimate content folders more often.