Adding MVP section

This commit is contained in:
User 2026-07-05 21:10:03 -07:00
parent 2ca9ad2948
commit 6d7e401188

178
PRD.md
View file

@ -1,6 +1,6 @@
# PRD — Local Web Search Stack (LWSS) # PRD — Local Web Search Stack (LWSS)
**Status:** Draft v1 **Status:** Draft v2 (MVP-scoped)
**Owner:** Neil **Owner:** Neil
**Last updated:** 2026-07-05 **Last updated:** 2026-07-05
@ -16,36 +16,67 @@ The stack is decomposed into single-responsibility Docker services so each layer
is independently deployable, testable, and debuggable. No third-party SaaS sits is independently deployable, testable, and debuggable. No third-party SaaS sits
in the request hot path. in the request hot path.
### MVP framing
The end goal is **private + free + reliable + high-quality**. The **MVP
deliberately sequences reliability and quality first**, deferring the
privacy/cost-distribution work (SearXNG rotation, VPS obfuscation, config UI).
The MVP runs **entirely on one local machine** and must be **usable as a drop-in
replacement for Tavily API calls** — that is the acceptance bar.
Quality is raised by an **LLM stage** (reranking candidate results before render,
and cleaning extracted content after), which is the only stage that needs the
good (single) GPU machine. Inference targets a **configurable OpenAI-compatible
endpoint**, so future remote deployments of the stack point *just that portion*
at the GPU machine (exposed via Tailscale/Cloudflared) while everything else runs
on modest hardware.
## 2. Goals ## 2. Goals
- Provide a Serper/Tavily/Firecrawl-equivalent API backed only by - Provide a Serper/Tavily/Firecrawl-equivalent API backed only by
self-hostable/free components. self-hostable/free components.
- **Privacy:** no commercial SaaS sees queries or scraped content. Search - **Reliability (MVP priority):** the pipeline doesn't fall over — retries,
reaches the open web via SearXNG, with query origin obfuscated by rotating timeouts, health checks, graceful partial results, caching. No single stage
across public + self-hosted SearXNG instances on rotating VPSs. (including the LLM endpoint) is a hard dependency; degrade instead of fail.
- **Modularity:** four core layers (`searcher`, `renderer`, `extractor`, - **Quality (MVP priority):** results return meaningful content, not render
failures or boilerplate. LLM reranking filters junk before render; LLM cleaning
guarantees high-quality markdown after extraction.
- **Modularity:** core layers (`searcher`, `renderer`, `extractor`, `llm`,
`formatter`) as separate containers, each curl-able in isolation. `formatter`) as separate containers, each curl-able in isolation.
- **Debuggability:** structured logging, `/health` on every service, per-stage - **Debuggability:** structured logging, `/health` on every service, per-stage
timing/trace in orchestrator responses. timing/trace in orchestrator responses.
- **Cost:** zero recurring SaaS cost; minimal external dependencies. - **Privacy (end goal, deferred past MVP):** no commercial SaaS sees queries or
scraped content; query origin obfuscated by rotating across public +
self-hosted SearXNG instances on rotating VPSs. MVP runs a single local
instance (see §4).
- **Cost (end goal):** zero recurring SaaS cost; minimal external dependencies.
The one paid resource is compute (VPS subscription or self-owned hardware),
never per-call API fees.
## 3. Non-Goals (v1) ## 3. Non-Goals (MVP)
- Answer synthesis / RAG generation — that is the downstream local LLM's job. - Answer synthesis / RAG generation — that is the downstream local LLM's job.
- LLM-powered schema extraction (Firecrawl `/extract` structured mode). - **LLM-powered _structured/schema_ extraction** (Firecrawl `/extract` structured
mode). Note: LLM **reranking** and **content cleaning** ARE in scope (see §6.6);
only structured-schema output is deferred.
- Truly airgapped search or a self-built web index — search is open-web only. - Truly airgapped search or a self-built web index — search is open-web only.
- Anti-bot/CAPTCHA defeat, residential proxy pools. Partial coverage is accepted. - Anti-bot/CAPTCHA defeat, residential proxy pools. Partial coverage is accepted.
- Multi-tenant auth / user accounts. - Multi-tenant auth / user accounts.
- SearXNG instance rotation / fan-out / VPS obfuscation and the config UI —
deferred past MVP (see §4, §10). MVP uses a single local instance.
## 4. Privacy & Threat Model ## 4. Privacy & Threat Model
- **Boundary:** "no SaaS logs my queries/content against my identity," **not** - **Boundary:** "no SaaS logs my queries/content against my identity," **not**
"airgapped." Queries still reach public search engines via SearXNG upstreams. "airgapped." Queries still reach public search engines via SearXNG upstreams.
- **Obfuscation:** searcher rotates across a configurable pool of SearXNG - **MVP:** a **single local self-hosted SearXNG** instance (now a **required**
instances (public + private self-hosted on rotating VPSs) to spread and container). No rotation, fan-out, or obfuscation yet — but the searcher keeps
obscure query origin. the **file-based instance-list abstraction** (§6.2) so rotation drops in later
- Self-hosted SearXNG instances are treated as **external** clients on VPSs; the with no refactor.
stack ships an optional reference SearXNG container but does not require it. - **End goal (deferred, see §10):** searcher rotates across a configurable pool of
SearXNG instances (public + private self-hosted on rotating VPSs) to spread and
obscure query origin. Self-hosted instances are then treated as **external**
clients on VPSs.
## 5. Architecture ## 5. Architecture
@ -54,29 +85,36 @@ in the request hot path.
│ │
▼ ▼
┌───────────────┐ public API (only exposed port) ┌───────────────┐ public API (only exposed port)
│ ORCHESTRATOR │ drives search → render → extract → format │ ORCHESTRATOR │ search → LLM rerank → render → extract → LLM clean → format
└──┬───┬───┬──┬─┘ └─┬──┬──┬──┬──┬─┘
│ │ │ └────────────────────────────┐ │ │ │ │ └──────────────────────────────────────┐
▼ ▼ ▼ ▼ ▼ │ │ │ ▼
┌────────┐ ┌─────────┐ ┌───────────┐ ┌───────────┐ ┌────────┐│ │ │ ┌───────────┐
│SEARCHER│ │RENDERER │ │ EXTRACTOR │ │ FORMATTER │ │SEARCHER││ │ │ │ FORMATTER │
│+configUI│ │Playwright│ │Trafilatura│ │ md+chunk │ └───┬────┘│ │ │ │ md+chunk │
└───┬────┘ └─────────┘ └───────────┘ └───────────┘ │ ▼ │ ▼ └───────────┘
│ ▲ SearXNG ┌─────────┐ ┌───────────┐
SearXNG pool │ (local) │RENDERER │ │ EXTRACTOR │ ┌──────────────────────────┐
(public + VPS) ┌─────────┐ │Playwright│ │Trafilatura│ │ LLM │
│ REDIS │ shared cache (search + rendered HTML) + health stats └─────────┘ └───────────┘ │ /rerank + /clean │
└─────────┘ ▲ │ OpenAI-compatible client │
│ │ (configurable endpoint) │
┌─────────┐ └──────────────────────────┘
│ REDIS │ shared cache (search + rendered HTML)
└─────────┘
``` ```
**Containers (7):** orchestrator, searcher, renderer, extractor, formatter, **Containers (8):** orchestrator, searcher, **searxng (required, local)**,
redis, (optional) reference searxng. renderer, extractor, **llm**, formatter, redis.
**Invariants:** **Invariants:**
- Workers are stateless and independently testable. - Workers are stateless and independently testable.
- Only shared state: Redis (cache + ephemeral health) and the searcher's - Only shared state: Redis (cache + ephemeral health) and the searcher's
instance-list file. instance-list file.
- Orchestrator is the only externally exposed service. - Orchestrator is the only externally exposed service.
- **The LLM is the only inference-heavy stage; its endpoint is independently
repointable** (env-configured OpenAI-compatible base URL), and the pipeline
degrades gracefully if it is unreachable.
## 6. Service Specifications ## 6. Service Specifications
@ -87,8 +125,9 @@ redis, (optional) reference searxng.
- **Endpoints:** - **Endpoints:**
- `POST /search` — results only (Serper-like): `{query, options}` → - `POST /search` — results only (Serper-like): `{query, options}` →
`{results: [{url,title,snippet,rank,source_instance}], trace}`. `{results: [{url,title,snippet,rank,source_instance}], trace}`.
- `POST /search/contents` — full flow (Tavily+Firecrawl-like): search → render - `POST /search/contents` — **(MVP primary)** full flow (Tavily-like): search →
→ extract → format for top-N results → `{results:[{...,markdown,chunks}], trace}`. **LLM rerank** → render → extract → **LLM clean** → format for top-N results →
`{results:[{...,markdown,chunks}], trace}`.
- `POST /scrape` — per-URL: render → extract → format for a given URL. - `POST /scrape` — per-URL: render → extract → format for a given URL.
- `GET /health`. - `GET /health`.
- Every response includes a `trace` with per-stage timing and cache hit/miss. - Every response includes a `trace` with per-stage timing and cache hit/miss.
@ -98,15 +137,18 @@ redis, (optional) reference searxng.
- **Responsibility:** query the SearXNG instance pool, normalize + dedup results, - **Responsibility:** query the SearXNG instance pool, normalize + dedup results,
track instance health, serve the config UI. track instance health, serve the config UI.
- **Rotation (configurable):** - **Rotation (configurable):**
- `failover` (default): one healthy instance per query, fail over on error. - `failover` (default, **MVP: only mode**): one healthy instance per query, fail
- `fanout`: query N instances in parallel, dedup by URL, merge/reconcile rank. over on error. MVP points at a single local SearXNG, so this is effectively a
Fan-out width is a setting. single-instance path — but the code reads the instance list from the file so
- **Health tracking:** per-instance success rate, latency, last-failure, in Redis; fan-out drops in later without refactor.
used for weighted selection and surfaced in the UI. - `fanout` (**post-MVP**): query N instances in parallel, dedup by URL,
- **Instance list persistence:** mounted YAML/JSON file (git-friendly, hand-editable, merge/reconcile rank. Fan-out width is a setting.
survives rebuilds). UI performs CRUD over this file. - **Health tracking (post-MVP):** per-instance success rate, latency, last-failure,
- **Config UI (v1 scope):** CRUD instance list + live health/status table in Redis; used for weighted selection and surfaced in the UI.
(last check, success rate, latency). Per-instance engine config / auth = v2. - **Instance list persistence (MVP):** mounted YAML/JSON file (git-friendly,
hand-editable, survives rebuilds). Kept even in the single-instance MVP.
- **Config UI (post-MVP):** CRUD instance list + live health/status table
(last check, success rate, latency). Per-instance engine config / auth later still.
- **Output contract:** `{url, title, snippet, rank, source_instance}`. - **Output contract:** `{url, title, snippet, rank, source_instance}`.
### 6.3 Renderer ### 6.3 Renderer
@ -132,7 +174,28 @@ redis, (optional) reference searxng.
- **Contract:** `{title, text, main_html, metadata}` → - **Contract:** `{title, text, main_html, metadata}` →
`{markdown, chunks: [{text, index, tokens}]}`. `{markdown, chunks: [{text, index, tokens}]}`.
### 6.6 Redis ### 6.6 LLM service
- **Runtime:** Python / FastAPI, thin **OpenAI-compatible client** (works with
Ollama, llama.cpp, vLLM, LM Studio, etc.).
- **Responsibility:** the only inference-heavy stage; owns all prompt templates,
endpoint config, retry/timeout behavior. Two jobs:
- `POST /rerank` — `{query, candidates:[{url,title,snippet,rank}]}` →
`{ranked:[{url,relevance,keep}]}`. Filters junk / off-topic results **before**
render so renders aren't wasted. Runs after search, before render.
- `POST /clean` — `{title, text, main_html, metadata, query?}` →
`{clean_text}`. Polishes/repairs extracted content into high-quality,
boilerplate-free text. Runs after extract, before format.
- **Config (env-driven):** `OPENAI_BASE_URL`, `OPENAI_API_KEY`, `LLM_MODEL`,
per-endpoint timeout + max retries. MVP defaults to `localhost`; remote stack
deployments override `OPENAI_BASE_URL` to reach the GPU machine via
Tailscale/Cloudflared. **This is the only container a remote deployment repoints.**
- **Graceful degradation (reliability):** if the endpoint is unreachable or times
out, `/rerank` falls back to the original SearXNG rank (keep all) and `/clean`
falls back to the Trafilatura text unchanged. The pipeline never hard-fails on
the LLM.
- `GET /health` reports endpoint reachability + model.
### 6.7 Redis
- Shared cache: search results (short TTL), rendered HTML (medium TTL). - Shared cache: search results (short TTL), rendered HTML (medium TTL).
- Ephemeral instance-health stats. - Ephemeral instance-health stats.
@ -148,7 +211,9 @@ redis, (optional) reference searxng.
- **Logging:** structured JSON on every service. - **Logging:** structured JSON on every service.
- **Health:** `GET /health` on every service; orchestrator aggregates. - **Health:** `GET /health` on every service; orchestrator aggregates.
- **Tracing:** per-stage timings + cache hit/miss returned to caller. - **Tracing:** per-stage timings + cache hit/miss returned to caller.
- **Config:** env-driven; instance list via mounted file. - **Config:** env-driven; instance list via mounted file. The LLM inference
endpoint (`OPENAI_BASE_URL` / `LLM_MODEL`) is independently repointable so the
inference-heavy stage can live on separate hardware from the rest of the stack.
- **Resource limits:** per-container CPU/RAM limits in compose; renderer - **Resource limits:** per-container CPU/RAM limits in compose; renderer
concurrency cap enforced. concurrency cap enforced.
- **Politeness:** per-domain rate limiting; caching to reduce upstream load/bans. - **Politeness:** per-domain rate limiting; caching to reduce upstream load/bans.
@ -163,22 +228,29 @@ redis, (optional) reference searxng.
handled by health tracking + rotation. handled by health tracking + rotation.
- No answer synthesis in-stack (by design). - No answer synthesis in-stack (by design).
## 10. Open Questions / Future (v2+) ## 10. Open Questions / Future (post-MVP)
- **Privacy/cost end goal:** multi-instance rotation, fan-out search, weighted
health-based selection, public + VPS instance pool, query-origin obfuscation,
and cost distribution across VPSs / friends' hardware.
- **Config UI:** instance CRUD + live health table; per-instance engine config +
authenticated private instances.
- Optional message queue for batch crawl jobs. - Optional message queue for batch crawl jobs.
- LLM-powered structured extraction endpoint. - LLM-powered **structured/schema** extraction endpoint.
- Conditional rendering (fetch-first escalation) as an optimization if always-render - Conditional rendering (fetch-first escalation) as an optimization if always-render
proves too heavy. proves too heavy.
- Per-instance engine config + authenticated private instances in the UI.
- Local private-corpus index (hybrid open-web + private). - Local private-corpus index (hybrid open-web + private).
## 11. Milestones (proposed) ## 11. Milestones (MVP: reliability + quality first)
1. **M1 — Skeleton:** compose file, 7 services stubbed, `/health` everywhere, 1. **M1 — Scrape spine:** compose up; `/scrape` (render → extract → format for one
end-to-end `/scrape` passing (render → extract → format for one URL). URL); `/health` everywhere; Redis render cache. Proves the quality path.
2. **M2 — Search:** searcher with single-instance failover + normalized contract; 2. **M2 — LLM clean:** add LLM service `/clean`; wire into `/scrape`; configurable
`/search` working; instance list from file. OpenAI-compatible endpoint; graceful fallback to Trafilatura-only.
3. **M3 — Full pipeline:** `/search/contents` wiring all stages; Redis caching; 3. **M3 — Search + rerank:** single local SearXNG + searcher (file-based, failover);
response traces. LLM `/rerank`; `/search` working.
4. **M4 — Rotation + UI:** fan-out mode, health tracking, config UI. 4. **M4 — Tavily parity:** `/search/contents` wiring all stages end-to-end with
5. **M5 — Hardening:** rate limiting, resource limits, timeouts, docs. per-stage traces + caching. **MVP acceptance: usable as a Tavily drop-in.**
5. **M5 — Hardening:** retries, per-domain rate limiting, resource limits, timeouts,
docs.
6. **Post-MVP:** rotation/fan-out, VPS obfuscation, config UI (see §10).