Skip to content

Commit 0a0efc0

Browse files
committed
Add intelligent path detection for nearby FSS-Mini-RAG indexes
- Implement find_nearby_index() to search current dir + 2 levels up - Add helpful navigation guidance when index found elsewhere - Update search command to show guidance instead of failing - Update status command to detect nearby indexes - Keep detection simple and not overly complex - Fix command parameter bug (--show-perf) Features: - Searches current directory, parent, and grandparent for .mini-rag - Shows exact navigation commands when index found nearby - Provides clear "cd path && rag-mini search" instructions - Falls back to "create index here" if not found nearby User experience improvements: - No more mysterious "not indexed" errors in subdirectories - Clear guidance on how to navigate to existing indexes - Simple 3-level search depth keeps it fast and predictable
1 parent af4db45 commit 0a0efc0

1 file changed

Lines changed: 72 additions & 4 deletions

File tree

mini_rag/cli.py

Lines changed: 72 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,52 @@
3838
console = Console()
3939

4040

41+
def find_nearby_index(start_path: Path = None) -> Optional[Path]:
42+
"""
43+
Find .mini-rag index in current directory or up to 2 levels up.
44+
45+
Args:
46+
start_path: Starting directory to search from (default: current directory)
47+
48+
Returns:
49+
Path to directory containing .mini-rag, or None if not found
50+
"""
51+
if start_path is None:
52+
start_path = Path.cwd()
53+
54+
current = start_path.resolve()
55+
56+
# Search current directory and up to 2 levels up
57+
for level in range(3): # 0, 1, 2 levels up
58+
rag_dir = current / ".mini-rag"
59+
if rag_dir.exists() and rag_dir.is_dir():
60+
return current
61+
62+
# Move up one level
63+
parent = current.parent
64+
if parent == current: # Reached filesystem root
65+
break
66+
current = parent
67+
68+
return None
69+
70+
71+
def show_index_guidance(query_path: Path, found_index_path: Path) -> None:
72+
"""Show helpful guidance when index is found in a different location."""
73+
relative_path = found_index_path.relative_to(Path.cwd()) if found_index_path != Path.cwd() else Path(".")
74+
75+
console.print(f"\n[yellow]📍 Found FSS-Mini-RAG index in:[/yellow] [blue]{found_index_path}[/blue]")
76+
console.print(f"[dim]Current directory:[/dim] [dim]{query_path}[/dim]")
77+
console.print()
78+
console.print("[green]🚀 To search the index, navigate there first:[/green]")
79+
console.print(f" [bold]cd {relative_path}[/bold]")
80+
console.print(f" [bold]rag-mini search 'your query here'[/bold]")
81+
console.print()
82+
console.print("[cyan]💡 Or specify the path directly:[/cyan]")
83+
console.print(f" [bold]rag-mini search -p {found_index_path} 'your query here'[/bold]")
84+
console.print()
85+
86+
4187
@click.group()
4288
@click.option("--verbose", "-v", is_flag=True, help="Enable verbose logging")
4389
@click.option("--quiet", "-q", is_flag=True, help="Suppress output")
@@ -153,7 +199,7 @@ def init(path: str, force: bool, reindex: bool, model: Optional[str]):
153199
)
154200
@click.option("--lang", multiple=True, help="Filter by language (python, javascript, etc.)")
155201
@click.option("--show-content", "-c", is_flag=True, help="Show code content in results")
156-
@click.option("--show-per", is_flag=True, help="Show performance metrics")
202+
@click.option("--show-perf", is_flag=True, help="Show performance metrics")
157203
def search(
158204
query: str,
159205
path: str,
@@ -166,10 +212,21 @@ def search(
166212
"""Search codebase using semantic similarity."""
167213
project_path = Path(path).resolve()
168214

169-
# Check if indexed
215+
# Check if indexed at specified path
170216
rag_dir = project_path / ".mini-rag"
171217
if not rag_dir.exists():
172-
console.print("[red]Error:[/red] Project not indexed. Run 'rag-mini init' first.")
218+
# Try to find nearby index if searching from current directory
219+
if path == ".":
220+
nearby_index = find_nearby_index()
221+
if nearby_index:
222+
show_index_guidance(project_path, nearby_index)
223+
sys.exit(0)
224+
225+
console.print(f"[red]Error:[/red] No FSS-Mini-RAG index found at [blue]{project_path}[/blue]")
226+
console.print()
227+
console.print("[yellow]💡 To create an index:[/yellow]")
228+
console.print(f" [bold]rag-mini init -p {project_path}[/bold]")
229+
console.print()
173230
sys.exit(1)
174231

175232
# Get performance monitor
@@ -714,7 +771,18 @@ def status(path: str, port: int, discovery: bool):
714771
console.print(f" • Error: {e}")
715772
else:
716773
console.print(" • Status: [red]❌ Not indexed[/red]")
717-
console.print(" • Run 'rag-mini init' to initialize")
774+
775+
# Try to find nearby index if checking current directory
776+
if path == ".":
777+
nearby_index = find_nearby_index()
778+
if nearby_index:
779+
console.print(f" • Found index in: [blue]{nearby_index}[/blue]")
780+
relative_path = nearby_index.relative_to(Path.cwd()) if nearby_index != Path.cwd() else Path(".")
781+
console.print(f" • Use: [bold]cd {relative_path} && rag-mini status[/bold]")
782+
else:
783+
console.print(" • Run 'rag-mini init' to initialize")
784+
else:
785+
console.print(" • Run 'rag-mini init' to initialize")
718786

719787
# Check server status
720788
console.print("\n[bold]🚀 Server Status:[/bold]")

0 commit comments

Comments
 (0)