-
Notifications
You must be signed in to change notification settings - Fork 215
Expand file tree
/
Copy pathdirectory_search.py
More file actions
34 lines (27 loc) · 1.04 KB
/
directory_search.py
File metadata and controls
34 lines (27 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
"""Framework-agnostic directory search implementation using embedchain."""
import os
from embedchain import DirectoryLoader
def search_directory(directory: str, query: str) -> str:
"""Search through files in a specified directory using embedchain's DirectoryLoader.
Args:
directory: Path to the directory to search
query: Search query string
Returns:
str: Search results as a string
"""
loader = DirectoryLoader(directory)
results = loader.search(query)
return str(results)
def search_fixed_directory(query: str) -> str:
"""Search through files in a preconfigured directory using embedchain's DirectoryLoader.
Args:
query: Search query string
Returns:
str: Search results as a string
Raises:
ValueError: If DIRECTORY_SEARCH_PATH environment variable is not set
"""
directory = os.getenv("DIRECTORY_SEARCH_PATH")
if not directory:
raise ValueError("DIRECTORY_SEARCH_PATH environment variable must be set")
return search_directory(directory, query)