lfnovo/open-notebook · error · HTTPException

Search failed: {str(e)}

Error message

Search failed: {str(e)}

What it means

500 raised when a DatabaseOperationError escapes during search — the underlying database (SurrealDB) operation failed. The original DB error message is appended to the detail.

Source

Thrown at api/routers/search.py:59

            # Text search
            results = await text_search(
                keyword=search_request.query,
                results=search_request.limit,
                source=search_request.search_sources,
                note=search_request.search_notes,
            )

        return SearchResponse(
            results=results or [],
            total_count=len(results) if results else 0,
            search_type=search_request.type,
        )

    except InvalidInputError as e:
        raise HTTPException(status_code=400, detail=str(e))
    except DatabaseOperationError as e:
        logger.error(f"Database error during search: {str(e)}")
        raise HTTPException(status_code=500, detail=f"Search failed: {str(e)}")
    except HTTPException:
        raise
    except OpenNotebookError:
        raise
    except Exception as e:
        logger.error(f"Unexpected error during search: {str(e)}")
        raise HTTPException(status_code=500, detail=f"Search failed: {str(e)}")


async def stream_ask_response(
    question: str, strategy_model: Model, answer_model: Model, final_answer_model: Model
) -> AsyncGenerator[str, None]:
    """Stream the ask response as Server-Sent Events."""
    try:
        final_answer = None

        # LangGraph accepts a partial state dict at runtime, but its typed
        # overloads require the full state type (langgraph typing limitation).

View on GitHub (pinned to a7de90d38a)

Solutions

  1. Confirm SurrealDB is running (make database) and reachable on port 8000
  2. Restart the API so automatic schema migrations run
  3. Inspect the appended message and SurrealDB logs for the failing query
  4. Rebuild search indexes if the error mentions index corruption
Defensive patterns

Strategy: fallback

Validate before calling

const ok = await fetch('/health').then(r => r.ok); // or DB status endpoint
if (!ok) showMaintenanceMessage();

Try / catch

catch (e) {
  if (e.status === 500 && /Search failed/.test(e.detail)) fallbackToLocalSearch();
}

Prevention

When it happens

Trigger: POST /api/search while SurrealDB is unreachable, the search index/table is missing, or a query times out; DatabaseOperationError is raised by the data layer and re-wrapped here.

Common situations: SurrealDB container stopped, schema migrations not run, network partition between API and DB, corrupt full-text index.

Related errors


AI-assisted analysis of lfnovo/open-notebook@a7de90d38a (2026-08-27). Data as JSON: /api/errors/7601d9e72112f2d9. Report an issue: GitHub.