mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-09-16 05:02:21 +02:00
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:
+13
-1
@@ -14,6 +14,7 @@ import numpy as np
|
||||
from typing import List, Dict, Any, Optional, Set
|
||||
|
||||
from src.constants import CHROMA_DIR
|
||||
from src.index_walk import prune_index_dirs, is_indexable_file
|
||||
from pathlib import Path
|
||||
|
||||
from src.embedding_lanes import (
|
||||
@@ -34,6 +35,10 @@ DEFAULT_FILE_EXTENSIONS: Set[str] = {
|
||||
'.csv', '.html', '.css', '.js', '.pdf'
|
||||
}
|
||||
|
||||
# Tool-internal directories that match DEFAULT_FILE_EXTENSIONS but are never
|
||||
# Directory-walk pruning is single-sourced in src.index_walk so the vector and
|
||||
# keyword indexers apply the same hidden/junk policy and cannot drift (#5559).
|
||||
|
||||
VECTOR_WEIGHT = 0.7
|
||||
KEYWORD_WEIGHT = 0.3
|
||||
|
||||
@@ -497,8 +502,15 @@ class VectorRAG:
|
||||
failed = 0
|
||||
|
||||
try:
|
||||
for root, _, files in os.walk(directory):
|
||||
for root, dirs, files in os.walk(directory):
|
||||
# Prune in place so os.walk never descends into hidden or junk
|
||||
# directories (#5559), via the shared index_walk policy. The
|
||||
# passed-in root is exempt: a user who deliberately targets a
|
||||
# hidden directory gets it.
|
||||
prune_index_dirs(dirs)
|
||||
for fname in files:
|
||||
if not is_indexable_file(fname):
|
||||
continue
|
||||
fpath = os.path.join(root, fname)
|
||||
ext = Path(fname).suffix.lower()
|
||||
if ext not in file_extensions:
|
||||
|
||||
Reference in New Issue
Block a user