_ripgrep_search() — langchain Function Reference
Architecture documentation for the _ripgrep_search() function in file_search.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD c95c91c6_daaf_119c_f394_b216ac96d04e["_ripgrep_search()"] c970c63b_27bf_364e_6a46_1e5cc38ce38f["FilesystemFileSearchMiddleware"] c95c91c6_daaf_119c_f394_b216ac96d04e -->|defined in| c970c63b_27bf_364e_6a46_1e5cc38ce38f 99cb0385_d25f_ae58_a625_e8187615e060["__init__()"] 99cb0385_d25f_ae58_a625_e8187615e060 -->|calls| c95c91c6_daaf_119c_f394_b216ac96d04e b4e992f2_93ef_4642_9ddf_328ed58f534b["_validate_and_resolve_path()"] c95c91c6_daaf_119c_f394_b216ac96d04e -->|calls| b4e992f2_93ef_4642_9ddf_328ed58f534b 3f120244_d865_db15_009c_7c3c7671ebd6["_python_search()"] c95c91c6_daaf_119c_f394_b216ac96d04e -->|calls| 3f120244_d865_db15_009c_7c3c7671ebd6 style c95c91c6_daaf_119c_f394_b216ac96d04e fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/langchain_v1/langchain/agents/middleware/file_search.py lines 259–310
def _ripgrep_search(
self, pattern: str, base_path: str, include: str | None
) -> dict[str, list[tuple[int, str]]]:
"""Search using ripgrep subprocess."""
try:
base_full = self._validate_and_resolve_path(base_path)
except ValueError:
return {}
if not base_full.exists():
return {}
# Build ripgrep command
cmd = ["rg", "--json"]
if include:
# Convert glob pattern to ripgrep glob
cmd.extend(["--glob", include])
cmd.extend(["--", pattern, str(base_full)])
try:
result = subprocess.run( # noqa: S603
cmd,
capture_output=True,
text=True,
timeout=30,
check=False,
)
except (subprocess.TimeoutExpired, FileNotFoundError):
# Fallback to Python search if ripgrep unavailable or times out
return self._python_search(pattern, base_path, include)
# Parse ripgrep JSON output
results: dict[str, list[tuple[int, str]]] = {}
for line in result.stdout.splitlines():
try:
data = json.loads(line)
if data["type"] == "match":
path = data["data"]["path"]["text"]
# Convert to virtual path
virtual_path = "/" + str(Path(path).relative_to(self.root_path))
line_num = data["data"]["line_number"]
line_text = data["data"]["lines"]["text"].rstrip("\n")
if virtual_path not in results:
results[virtual_path] = []
results[virtual_path].append((line_num, line_text))
except (json.JSONDecodeError, KeyError):
continue
return results
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does _ripgrep_search() do?
_ripgrep_search() is a function in the langchain codebase, defined in libs/langchain_v1/langchain/agents/middleware/file_search.py.
Where is _ripgrep_search() defined?
_ripgrep_search() is defined in libs/langchain_v1/langchain/agents/middleware/file_search.py at line 259.
What does _ripgrep_search() call?
_ripgrep_search() calls 2 function(s): _python_search, _validate_and_resolve_path.
What calls _ripgrep_search()?
_ripgrep_search() is called by 1 function(s): __init__.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free