Migration Plan: Path-Based to ID-Based API (v1 → v2)
Overview
Migrate the Basic Memory API from path-based entity identifiers to integer ID-based identifiers for improved performance, stability, and developer experience. This will be implemented as a new /v2 API namespace with immediate v1 deprecation.
Problem Statement
Current v1 API uses path-based identifiers (/{project}/knowledge/entities/{identifier:path}) which:
- Require cascading database lookups (permalink → title → file_path → search)
- Change when files are moved or renamed
- Are difficult to cache effectively
- Have performance overhead from string comparisons
Solution
Create a new /v2 API namespace that uses integer entity IDs as primary identifiers:
- Direct database lookups via indexed integer primary keys
- Stable references that don't change with file moves
- Better caching support
- Improved performance
Migration Strategy
Phase 1: Create /api/v2 + Deprecate V1 (3-4 weeks)
Build v2 API with ID-based endpoints:
Add v1 deprecation markers immediately:
Testing:
Deliverables:
- v2 API fully functional with ID-based operations
- v1 API marked deprecated with 6-month sunset date
- Migration documentation ready
- Metrics tracking v1/v2 usage
Phase 2: Update MCP Tools to Use V2 (3-4 weeks)
Migrate MCP tools to v2:
Update memory:// URL handling:
Documentation updates:
Testing:
Deliverables:
- All MCP tools using v2 API
- Tools accept both IDs and legacy identifiers
- Updated documentation and examples
Phase 3: Monitor Usage & Support Migration (6 months)
Monitoring:
User support:
Client library updates:
Success criteria:
- v2 adoption > 80% by month 3
- v2 adoption > 95% by month 5
- No critical v2 bugs
- Ready to remove v1 at 6 months
Deliverables:
- 95%+ v2 adoption rate
- Migration tooling and documentation proven effective
- User feedback incorporated
Phase 4: Remove V1 API (2-3 weeks)
Final preparations:
Code cleanup:
Version and release:
Testing:
Deliverables:
- Clean v2-only codebase
- Basic Memory 2.0.0 release
- Performance improvements realized
Key Benefits
- Performance: Direct integer lookups vs cascading string comparisons
- Stability: IDs don't change when files move
- Caching: Stable IDs enable effective caching strategies
- Developer Experience: Clear, predictable API patterns
- Database Optimization: Integer indexes more efficient than string indexes
API Comparison
| Feature |
V1 (Deprecated) |
V2 (New) |
| URL Pattern |
/{project}/knowledge/entities/{path:path} |
/v2/{project}/knowledge/entities/{id} |
| Identifier |
Path/Permalink/Title |
Integer ID |
| Lookup Speed |
Multiple queries (cascade) |
Single indexed query |
| Stability |
Changes with file moves |
Immutable |
| Memory URLs |
memory://path/to/note |
memory://123 |
| Caching |
Difficult |
Easy |
Timeline
- Phase 1: 3-4 weeks (v2 build + v1 deprecation)
- Phase 2: 3-4 weeks (MCP tool migration)
- Phase 3: 6 months (monitoring & support)
- Phase 4: 2-3 weeks (v1 removal)
Total: ~2-3 months development + 6 months deprecation period
Sunset Date
V1 API End of Life: 6 months after v2 release (tentatively June 30, 2025)
Migration Support
- Migration guide:
docs/migration/v1-to-v2.md
- CLI tool:
basic-memory migrate-to-v2
- Deprecation endpoint:
/management/deprecation-info
- Metrics endpoint:
/management/metrics/deprecation
References
- Database models:
src/basic_memory/models/knowledge.py
- Current v1 routers:
src/basic_memory/api/routers/
- LinkResolver:
src/basic_memory/services/link_resolver.py
This is a comprehensive migration that will significantly improve API performance and developer experience while maintaining backward compatibility during the transition period.
Migration Plan: Path-Based to ID-Based API (v1 → v2)
Overview
Migrate the Basic Memory API from path-based entity identifiers to integer ID-based identifiers for improved performance, stability, and developer experience. This will be implemented as a new
/v2API namespace with immediate v1 deprecation.Problem Statement
Current v1 API uses path-based identifiers (
/{project}/knowledge/entities/{identifier:path}) which:Solution
Create a new
/v2API namespace that uses integer entity IDs as primary identifiers:Migration Strategy
Phase 1: Create /api/v2 + Deprecate V1 (3-4 weeks)
Build v2 API with ID-based endpoints:
src/basic_memory/api/v2/POST /v2/{project}/knowledge/resolve/v2prefixAdd v1 deprecation markers immediately:
Deprecation: trueSunset: <6 months from release>Link: </v2>; rel="successor-version"/management/deprecation-info)docs/migration/v1-to-v2.md)Testing:
Deliverables:
Phase 2: Update MCP Tools to Use V2 (3-4 weeks)
Migrate MCP tools to v2:
async_client_v2.pywith/v2prefix supportread_note()to use v2 APIedit_note()to use v2 APIdelete_note()to use v2 APImove_note()to use v2 APIview_note()to use v2 APIbuild_context()to use v2 APIUpdate memory:// URL handling:
memory://id/123formatmemory://123shorthand formatnormalize_memory_url()for ID patternsDocumentation updates:
ai_assistant_guidewith v2 examplesTesting:
Deliverables:
Phase 3: Monitor Usage & Support Migration (6 months)
Monitoring:
User support:
basic-memory migrate-to-v2CLI commandClient library updates:
use_v1=Trueflag for backward compatibilitySuccess criteria:
Deliverables:
Phase 4: Remove V1 API (2-3 weeks)
Final preparations:
Code cleanup:
Version and release:
Testing:
Deliverables:
Key Benefits
API Comparison
/{project}/knowledge/entities/{path:path}/v2/{project}/knowledge/entities/{id}memory://path/to/notememory://123Timeline
Total: ~2-3 months development + 6 months deprecation period
Sunset Date
V1 API End of Life: 6 months after v2 release (tentatively June 30, 2025)
Migration Support
docs/migration/v1-to-v2.mdbasic-memory migrate-to-v2/management/deprecation-info/management/metrics/deprecationReferences
src/basic_memory/models/knowledge.pysrc/basic_memory/api/routers/src/basic_memory/services/link_resolver.pyThis is a comprehensive migration that will significantly improve API performance and developer experience while maintaining backward compatibility during the transition period.