Overview
Storage providers manage conversation persistence and provide access to collections and indexes. TypeAgent supports two implementations:- MemoryStorageProvider - Fast, in-memory storage (data lost on exit)
- SqliteStorageProvider - Persistent SQLite storage with transactions
IStorageProvider Protocol
Type Parameters
The message type this provider stores (e.g.,
ConversationMessage).Collection Getters
get_message_collection
Message collection supporting append, size, get_item, get_slice operations.
get_semantic_ref_collection
Semantic reference collection containing entities, actions, topics, and tags.
Index Getters
All 6 index types are accessible:get_semantic_ref_index
get_property_index
get_timestamp_index
get_message_text_index
get_related_terms_index
get_conversation_threads
Metadata Management
get_conversation_metadata
Metadata object with fields:
name_tag: str | None- Conversation nameschema_version: int | None- Database schema versioncreated_at: datetime | None- Creation timestampupdated_at: datetime | None- Last update timestampembedding_model: str | None- Embedding model nametags: list[str] | None- Conversation tagsextra: dict[str, str] | None- Custom metadata
set_conversation_metadata
Metadata keys and values:
strvalue: Sets a single key-value pair (replaces existing)list[str]value: Sets multiple values for the same keyNonevalue: Deletes all rows for the given key
update_conversation_timestamps
Source Tracking
Track which external sources (files, emails, etc.) have been ingested to prevent duplicates.is_source_ingested
External source identifier (e.g.,
"email:12345", "file:/path/to/transcript.txt").get_source_status
Status string (e.g.,
"ingested") or None if not found.mark_source_ingested
External source identifier.
Status string (default:
"ingested").Transaction Management
Providers support async context manager protocol for transactions.__aenter__
begin_transaction() for SQLite providers.
__aexit__
close
MemoryStorageProvider
Constructor
Configuration for message text embedding index.
Configuration for related terms embedding index.
Optional conversation metadata. If
None, creates empty metadata.Characteristics
Performance
Fastest storage option with no disk I/O
Persistence
No persistence - data lost on exit
Transactions
No-op transactions (always succeeds)
Rollback
No rollback support on errors
Example
Best Practice: Use
create_conversation(dbname=None, ...) instead of manually creating MemoryStorageProvider.SqliteStorageProvider
Constructor
Path to SQLite database file, or
":memory:" for in-memory SQLite.Example: "conversations/chat.db"Message type class for deserialization.
Semantic reference type class for deserialization.
Message text index configuration. If
None, reads from database metadata or creates default.Related terms index configuration. If
None, uses same embedding model as message text index.Conversation metadata. For existing databases, this is validated against stored metadata.
Characteristics
Persistence
Full persistence to disk
Transactions
ACID transactions with rollback
Performance
Optimized with WAL mode and indexes
Consistency
Validates embedding model compatibility
Performance Optimizations
The provider automatically configures SQLite for optimal performance:Embedding Model Consistency
The provider performs consistency checks on initialization:- Validates existing embeddings have compatible dimensions
- Checks metadata for embedding model name
- Raises ValueError if mismatch detected
Transaction Example
Database Schema
The provider uses the following tables:Messages- Message data with JSON serializationSemanticRefs- Extracted semantic referencesSemanticRefIndex- Term-to-semref mappingsPropertyIndex- Property-value indexMessageTextIndex- Message text embeddingsRelatedTermsAliases- Term synonym mappingsRelatedTermsFuzzy- Fuzzy term matching embeddingsTimestampIndex- Timestamp-to-range mappingsConversationMetadata- Metadata key-value pairsIngestedSources- Source tracking
Example
Best Practice: Use
create_conversation(dbname="path.db", ...) instead of manually creating SqliteStorageProvider.ConversationMetadata
Fields
Conversation name identifier.
Database schema version number.
Conversation creation timestamp.
Last update timestamp.
Embedding model name (e.g.,
"text-embedding-3-small").Conversation-level tags.
Custom metadata key-value pairs.
Related
- IMessageCollection - Collection interfaces
- Index Types - All 6 index interfaces
- create_conversation - Factory function