Remove defensive app() try/except, let errors propagate if they occur
This commit is contained in:
parent
affffc1013
commit
345807e699
2 changed files with 157 additions and 181 deletions
|
|
@ -78,12 +78,8 @@ class HaikuRAGApp:
|
||||||
return
|
return
|
||||||
|
|
||||||
# Connect without going through Store to avoid upgrades/validation writes
|
# Connect without going through Store to avoid upgrades/validation writes
|
||||||
try:
|
|
||||||
db = lancedb.connect(self.db_path)
|
db = lancedb.connect(self.db_path)
|
||||||
table_names = set(db.table_names())
|
table_names = set(db.table_names())
|
||||||
except Exception as e:
|
|
||||||
self.console.print(f"[red]Failed to open database: {e}[/red]")
|
|
||||||
return
|
|
||||||
|
|
||||||
versions = get_package_versions()
|
versions = get_package_versions()
|
||||||
|
|
||||||
|
|
@ -418,7 +414,6 @@ class HaikuRAGApp:
|
||||||
read_only=self.read_only,
|
read_only=self.read_only,
|
||||||
before=self.before,
|
before=self.before,
|
||||||
) as self.client:
|
) as self.client:
|
||||||
try:
|
|
||||||
citations = []
|
citations = []
|
||||||
if deep:
|
if deep:
|
||||||
graph = build_research_graph(config=self.config)
|
graph = build_research_graph(config=self.config)
|
||||||
|
|
@ -460,8 +455,6 @@ class HaikuRAGApp:
|
||||||
if cite and citations:
|
if cite and citations:
|
||||||
for renderable in format_citations_rich(citations):
|
for renderable in format_citations_rich(citations):
|
||||||
self.console.print(renderable)
|
self.console.print(renderable)
|
||||||
except Exception as e:
|
|
||||||
self.console.print(f"[red]Error: {e}[/red]")
|
|
||||||
|
|
||||||
async def research(self, question: str, filter: str | None = None):
|
async def research(self, question: str, filter: str | None = None):
|
||||||
"""Run research via the pydantic-graph pipeline.
|
"""Run research via the pydantic-graph pipeline.
|
||||||
|
|
@ -476,7 +469,6 @@ class HaikuRAGApp:
|
||||||
read_only=self.read_only,
|
read_only=self.read_only,
|
||||||
before=self.before,
|
before=self.before,
|
||||||
) as client:
|
) as client:
|
||||||
try:
|
|
||||||
self.console.print("[bold cyan]Starting research[/bold cyan]")
|
self.console.print("[bold cyan]Starting research[/bold cyan]")
|
||||||
self.console.print(f"[bold blue]Question:[/bold blue] {question}")
|
self.console.print(f"[bold blue]Question:[/bold blue] {question}")
|
||||||
self.console.print()
|
self.console.print()
|
||||||
|
|
@ -545,9 +537,6 @@ class HaikuRAGApp:
|
||||||
self.console.print("[bold cyan]Sources:[/bold cyan]")
|
self.console.print("[bold cyan]Sources:[/bold cyan]")
|
||||||
self.console.print(report.sources_summary)
|
self.console.print(report.sources_summary)
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
self.console.print(f"[red]Error during research: {e}[/red]")
|
|
||||||
|
|
||||||
async def rebuild(self, mode: RebuildMode = RebuildMode.FULL):
|
async def rebuild(self, mode: RebuildMode = RebuildMode.FULL):
|
||||||
async with HaikuRAG(
|
async with HaikuRAG(
|
||||||
db_path=self.db_path,
|
db_path=self.db_path,
|
||||||
|
|
@ -556,14 +545,11 @@ class HaikuRAGApp:
|
||||||
read_only=self.read_only,
|
read_only=self.read_only,
|
||||||
before=self.before,
|
before=self.before,
|
||||||
) as client:
|
) as client:
|
||||||
try:
|
|
||||||
documents = await client.list_documents()
|
documents = await client.list_documents()
|
||||||
total_docs = len(documents)
|
total_docs = len(documents)
|
||||||
|
|
||||||
if total_docs == 0:
|
if total_docs == 0:
|
||||||
self.console.print(
|
self.console.print("[yellow]No documents found in database.[/yellow]")
|
||||||
"[yellow]No documents found in database.[/yellow]"
|
|
||||||
)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
mode_desc = {
|
mode_desc = {
|
||||||
|
|
@ -583,12 +569,9 @@ class HaikuRAGApp:
|
||||||
self.console.print(
|
self.console.print(
|
||||||
"[bold green]Database rebuild completed successfully.[/bold green]"
|
"[bold green]Database rebuild completed successfully.[/bold green]"
|
||||||
)
|
)
|
||||||
except Exception as e:
|
|
||||||
self.console.print(f"[red]Error rebuilding database: {e}[/red]")
|
|
||||||
|
|
||||||
async def vacuum(self):
|
async def vacuum(self):
|
||||||
"""Run database maintenance: optimize and cleanup table history."""
|
"""Run database maintenance: optimize and cleanup table history."""
|
||||||
try:
|
|
||||||
async with HaikuRAG(
|
async with HaikuRAG(
|
||||||
db_path=self.db_path,
|
db_path=self.db_path,
|
||||||
config=self.config,
|
config=self.config,
|
||||||
|
|
@ -597,15 +580,10 @@ class HaikuRAGApp:
|
||||||
before=self.before,
|
before=self.before,
|
||||||
) as client:
|
) as client:
|
||||||
await client.vacuum()
|
await client.vacuum()
|
||||||
self.console.print(
|
self.console.print("[bold green]Vacuum completed successfully.[/bold green]")
|
||||||
"[bold green]Vacuum completed successfully.[/bold green]"
|
|
||||||
)
|
|
||||||
except Exception as e:
|
|
||||||
self.console.print(f"[red]Error during vacuum: {e}[/red]")
|
|
||||||
|
|
||||||
async def create_index(self):
|
async def create_index(self):
|
||||||
"""Create vector index on the chunks table."""
|
"""Create vector index on the chunks table."""
|
||||||
try:
|
|
||||||
async with HaikuRAG(
|
async with HaikuRAG(
|
||||||
db_path=self.db_path,
|
db_path=self.db_path,
|
||||||
config=self.config,
|
config=self.config,
|
||||||
|
|
@ -637,8 +615,6 @@ class HaikuRAGApp:
|
||||||
self.console.print(
|
self.console.print(
|
||||||
"[bold green]Vector index created successfully.[/bold green]"
|
"[bold green]Vector index created successfully.[/bold green]"
|
||||||
)
|
)
|
||||||
except Exception as e:
|
|
||||||
self.console.print(f"[red]Error creating index: {e}[/red]")
|
|
||||||
|
|
||||||
async def download_models(self):
|
async def download_models(self):
|
||||||
"""Download Docling, HuggingFace tokenizer, and Ollama models per config."""
|
"""Download Docling, HuggingFace tokenizer, and Ollama models per config."""
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ def run_chat(
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
from haiku.rag.chat.app import ChatApp
|
from haiku.rag.chat.app import ChatApp
|
||||||
except ImportError as e:
|
except ImportError as e: # pragma: no cover
|
||||||
raise ImportError(
|
raise ImportError(
|
||||||
"textual is not installed. Please install it with `pip install 'haiku.rag-slim[tui]'` or use the full haiku.rag package."
|
"textual is not installed. Please install it with `pip install 'haiku.rag-slim[tui]'` or use the full haiku.rag package."
|
||||||
) from e
|
) from e
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue