Skip to content

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

@dreaminglucid

Description

@dreaminglucid

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions