flutter_agentic_memory 0.2.0
flutter_agentic_memory: ^0.2.0 copied to clipboard
Semantic memory for Flutter AI agents — embeddings, on-device vector search, and long-term recall that plugs into flutter_agentic.
// Example: an agent with semantic long-term memory.
// ignore_for_file: avoid_print
import 'package:flutter_agentic/flutter_agentic.dart';
import 'package:flutter_agentic_memory/flutter_agentic_memory.dart';
Future<void> main() async {
final memory = SemanticMemory(
embedder: GeminiEmbeddingProvider(apiKey: 'YOUR_GEMINI_API_KEY'),
vectors: InMemoryVectorStore(), // or: await HiveVectorStore.open('mem')
);
final agent = AgenticAgent(
provider: GeminiProvider(apiKey: 'YOUR_GEMINI_API_KEY'),
memory: memory,
sessionId: 'user_42',
);
await agent.chat('Remember: I am vegetarian and I live in Mumbai.');
await agent.chat('I mostly code Flutter apps on weekends.');
// Later — recall by meaning, not keywords:
final recalled = await memory.recall('user_42', 'dinner suggestions?');
for (final r in recalled) {
print('${r.score.toStringAsFixed(2)} ${r.message.content}');
}
// Build a prompt window: recent tail + relevant older messages.
final context = await memory.buildContext(
'user_42',
'what should I eat tonight?',
);
print('Context window: ${context.length} messages');
}