On-Device RAG and Memory

An on-device model only knows what's baked into its weights — nothing about the user's notes, messages, or documents. On-device RAG fixes that by doing retrieval entirely on the phone: embed the user's data locally, store the vectors locally, and retrieve locally, so the model can reason over personal data that never touches a server. It's the technique that makes a private assistant actually useful.

A local Gemma model is capable but ignorant of the user’s world. To answer “what did I spend on groceries last month?” or “summarize my notes about the project,” it needs the user’s data — and the whole point of on-device AI is that this data must not leave the device. On-device RAG (retrieval-augmented generation) is how you square that circle: the entire retrieval pipeline runs locally. This post adapts the RAG concepts from the Agentic RAG series to the edge, where “no server” is the defining constraint.

Why RAG, and why on-device changes it

RAG’s premise (from the Agentic RAG series) is unchanged: rather than relying on a model’s baked-in knowledge, you retrieve relevant information and put it in the model’s context so it answers from real, current, specific data. On the edge, RAG is doubly important, because on-device models are small — they have less baked-in knowledge than a frontier model, so grounding them in retrieved facts matters even more for quality.

What changes is that every stage must run locally. Normal RAG assumes servers: a cloud embedding API, a hosted vector database, a big model. On-device RAG replaces each with a local equivalent:

Cloud RAG:                          On-device RAG:
  embed via API             →         embed with a local embedding model
  store in hosted vector DB  →        store in an on-device vector store
  retrieve over network      →        retrieve locally (no network)
  generate with cloud LLM    →        generate with on-device Gemma

The payoff is that the user’s data — their most private data, the kind you’d never send to a server — becomes usable by the assistant without ever leaving the device. That’s a capability cloud RAG structurally cannot offer for truly sensitive data.

The local pipeline, stage by stage

Each RAG stage has an on-device form, and the good news is that modern on-device stacks (including flutter_gemma, which supports embeddings and RAG) provide the building blocks.

The entire loop — embed, store, retrieve, generate — happens on the phone. There is no server anywhere in the path, which is precisely what makes it private.

Edge-specific RAG design

On-device RAG isn’t just cloud RAG with local parts; the edge constraints reshape the design decisions:

Memory: the assistant that remembers

RAG over documents naturally extends to conversational memory — an on-device assistant that remembers past interactions. The same machinery applies: store past conversation turns (or summaries of them) locally, embed them, and retrieve relevant past context when it bears on the current query. This gives a local assistant long-term, private memory — it remembers what the user told it weeks ago, entirely on-device, with nothing stored on a server.

The distinction from the LLM serving series holds: conversation memory (what was said) and retrieved knowledge (the user’s documents) are different sources, and a good on-device assistant uses both — short-term chat history in the context window, plus retrieval over a local store of long-term memories and documents. Bounding and summarizing older memory (the memory-management strategies from the serving series) keeps it within the phone’s limits.

Putting it together for a private assistant

On-device RAG is what turns a local model from a generic chatbot into a personal assistant grounded in the user’s own private world. The last two posts cover the architecture that keeps it trustworthy (privacy and local-first design) and the practicalities of getting it into users’ hands (shipping).

Key takeaways

Further reading

Sources & References

On-device embeddings and RAG