Skip to content

fix: surface storage failures in /local/embed and /embed-upload - #306

Open
nangelovv wants to merge 1 commit into
LibreChat-AI:mainfrom
nangelovv:fix/embed-surface-storage-failures
Open

nangelovv wants to merge 1 commit into
LibreChat-AI:mainfrom
nangelovv:fix/embed-surface-storage-failures

Conversation

@nangelovv

Copy link
Copy Markdown

What

Make POST /local/embed and POST /embed-upload surface a storage failure (HTTP 500) instead of reporting success.

Why

Fixes #305. store_data_in_vector_db always returns a dict (with an "error" key on failure), but embed_local_file used if result: and embed_file_upload used if not result: — a failure dict is truthy / not-falsy, so both reported status:True / 200 while nothing was persisted.

Change

Both endpoints now treat not result or "error" in result as a failure and raise HTTP 500 with the error detail:

if not result or "error" in result:
    error_detail = (
        result["error"]
        if isinstance(result, dict) and isinstance(result.get("error"), str)
        else <endpoint default>
    )
    raise HTTPException(status_code=500, detail=error_detail)

POST /embed already performs this check and is unchanged. The success path is unchanged.

Testing

  • New tests/test_main.py: test_embed_local_file_storage_error_returns_500 and test_embed_file_upload_storage_error_returns_500 (store returns an {"error": ...} dict → endpoint returns 500).
  • Existing success-path embed tests still pass. tests/test_main.py: 12 passed.

store_data_in_vector_db always returns a dict, with an "error" key on failure.
embed_local_file used `if result:` and embed_file_upload used `if not result:`,
which are always truthy / never-falsy for a dict — so both returned
status:True / HTTP 200 even when embedding or insertion failed and nothing was
persisted. The client marks the file as indexed while later queries return
nothing: silent data loss.

Inspect the result for an "error" key (or a falsy value) in both endpoints and
raise HTTP 500 with the error detail. /embed already performs this check and is
left unchanged. The success path is unchanged.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

/embed and /embed-upload report success when storage fails (silent data loss)

1 participant