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.
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.