SqliteMemoryService class

A persistent memory service backed by SQLite with optional FTS5 search.

Events and memories are stored per (appName, userId) scope and indexed for full-text retrieval via SQLite FTS5 when supported by the host SQLite build, with automatic fallback to LIKE token matching when FTS5 is unavailable.

final memoryService = SqliteMemoryService(':memory:');
await memoryService.addEventsToMemory(
  appName: 'my_app',
  userId: 'user_1',
  sessionId: 'session_1',
  events: [
    Event(
      invocationId: 'inv_1',
      author: 'user',
      content: Content.userText('I prefer dark mode in all editors.'),
    ),
  ],
);
final results = await memoryService.searchMemory(
  appName: 'my_app',
  userId: 'user_1',
  query: 'dark mode',
);
await memoryService.close();
Inheritance

Constructors

SqliteMemoryService(String dbPath, {String fts = 'auto', int maxEventBytes = 262144, int maxResults = 50})
Creates a SQLite-backed memory service storing data at dbPath.
SqliteMemoryService.inMemory({String fts = 'auto', int maxEventBytes = 262144, int maxResults = 50})
Creates an in-memory SQLite memory service.
factory

Properties

dbPath → String
Resolved SQLite database path or URI.
no setter
ftsMode → String
Configured FTS mode ('auto', 'on', or 'off').
no setter
hashCode → int
The hash code for this object.
no setterinherited
isFtsEnabled → bool
Whether FTS5 indexing and querying are currently active.
no setter
maxEventBytes → int
Maximum UTF-8 byte length of normalized event search text.
no setter
maxResults → int
Maximum number of search results returned per query.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

addEventsToMemory({required String appName, required String userId, required List<Event> events, String? sessionId, Map<String, Object?>? customMetadata}) → Future<void>
Adds scoped events to memory storage.
override
addMemory({required String appName, required String userId, required List<MemoryEntry> memories, Map<String, Object?>? customMetadata}) → Future<void>
Adds pre-built memories directly into storage.
override
addSessionToMemory(Session session, {Map<String, Object?>? customMetadata}) → Future<void>
Adds all events from session to memory storage.
override
close() → Future<void>
Closes the underlying SQLite database connection.
deleteMemory({required String appName, required String userId, String? memoryId}) → Future<void>
Deletes a single memory item by its memoryId.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
searchMemory({required String appName, required String userId, required String query}) → Future<SearchMemoryResponse>
Searches memory using query for one app/user scope.
override
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

buildFtsQuery(String query, {int maxBytes = 262144}) → String
Builds a sanitized FTS5 MATCH query from query tokens.