flutter_agentic_memory โ Semantic Memory for Flutter AI Agents
Give your Flutter AI agent long-term memory. Embeddings (Gemini, OpenAI, or your own), on-device vector search with cosine similarity, persistent storage via Hive, and a drop-in SemanticMemory store for flutter_agentic agents that recalls past conversation by meaning, not just recency.
๐ View on pub.dev ยท API docs ยท GitHub
Part of the flutter_agentic family: flutter_agentic (core SDK) ยท flutter_agentic_graph ยท flutter_agentic_ui ยท flutter_agentic_tools
Installation
dependencies:
flutter_agentic_memory: ^0.1.1
Quick start โ agent that remembers
import 'package:flutter_agentic/flutter_agentic.dart';
import 'package:flutter_agentic_memory/flutter_agentic_memory.dart';
final memory = SemanticMemory(
embedder: GeminiEmbeddingProvider(apiKey: 'YOUR_KEY'), // free tier works
vectors: InMemoryVectorStore(),
);
final agent = AgenticAgent(
provider: GeminiProvider(apiKey: 'YOUR_KEY'),
memory: memory, // drop-in MemoryStore โ nothing else changes
);
await agent.chat('Remember: I am vegetarian and allergic to peanuts.');
// ...hundreds of turns later:
final recalled = await memory.recall('default', 'what should I cook tonight?');
// โ "Remember: I am vegetarian and allergic to peanuts." (score 0.87)
Prompt-ready context windows
buildContext assembles the last N messages plus older messages relevant to the current query โ the standard fix for context windows that can't hold the whole conversation:
final window = await memory.buildContext(
'default',
userInput,
recentCount: 6, // always keep the recent tail
relevantCount: 4, // plus up to 4 semantically recalled older messages
);
Vector stores
| Store | Persistence | Use case |
|---|---|---|
InMemoryVectorStore |
session only | tests, ephemeral chat |
HiveVectorStore |
on-device, survives restarts | production apps |
await Hive.initFlutter();
final vectors = await HiveVectorStore.open('agent_memory');
Both support search(topK:, minScore:, filter:), metadata filtering, and deleteWhere. Implement VectorStore to back it with sqlite-vec, ObjectBox, or a server.
Embedding providers
GeminiEmbeddingProvider(apiKey: '...') // text-embedding-004
OpenAIEmbeddingProvider(apiKey: '...') // text-embedding-3-small
OpenAIEmbeddingProvider(apiKey: '...', baseUrl: '...') // Azure / proxy / local
Implement EmbeddingProvider (one method) to plug in any other model โ including on-device embedders.
Direct vector search (RAG building block)
You don't need SemanticMemory to use the primitives:
final store = InMemoryVectorStore();
await store.add(VectorRecord(
id: 'doc1',
text: 'Flutter widgets are built with composition.',
embedding: await embedder.embed('Flutter widgets are built with composition.'),
metadata: {'source': 'docs'},
));
final hits = await store.search(await embedder.embed('how do widgets work?'),
topK: 3, minScore: 0.5);
License
MIT โ see LICENSE.
Libraries
- flutter_agentic_memory
- flutter_agentic_memory โ semantic memory for Flutter AI agents.