Skip to main content
Annotations provide semantic hints about how data should be stored and accessed. They enable backend-specific optimizations without changing the logical domain model.

What Are Annotations?

Annotations are metadata markers that hint at the intended usage pattern of a field:
Annotations:
  • Do not change the logical data model
  • Do not force a specific backend implementation
  • Enable future routing and optimization
  • Are validated at compile time

Available Annotations

@cache

Marks data as ephemeral or frequently accessed:
annotation
Indicates data that is ephemeral, frequently read, or needs fast access.Use Cases:
  • Session tokens
  • Rate limiting counters
  • Temporary data
  • View counts
  • Cache keys
Example:
Current Behavior (v1.0):
  • Fields are stored in the primary backend (PostgreSQL)
  • Annotation is preserved for future routing
Future Behavior:
  • May route to Redis or similar cache backends
  • May use different TTL policies
  • May implement automatic expiration

@olap

Marks data optimized for analytical queries:
annotation
Indicates data used for analytical queries, aggregations, and reporting.Use Cases:
  • Metrics and aggregates
  • Historical data
  • Data warehouse fields
  • BI reporting
  • Time-series data
Example:
Current Behavior (v1.0):
  • Fields are stored in the primary backend (PostgreSQL)
  • Annotation is preserved for future routing
Future Behavior:
  • May route to DuckDB or columnar stores
  • May use different indexing strategies
  • May enable specialized aggregation paths

@vector

Marks vector embeddings for similarity search:
annotation
Indicates vector embeddings used for similarity search and ML operations.Requirements:
  • Must be used with vector(N) type
  • Dimension count required
Use Cases:
  • Text embeddings
  • Image embeddings
  • Similarity search
  • Semantic search
  • Recommendation systems
Example:
Current Behavior (v1.0):
  • Requires PostgreSQL with pgvector extension
  • Stored as VECTOR(N) column type
  • Can use vector similarity queries
Future Behavior:
  • May route to specialized vector databases (Pinecone, Weaviate)
  • May use optimized similarity algorithms
  • May enable hybrid search

Annotation Syntax

Annotations appear after the field type and constraints:
Examples:

Validation Rules

Annotations are validated at compile time:
Type Compatibility - @vector requires vector(N) type
Single Annotation - Each field can have at most one backend annotation
Valid Annotation - Only recognized annotations are allowed

Complete Example

Here’s a complete schema using all annotations:

Current Implementation (v1.0)

In v1.0-alpha, all fields are stored in PostgreSQL regardless of annotation:
Annotations are:
  • Parsed and validated
  • Stored in the schema vault
  • Preserved for future use
  • Not yet routed to specialized backends

Future Backend Routing

In future versions, annotations will enable automatic routing:
Planned features:
  • Automatic backend selection
  • Fallback strategies
  • Cross-backend queries
  • Consistency guarantees

Use Case Patterns

Session Management

Analytics Dashboard

E-commerce Product

Best Practices

Use @cache for ephemeral data - Session tokens, counters, temporary flags
Use @olap for aggregates - Metrics, historical data, reporting fields
Use @vector for embeddings - Always pair with vector(N) type
Don’t over-annotate - Only annotate fields with clear performance needs
Annotations are hints, not guarantees. The runtime may store data differently based on available backends.

Design Philosophy

Annotations follow these principles:
  1. Declarative - Express intent, not implementation
  2. Optional - Fields work without annotations
  3. Non-breaking - Adding/removing annotations doesn’t break the schema
  4. Future-proof - Enable optimization without rewriting schemas

Annotation Reference

Next Steps

Field Types

Learn about the vector(N) type

Migrations

Apply schema changes safely