|
1 | | -# sqlite-rag |
| 1 | +# SQLite RAG |
| 2 | + |
| 3 | +A hybrid search engine built on SQLite with AI and Vector extensions. SQLite-RAG combines vector similarity search with full-text search using Reciprocal Rank Fusion (RRF) for enhanced document retrieval. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- **Hybrid Search**: Combines vector embeddings with full-text search for optimal results |
| 8 | +- **SQLite-based**: Built on SQLite with AI and Vector extensions for reliability and performance |
| 9 | +- **Multi-format Support**: Process 25+ file formats including PDF, DOCX, Markdown, code files |
| 10 | +- **Intelligent Chunking**: Token-aware text chunking with configurable overlap |
| 11 | +- **Interactive CLI**: Command-line interface with interactive REPL mode |
| 12 | +- **Flexible Configuration**: Customizable embedding models, search weights, and chunking parameters |
2 | 13 |
|
3 | 14 | ## Installation |
4 | 15 |
|
5 | 16 | ```bash |
6 | | -pip install .[dev] |
| 17 | +pip install sqlite-rag |
| 18 | +``` |
| 19 | + |
| 20 | +## Quick Start |
| 21 | + |
| 22 | +```bash |
| 23 | +# Initialize and add documents |
| 24 | +sqlite-rag add /path/to/documents --recursive |
| 25 | + |
| 26 | +# Search your documents |
| 27 | +sqlite-rag search "your search query" |
| 28 | + |
| 29 | +# Interactive mode |
| 30 | +sqlite-rag |
| 31 | +> help |
| 32 | +> search "interactive search" |
| 33 | +> exit |
| 34 | +``` |
| 35 | + |
| 36 | +## CLI Commands |
| 37 | + |
| 38 | +### Document Management |
| 39 | + |
| 40 | +**Add files or directories:** |
| 41 | +```bash |
| 42 | +sqlite-rag add <path> [--recursive] [--absolute-paths] [--metadata '{"key": "value"}'] |
| 43 | +``` |
| 44 | + |
| 45 | +**Add raw text:** |
| 46 | +```bash |
| 47 | +sqlite-rag add-text "your text content" [uri] [--metadata '{"key": "value"}'] |
| 48 | +``` |
| 49 | + |
| 50 | +**List all documents:** |
| 51 | +```bash |
| 52 | +sqlite-rag list |
| 53 | +``` |
| 54 | + |
| 55 | +**Remove documents:** |
| 56 | +```bash |
| 57 | +sqlite-rag remove <path-or-uuid> [--yes] |
| 58 | +``` |
| 59 | + |
| 60 | +### Search & Query |
| 61 | + |
| 62 | +**Hybrid search:** |
| 63 | +```bash |
| 64 | +sqlite-rag search "your query" [--limit 10] [--debug] |
| 65 | +``` |
| 66 | + |
| 67 | +Use `--debug` to see detailed ranking information including vector ranks, FTS ranks, and combined scores. |
| 68 | + |
| 69 | +### Database Operations |
| 70 | + |
| 71 | +**Rebuild indexes and embeddings:** |
| 72 | +```bash |
| 73 | +sqlite-rag rebuild [--remove-missing] |
7 | 74 | ``` |
| 75 | + |
| 76 | +**Clear entire database:** |
| 77 | +```bash |
| 78 | +sqlite-rag reset [--yes] |
| 79 | +``` |
| 80 | + |
| 81 | +### Configuration |
| 82 | + |
| 83 | +**View current settings:** |
| 84 | +```bash |
| 85 | +sqlite-rag settings |
| 86 | +``` |
| 87 | + |
| 88 | +**Update configuration:** |
| 89 | +```bash |
| 90 | +sqlite-rag set [options] |
| 91 | +``` |
| 92 | + |
| 93 | +Available settings: |
| 94 | +- `--model-path-or-name`: Embedding model (file path or HuggingFace model) |
| 95 | +- `--embedding-dim`: Vector dimensions |
| 96 | +- `--chunk-size`: Text chunk size (tokens) |
| 97 | +- `--chunk-overlap`: Token overlap between chunks |
| 98 | +- `--weight-fts`: Full-text search weight (0.0-1.0) |
| 99 | +- `--weight-vec`: Vector search weight (0.0-1.0) |
| 100 | +- `--quantize-scan`: Enable quantized vectors for faster search |
| 101 | +- `--quantize-preload`: Preload quantized vectors in memory |
| 102 | + |
| 103 | +## Python API |
| 104 | + |
| 105 | +```python |
| 106 | +from sqlite_rag import SQLiteRag |
| 107 | + |
| 108 | +# Create RAG instance |
| 109 | +rag = SQLiteRag.create("./database.sqlite") |
| 110 | + |
| 111 | +# Add documents |
| 112 | +rag.add("/path/to/documents", recursive=True) |
| 113 | +rag.add_text("Raw text content", uri="doc.txt") |
| 114 | + |
| 115 | +# Search |
| 116 | +results = rag.search("search query", top_k=5) |
| 117 | +for result in results: |
| 118 | + print(f"Score: {result.score}") |
| 119 | + print(f"Content: {result.content}") |
| 120 | + print(f"URI: {result.uri}") |
| 121 | + |
| 122 | +# List documents |
| 123 | +documents = rag.list_documents() |
| 124 | + |
| 125 | +# Remove document |
| 126 | +rag.remove_document("document-id-or-path") |
| 127 | + |
| 128 | +# Database operations |
| 129 | +rag.rebuild(remove_missing=True) |
| 130 | +rag.reset() |
| 131 | +``` |
| 132 | + |
| 133 | +## Supported File Formats |
| 134 | + |
| 135 | +SQLite-RAG supports 25+ file formats through the MarkItDown library: |
| 136 | + |
| 137 | +- **Text**: `.txt`, `.md`, `.csv`, `.json`, `.xml` |
| 138 | +- **Documents**: `.pdf`, `.docx`, `.pptx`, `.xlsx` |
| 139 | +- **Code**: `.py`, `.js`, `.html`, `.css`, `.sql` |
| 140 | +- **And many more**: `.rtf`, `.odt`, `.epub`, `.zip`, etc. |
| 141 | + |
| 142 | +## How It Works |
| 143 | + |
| 144 | +1. **Document Processing**: Files are processed and split into overlapping chunks |
| 145 | +2. **Embedding Generation**: Text chunks are converted to vector embeddings using AI models |
| 146 | +3. **Dual Indexing**: Content is indexed for both vector similarity and full-text search |
| 147 | +4. **Hybrid Search**: Queries are processed through both search methods |
| 148 | +5. **Result Fusion**: Results are combined using Reciprocal Rank Fusion for optimal relevance |
| 149 | + |
| 150 | +## Default Configuration |
| 151 | + |
| 152 | +- **Model**: Qwen3-Embedding-0.6B (Q8_0 quantized, 1024 dimensions) |
| 153 | +- **Chunking**: 12,000 tokens per chunk with 1,200 token overlap |
| 154 | +- **Vectors**: FLOAT16 storage with cosine similarity |
| 155 | +- **Search**: Equal weighting (1.0) for vector and full-text results |
| 156 | +- **Database**: `./sqliterag.sqlite` |
| 157 | + |
| 158 | +## Extensions Required |
| 159 | + |
| 160 | +SQLite-RAG requires these SQLite extensions: |
| 161 | + |
| 162 | +- **[sqlite-ai](https://github.com/sqliteai/sqlite-ai)**: LLM model loading and embedding generation |
| 163 | +- **[sqlite-vector](https://github.com/sqliteai/sqlite-vector)**: Vector storage and similarity search |
| 164 | + |
| 165 | +These are automatically installed as dependencies. |
0 commit comments