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

Replace Integer IDs with UUIDs for Enhanced Scalability and Security #9

Open
dreaminglucid opened this issue Aug 25, 2023 · 0 comments

Comments

@dreaminglucid
Copy link

The current implementation uses auto-incrementing integers as primary keys for the tables. This approach might lead to several challenges, especially in distributed systems.

Proposed Changes:

  • Replace integer IDs with UUIDs in the schema.
  • Update the insertion logic to generate UUIDs if not provided.

Benefits:

  • Global Uniqueness: Ensures that IDs are unique across different parts of the system, whether within a single application or across distributed systems.
  • Scalability: UUIDs facilitate handling large-scale systems, from mobile apps to distributed databases, without requiring centralized coordination.
  • Security: Non-sequential UUIDs enhance security by preventing enumeration attacks.
  • Flexibility in Migrations: UUIDs remain consistent across different databases and platforms, aiding in data migration and synchronization.

Example Modification:

# Table creation
def ensure_table_exists(self, category):
    table_name = self._table_name(category)
    self.cur.execute(
        f"""
        CREATE TABLE IF NOT EXISTS {table_name} (
            id UUID PRIMARY KEY DEFAULT uuid-ossp.uuid_generate_v4(),
            document TEXT NOT NULL,
            embedding VECTOR(384)
        )
    """
    )
    self.connection.commit()

# Insertion
def insert_memory(self, category, document, metadata={}, embedding=None, id=None):
    #...
    if id is None:
        id = uuid.uuid4()
    #...

Dependencies:

  • Include the uuid library in the code.
  • Ensure the PostgreSQL server has the uuid-ossp extension enabled.

Please review and let me know your thoughts on implementing this enhancement.

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

No branches or pull requests

1 participant