fix: Skip node_modules and common build directories during ingestion
The ingest_directory function was recursively indexing ALL files including node_modules, which caused: - Massive index bloat (thousands of irrelevant library files) - Polluted search results with third-party code - Very slow indexing times Added SKIP_DIRECTORIES set with common directories to exclude: - Package managers: node_modules, vendor, Pods - Build outputs: dist, build, target, .next, .nuxt - VCS: .git, .svn, .hg - Caches: __pycache__, .pytest_cache, .mypy_cache, .cache - IDE: .vscode, .idea - Our own: .claude-os Also added should_skip_path() helper function with wildcard support for patterns like *.egg-info.
This commit is contained in:
parent
046f18949c
commit
e63466845f
1 changed files with 48 additions and 1 deletions
|
|
@ -323,12 +323,56 @@ def ingest_documents(
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# Directories to always skip during ingestion
|
||||||
|
SKIP_DIRECTORIES = {
|
||||||
|
'node_modules',
|
||||||
|
'.git',
|
||||||
|
'.svn',
|
||||||
|
'.hg',
|
||||||
|
'__pycache__',
|
||||||
|
'.pytest_cache',
|
||||||
|
'.mypy_cache',
|
||||||
|
'.tox',
|
||||||
|
'.nox',
|
||||||
|
'.eggs',
|
||||||
|
'*.egg-info',
|
||||||
|
'dist',
|
||||||
|
'build',
|
||||||
|
'.next',
|
||||||
|
'.nuxt',
|
||||||
|
'.output',
|
||||||
|
'coverage',
|
||||||
|
'.nyc_output',
|
||||||
|
'.cache',
|
||||||
|
'vendor',
|
||||||
|
'target', # Rust/Java
|
||||||
|
'Pods', # iOS
|
||||||
|
'.gradle',
|
||||||
|
'.idea',
|
||||||
|
'.vscode',
|
||||||
|
'.claude-os', # Our own cache
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def should_skip_path(file_path: Path) -> bool:
|
||||||
|
"""Check if a file path should be skipped based on directory exclusions."""
|
||||||
|
for part in file_path.parts:
|
||||||
|
if part in SKIP_DIRECTORIES:
|
||||||
|
return True
|
||||||
|
# Handle wildcard patterns like *.egg-info
|
||||||
|
for pattern in SKIP_DIRECTORIES:
|
||||||
|
if '*' in pattern and part.endswith(pattern.replace('*', '')):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def ingest_directory(
|
def ingest_directory(
|
||||||
dir_path: str,
|
dir_path: str,
|
||||||
collection_name: str
|
collection_name: str
|
||||||
) -> List[Dict[str, any]]:
|
) -> List[Dict[str, any]]:
|
||||||
"""
|
"""
|
||||||
Recursively ingest all supported files from a directory.
|
Recursively ingest all supported files from a directory.
|
||||||
|
Automatically skips common non-source directories like node_modules, .git, etc.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
dir_path: Path to directory
|
dir_path: Path to directory
|
||||||
|
|
@ -347,8 +391,11 @@ def ingest_directory(
|
||||||
"error": f"Directory not found: {dir_path}"
|
"error": f"Directory not found: {dir_path}"
|
||||||
}]
|
}]
|
||||||
|
|
||||||
# Recursively find all supported files
|
# Recursively find all supported files, skipping excluded directories
|
||||||
for file_path in dir_path.rglob("*"):
|
for file_path in dir_path.rglob("*"):
|
||||||
|
# Skip excluded directories
|
||||||
|
if should_skip_path(file_path):
|
||||||
|
continue
|
||||||
if file_path.is_file() and Config.is_supported_file(file_path.name):
|
if file_path.is_file() and Config.is_supported_file(file_path.name):
|
||||||
result = ingest_file(
|
result = ingest_file(
|
||||||
str(file_path),
|
str(file_path),
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue