# v1.13.0 — Codebase RAG (2026-05-21)

The **Codebase RAG** milestone of the Complete Context System.
OpenLife now indexes the project's source files, embeds them with
a local-first provider, and supports semantic retrieval — laying
the groundwork for the v1.14 Context Composer.

## What landed

### `src/orchestrator/rag/` — RAG primitives

| File                          | Role                                    |
|-------------------------------|-----------------------------------------|
| `EmbeddingProvider.ts`        | Provider contract + abstract base       |
| `OllamaEmbeddingProvider.ts`  | Local default — `nomic-embed-text`/768d |
| `OpenAIEmbeddingProvider.ts`  | Opt-in cloud — `text-embedding-3-small` |
| `EmbeddingRegistry.ts`        | env-driven provider selection           |
| `VectorStore.ts`              | Store contract                          |
| `SqliteVectorStore.ts`        | SQLite + `sqlite-vec`, file-based       |
| `VectorStoreRegistry.ts`      | env-driven store selection              |
| `Chunker.ts`                  | TS/JS boundary + sliding-window fallback |
| `Indexer.ts`                  | Walk → chunk → embed → upsert + incremental |
| `Retriever.ts`                | `query → embed → KNN → file:line refs`  |

### `openlife index <verb>` — CLI surface

```
openlife index build    [--root <path>]
openlife index update   [--root <path>]
openlife index status
openlife index query <q> [--top <n>] [--file <p>] [--language <lang>]
openlife index purge --file <path>
```

`build` does a full embed; `update` only re-embeds files whose mtime
changed (verified by 50ms-resolution test on real fs).

### Environment

| Variable                          | Default               | Effect                                  |
|-----------------------------------|-----------------------|-----------------------------------------|
| `OPENLIFE_EMBEDDING_PROVIDER`     | `ollama`              | `ollama` or `openai`                    |
| `OPENLIFE_VECTOR_STORE`           | `sqlite`              | `sqlite` only for now                   |
| `OPENLIFE_INDEX_DIR`              | `~/.openlife/index`   | Where `codebase.db` lives               |
| `OLLAMA_URL`                      | `http://localhost:11434` | Ollama daemon                         |
| `OPENLIFE_OLLAMA_EMBED_MODEL`     | `nomic-embed-text`    | Ollama model id                         |
| `OPENLIFE_OLLAMA_EMBED_DIM`       | `768`                 | dim of Ollama embeddings                |
| `OPENLIFE_OPENAI_EMBED_MODEL`     | `text-embedding-3-small` | OpenAI embedding model               |

### Tests

| Test                          | What it asserts                                    |
|-------------------------------|----------------------------------------------------|
| `test_chunker.ts`             | TS boundary split, sliding window, overlap, token cap |
| `test_embedding_providers.ts` | Registry selection, provider defaults, availability gate |
| `test_indexer.ts`             | Build/incremental update/retrieve/delete round-trip with deterministic mock embeddings |

Wired into `test:all` and the new `test:rag` aggregator.

### Dependencies

Added: `better-sqlite3`, `@types/better-sqlite3`, `sqlite-vec`.
(Tree-sitter + tiktoken arrive in v1.14.)

## Notes

- The default Ollama embedding provider keeps everything local —
  zero cost, zero data leakage.
- `sqlite-vec` is loaded via `better-sqlite3.loadExtension` from the
  prebuilt platform binary that ships in `sqlite-vec-linux-x64`/etc.
- The SQLite DB at `~/.openlife/index/codebase.db` is chmod 600.
- The index supports incremental updates: only files whose mtime
  changed are re-embedded. Useful for re-running after a few edits.

## What's next

- **v1.14** — Codebase Graph (tree-sitter) + Context Composer +
  per-CLI tier router. The composer ties stories (v1.12), RAG chunks
  (v1.13), and AST symbols (v1.14) into a budgeted "Contexto do
  projeto" block injected into Brain via `Gatekeeper.handleFastPath`.
  Includes a zero-config first-run wizard
  (`openlife provider setup`) and the `cli-only` default inference
  mode so users can drive everything from their existing
  `claude` / `gemini` / `codex` sessions.
