๐ง Core Concepts¶
Understanding the fundamental concepts behind SpecMem.
SpecIR (Specification Intermediate Representation)¶
SpecIR is the canonical, normalized format that SpecMem uses internally. All specifications from different frameworks are converted to SpecIR.
@dataclass
class SpecBlock:
"""A single specification block."""
id: str # Unique identifier
path: str # Source file path
framework: str # Source framework (kiro, cursor, etc.)
spec_type: SpecType # requirement, design, task, constraint
title: str # Human-readable title
content: str # Full content
summary: str # Brief summary
tags: list[str] # Categorization tags
lifecycle: Lifecycle # active, deprecated, legacy, obsolete
priority: Priority # critical, high, medium, low
created_at: datetime # Creation timestamp
updated_at: datetime # Last update timestamp
metadata: dict # Additional metadata
Spec Types¶
| Type | Description | Example |
|---|---|---|
requirement |
What the system should do | User stories, acceptance criteria |
design |
How the system works | Architecture, data models |
task |
Implementation steps | Coding tasks, TODOs |
constraint |
Limitations and rules | Performance requirements, security rules |
Memory Types¶
SpecMem uses different memory types for different purposes:
๐ Vector Memory¶
Semantic search using embeddings. Best for:
- Natural language queries
- Finding related specs
- Similarity-based retrieval
๐ Pinned Memory¶
Guaranteed recall for critical information. Best for:
- Security constraints
- Compliance requirements
- Critical business rules
# Pin a spec for guaranteed recall
sm.pin_spec("security-requirements")
# Pinned specs always appear in context
bundle = sm.get_context_for_change(files)
# bundle.pinned contains all pinned specs
๐ Graph Memory¶
Relationship-based retrieval. Best for:
- Impact analysis
- Dependency tracking
- Test selection
Lifecycle Management¶
Specs progress through lifecycle stages:
stateDiagram-v2
[*] --> Active
Active --> Deprecated: Mark deprecated
Deprecated --> Legacy: Time passes
Legacy --> Obsolete: No longer relevant
Obsolete --> [*]: Archive/Delete
| Stage | Description | Behavior |
|---|---|---|
active |
Current, in-use spec | Full weight in queries |
deprecated |
Being phased out | Reduced weight, warnings |
legacy |
Old but still referenced | Low weight, info only |
obsolete |
No longer relevant | Excluded from queries |
Priority Levels¶
Specs have priority levels affecting their ranking:
| Priority | Weight | Use Case |
|---|---|---|
critical |
1.0 | Security, compliance, core features |
high |
0.8 | Important features, key requirements |
medium |
0.5 | Standard features, nice-to-haves |
low |
0.3 | Minor features, future considerations |
Architecture Overview¶
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ SpecMem Core โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โ
โ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โ
โ โ Adapters โ โ Adapters โ โ Adapters โ โ
โ โ (Kiro) โ โ (Cursor) โ โ (Claude) โ ... โ
โ โโโโโโโโฌโโโโโโโ โโโโโโโโฌโโโโโโโ โโโโโโโโฌโโโโโโโ โ
โ โ โ โ โ
โ โโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโ โ
โ โ โ
โ โโโโโโโโผโโโโโโโ โ
โ โ SpecIR โ โ Canonical Format โ
โ โโโโโโโโฌโโโโโโโ โ
โ โ โ
โ โโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโ โ
โ โ โ โ โ
โ โโโโโโโโผโโโโโโโ โโโโโโโโผโโโโโโโ โโโโโโโโผโโโโโโโ โ
โ โ Memory Bank โ โ Impact โ โ SpecDiff โ โ
โ โ (Vector DB) โ โ Graph โ โ Timeline โ โ
โ โโโโโโโโฌโโโโโโโ โโโโโโโโฌโโโโโโโ โโโโโโโโฌโโโโโโโ โ
โ โ โ โ โ
โ โโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโ โ
โ โ โ
โ โโโโโโโโผโโโโโโโ โ
โ โ Client โ โ Unified API โ
โ โโโโโโโโฌโโโโโโโ โ
โ โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโผโโโโโโโโโโโโโ
โ โ โ
โโโโโโโโผโโโโโโโ โโโโโผโโโโ โโโโโโโโผโโโโโโโ
โ CLI โ โ API โ โ Web UI โ
โโโโโโโโโโโโโโโ โโโโโโโโโ โโโโโโโโโโโโโโโ
Context Bundles¶
When you request context, SpecMem returns a ContextBundle:
@dataclass
class ContextBundle:
"""Context package for AI agents."""
tldr: str # Brief summary
specs: list[SpecBlock] # Relevant specs
pinned: list[SpecBlock] # Pinned specs (always included)
impacted: list[SpecBlock] # Specs impacted by changes
recommended_tests: list[str] # Tests to run
warnings: list[str] # Validation warnings
metadata: dict # Additional context
Embedding Models¶
SpecMem supports multiple embedding providers:
| Provider | Model | Dimensions | Speed | Quality |
|---|---|---|---|---|
| Local | all-MiniLM-L6-v2 | 384 | โกโกโก | โญโญโญ |
| OpenAI | text-embedding-3-small | 1536 | โกโก | โญโญโญโญ |
| OpenAI | text-embedding-3-large | 3072 | โก | โญโญโญโญโญ |
Vector Stores¶
SpecMem supports multiple vector database backends:
| Backend | Best For | Persistence | Scalability |
|---|---|---|---|
| LanceDB | Local development | โ File-based | Medium |
| ChromaDB | Prototyping | โ File-based | Medium |
| Qdrant | Production | โ Server/Cloud | High |