Context Store Abstraction
The ECM Protocol defines a standard interface for context stores, enabling AI applications to work with different storage backends through a consistent API. This specification covers the protocol binding requirements.
Required Interface Methods
Storage Operations
Compliant stores must implement core operations:
interface ContextStore {
put(context: Context): Promise<ContextRef>;
get(id: ContextId): Promise<Context | null>;
update(id: ContextId, context: Context): Promise<ContextRef>;
delete(id: ContextId): Promise<void>;
query(filter: ContextFilter): Promise<Context[]>;
}
Concurrency Control
Stores must support optimistic concurrency. ETags or version numbers for conflict detection. Conditional operations support (If-Match, If-None-Match). Clear error semantics for conflicts (HTTP 409 or equivalent).
Transactional Support
Optional transaction support for multi-context operations. Begin/commit/rollback semantics. Isolation level specifications. Timeout and cleanup for abandoned transactions.
Query Language Binding
Filter Expression Syntax
ECM Query Language (ECM-QL) provides portable queries:
{
"filter": {
"and": [
{"field": "type", "op": "eq", "value": "user-context"},
{"field": "metadata.region", "op": "in", "value": ["us-east", "us-west"]},
{"field": "updated_at", "op": "gte", "value": "2024-01-01T00:00:00Z"}
]
},
"projection": ["id", "data.preferences"],
"sort": [{"field": "updated_at", "order": "desc"}],
"limit": 100,
"offset": 0
}
Supported Operators
Standard comparison operators: eq (equals), ne (not equals), gt/gte/lt/lte (comparisons), in (set membership), contains (substring), exists (field presence).
Event Emission
Change Events
Stores should emit events for context changes. Event types: context.created, context.updated, context.deleted. Events carry sufficient detail for consumers to react. At-least-once delivery semantics.
Event Format
{
"event_type": "context.updated",
"context_id": "string",
"context_type": "string",
"timestamp": "ISO-8601",
"changes": {
"fields": ["data.preferences.theme"]
}
}
Error Handling
Standardized error responses:
- NOT_FOUND: Context ID does not exist
- CONFLICT: Optimistic concurrency violation
- VALIDATION_ERROR: Invalid context data
- QUOTA_EXCEEDED: Storage limits reached
- UNAUTHORIZED: Invalid or missing credentials
- FORBIDDEN: Insufficient permissions
Conclusion
The Context Store Interface specification ensures interoperability between ECM Protocol clients and storage backends. Implementations must support core operations and event emission for full compliance.