# Implementation Plan: RAG Support

## Phase 1: Foundation & Vector Store Integration [checkpoint: dd042d9]
- [x] Task: Define the RAG architecture and configuration schema. e80cd6b
    - [x] Update `src/models.py` to include `RAGConfig` and `VectorStoreConfig`. e80cd6b
    - [x] Implement configuration loading/saving in `AppController`. e80cd6b
- [x] Task: Integrate a local vector store. e80cd6b
    - [x] Add `chromadb` or `qdrant-client` to `requirements.txt`. e80cd6b
    - [x] Create `src/rag_engine.py` to manage the vector database lifecycle (init, add, search, delete). e80cd6b
- [x] Task: Implement embedding providers. e80cd6b
    - [x] Implement Gemini embedding wrapper in `src/rag_engine.py`. e80cd6b
    - [x] Implement local embedding wrapper (e.g., using `sentence-transformers`) in `src/rag_engine.py`. e80cd6b
- [x] Task: Write unit tests for vector store operations and embedding generation. e80cd6b
- [x] Task: Conductor - User Manual Verification 'Phase 1: Foundation & Vector Store' (Protocol in workflow.md) dd042d9

## Phase 2: Indexing & Retrieval Logic [checkpoint: fe0069c]
- [x] Task: Implement the indexing pipeline. fe0069c
    - [x] Implement file chunking strategies (e.g., character-based, AST-aware) in `src/rag_engine.py`. fe0069c
    - [x] Create a background indexing task in `AppController`. fe0069c
    - [x] Implement auto-indexing logic triggered by Context Hub changes. fe0069c
- [x] Task: Implement the retrieval pipeline. fe0069c
    - [x] Implement similarity search with configurable top-k and threshold. fe0069c
    - [x] Implement "Native Retrieval" logic for Gemini (leveraging `ai_client.py`). fe0069c
- [x] Task: Update `ai_client.py` to support RAG. fe0069c
    - [x] Add a `retrieve_context()` step to the `send()` loop. fe0069c
    - [x] Format and inject retrieved fragments into the model's system prompt or context block. fe0069c
- [x] Task: Write integration tests for the indexing and retrieval flow. fe0069c
- [x] Task: Conductor - User Manual Verification 'Phase 2: Indexing & Retrieval Logic' (Protocol in workflow.md) fe0069c

## Phase 3: GUI Integration & Visualization
- [x] Task: Implement the RAG Settings panel in `src/gui_2.py`. f57e2fe
    - [x] Add UI controls for choosing the RAG source, embedding model, and retrieval parameters. f57e2fe
    - [x] Add a "Rebuild Index" button and status progress bar. f57e2fe
- [x] Task: Implement retrieval visualization in the Discussion history. d4dc237
    - [x] Display "Retrieved Context" blocks with expandable summaries. d4dc237
    - [x] Add "Source" buttons to each block that open the file at the specific chunk's location. d4dc237
- [x] Task: Implement auto-start/indexing status indicators in the GUI. 8b48753
- [x] Task: Write visual regression tests or simulation scripts to verify the RAG UI components. f57e2fe
- [x] Task: Conductor - User Manual Verification 'Phase 3: GUI Integration & Visualization' (Protocol in workflow.md) [checkpoint: 213747a]

## Phase 4: Refinement & Advanced RAG
- [x] Task: Implement support for external RAG APIs/MCP servers. f57e2fe
    - [x] Create a bridge in `src/rag_engine.py` to call external RAG tools via the MCP interface. f57e2fe
- [x] Task: Optimize indexing performance for large projects (e.g., incremental updates, parallel chunking). f57e2fe
- [ ] Task: Perform a final end-to-end verification with a large codebase.
- [ ] Task: Conductor - User Manual Verification 'Phase 4: Refinement & Advanced RAG' (Protocol in workflow.md)
