Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supabase Adapter - Create Memory. supabase setup #3160

Open
rferrari opened this issue Feb 2, 2025 · 0 comments
Open

Supabase Adapter - Create Memory. supabase setup #3160

rferrari opened this issue Feb 2, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@rferrari
Copy link
Contributor

rferrari commented Feb 2, 2025

Describe the bug

ERROR:
err: {
"type": "Error",
"message": "{"code":"22008","details":null,"hint":"Perhaps you need a different \"datestyle\" setting.","message":"date/time field value out of range: \"1738506666089\""}",
"stack":
Error: {"code":"22008","details":null,"hint":"Perhaps you need a different "datestyle" setting.","message":"date/time field value out of range: "1738506666089""}
at SupabaseDatabaseAdapter.createMemory

To Reproduce

  1. execute "packages/adapter-supabase/schema.sql" into supabase sql editor

  2. fix packages/adapter-supabase/seed.sql editing userId to UUID instead of String
    INSERT INTO public.participants (id, "createdAt", "userId", "roomId", "userState", last_message_read) VALUES ('00000000-0000-0000-0000-000000000000', NOW(), '00000000-0000-0000-0000-000000000000', '00000000-0000-0000-0000-000000000000', NULL, NULL);

  3. Execute "packages/adapter-supabase/seed.sql" into supabase sql editor

  4. Create functions


CREATE OR REPLACE FUNCTION public.create_room("roomId" UUID DEFAULT NULL)
RETURNS UUID
LANGUAGE plpgsql
AS $function$
DECLARE
    new_room_id UUID;
BEGIN
    IF "roomId" IS NULL THEN
        new_room_id := gen_random_uuid();  -- Generate a new UUID if roomId is not provided
    ELSE
        new_room_id := "roomId";  -- Use the provided roomId
    END IF;

    INSERT INTO rooms (id) VALUES (new_room_id);  -- Insert the new room into the rooms table
    RETURN new_room_id;  -- Return the new room ID
END;
$function$;

CREATE OR REPLACE FUNCTION insert_into_memories()
RETURNS TRIGGER AS $$
BEGIN
    -- Check the size of the embedding vector
    IF array_length(NEW.embedding, 1) = 1536 THEN
        INSERT INTO memories_1536 ("id", "type", "createdAt", "content", "embedding", "userId", "agentId", "roomId", "unique")
        VALUES (NEW."id", NEW."type", NEW."createdAt", NEW."content", NEW."embedding", NEW."userId", NEW."agentId", NEW."roomId", NEW."unique");
    ELSIF array_length(NEW.embedding, 1) = 1024 THEN
        INSERT INTO memories_1024 ("id", "type", "createdAt", "content", "embedding", "userId", "agentId", "roomId", "unique")
        VALUES (NEW."id", NEW."type", NEW."createdAt", NEW."content", NEW."embedding", NEW."userId", NEW."agentId", NEW."roomId", NEW."unique");
    ELSIF array_length(NEW.embedding, 1) = 768 THEN
        INSERT INTO memories_768 ("id", "type", "createdAt", "content", "embedding", "userId", "agentId", "roomId", "unique")
        VALUES (NEW."id", NEW."type", NEW."createdAt", NEW."content", NEW."embedding", NEW."userId", NEW."agentId", NEW."roomId", NEW."unique");
    ELSIF array_length(NEW.embedding, 1) = 384 THEN
        INSERT INTO memories_384 ("id", "type", "createdAt", "content", "embedding", "userId", "agentId", "roomId", "unique")
        VALUES (NEW."id", NEW."type", NEW."createdAt", NEW."content", NEW."embedding", NEW."userId", NEW."agentId", NEW."roomId", NEW."unique");
    ELSE
        RAISE EXCEPTION 'Invalid embedding size: %', array_length(NEW.embedding, 1);
    END IF;

    RETURN NEW;  -- Return the new row
END;
$$ LANGUAGE plpgsql;

CREATE TRIGGER memories_insert_trigger
INSTEAD OF INSERT ON memories
FOR EACH ROW
EXECUTE FUNCTION insert_into_memories();


  1. Execute agent with supabase SUPABASE_URL && SUPABASE_ANON_KEY

Additional context

@rferrari rferrari added the bug Something isn't working label Feb 2, 2025
@rferrari rferrari changed the title Supabase Create Memory Supabase Adapter - Create Memory. supabase setup Feb 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant