Skip to main content

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

  1. Coverage Gate (scoutrag/coverage.py): Embeds the question, retrieves top-10 non-stale chunks, counts hits (similarity >= 0.35) and best_similarity. Routes to INDEX only if hits >= 3 and best_similarity >= 0.45; otherwise EXPLORE.
  2. Exploration Planner (scoutrag/planner.py): One LLM call generates 2–4 search queries (hard-capped at 4), optional target_domains (only if named in the question), and stop_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 HTTP 202 or a challenge page, ScoutRAG halts immediately with "Search unavailable".
  3. Polite Fetcher (scoutrag/fetcher.py): Checks robots.txt per host, enforces ≥1s gap per host, aborts a host on 429, fetches up to 8 pages (15s timeout), and strips nav/ads/scripts/chrome.
  4. 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_count exposed in API & UI).
  5. Answerer (scoutrag/answerer.py): Retrieves top-5 non-stale chunks, runs one strictly grounded LLM call, programmatically verifies every [n] citation against sources in SQLite, and forces exact refusal if no verified citation exists.
  6. 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, and stale_count
  • DELETE /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.json and 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:

  1. 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).
  2. 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; supports commoncrawl and brave)
  • 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 or ollama by default; gemini opt-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.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for scoutrag 0.1.1
File Size Uploaded Provenance Actions
scoutrag-0.1.1.tar.gz 46.6 kB Without provenance Details for scoutrag-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for scoutrag 0.1.1
File Interpreter ABI Platform Actions
scoutrag-0.1.1-py3-none-any.whl Python 3 none any Details for scoutrag-0.1.1-py3-none-any.whl

Total release size: 85.9 kB

Release files / scoutrag-0.1.1.tar.gz

Download URL scoutrag-0.1.1.tar.gz
Size 46.6 kB
Tags Source
SHA-256 checksum
How to use checksums
0e4e7d243fb01d71bf6124eaeba63f601ed786a64600a7a55d0d042a5ef4b897
BLAKE2b-256 checksum
How to use checksums
21b4eea3bf3ede7dfb5c652e1b6f87226d1b8ae94733ac4c4644503c5e826838
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.1-py3-none-any.whl

Download URL scoutrag-0.1.1-py3-none-any.whl
Size 39.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
802654fa180260077d8ad799d5a99cdf95e2113ddc02189b07b6bddab9607056
BLAKE2b-256 checksum
How to use checksums
bc7ca9f33d869e9dd58b0617052efaeea06e4fb97d1d48cb00a54d9ae54533fe
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.1

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.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page