fix(rag): skip hidden and junk directories when indexing (#5633)

* fix(rag): skip hidden and junk directories when indexing (#5559)

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.

* fix(rag): prune hidden/junk dirs in the keyword index too, via a shared helper

The #5559 fix pruned only VectorRAG.index_personal_documents (the vector index).
The parallel keyword index built by PersonalDocsManager.refresh_index ->
load_personal_index walked the same tree unpruned, so .obsidian/, .git/,
node_modules/ etc. still swept into keyword retrieval and the file listing —
the 'end-to-end' guarantee was only half true.

Single-source the pruning policy in src/index_walk (prune_index_dirs +
is_indexable_file) and use it from both walkers so they cannot drift again.
The junk-dir match is now case-insensitive, so a Node_Modules on a
case-insensitive filesystem is pruned too.

Tests: keyword-path regressions covering hidden/junk dirs, hidden files, junk
at depth (not just top level), case-insensitive junk, and the explicit-hidden-
root exemption. The existing vector tests still pass against the shared helper.
This commit is contained in:
Joeseph Grey
2026-07-23 14:18:08 +02:00
committed by GitHub
parent d49629fa14
commit 4c9a8ca115
5 changed files with 203 additions and 4 deletions
+14 -3
View File
@@ -6,6 +6,8 @@ import logging
from typing import List, Dict, Set, Any, Tuple
from dataclasses import dataclass
from src.index_walk import prune_index_dirs, is_indexable_file
from src.markitdown_runtime import MARKITDOWN_EXTS
logger = logging.getLogger(__name__)
@@ -94,13 +96,22 @@ def tokenize(s: str) -> Set[str]:
return set(t for t in tokens if t not in config.STOP_WORDS and len(t) > 1)
def load_personal_index(
personal_dir: str,
personal_dir: str,
extensions: Tuple[str, ...] = config.DEFAULT_EXTENSIONS
) -> List[Dict[str, Any]]:
"""Load and index personal documents."""
"""Load and index personal documents.
Skips hidden and junk directories and hidden files via the shared
``index_walk`` policy, so the keyword index matches the vector index and a
real vault/repo does not sweep in ``.obsidian/`` / ``.git/`` /
``node_modules/`` content (#5559).
"""
files = []
for root, _, names in os.walk(personal_dir):
for root, dirs, names in os.walk(personal_dir):
prune_index_dirs(dirs)
for name in sorted(names):
if not is_indexable_file(name):
continue
p = os.path.join(root, name)
if not os.path.isfile(p):
continue