ScoutRAG
Active-exploration RAG agent that refuses to answer from an empty or thin index.
When a question arrives, ScoutRAG checks what its local vector index actually covers. If coverage is thin or empty, it does not hallucinate from model weights—it plans search queries, searches DuckDuckGo HTML, fetches live web pages politely with headless Playwright, chunks and embeds them locally into sqlite-vec, and synthesizes a grounded answer where every factual claim cites a page actually fetched in SQLite. If the fetched pages don't contain the answer, it replies "I could not find that in the sources I fetched." with zero citations.
Architecture & Deliberate Trade-offs
| Layer | Choice | Why (1-week solo developer tool) |
|---|---|---|
| Embeddings | sentence-transformers/all-MiniLM-L6-v2 (CPU) |
Zero API keys, zero network latency per chunk, reproducible locally. |
| Chunking | ~256 tokens / 50-token overlap | Deliberate deviation from ~500 tokens: all-MiniLM-L6-v2 silently truncates inputs past 256 wordpiece tokens. Sizing chunks to ~256 tokens ensures 100% of every chunk is represented in its embedding, while top-5 retrieval still provides ~1,250 tokens of synthesis context. |
| Vector Store | sqlite-vec |
Single inspectable local SQLite file (~/.scoutrag/scoutrag.db) alongside source metadata and fetch timestamps—no separate vector DB server. |
| Search (Default) | DuckDuckGo HTML (html.duckduckgo.com/html/) |
Zero search API keys required. If DDG returns HTTP 202 or a human-verification challenge, ScoutRAG stops immediately (never retries or falls back to another DDG endpoint) and surfaces an explicit "Search unavailable" error (HTTP 503 / CLI exit 1). |
| Search (Opt-in CC) | Common Crawl (SCOUTRAG_SEARCH=commoncrawl) |
Free, open, zero API key or card required. Resolves the latest crawl from collinfo.json and queries its CDX index. Snapshot data (weeks old, not live) and URL-pattern matching (not keyword ranking) — works best when questions name target domains; returns no candidates (not_found) if no domain is named. |
| Search (Opt-in Brave) | Brave Search API (SCOUTRAG_SEARCH_API_KEY) |
Optional sanctioned JSON API (api.search.brave.com/res/v1/web/search) used when SCOUTRAG_SEARCH=brave or SCOUTRAG_SEARCH_API_KEY is set. Brave provides $5/month in free credits (~1,000 queries/month) after payment-card verification at signup. |
| Fetcher | Headless Playwright (Chromium) | Handles JS-rendered docs; hard-capped at 8 pages/question, 15s timeout/page, 1s per-host gap, robots.txt enforced, stops host on HTTP 429. |
| LLM (Default) | Local Ollama (qwen2.5:7b) |
Runs 100% locally with no API keys set. |
| LLM (Opt-in) | Gemini API (SCOUTRAG_LLM=gemini + GEMINI_API_KEY) |
Strictly opt-in only. Even if GEMINI_API_KEY is in your shell, Ollama stays active unless SCOUTRAG_LLM=gemini is explicitly set. Setting the flag without a key fails loudly instead of falling back. |
Pipeline Flow
- Coverage Gate (
scoutrag/coverage.py): Embeds the question, retrieves top-10 non-stale chunks, countshits(similarity >= 0.35) andbest_similarity. Routes toINDEXonly ifhits >= 3andbest_similarity >= 0.45; otherwiseEXPLORE. - Exploration Planner (
scoutrag/planner.py): One LLM call generates 2–4 search queries (hard-capped at 4), optionaltarget_domains(only if named in the question), andstop_if, then routes to DuckDuckGo HTML by default (SCOUTRAG_SEARCH=duckduckgo), Common Crawl (SCOUTRAG_SEARCH=commoncrawl), or Brave Search (SCOUTRAG_SEARCH=brave/SCOUTRAG_SEARCH_API_KEY), interleaving URLs round-robin. If DDG returns HTTP202or a challenge page, ScoutRAG halts immediately with"Search unavailable". - Polite Fetcher (
scoutrag/fetcher.py): Checksrobots.txtper host, enforces ≥1s gap per host, aborts a host on429, fetches up to 8 pages (15stimeout), and strips nav/ads/scripts/chrome. - Indexer (
scoutrag/indexer.py): Deduplicates chunks by(url, sha256), refreshes timestamps on re-fetch without duplicating vectors, and excludes chunks older than 7 days (stale_countexposed in API & UI). - Answerer (
scoutrag/answerer.py): Retrieves top-5 non-stale chunks, runs one strictly grounded LLM call, programmatically verifies every[n]citation againstsourcesin SQLite, and forces exact refusal if no verified citation exists. - Observability (
scoutrag/logging_utils.py): Appends 1 JSON line per question to~/.scoutrag/queries.jsonl.
Setup
1. Python environment & package
python3.12 -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"
2. Playwright Chromium
playwright install chromium
3. Local LLM via Ollama (qwen2.5:7b)
brew install ollama
ollama serve &
ollama pull qwen2.5:7b
Usage
Web UI & API Server
scoutrag serve
# Open http://127.0.0.1:8000
Endpoints:
POST /ask—{"question": "..."}→{"answer", "route", "coverage", "fetched_pages", "citations", "latency_ms", "queries"}GET /index— indexed sources, chunk counts, fetch times, andstale_countDELETE /index— clear the local index
CLI
scoutrag ask "How do you configure timeouts in Python HTTPX?"
scoutrag index --list
scoutrag index --clear
Opt-in Common Crawl Discovery (Free, Keyless, No Card)
If DuckDuckGo gates automated requests and you want a 100% free, open, zero-key discovery backend, set SCOUTRAG_SEARCH=commoncrawl:
export SCOUTRAG_SEARCH=commoncrawl
scoutrag ask "According to flask.palletsprojects.com, what are blueprints in Flask intended for?"
Important characteristics of the Common Crawl backend:
- Free & open: Uses
https://index.commoncrawl.org/collinfo.jsonand the latest CDX index API with no API key or payment card. - Snapshot data: Reflects the latest completed Common Crawl snapshot (typically weeks old, not live real-time web results).
- URL-pattern matching, not keyword ranking: Matches domains and URL slugs rather than full-text page relevance, so it works best when the question explicitly names a domain (allowing the planner to emit
target_domains). If the planner names no domains, it returns no candidates (not_found) and never falls back to DuckDuckGo.
Opt-in Brave Search API (Optional)
ScoutRAG defaults to keyless DuckDuckGo HTML so the local demo requires zero API keys. However, automated IPs may occasionally be gated by DuckDuckGo (HTTP 202 / challenge), which causes ScoutRAG to stop with a clear "Search unavailable" error (503).
To use the sanctioned Brave Search API instead:
- Sign up at Brave Search API (Brave includes $5/month in free credits — ~1,000 search queries/month — and requires payment-card verification during account creation).
- Export your token:
export SCOUTRAG_SEARCH_API_KEY="your-brave-subscription-token"
scoutrag ask "Your question"
Opt-in Gemini Backend
Ollama (qwen2.5:7b) is always the default—even if GEMINI_API_KEY is exported. To opt in to Gemini:
export SCOUTRAG_LLM=gemini
export GEMINI_API_KEY="your-key-here"
scoutrag ask "Your question"
If SCOUTRAG_LLM=gemini is set without GEMINI_API_KEY, ScoutRAG exits with a clear configuration error instead of falling back silently.
Configuration Environment Variables
SCOUTRAG_DATA_DIR(default:~/.scoutrag)SCOUTRAG_DB_PATH(default:~/.scoutrag/scoutrag.db)SCOUTRAG_LOG_PATH(default:~/.scoutrag/queries.jsonl)SCOUTRAG_SEARCH(default:duckduckgo; supportscommoncrawlandbrave)SCOUTRAG_CC_COLLINFO_URL(default:https://index.commoncrawl.org/collinfo.json)SCOUTRAG_SEARCH_API_KEY(unset by default; enables opt-in Brave Search API)SCOUTRAG_DDG_URL(default:https://html.duckduckgo.com/html/)SCOUTRAG_BRAVE_URL(default:https://api.search.brave.com/res/v1/web/search)SCOUTRAG_LLM(unset orollamaby default;geminiopt-in)SCOUTRAG_OLLAMA_URL(default:http://localhost:11434)SCOUTRAG_OLLAMA_MODEL(default:qwen2.5:7b)SCOUTRAG_GEMINI_MODEL(default:gemini-2.5-flash)
Running Tests
pytest
See demo/script.md for the ~2-minute walkthrough.
Metadata
Release files for scoutrag 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| scoutrag-0.1.0.tar.gz | 42.2 kB | Without provenance | Details for scoutrag-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| scoutrag-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for scoutrag-0.1.0-py3-none-any.whl |
Total release size: 77.1 kB
Release files / scoutrag-0.1.0.tar.gz
| Download URL | scoutrag-0.1.0.tar.gz |
|---|---|
| Size | 42.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
58c3a45ea66e72f80107f05d26a852438860eec3cb38f62359e48d0df7f56624
|
|
BLAKE2b-256 checksum How to use checksums |
4ac065e5ec7762468d4699f17d3304838dfeabd0ba993a690c47d6fe00eb9623
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.16
|
Release files / scoutrag-0.1.0-py3-none-any.whl
| Download URL | scoutrag-0.1.0-py3-none-any.whl |
|---|---|
| Size | 34.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
35a3376cbf24286743437d6af1c9f4266969bdf44d8bc2268c0344e0c17cae0c
|
|
BLAKE2b-256 checksum How to use checksums |
00e142714b60b4cc7bf0e447454dbaa759a92930309ada070c6987de8e64d761
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.16
|
Security for scoutrag 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.