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

fix: aligned SB with the new PG scheme (#1389) #1800

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from

Conversation

AIFlowML
Copy link
Collaborator

@AIFlowML AIFlowML commented Jan 4, 2025

PR: Rebuild Supabase Adapter with PostgreSQL Schema Alignment #1389

Overview

This PR rebuilds the Supabase adapter to align with the new PostgreSQL adapter schema, improving consistency across database adapters and enhancing functionality.

Key Changes

1. Schema Alignment

  • Synchronized Supabase schema with PostgreSQL adapter
  • Implemented consistent table structures and relationships
  • Added proper indexing and constraints for better performance

2. New SQL Files

  • Added comprehensive seed.sql for testing and development
    • Default test agent account
    • Test room setup
    • Initial participant configuration
  • Enhanced rpc_functions.sql with improved database functions
    • Vector similarity search optimization
    • Memory management functions
    • Goal tracking capabilities
    • Cached embedding retrieval

3. Documentation

  • Created detailed readme.md with:
    • Step-by-step setup instructions
    • Environment configuration guide
    • Troubleshooting section
    • Security best practices
    • Common issues and solutions

4. Code Quality

  • Fixed ESLint warnings and errors in src/index.ts
  • Improved type safety by removing any types
  • Enhanced error handling and logging
  • Added proper type definitions for database operations

Testing

  • ✅ All adapter tests passing
  • ✅ Memory management tests successful
  • ✅ Goal tracking functionality verified
  • ✅ Participant management tests passed
  • ✅ Room operations validated
  • ✅ ESLint compliance achieved

Technical Details

Database Functions

  • create_room: Room initialization
  • remove_memories: Memory cleanup
  • search_memories: Vector similarity search
  • get_embedding_list: Cached embedding retrieval
  • get_goals: Goal management
  • check_vector_extension: Vector extension validation

Schema Improvements

  • Proper foreign key constraints
  • Indexed vector columns
  • Optimized query performance
  • Consistent naming conventions

Migration Notes

  • No breaking changes to existing APIs
  • Backward compatible with current implementations
  • Improved error handling for better debugging

Security Considerations

  • Environment variable management
  • API key security
  • Database access controls
  • Data validation and sanitization

Next Steps

  • Deploy to staging environment
  • Monitor performance metrics
  • Gather user feedback
  • Plan for production rollout

Screenshot 2025-01-04 at 11 40 31

@hellopleasures
Copy link
Contributor

11
I followed all the steps but it's showing me this

@AIFlowML
Copy link
Collaborator Author

AIFlowML commented Jan 4, 2025 via email

@hellopleasures
Copy link
Contributor

You added all 3 sql right ? Seed Schema Rpc In supabsse ? And no logging of the error seem strange because we have error handling now.

On Sun, Jan 5, 2025 at 03:08, Patrick @.(mailto:On Sun, Jan 5, 2025 at 03:08, Patrick < wrote: 11.png (view on web) I followed all the steps but it's showing me this — Reply to this email directly, [view it on GitHub](#1800 (comment)), or unsubscribe. You are receiving this because you authored the thread.Message ID: @.>

yeah i added all the 3 sql, yes in supabase. im using 0.1.7.1-alpha.2 right now.

@hellopleasures
Copy link
Contributor

Thank you, I tried again but still no luck. Same error. Take your time!

@AIFlowML
Copy link
Collaborator Author

AIFlowML commented Jan 5, 2025

I added much more tests my side on the unit test and also handled an embedding issue.

Screenshot 2025-01-05 at 09 01 24

I added s custom cirquit breaker because the core one was failing
I added more error handling and retry
I run all 4 tests in the test folder (that i did not uplaod i can do it if you want) and al now passes.
Screenshot 2025-01-05 at 10 16 21

The main isseu was that like in the Pg we handle the embedding in a dinamic way now.
So for sure when my test runned they did run only on the OAI embedding now they try them all and no failure.
I will uploda the index again fro review. Sorry for tthe issue.

…plementation

- Add dynamic embedding dimension validation\n- Implement robust circuit breaker pattern for database operations\n- Add comprehensive error handling for memory operations\n- Improve validation checks for memory fields and UUID formats\n- Add retry mechanism with exponential backoff for database operations\n- Enhance logging for better error tracking and debugging
@hellopleasures
Copy link
Contributor

I added much more tests my side on the unit test and also handled an embedding issue.

Screenshot 2025-01-05 at 09 01 24

I added s custom cirquit breaker because the core one was failing I added more error handling and retry I run all 4 tests in the test folder (that i did not uplaod i can do it if you want) and al now passes. Screenshot 2025-01-05 at 10 16 21

The main isseu was that like in the Pg we handle the embedding in a dinamic way now. So for sure when my test runned they did run only on the OAI embedding now they try them all and no failure. I will uploda the index again fro review. Sorry for tthe issue.

gmgm, so i copied all the code and follow all the steps, this is the error logs that i got
image

…eddings implementation to properly use RPC functions - Updated memory creation error handling in tests - Improved type safety in agent initialization - Ensured consistent behavior across database operations
@AIFlowML
Copy link
Collaborator Author

AIFlowML commented Jan 6, 2025

I resolved the RPC problem in Supabase that was trying to write into a document table that was not existing.
I tested the adapter via vitest and also by adding into the agent index.ts.
I uploaded also the agent index and the packages.json that is need have the adapter in the workspace.
Now it not make any error in the loading anyway in the adapter the logging is very granular so in case of errors we will have a way to see what is actually going wrong.

Screenshot 2025-01-06 at 21 41 42
Screenshot 2025-01-06 at 21 41 16
Screenshot 2025-01-06 at 21 40 50

…again and the table management in the index.ts
@AIFlowML
Copy link
Collaborator Author

AIFlowML commented Jan 6, 2025

I did a coordinate test with the user that is collaborating and sue supabase also with various clients.
The previous errors are fixed by the new sql fix (already incorporated also in the rpc_functions.sql
All seem to work fine also from the logs that are way more granualat that before.
Added more tests too that we can operate in the code. I will pass a separate PR for the teste files that we should keep in the folder just in case there are more issues later.

Screenshot 2025-01-07 at 04 25 54

@hellopleasures
Copy link
Contributor

Awesome, happy collaborating with you!

@shakkernerd shakkernerd changed the title fix: alighed SB with the new PG scheme (#1389) fix: aligned SB with the new PG scheme (#1389) Jan 7, 2025
@AIFlowML
Copy link
Collaborator Author

AIFlowML commented Jan 9, 2025

@hellopleasures Is it all good now ?
Can we merge this ?

@hellopleasures
Copy link
Contributor

@hellopleasures Is it all good now ? Can we merge this ?

@AIFlowML yes, we can merge this. all clear and ready to merge. sorry for late response. i have fever this past few days.

@AIFlowML
Copy link
Collaborator Author

AIFlowML commented Jan 9, 2025

@odilitime @shakkernerd @azep-ninja

During conflict resolution with develop, I've identified an important consideration:

PR #1620 (merged last week) introduced the RAGKnowledgeItem feature for knowledge system separation and multi-agent RAG optimization. My PR (#1800) contains a complete rework of the Supabase adapter to align with the new PostgreSQL schema.

Current situation:

  1. My changes fix the original Supabase adapter issues and align with the new PG schema
  2. PR feat: Separate Knowledge system + Multi-Agent RAG Optimization #1620 added RAGKnowledgeItem functionality which isn't present in my implementation
  3. Both changes are important: mine fixes core functionality, feat: Separate Knowledge system + Multi-Agent RAG Optimization #1620 adds new features

I need guidance on how to proceed:

  1. Should I integrate RAGKnowledgeItem into my reworked adapter implementation?
  2. Would you prefer to handle this merge on your side?
  3. Should we schedule a pair programming session to properly combine both changes?

I've paused the merge process until we decide the best approach to preserve both the new schema alignment and the RAGKnowledgeItem functionality.

This is only related to the file packages/adapter-supabase/src/index.ts
that in my versio competely miminc the behavious of the Postgres including al the procedures.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A LOT of plugins are removed, going to need some extra time/effort to merge this one

@AIFlowML AIFlowML closed this Jan 12, 2025
@AIFlowML AIFlowML reopened this Jan 15, 2025
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