mckaywrigley / chatbot-ui

Come join the best place on the internet to learn AI skills. Use code "chatbotui" for an extra 20% off.
https://JoinTakeoff.com
MIT License
28.76k stars 8.01k forks source link

Unable to read upload file for supabase docker self-hosted #1661

Closed NoTitle90 closed 7 months ago

NoTitle90 commented 7 months ago

Bug Description

Supabse is installed via self-hosted docker. File uploaded successfully, but Chatbot-ui is unable to read it while chatting. Press F12 to open developer tools for browser, we can see a request, status=500,file=retrieve,response={message:"An unexpected error occurred"}. It shows nothing helpful for us. So let's make the response more friendly. Open file app/api/retrieval/retrieve/route.ts, and edit Line 96 like below:

//    const errorMessage = error.error?.message || "An unexpected error occurred"
    const errorMessage = JSON.stringify(error || {message:"An unexpected error occurred"})
    const errorCode = error.status || 500
//     return new Response(JSON.stringify({ message: errorMessage }), {
    return new Response(errorMessage , {
      status: errorCode
    })

Restart the app, upload file, and chat. This time we get a response like below:

{
"code":"42883",
"details":null,
"hint":"No operator matches the given name and argument types. You might need to add explicit type casts.",
"message":"operator does not exist: extensions.vector <=> extensions.vector"
}

Go to supabase admin, Database --> Extensions, ensure extension vector is enabled. image

If extension vector is enabled, it seems that postgrest cannot search for it.

Solution

Go to the supabase docker compose file, find Rest section:

  rest:
    container_name: supabase-rest
    image: postgrest/postgrest:v12.0.1
    depends_on:
      db:
        # Disable this if you are using an external Postgres database
        condition: service_healthy
      analytics:
        condition: service_healthy
    restart: unless-stopped
    environment:
      PGRST_DB_URI: postgres://authenticator:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}
      PGRST_DB_SCHEMAS: ${PGRST_DB_SCHEMAS}
# Add below line to set the env variable PGRST_DB_EXTRA_SEARCH_PATH
      PGRST_DB_EXTRA_SEARCH_PATH: ${PGRST_DB_EXTRA_SEARCH_PATH}
      PGRST_DB_ANON_ROLE: anon
      PGRST_JWT_SECRET: ${JWT_SECRET}
      PGRST_DB_USE_LEGACY_GUCS: "false"
      PGRST_APP_SETTINGS_JWT_SECRET: ${JWT_SECRET}
      PGRST_APP_SETTINGS_JWT_EXP: ${JWT_EXPIRY}
    command: "postgrest"

Go to supabase .env file, find API section:

############
# API - Configuration for PostgREST.
############

PGRST_DB_SCHEMAS=public,storage,graphql_public
# Add below line to set extra search path within "public" and "extensions".
PGRST_DB_EXTRA_SEARCH_PATH=public,extensions

Restart supabase:

docker compose stop && docker compose up -d

Try to chat with file again, and finally find the issue is solved.

tanvlt commented 6 months ago

Thanks @NoTitle90 it helps on my issue

em-le-ts commented 5 months ago

Thank @NoTitle90. It work with me