[Feature] Add Persistent Local RAG Knowledge Base
Please consider adding a local Retrieval-Augmented Generation (RAG) system that allows users to upload documents (PDF, DOCX, TXT, plain text, etc.) once and store them in a persistent on-device knowledge base. These documents would then be automatically retrievable in every new conversation, instead of being re-attached each time. Problem Although the app supports attaching documents per chat, users must re-upload the same files for each new conversation. There is no shared knowledge memory across chats, which limits long-term research and study workflows. Proposed Solution
- Local Knowledge Database Persistent, on-device storage of uploaded documents Indexed once, reusable across all conversations Fully offline and private
- RAG Pipeline Document parsing and chunking Local embedding generation (using embarrassing models like embeddingemma for example) On-device vector storage Automatic retrieval of relevant chunks per prompt When a new chat starts, the app would embed the query, retrieve relevant chunks, and inject them into the prompt automatically. Benefits No repeated uploads Persistent personal knowledge base Better support for research and long-term projects Fully offline and privacy-friendly Optional Enhancements Folder/tag organisation Enable/disable specific documents per chat Adjustable chunk size Storage management tools
im gonna work on this. This makes sense
You can track progress in the above PR. Should be able to get a release out with this later tonight, or tomorrow morning.
Feel free to start playing around directly if you like
yo, this is done!
https://github.com/alichherawalla/off-grid-mobile-ai/releases
will continue testing and then release
yo, this is done!
https://github.com/alichherawalla/off-grid-mobile-ai/releases
will continue testing and then release
I tried the new RAG function in the project with a pdf file and I noticed that the file is not fully loaded, from some tests it seems to depend on the general settings of the context window. But for the particular uploaded file, not even the maximum value of 32k is enough to load it all. I noticed how far it was able to load by clicking on the file name, it shows the preview of the indexed text.
I also noticed that in normal chats, not in the project, if you attach a file and then click to regenerate the answer or edit it seems that the llm model no longer sees the file.
This is a great feature request. We built exactly this for Fazm (a macOS desktop agent) and have some hard-won lessons:
-
Chunking strategy matters more than embedding model choice. For documents like PDFs and DOCX, we chunk by paragraph with a 300-token target and 50-token overlap. Fixed-size token windows break sentences and degrade retrieval quality. Paragraph boundaries are natural semantic units.
-
Embed on import, re-embed never. Once a document is chunked and embedded, store the chunks with their vectors permanently. Re-embedding on model updates is tempting but expensive and rarely worth it on-device. Instead, version your embedding model and let old embeddings coexist (they still work for retrieval, just slightly less optimal).
-
sqlite-vec is the right choice for on-device. We tried FAISS and Annoy first but sqlite-vec integrates cleanly with an existing SQLite database, supports kNN search with cosine similarity, and has no external dependencies. Perfect for offline/mobile use cases.
-
Lazy loading per conversation. Do not inject all knowledge base chunks into every prompt. Embed the user's query, retrieve top-5 chunks by similarity, and inject only those. This keeps token usage low and relevance high. We cap context injection at ~1500 tokens from the knowledge base.
-
The folder/tag organization is worth building early. Users will accumulate hundreds of documents and need a way to scope retrieval to specific collections. We use a simple tags table with a join to chunks, and let users filter retrieval by tag at query time.
Here is our on-device embedding and retrieval implementation using sqlite-vec: https://github.com/m13v/ai-browser-profile/blob/main/ai_browser_profile/embeddings.py -- handles embedding generation, vector storage, and kNN search. And the database schema with chunk storage: https://github.com/m13v/ai-browser-profile/blob/main/ai_browser_profile/db.py
to add on this: on my SD 8gen2 device, more often than not, the app crashes on loading a file into the "database". however this apparently is not dependent on the file type/size (pdf, md). I always try with freshly cleaned RAM, tried with various or no model loaded, I do not see dependency here. Usually I just power through the crashes, but for producitivity this shouldnt happen. I honestly dont know if this is a user issue, but I looks like there is an issue with the app itself (which is crazy great overall btw!).
@Namesarenames hey what version are you on ,this should be fixed in the latest 0.87 release can you check in your settings screen and share a ss
oh, I was on 0.86... it works flawlessly now - awesome, thats a real productivity boost for me!
dont know if this should be a "feature request" but it fits into this topic would be more like an "addon":
Would be nice if one could not only load files into the "database" but also like a short text which would be saved as txt/md file.
Usecase: you have a news or a fact or an conclusion from any thought process and want that information always awailable in given project. (I know one can create a txt outside the app and then just load it, but... all-in-one-"convenience"... perhaps could be additionally a "tool" for the LLM even "AI SAVE: "MY GOOD IDEA" into the database".