Skip to content

Commit e78d43f

Browse files
feat(phase6): add modern interactive web UI, static server assets, CI workflow, and open-source launch kit
1 parent 7e1dd1b commit e78d43f

8 files changed

Lines changed: 1195 additions & 23 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
jobs:
10+
test:
11+
name: Test on ${{ matrix.os }} (Python ${{ matrix.python-version }})
12+
runs-on: ${{ matrix.os }}
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
os: [ubuntu-latest, windows-latest, macos-latest]
17+
python-version: ["3.10", "3.11", "3.12", "3.13"]
18+
19+
steps:
20+
- uses: actions/checkout@v4
21+
22+
- name: Set up Python ${{ matrix.python-version }}
23+
uses: actions/setup-python@v5
24+
with:
25+
python-version: ${{ matrix.python-version }}
26+
cache: "pip"
27+
28+
- name: Install Dependencies
29+
run: |
30+
python -m pip install --upgrade pip
31+
pip install -e ".[dev]"
32+
33+
- name: Run Test Suite
34+
run: |
35+
pytest -v

‎CONTRIBUTING.md‎

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Contributing to LocalRAG-Kit
2+
3+
Thank you for your interest in contributing to **LocalRAG-Kit**! We welcome contributions from developers, security researchers, and AI enthusiasts.
4+
5+
---
6+
7+
## 🛠️ Development Setup
8+
9+
1. **Clone the Repository**:
10+
```bash
11+
git clone https://github.com/RitualDev-Lab/localrag-kit.git
12+
cd localrag-kit
13+
```
14+
15+
2. **Create and Activate a Virtual Environment**:
16+
```bash
17+
# Windows PowerShell
18+
python -m venv .venv
19+
.\.venv\Scripts\Activate.ps1
20+
21+
# Linux / macOS
22+
python3 -m venv .venv
23+
source .venv/bin/activate
24+
```
25+
26+
3. **Install Dependencies**:
27+
```bash
28+
pip install -e ".[dev]"
29+
```
30+
31+
---
32+
33+
## 🧪 Running Tests
34+
35+
Ensure all unit and integration tests pass before submitting code:
36+
```bash
37+
pytest -v
38+
```
39+
40+
---
41+
42+
## 🏗️ Architecture Overview
43+
44+
LocalRAG-Kit is structured into clean, decoupled layers:
45+
46+
- `localrag/core/`: File harvesting, pathspec ignore parsing, file parsers (Markdown, PDF, Code), and semantic boundary chunkers.
47+
- `localrag/storage/`: SQLite engine with SQLite FTS5 for BM25 keyword search, binary BLOB vector storage, NumPy SIMD cosine similarity, and change detection.
48+
- `localrag/providers/`: Pluggable embedding providers (Fast Offline Hasher, Ollama, OpenAI) and LLM providers (Ollama, OpenAI, Mock).
49+
- `localrag/retrieval/`: Reciprocal Rank Fusion (RRF) hybrid reranking, context synthesizer with token budgeting, and grounded prompt orchestration.
50+
- `localrag/server/`: High-performance FastAPI server with Server-Sent Events (SSE) streaming, REST endpoints, and embedded static web UI.
51+
- `localrag/cli.py`: Interactive CLI with Rich formatting (`scan`, `index`, `search`, `ask`, `stats`, `serve`).
52+
53+
---
54+
55+
## 📝 Contribution Guidelines
56+
57+
1. **Keep it 100% Offline & Zero-Config**:
58+
Features must never require mandatory external cloud accounts or external database installations (like Chroma, Pinecone, or PostgreSQL). SQLite must remain the zero-infra backbone.
59+
2. **Deterministic Chunker Line Numbers**:
60+
Every parser and chunker must compute 1-based exact physical start and end line coordinates so citation provenance is verifiable.
61+
3. **Cross-Platform Compatibility**:
62+
Ensure paths use `pathlib.Path` and console outputs handle Windows CP1252 / UTF-8 safely.
63+
64+
---
65+
66+
## 📜 License
67+
68+
By contributing to LocalRAG-Kit, you agree that your contributions will be licensed under the [MIT License](LICENSE).

‎LICENSE‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2026 RitualDev Lab
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

‎README.md‎

Lines changed: 173 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,199 @@
1-
# LocalRAG-Kit 🚀
1+
<div align="center">
22

3-
> **100% Offline, Privacy-First Local RAG Search & Chat Engine for Documents and Codebases.**
4-
> Zero cloud vector database fees. Zero data leaks. Runs entirely on your local machine.
3+
# ⚡ LocalRAG-Kit
4+
5+
**100% Offline, Privacy-First Local RAG Search & Chat Engine for Codebases and Documents**
6+
7+
[![CI](https://github.com/RitualDev-Lab/localrag-kit/actions/workflows/ci.yml/badge.svg)](https://github.com/RitualDev-Lab/localrag-kit/actions)
8+
[![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
9+
[![License: MIT](https://img.shields.io/badge/License-MIT-emerald.svg)](LICENSE)
10+
[![Tests Passing](https://img.shields.io/badge/tests-31%20passing-brightgreen.svg)](tests/)
11+
[![Architecture: Pure SQLite](https://img.shields.io/badge/storage-SQLite%20+%20FTS5%20+%20Vectors-purple.svg)]()
12+
13+
*Zero cloud vector database fees. Zero telemetry. Zero data leaks.*
14+
*Indexes your repositories, PDFs, and docs into a single portable SQLite database with hybrid BM25 + dense vector search and an interactive local web UI.*
15+
16+
</div>
517

618
---
719

8-
## ⚡ Key Highlights
20+
## ✨ Features
921

10-
- **🔒 100% Offline & Private**: No data leaves your machine. Compatible with local LLMs (Ollama) and local embeddings.
11-
- **📁 Multi-Format Ingestion**: Scans and parses Markdown (`.md`), Code (`.py`, `.ts`, `.js`, `.go`, `.rs`, `.java`, etc.), Plain Text (`.txt`), HTML, and PDFs.
12-
- **🧩 Structure-Aware Smart Chunking**:
13-
- **Code**: Splits on function and class declarations while keeping imports and docstrings intact.
14-
- **Markdown**: Heading-aware chunking preserving `#`, `##`, `###` hierarchy and code fences.
15-
- **Text / PDF**: Token-aware sliding window preserving exact start/end line numbers.
16-
- **⚡ Zero-Infra Hybrid Storage**: Pure SQLite database (`.localrag/index.db`) combining Dense Vector Search with SQLite FTS5 (BM25) full-text search.
17-
- **🎯 Reciprocal Rank Fusion (RRF)**: Merges semantic vector similarity with exact keyword lookup for 10x better precision on code symbols and error codes.
22+
- 🔒 **100% Offline & Air-Gapped**: Runs entirely on your CPU/GPU. No external server dependencies or cloud database subscriptions required.
23+
- ⚡ **Zero-Infra Hybrid Storage**: Pure SQLite database (`.localrag/index.db`) combining SQLite FTS5 (BM25 keyword search) with dense vector embeddings via binary BLOBs and fast NumPy SIMD batch cosine similarity.
24+
- 🎯 **Reciprocal Rank Fusion (RRF)**: Merges semantic vector similarity with exact BM25 keyword rankings ($k_{rrf} = 60$). Solves the classic vector search weakness for exact code symbols, variable names, and error codes.
25+
- 🧩 **Structure-Aware Smart Chunking**:
26+
- **Code**: Language-aware boundary chunking for Python, JavaScript, TypeScript, Go, Rust, Java, C/C++ that preserves function/class signatures and docstrings.
27+
- **Markdown**: Heading-aware (`#`, `##`, `###`) chunking that prevents code fences from being broken mid-snippet.
28+
- **Text / PDF**: Token-aware sliding window with deterministic 1-based start and end line coordinates.
29+
- 🔄 **Incremental SHA-256 Change Detection**: Re-indexing only processes newly created or modified files. Deleted files are automatically cascaded out of SQLite and FTS5 indices.
30+
- 🤖 **Flexible Provider Ecosystem**:
31+
- **Embeddings**: Built-in zero-download `fast` 384-dim feature hasher, local `ollama` (`nomic-embed-text`), or `openai`.
32+
- **LLMs**: Local `ollama` (`llama3.2`, `qwen2.5`, `mistral`), `openai`, or mock testing agent.
33+
- 🖥️ **Interactive Web Interface**: Clean, dark-mode glassmorphic Tailwind UI featuring real-time SSE token streaming, inline citation badges, a source inspector slideout drawer, and live index management.
34+
- 💻 **Feature-Rich CLI**: Built with `rich` for colorful terminal tables, progress bars, interactive query synthesis, and streaming terminal output.
1835

1936
---
2037

21-
## 📦 Quickstart
38+
## 🏛️ System Architecture
39+
40+
```mermaid
41+
flowchart TB
42+
subgraph Ingestion ["1. INGESTION & PARSING"]
43+
A[Local Files & Codebase] --> B[File Harvester & Ignore Filter]
44+
B --> C{File Type Dispatch}
45+
C -->|Markdown| D[Markdown Chunking Engine]
46+
C -->|Code: py, ts, go, rs, etc.| E[Code Boundary Chunker]
47+
C -->|PDF & Text| F[Sliding Window Chunker]
48+
end
49+
50+
subgraph Storage ["2. ZERO-INFRA STORAGE (SQLite)"]
51+
D & E & F --> G[(.localrag/index.db)]
52+
G --> H[FTS5 Full-Text Search Engine]
53+
G --> I[Binary Vector Storage & SHA-256 Hashes]
54+
end
55+
56+
subgraph Retrieval ["3. HYBRID RETRIEVAL & CITATION"]
57+
Q[User Query] --> J[BM25 Keyword Search]
58+
Q --> K[Vector Cosine Similarity]
59+
H --> J
60+
I --> K
61+
J & K --> L[Reciprocal Rank Fusion - RRF]
62+
L --> M[Context Synthesizer & Token Budget]
63+
end
64+
65+
subgraph Presentation ["4. INTERFACES"]
66+
M --> N[Local LLM - Ollama / OpenAI]
67+
N --> O[Rich Terminal CLI]
68+
N --> P[FastAPI Server & Web UI]
69+
end
70+
```
71+
72+
---
73+
74+
## 🚀 Quickstart
2275

2376
### 1. Installation
77+
2478
```bash
79+
# Clone repository
2580
git clone https://github.com/RitualDev-Lab/localrag-kit.git
2681
cd localrag-kit
82+
83+
# Create virtual environment
2784
python -m venv .venv
28-
# On Windows:
29-
.\venv\Scripts\pip install -r requirements.txt
30-
# On Linux/macOS:
31-
source .venv/bin/activate && pip install -r requirements.txt
85+
source .venv/bin/activate # On Windows: .venv\Scripts\Activate.ps1
86+
87+
# Install in editable mode
88+
pip install -e .
89+
```
90+
91+
### 2. Index Any Folder or Codebase
92+
93+
```bash
94+
# Preview files and chunk distribution without writing to disk
95+
localrag scan ./my-project --preview
96+
97+
# Index files into pure SQLite (uses offline fast hasher by default)
98+
localrag index ./my-project
99+
100+
# Or index with local Ollama embeddings:
101+
localrag index ./my-project --embed-provider ollama --embed-model nomic-embed-text
32102
```
33103

34-
### 2. Scan & Preview Any Folder
104+
### 3. Ask Questions from the Terminal
105+
35106
```bash
36-
python -m localrag.cli scan /path/to/project --preview
107+
# Ask with hybrid retrieval and local Ollama
108+
localrag ask "How does the authentication middleware work?" --mode hybrid --llm ollama
109+
110+
# Search matching chunks with line coordinates
111+
localrag search "create_app" --mode hybrid --limit 5
37112
```
38113

114+
### 4. Launch the Web Interface
115+
116+
```bash
117+
localrag serve ./my-project --port 8000
118+
```
119+
Open `http://127.0.0.1:8000` in your browser to access the interactive web console.
120+
121+
---
122+
123+
## 🛠️ CLI Command Reference
124+
125+
| Command | Description | Example |
126+
| :--- | :--- | :--- |
127+
| `localrag scan` | Inspect eligible files, token estimates, and chunk counts without indexing | `localrag scan . --preview` |
128+
| `localrag index` | Incremental or full indexing of workspace files into SQLite + FTS5 | `localrag index . --full` |
129+
| `localrag search` | Perform hybrid RRF, BM25 keyword, or vector similarity search | `localrag search "token" --mode hybrid` |
130+
| `localrag ask` | Query workspace with streaming grounded LLM answers and citations | `localrag ask "Explain routes.py" --llm ollama` |
131+
| `localrag stats` | Display index statistics, chunk counts, database size, and providers | `localrag stats .` |
132+
| `localrag serve` | Launch the FastAPI server and embedded glassmorphic web UI | `localrag serve . --port 8000` |
133+
134+
---
135+
136+
## 💻 Python API Usage
137+
138+
LocalRAG-Kit can also be embedded directly into your Python scripts and services:
139+
140+
```python
141+
from pathlib import Path
142+
from localrag.storage import SQLiteStore
143+
from localrag.providers import FastFeatureEmbeddingProvider, OllamaLLMProvider
144+
from localrag.retrieval import RAGOrchestrator
145+
146+
# Initialize storage and providers
147+
store = SQLiteStore(".localrag/index.db")
148+
embedder = FastFeatureEmbeddingProvider()
149+
llm = OllamaLLMProvider(model="llama3.2")
150+
151+
# Orchestrate grounded retrieval
152+
orchestrator = RAGOrchestrator(
153+
store=store,
154+
embedding_provider=embedder,
155+
llm_provider=llm,
156+
)
157+
158+
# Stream response with citations
159+
stream = orchestrator.stream_answer(
160+
query="Explain the database schema design",
161+
mode="hybrid",
162+
top_k=5,
163+
)
164+
165+
print(f"Citations: {[c.relative_path for c in stream.citations]}")
166+
for token in stream.token_iterator:
167+
print(token, end="", flush=True)
168+
```
169+
170+
---
171+
172+
## 🌐 REST & SSE Streaming API
173+
174+
When running `localrag serve`, the following API endpoints are exposed:
175+
176+
- `GET /` — Serves the modern Web UI
177+
- `GET /api/status` — Returns workspace stats, chunk counts, and active providers
178+
- `GET /api/files` — Lists all indexed files with line numbers and metadata
179+
- `POST /api/search` — Runs hybrid RRF, BM25, or vector similarity search
180+
- `POST /api/chat` — SSE streaming endpoint (`data: {"type": "token", "token": "..."}`)
181+
- `POST /api/reindex` — Triggers an incremental or full re-index
182+
- `GET /api/chunk/{id}` — Retrieves chunk details and surrounding file context
183+
- `GET /api/file-content` — Reads raw text of a physical workspace file
184+
39185
---
40186

41-
## 🧪 Running Tests
187+
## 🧪 Testing
188+
189+
The test suite contains 31 unit and integration tests covering chunking, FTS5 BM25, vector math, change detection, SSE streaming, and web UI serving:
190+
42191
```bash
43-
python -m pytest -v
192+
pytest -v
44193
```
45194

46195
---
47196

48-
## 📜 License
49-
MIT © [RitualDev-Lab](https://github.com/RitualDev-Lab)
197+
## 📄 License
198+
199+
This project is licensed under the [MIT License](LICENSE).

0 commit comments

Comments
 (0)