RAG & Documents
Upload documents and get AI responses grounded in your own content.
What is RAG?
RAG (Retrieval-Augmented Generation) is a technique that grounds AI responses in your own documents. Instead of relying solely on the AI model's training data, RAG retrieves relevant sections from your uploaded documents and includes them as context when generating a response.
Here's how it works in SafeRag SE:
- Upload documents — Add PDF, TXT, or MD files to SafeRag SE.
- Automatic processing — The app extracts text, splits it into chunks, and creates vector embeddings locally using sqlite-vec.
- Ask questions — When you ask a question with RAG enabled, SafeRag SE finds the most relevant document sections and passes them as context to the AI.
- Grounded responses — The AI generates a response based on your actual document content, reducing hallucination and improving accuracy.
Supported Document Types
| Format | Extension | Notes |
|---|---|---|
| Text-based PDFs. Scanned/image-only PDFs may have limited text extraction. | ||
| Plain Text | .txt | Any plain text file. |
| Markdown | .md | Markdown documents with formatting preserved during extraction. |
Keep in mind that very large files take longer to process. For best results, use documents that are primarily text-based.
Uploading Documents
Open the Documents Tab
Click the Documents tab in the sidebar to view your document library.
Click Upload
Click the Upload button to open the file picker. Select one or more files to add.
Wait for Processing
SafeRag SE extracts text from your document, splits it into chunks, and creates vector embeddings. A progress indicator shows the current status. When you see a green checkmark, the document is ready for RAG queries.
Using RAG in Chat
Once your documents are processed, you can start chatting with them:
- Enable RAG mode — Toggle the RAG button in the chat input area. You can also press Cmd+Shift+R to toggle it.
- Ask your question — Type a question related to your documents and send it.
- Review the response — The AI generates a response using relevant document sections as context. Responses are grounded in your actual content.
- Ask specific questions rather than broad ones.
- Reference topics or terms that appear in your documents.
- Upload focused documents rather than very large, multi-topic files.
- Use follow-up questions to dig deeper into a topic.
Watch Folders
Watch Folders let SafeRag SE automatically index new documents from specified folders on your Mac.
- Setup — Go to Settings > Documents > Watch Folders and add a folder to watch.
- Grant access — Since SafeRag SE is a sandboxed app, you need to grant permission to access the folder when prompted.
- Automatic processing — Any new supported files added to the watched folder are automatically detected and processed for RAG.
This is useful if you have a folder where you regularly save research papers, notes, or documentation that you want to query with AI.
Managing Documents
The Documents tab provides a complete view of all your uploaded and indexed documents.
- View documents — Browse all uploaded documents with their processing status.
- Delete a document — Remove a document and its associated vector embeddings.
- Re-process — If a document didn't process correctly, you can re-upload it to regenerate embeddings.
How It Works (Technical)
For those interested in the technical details, here is how RAG works under the hood in SafeRag SE:
- Vector storage — Document chunk embeddings are stored locally using sqlite-vec, a SQLite extension for vector similarity search.
- Search — When you ask a question, SafeRag SE converts your query into an embedding and performs a KNN (K-Nearest Neighbors) search against your document vectors to find the most relevant chunks.
- Context injection — The retrieved chunks are passed as context to the LLM alongside your question, so the AI can generate a response informed by your documents.