-
Notifications
You must be signed in to change notification settings - Fork 0
Tutorial Using RAG with Documents
This tutorial walks you through Mosaic's Retrieval-Augmented Generation (RAG) system — uploading documents, enabling context-aware queries, and getting the most out of your data.
Estimated time: 15 minutes
Before starting, ensure:
- Mosaic is installed and running
- At least one LLM provider is configured (API key entered in Settings)
- You have a text file, markdown file, or code file ready to upload
- Click the Documents icon (📄) in the TopBar
- The DocumentPanel slides in from the right side
- You'll see an empty document list with an Upload button
- Click Upload
- Select a file from your computer (supports .txt, .md, .json, .csv, .py, .js, .ts, .rs, .go, .java, .c, .cpp, .css, .html, .xml, .yaml, .yml)
- The file is processed automatically — you'll see it appear in the list
- The file is read as text
- The text is split into chunks of 800 characters with 100 characters of overlap
- Each chunk is stored with metadata (source filename, chunk index)
- The document appears in the panel with:
- Filename
- File size
- Number of chunks created
Upload a file called my-notes.txt (3,200 characters). It will be split into approximately 5 chunks (800 × 4 = 3,200 + overlap).
Toggle the RAG Enable switch in the DocumentPanel:
- ON: The top 3 most relevant chunks from your documents are automatically included with every AI query
- OFF: Documents are stored but not searched
Make sure it's toggled ON.
Now ask the AI questions about your uploaded content:
- Click the root node (or any existing node)
- Type a question related to your document, for example:
What are the key points about error handling mentioned in my notes?
- Press Enter
The AI's response should reference content from your document. Unlike a normal query (where the AI relies only on its training data), the RAG system has injected relevant context from your uploaded file.
To see the difference RAG makes:
- Toggle RAG OFF in the DocumentPanel
- Ask the same question again (branch from an earlier node)
What are the key points about error handling mentioned in my notes?
-
Note the difference: without RAG, the AI has no access to your document and may respond generically (or state it doesn't have access to your notes).
-
Toggle RAG back ON for continued context-aware queries.
For richer context, upload several related documents:
- Upload a code file (e.g.,
api-handler.py) - Upload a documentation file (e.g.,
api-docs.md) - Upload a notes file (e.g.,
meeting-notes.txt)
Now when you ask questions, the RAG system searches across all documents and returns the 3 most relevant chunks regardless of source.
What's the relationship between the error handling strategy in api-handler.py
and the requirements in the meeting notes?
The AI can synthesize information across all your documents.
RAG works seamlessly with branching:
- Branch from a RAG-informed response
- Ask a follow-up that drills deeper into the document content
- Each branch query independently searches for relevant chunks
This means each branch gets context tailored to its specific question, even when exploring different aspects of the same document.
Combine RAG with code execution for powerful workflows:
- Upload a data file (e.g.,
sales-data.csv) - Ask:
Analyze the sales trends in my data - The AI sees the data context and can generate analysis code
- Run the generated Python code inline to see actual analysis
Example:
Based on the sales data in the CSV I uploaded, write a Python script
using pandas to calculate monthly totals and identify the best-performing month.
The AI will: (1) reference your document context, (2) write appropriate code, and (3) you can run it to see results.
Click the expand arrow on any document entry to see:
- Number of chunks
- Individual chunk previews
Click the delete icon (trash) next to a document to remove it. Its chunks are immediately removed from the search index.
Click Clear All to remove all documents. A confirmation dialog appears.
| Limit | Value | What Happens When Exceeded |
|---|---|---|
| Max documents | 50 | Upload is rejected with a message |
| Max total size | 50 MB | Upload is rejected |
| Max per file | 10 MB | File is rejected |
| Possible Cause | Solution |
|---|---|
| RAG is toggled OFF | Check the toggle in DocumentPanel |
| Query doesn't match document content | Try rephrasing with keywords from the document |
| Embedding API is down | Mosaic falls back to TF-IDF, which is less semantically accurate |
| Document is too large | Check that it's under 10 MB |
| Document format not supported | Check the supported formats list |
The RAG system returns the top 3 chunks across all documents. If you have many documents, some may not be represented in the top results. Try more specific queries.
The default chunk size of 800 characters works well for most use cases. If you need larger context, consider:
- Breaking your document into smaller files focused on specific topics
- Using more specific queries that match fewer, more relevant chunks
Query: "What is the error handling strategy?"
1. Query → Embedding API → Query Vector
(or TF-IDF vector if embeddings unavailable)
2. For each chunk:
similarity = cosine(vector_query, vector_chunk)
3. Top 3 chunks selected
4. Context injected into system prompt:
[RELEVANT CONTEXT]
Source: api-docs.md
The error handling strategy uses circuit breakers...
5. AI generates response with context
Mosaic uses fixed-size chunking with overlap:
Document text:
[--- 800 chars ---][--- overlap 100 ---][--- 800 chars ---]
[ ][--- overlap 100 ---][--- 800 chars ---]
Why 800 characters?
- Long enough to contain meaningful context (several paragraphs)
- Short enough to fit within most LLM context windows
- Multiple chunks can be included (top 3 = ~2,400 characters of context)
- Embedding models typically work best with 256-512 tokens (~200-800 words)
Why 100-character overlap?
- Prevents information loss at chunk boundaries
- If a sentence spans two chunks, it appears in both
- Ensures context isn't cut mid-paragraph
- Increases recall for queries about boundary-spanning content
For a 2,000-character document:
Chunk 1: [characters 0-800]
Chunk 2: [characters 700-1500] (overlaps 100 chars with chunk 1)
Chunk 3: [characters 1400-2000] (overlaps 100 chars with chunk 2)
Total: 3 chunks covering the full document with overlap buffer at each boundary.
See the RAG System Guide for a complete technical explanation.
- RAG System Guide — Technical deep dive into the RAG system
- Advanced AI Features — Combine RAG with distillation, pruning, and debate
- Tutorial - Advanced Features in Practice — Full workflow combining all features
Mosaic — Branch, explore, and run code inline — an infinite canvas for AI conversations.
Built with Tauri, React, and Mistral AI.
GitHub Repository |
Report an Issue |
Releases
- Canvas and Node System
- LLM Provider Integration
- RAG System Guide
- Advanced AI Features
- Keyboard Shortcuts and UI Reference
- Tutorial - Branching and Parallel Exploration
- Tutorial - Using RAG with Documents
- Tutorial - Advanced Features in Practice
- Tutorial - Customizing Mosaic