brianpetro / obsidian-smart-connections

Chat with your notes & see links to related content with AI embeddings. Use local models or 100+ via APIs like Claude, Gemini, ChatGPT & Llama 3
https://smartconnections.app
GNU General Public License v3.0
2.65k stars 178 forks source link

Another 400 error #10

Closed Fusion closed 1 year ago

Fusion commented 1 year ago

Hi,

what I am seeing is 24 x "skipping block (mtime)"

followed by:

plugin:smart-connections:508 Error: Request failed, status 400
    at new t (app.js:1:710073)
    at Aw (app.js:1:710265)
    at app.js:1:710942
    at app.js:1:235505
    at Object.next (app.js:1:235610)
    at a (app.js:1:234349)
plugin:smart-connections:466 Uncaught (in promise) TypeError: Cannot read properties of null (reading 'usage')
    at SmartConnectionsPlugin.get_embeddings (plugin:smart-connections:466:51)
    at async Promise.all (index 0)
    at async SmartConnectionsPlugin.get_file_embeddings (plugin:smart-connections:454:5)
    at async Promise.all (index 0)
    at async SmartConnectionsPlugin.get_all_embeddings (plugin:smart-connections:201:9)
    at async SmartConnectionsPlugin.find_note_connections (plugin:smart-connections:628:7)
    at async SmartConnectionsPlugin.render_note_connections (plugin:smart-connections:564:21)
get_embeddings @ plugin:smart-connections:466
await in get_embeddings (async)
eval @ plugin:smart-connections:116
e.tryTrigger @ app.js:1
e.trigger @ app.js:1
t.trigger @ app.js:1
t.activeLeafEvents @ app.js:1
s @ app.js:1
l @ app.js:1

Adding a breakpoint in the catch block, this is the response:

{
    "error": {
        "status": 400,
        "headers": {
            "date": "Sun, 08 Jan 2023 05:53:01 GMT",
            "content-type": "application/json",
            "content-length": "294",
            "access-control-allow-origin": "*",
            "openai-organization": "user-<redacted>",
            "openai-processing-ms": "117",
            "openai-version": "2020-10-01",
            "strict-transport-security": "max-age=15724800; includeSubDomains",
            "x-request-id": "<redacted>"
        }
    }
}

Request:

{
    "usedParams": {
        "model": "text-embedding-ada-002",
        "input": "<some enormous escaped page content here>"
    },
    "reqParams": {
        "url": "https://api.openai.com/v1/embeddings",
        "method": "POST",
        "body": "{\"model\":\"text-embedding-ada-002\",\"input\":\"<same enormous page content as above>\"}",
        "headers": {
            "Content-Type": "application/json",
            "Authorization": "Bearer sk-<redacted>"
        }
    }
}
brianpetro commented 1 year ago

Hi @Fusion

Thanks for the detailed report.

The skipping block (mtime) was a remnant of development. It's just saying that it's skipping getting embeddings because the file modified time hasn't changed. I removed this logging in the most recent patch.

The next issue is being worked on here https://github.com/brianpetro/obsidian-smart-connections/issues/12

It's partially fixed, and the null issue is handled, but we're still figuring out what is causing OpenAI to respond with a 400 error in the first place. The more recent patch version also adds information to the log about the 400 error, but I'm not sure that will give us anything else.

I'm glad you added the details about the request. Particularly the <some enormous escaped page content here> part. It's making me think that a string that exceeds the token limit is making it to the request, which would cause the 400 error. To address this, I just decreased the maximum length string that will be passed into the request from 30K characters to 25K characters. In the future, this can be improved by better calculating the exact number of tokens, but reducing the current character limit should be a good indicator of whether the length is the issue or something else like character encoding.

Let me know if you continue having issues after the latest patch (1.0.30).

Thanks again for the report, Brian

Fusion commented 1 year ago

Unfortunately, even after performing a force reload, I am still seeing the issue.

Please note that, below, the "enormous" content, encoded, is 33716 characters long.

Error:

undefined
plugin:smart-connections:595 Error: Request failed, status 400
    at new t (app.js:1:710073)
    at Aw (app.js:1:710265)
    at app.js:1:710942
    at app.js:1:235505
    at Object.next (app.js:1:235610)
    at a (app.js:1:234349)
plugin:smart-connections:510 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'save_embeddings_to_file')
    at process_batch (plugin:smart-connections:510:20)
    at async SmartConnectionsPlugin.get_file_embeddings (plugin:smart-connections:400:11)
    at async Promise.all (index 1)
    at async SmartConnectionsPlugin.get_all_embeddings (plugin:smart-connections:189:9)
    at async SmartConnectionsPlugin.find_note_connections (plugin:smart-connections:656:7)
    at async SmartConnectionsView.render_note_connections (plugin:smart-connections:1020:21)
process_batch @ plugin:smart-connections:510
await in process_batch (async)
eval @ plugin:smart-connections:958
e.tryTrigger @ app.js:1
e.trigger @ app.js:1
t.trigger @ app.js:1
t.activeLeafEvents @ app.js:1
s @ app.js:1
l @ app.js:1

Response:

{
    "status": 400,
    "headers": {
        "date": "Thu, 12 Jan 2023 05:11:06 GMT",
        "content-type": "application/json",
        "content-length": "294",
        "access-control-allow-origin": "*",
        "openai-organization": "user-<redacted>",
        "openai-processing-ms": "138",
        "openai-version": "2020-10-01",
        "strict-transport-security": "max-age=15724800; includeSubDomains",
        "x-request-id": "<redacted>"
    }
}

Request:

{
    "usedParams": {
        "model": "text-embedding-ada-002",
        "input": "<some enormous escaped page content here>"
    },
    "reqParams": {
        "url": "https://api.openai.com/v1/embeddings",
        "method": "POST",
        "body": "{\"model\":\"text-embedding-ada-002\",\"input\":\"<some enormous escaped page content here>\"}",
        "headers": {
            "Content-Type": "application/json",
            "Authorization": "Bearer <redacted>"
        }
    }
}
brianpetro commented 1 year ago

@Fusion Thanks for the update!

That size, 33716 characters long, is undoubtedly problematic.

I recently put in some limits that should have prevented that long of an input. I also tested on a 90K character length note and couldn't reproduce this.

Can you confirm which version you're using?

Fusion commented 1 year ago

I tried with version 1.0.38.

Now at work, I tried on my other MacBook (sync’d up) and after updating to 1.0.41, I got this error instead:

embeddings_file()
plugin:smart-connections:1082 failed to load embeddings file, prompting user to bulk embed
plugin:smart-connections:1084 Uncaught (in promise) Error: Error: Prompting user to create a new embeddings file or retry.
at SmartConnectionsView.load_embeddings_file (plugin:smart-connections:1084:15)
at async SmartConnectionsView.load_embeddings_file (plugin:smart-connections:1080:9)
at async SmartConnectionsView.load_embeddings_file (plugin:smart-connections:1080:9)
at async SmartConnectionsView.load_embeddings_file (plugin:smart-connections:1080:9)
at async SmartConnectionsView.render_note_connections (plugin:smart-connections:1014:7)

--

On Thursday, Jan 12, 2023 at 8:04 AM, Brian Petro @. @.)> wrote:

@Fusion (https://github.com/Fusion) Thanks for the update!

That size, 33716 characters long, is undoubtedly problematic.

I recently put in some limits that should have prevented that long of an input. I also tested on a 90K character length note and couldn't reproduce this.

Can you confirm which version you're using?

— Reply to this email directly, view it on GitHub (https://github.com/brianpetro/obsidian-smart-connections/issues/10#issuecomment-1380620616), or unsubscribe (https://github.com/notifications/unsubscribe-auth/AAAHAG3PRIJS52ODEAY4ITTWSATP7ANCNFSM6AAAAAATUMLAEU). You are receiving this because you were mentioned.Message ID: @.***>

brianpetro commented 1 year ago

That is the error that's intentionally thrown when the embeddings.json file is missing. It's intentional to halt processes that might otherwise overwrite data.

When that happens, you should see a button to "Create embeddings.json" in the right-hand sidebar. There is also a retry button in cases where the embeddings.json file should already exist.

Fusion commented 1 year ago

Yes I was thinking along these lines. I don’t think that Obisidian sync synced’s up the json file by default (I think it’s an additional setting)

I got the error message but not the dialog. Could be nothing, sorry for the added noise.

--

On Thursday, Jan 12, 2023 at 9:41 AM, Brian Petro @. @.)> wrote:

That is the error that's intentionally thrown when the embeddings.json file is missing. It's intentional to halt processes that might otherwise overwrite data.

When that happens, you should see a button to "Create embeddings.json" in the right-hand sidebar. There is also a retry button in cases where the embeddings.json file should already exist.

— Reply to this email directly, view it on GitHub (https://github.com/brianpetro/obsidian-smart-connections/issues/10#issuecomment-1380773167), or unsubscribe (https://github.com/notifications/unsubscribe-auth/AAAHAGYJ4AKQJUW7EHT3LODWSA625ANCNFSM6AAAAAATUMLAEU). You are receiving this because you were mentioned.Message ID: @.***>

brianpetro commented 1 year ago

Not a problem at all. It helps me solve this for others who might otherwise move on without reporting the issue.

If the view with the dialog options isn't visible, you can try the Open: View Smart Connections command or disable and re-enable the plug-in. It will take ~10 seconds after doing either of those before the prompt appears.

Thanks for your help!

brianpetro commented 1 year ago

@Fusion were you able to make it work?

Fusion commented 1 year ago

Not sure what happened there (now v1.0.45):

image

Note the number of retries before I managed to unload the plugin.

brianpetro commented 1 year ago

@Fusion with that many 429 retries, I think it's worth double checking your API key is working, as we discovered in this issue https://github.com/brianpetro/obsidian-smart-connections/issues/13#issuecomment-1382631794

brianpetro commented 1 year ago

@Fusion latest version backs off the API exponentially to prevent further 429s and implements skipping of previously failed files. These files can be manually retried from the settings but should allow the plugin to work with partial vault embeddings.

vguillet commented 1 year ago

I am getting a 429 error

Error: Request failed, status 429 at new t (app.js:1:710073) at Aw (app.js:1:710265) at app.js:1:710942 at app.js:1:235505 at Object.next (app.js:1:235610) at a (app.js:1:234349)

Can't seem to find a way around it

EDIT: Solved by upgrading to pay-as-you-go account, might be worth specifying in the doc for future users!

brianpetro commented 1 year ago

@vguillet check out https://github.com/brianpetro/obsidian-smart-connections/issues/24#issuecomment-1397751726 and let me know if you think it's the issue (free plan rate limits). If so, I have an update in the works that should alleviate some/all of the problem.