Repository navigation
Closed
Labels
scope:coreCore engine work
Milestone
Description
Problem
Tags are stored as JSON strings (["tag1","tag2"]) in a SQLite TEXT column and queried with LIKE '%"tagname"%'. This is:
- Fragile β tag names containing quotes (
") break matching - O(n) full-scan β no index utilization despite JSON data
- Incorrect β searching for literal
%or_wildcards returns everything - Untenable β N+1 query pattern in
tags_with_counts()(one SQL query per unique tag)
Affected Code
crates/uteke-core/src/memory/store.rs:192-205β tag storage/insertcrates/uteke-core/src/memory/store.rs:493-504β tag search via LIKEcrates/uteke-core/src/memory/store.rs:516-527β tag filteringcrates/uteke-core/src/memory/store.rs:556-591β tag renamecrates/uteke-core/src/memory/store.rs:476-490β N+1count_tag()calls
Proposed Solution
Option A: Junction table (recommended)
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);Option B: SQLite JSON1 extension β Use json_each() for proper JSON querying. Simpler but slightly slower than junction table.
Option A recommended because:
- Proper foreign key constraints + CASCADE delete
- Direct index on tag column
- Standard SQL patterns
- Better query planner visibility
Migration Strategy
- Create
memory_tagstable - Migrate existing JSON tags β rows (handle corrupted JSON gracefully)
- Add
versioncolumn to track schema version (currently ad-hoc, no version tracking) - Update all tag operations to use junction table
- Drop old
tagsTEXT column (or keep as cached view for backward compat)
Acceptance Criteria
- Tag storage uses junction table or
json_each() - All tag operations (add, remove, rename, delete, filter, count) work correctly
-
tags_with_counts()uses singleGROUP BYquery - Migration runs cleanly on existing databases (zero data loss)
- Tags containing quotes,
%,_characters work correctly - All existing tests pass + new tests for edge cases
- No performance regression (benchmark with 1000+ memories, 50+ tags)
Breaking Change
Metadata
Metadata
Assignees
Labels
scope:coreCore engine work
Activity
feat: v0.0.7 β core stability (#157)
release: initial sync β main catches up to develop (#171)
feat: v0.0.7 β core stability (#157)