Skip to content

enhancement: normalize tags with junction table (schema v2) #184

Closed

Description

@ajianaz

Problem

Tags are stored as comma-separated TEXT column (tags TEXT). Searching by tag uses LIKE "%tag%" which is O(n) full scan and fragile (partial match: tag "rust" matches "rustic").

Current Schema (v1)

CREATE TABLE memories (
    ...
    tags TEXT,  -- comma-separated string
    ...
);
CREATE INDEX idx_memories_tags ON memories(tags);  -- index on text, not useful for individual tags

Proposed Schema (v2)

-- New junction table
CREATE TABLE memory_tags (
    memory_id TEXT NOT NULL REFERENCES memories(id) ON DELETE CASCADE,
    tag TEXT NOT NULL,
    PRIMARY KEY (memory_id, tag)
);
CREATE INDEX idx_memory_tags_tag ON memory_tags(tag);

Migration Plan (schema v1 → v2)

  1. Create memory_tags table
  2. Parse existing tags column → insert rows into memory_tags
  3. Add memory_tags methods to Store
  4. Update queries: list(tag=...), unique_tags(), tags_with_counts(), etc.
  5. Keep tags column for backward compat during migration
  6. Remove tags column in future version

Benefits

  • O(log n) tag lookups instead of O(n)
  • No partial match bugs
  • tags_with_counts() becomes a simple GROUP BY instead of parsing

Depends On

Target

  • v0.1.0 (schema v2 migration)

Activity

  1. added
    scope:core
    type:feature
    priority:low
    v0.1.0
    enhancement
    and removed
    type:feature
    on Jun 7, 2026
  2. added this to the milestone on Jun 11, 2026
  3. ajianaz commented on Jun 13, 2026

    @ajianaz
    CollaboratorAuthor

    Implemented in PR #314, merged to develop.

  4. added a commit that references this issue on Jun 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementpriority:lowscope:corev0.1.0

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions