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 Updates #3221

Closed
wants to merge 0 commits into from
Closed

Supabase Adapter Updates #3221

wants to merge 0 commits into from

Conversation

rferrari
Copy link
Contributor

@rferrari rferrari commented Feb 4, 2025

Relates to

#1389
#3160

Risks

Low – This PR primarily updates the schema and seed files with minimal code changes.

Background

This PR addresses issues with the Supabase adapter by updating the schema and seed files. The previous implementation did not correctly create rooms and memories, leading to inconsistencies in data persistence.

What does this PR do?

  • Changes Introduced
  • Updated the Supabase adapter to correctly handle create_room and create_memory operations.
  • Fixed issues in the schema.sql and seed.sql files.
  • Minimal code changes to improve functionality without introducing breaking changes.

What kind of change is this?

Bug fixes (non-breaking change which fixes an issue)

The Supabase adapter was not correctly creating rooms and memories due to outdated or incorrect schema definitions. This update ensures the expected behavior when interacting with the database.

Documentation changes needed?

My changes do not require a change to the project documentation.

Testing

-Add the following environment variables to your .env file:

SUPABASE_URL=your_supabase_url
SUPABASE_ANON_KEY=your_supabase_anon_key

-Start Eliza.
-Verify that rooms and memories are correctly created in the Supabase dashboard.

Where should a reviewer start?

packages/adapter-supabase/src/index.ts (Line 402)
packages/adapter-supabase/schema.sql
packages/adapter-supabase/seed.sql

Detailed testing steps

  1. Start Eliza with the updated Supabase adapter.
  2. Trigger room and memory creation events.
  3. Check the Supabase dashboard to confirm the expected records are created.
  4. Review logs for errors or unexpected behavior.

Before

  • ERROR: Error adding participant: operator does not exist: timestamp with time zone / numeric
  • ERROR: "code":"PGRST202","details":"Searched for the function public.get_embedding_list with parameters query_field_name, query_field_sub_name, query_input, query_match_count, query_table_name, query_threshold or with a single unnamed json/jsonb parameter, but no matches were found in the schema cache.
  • ERROR: Error creating room: Could not find the function public.create_room(roomId) in the schema cache at SupabaseDatabaseAdapter.createRoom
  • 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

Screenshots

image image
image image

Copy link
Contributor

coderabbitai bot commented Feb 4, 2025

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@retwn
Copy link

retwn commented Feb 5, 2025

got this error:

throw new Error(`Error retrieving memories: ${error.message}`);
                  ^

Error: Error retrieving memories: relation "public.messages" does not exist
    at SupabaseDatabaseAdapter.getMemories

@rferrari
Copy link
Contributor Author

rferrari commented Feb 5, 2025

I'm still debugging that... You can try for now

I think this tableName is query parameters not table name. Messages is a collum not table...

try updating the getMemories with this:

async getMemories(params: {
roomId: UUID;
count?: number;
unique?: boolean;
tableName: string;
agentId?: UUID;
start?: number;
end?: number;
}): Promise<Memory[]> {
const query = this.supabase
// .from(params.tableName) error here trying to get messages table. IDK why
.from("memories")
.select("*")
.eq("roomId", params.roomId);

...

And also update next :

async getMemoriesByRoomIds(params: {
roomIds: UUID[];
agentId?: UUID;
tableName: string;
limit?: number;
}): Promise<Memory[]> {
let query = this.supabase
.from("memories") //params.tableName)
.select("*")
.in("roomId", params.roomIds)
.order("createdAt", { ascending: false });

@brianpricesmith
Copy link

The public.messages thing is also an issue for me. It seems it's coming from the runtime ctor
this.messageManager = new MemoryManager({ runtime: this, tableName: "messages", });

Anyway after making the above change I also run in to some issues with the rpc's. Specifically Error: Could not find the function public.get_goals(only_in_progress, query_roomId, row_count) in the schema cache.

The schema.sql doesn't set up any rpc's, should these exist somewhere?

@brianpricesmith
Copy link

brianpricesmith commented Feb 14, 2025

You can disregard my comment above about the rpc's. I found the latest version of the schema. What's weird is even with the convert_timestamp triggers set up correctly I am still getting the error from the adapter.

[2025-02-14 06:53:16] ERROR: Error retrieving memory by ID:
code: "PGRST116"
details: "The result contains 0 rows"
hint: null
message: "JSON object requested, multiple (or no) rows returned"
file:///C:/Users/brian/crypto/src/repos/eliza/node_modules/@elizaos/adapter-supabase/dist/index.js:250
throw new Error(JSON.stringify(error));
Error: {"code":"22008","details":null,"hint":"Perhaps you need a different "datestyle" setting.","message":"date/time field value out of range: "1739515996318""}
at SupabaseDatabaseAdapter.createMemory

@rferrari
Copy link
Contributor Author

@brianpricesmith use new PR in plugins repo.

If issues let me know.

@brianpricesmith
Copy link

Works great with the latest. That code isn't published in npm yet, so I copied the dist/index. I'll watch for the next publish. Thanks, cheers. LMK if you want help contributing to this repo.

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.

3 participants