# How does Irene search my own documents (rag)?

**The `rag` toolkit turns your files (PDFs, Word, slides, spreadsheets, notes, whole folders) into a library Irene can search by meaning. It's like NotebookLM, but on your device: the index lives on your computer, searches run there with no model and no internet, and a search returns exact places to read instead of a wall of text.**

---

## What makes it different

| what it does | the primitive behind it | what that buys you |
|---|---|---|
| **Search engine on your computer** | A multilingual embedding model runs locally, vectors are stored in a local database, and ranking is a single calculation | Your documents are never uploaded to be searched, and a search costs nothing |
| **Never parses twice** | Each document is identified by its content; adding it again is instant | Re-adding a folder only processes what's new |
| **Whole chunks reach the search** | Pieces are cut to fit the model's reading window (200 to 1,200 characters), and each carries its heading path | Before this, 36.6% of the library's text sat outside the search. Now none does, and a piece is findable by *where* it sits ("Pricing › Annual plans") |
| **Pointers, not pages** | Results are heading, line range, score and a short preview; the agent then reads just that span | Searching a thousand documents doesn't flood the conversation |
| **Libraries of many documents** | A named collection (a "corpus") over any number of documents, searched as one | Your marketing library or research papers become one thing to ask |
| **Big folders, no frozen calls** | Adding a folder works in rounds of 45 seconds or 200 files, reporting what's left | A folder that takes an hour loads in steps you can stop any time, keeping what's done |
| **It can't leave your device** | Agents that carry `rag` can't be deployed to the cloud | Your private index stays private. Cloud agents use [store](https://mycelen.com/manual/reference/toolkits/store) instead |

---

## How it works

### Adding documents

- **One document:** `ingest` a file or web address. It's read with the same readers as [file](https://mycelen.com/manual/reference/toolkits/file) and [web](https://mycelen.com/manual/reference/toolkits/web), so every format they handle works: PDF (including scans), Word, PowerPoint, Excel, images, and pages.
- **A whole folder:** `corpus(action="add")` walks the folder and its subfolders for `.md`, `.txt`, `.pdf`, `.docx`, `.pptx`, `.xlsx`, `.csv`, `.html`, `.json`, `.yaml` and similar. Hidden folders (like `.git`) are skipped, and files over 25 MB are reported rather than read.
- **Already read it?** Pass the stored result (`content=@read_file_001`) and nothing is read twice.
- **Each document also gets a note in your vault,** in the library's folder when you name one.
- **Indexing only happens when asked.** Nothing watches your folders.

### How it's cut and stored

- **Split by headings,** then sized: anything over 1,200 characters is split, anything under 200 is folded into the section it introduces.
- **Each piece is stored with its heading path,** so it's found by where it sits as well as what it says.
- **Embedding:** a small multilingual model (about 100 languages), run on your computer in batches of 8. **Why batches of 8:** larger batches made memory balloon to 6 GB and stay there. In batches of 8 it peaks around 1.5 GB.
- **Stored in** `~/.irene/documents/rag.db`, with readable copies of each document in `~/.irene/documents/cache/`. The model itself is kept in `~/.irene/models/`.

### Searching

- **One document:** `search_files(path, query, semantic=True)` from the [file](https://mycelen.com/manual/reference/toolkits/file) toolkit returns up to 12 pointers.
- **A library:** `corpus(action="search")` ranks every piece in the collection, removes near-identical duplicates, and returns up to 25 pointers (8 by default). It can be filtered to sources whose name matches.
- **Every result is a pointer:** title, heading path, line range, score and a 140-character preview. The agent reads the span it needs.
- **Fast enough to skip shortcuts:** ranking about 120,000 pieces takes around a tenth of a second, so there's no approximate index trading accuracy for speed.

**Measured on a real 8,000-document library:** the right passage is in the top 5 results 84% of the time, and in the top 10 91% of the time.

### Libraries (corpora)

- **Create, list, add, search, stats, forget.** Names are tidied, so "Marketing Library" and "marketing library" are the same.
- **A document can belong to several libraries** without being processed again.
- **Forget** removes a document from one library. It stays indexed for any others.
- To remove a document from search, ask Irene: 'forget <file> from <collection>'.

---

## Its tools

| tool | does |
|---|---|
| `ingest` | read one file or address, index it, and optionally add it to a library |
| `corpus` | create, list, add a folder to, search, inspect or forget a library |

Search within one document lives on the [file](https://mycelen.com/manual/reference/toolkits/file) toolkit (`search_files` with `semantic=True`).

`rag` is **added when needed**. Agents attach it when a long document needs searching rather than reading whole, or you type `@rag`.

---

## How agents are told to use it

- **Long prose documents:** index once, search by meaning, then read the span. Don't read the whole thing into the chat.
- **Exact words or patterns:** use plain search instead (`search_files`). Search by meaning is for concepts.
- **A whole folder:** add it as a library, calling again until it says it's done.

---

## Approvals

- **Both tools ask first.**
- **In auto mode:** adding documents counts as a local change. Searching, listing and stats count as reads. Forgetting counts as a delete. Searching your library never goes to the judge, because nothing leaves your computer.

---

## Where you see it

- **Index cards:** pieces, sections and length, a table of contents, a preview for short documents, and *cached* and *in vault* badges.
- **Search cards:** heading path, line range, score and snippet, with "read_file a span →".
- **Your vault:** a note for each document you add.

---

## What it costs

- **Indexing and searching are free.** They run on your computer with no model call.
- **Reading can cost:** scanned PDFs and images go through text recognition or an image-reading model to become text, and web addresses are fetched over the internet. After that, everything is local.

---

## Limits

- **Your computer only.** Agents carrying `rag` can't be deployed. For a cloud agent, use [store](https://mycelen.com/manual/reference/toolkits/store).
- **Changed files aren't re-detected.** Adding a changed document again reports "already indexed". Forget it, then add it again.
- **25 MB per file** when adding a folder.
- **It finds; it doesn't write answers.** Results are places to read, and the agent writes the answer from them. There's no audio overview.

---

## Related

- [File](https://mycelen.com/manual/reference/toolkits/file) · [Web](https://mycelen.com/manual/reference/toolkits/web) · [Store, database & agent memory](https://mycelen.com/manual/reference/toolkits/store) · [Chronicle](https://mycelen.com/manual/reference/toolkits/chronicle) (your vault)
- Skill: **working-with-a-pdf** (Capabilities → Skills)

[Ask Irene about this]
