Initial commit: Add product requirements document
This commit is contained in:
commit
2ca9ad2948
1 changed files with 184 additions and 0 deletions
184
PRD.md
Normal file
184
PRD.md
Normal file
|
|
@ -0,0 +1,184 @@
|
|||
# PRD — Local Web Search Stack (LWSS)
|
||||
|
||||
**Status:** Draft v1
|
||||
**Owner:** Neil
|
||||
**Last updated:** 2026-07-05
|
||||
|
||||
---
|
||||
|
||||
## 1. Summary
|
||||
|
||||
A containerized, self-hosted stack that provides the capabilities of Serper
|
||||
(search), Tavily (LLM-optimized retrieval), and Firecrawl (render + extract +
|
||||
clean) **fully locally and privately**, purpose-built to feed a local LLM.
|
||||
|
||||
The stack is decomposed into single-responsibility Docker services so each layer
|
||||
is independently deployable, testable, and debuggable. No third-party SaaS sits
|
||||
in the request hot path.
|
||||
|
||||
## 2. Goals
|
||||
|
||||
- Provide a Serper/Tavily/Firecrawl-equivalent API backed only by
|
||||
self-hostable/free components.
|
||||
- **Privacy:** no commercial SaaS sees queries or scraped content. Search
|
||||
reaches the open web via SearXNG, with query origin obfuscated by rotating
|
||||
across public + self-hosted SearXNG instances on rotating VPSs.
|
||||
- **Modularity:** four core layers (`searcher`, `renderer`, `extractor`,
|
||||
`formatter`) as separate containers, each curl-able in isolation.
|
||||
- **Debuggability:** structured logging, `/health` on every service, per-stage
|
||||
timing/trace in orchestrator responses.
|
||||
- **Cost:** zero recurring SaaS cost; minimal external dependencies.
|
||||
|
||||
## 3. Non-Goals (v1)
|
||||
|
||||
- Answer synthesis / RAG generation — that is the downstream local LLM's job.
|
||||
- LLM-powered schema extraction (Firecrawl `/extract` structured mode).
|
||||
- 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.
|
||||
- Multi-tenant auth / user accounts.
|
||||
|
||||
## 4. Privacy & Threat Model
|
||||
|
||||
- **Boundary:** "no SaaS logs my queries/content against my identity," **not**
|
||||
"airgapped." Queries still reach public search engines via SearXNG upstreams.
|
||||
- **Obfuscation:** searcher rotates across a configurable pool of SearXNG
|
||||
instances (public + private self-hosted on rotating VPSs) to spread and
|
||||
obscure query origin.
|
||||
- Self-hosted SearXNG instances are treated as **external** clients on VPSs; the
|
||||
stack ships an optional reference SearXNG container but does not require it.
|
||||
|
||||
## 5. Architecture
|
||||
|
||||
```
|
||||
client / local LLM
|
||||
│
|
||||
▼
|
||||
┌───────────────┐ public API (only exposed port)
|
||||
│ ORCHESTRATOR │ drives search → render → extract → format
|
||||
└──┬───┬───┬──┬─┘
|
||||
│ │ │ └────────────────────────────┐
|
||||
▼ ▼ ▼ ▼
|
||||
┌────────┐ ┌─────────┐ ┌───────────┐ ┌───────────┐
|
||||
│SEARCHER│ │RENDERER │ │ EXTRACTOR │ │ FORMATTER │
|
||||
│+configUI│ │Playwright│ │Trafilatura│ │ md+chunk │
|
||||
└───┬────┘ └─────────┘ └───────────┘ └───────────┘
|
||||
│ ▲
|
||||
SearXNG pool │
|
||||
(public + VPS) ┌─────────┐
|
||||
│ REDIS │ shared cache (search + rendered HTML) + health stats
|
||||
└─────────┘
|
||||
```
|
||||
|
||||
**Containers (7):** orchestrator, searcher, renderer, extractor, formatter,
|
||||
redis, (optional) reference searxng.
|
||||
|
||||
**Invariants:**
|
||||
- Workers are stateless and independently testable.
|
||||
- Only shared state: Redis (cache + ephemeral health) and the searcher's
|
||||
instance-list file.
|
||||
- Orchestrator is the only externally exposed service.
|
||||
|
||||
## 6. Service Specifications
|
||||
|
||||
### 6.1 Orchestrator (API Gateway)
|
||||
- **Runtime:** Python / FastAPI.
|
||||
- **Responsibility:** expose the public API, run the pipeline, aggregate
|
||||
per-stage traces, handle errors/partial results.
|
||||
- **Endpoints:**
|
||||
- `POST /search` — results only (Serper-like): `{query, options}` →
|
||||
`{results: [{url,title,snippet,rank,source_instance}], trace}`.
|
||||
- `POST /search/contents` — full flow (Tavily+Firecrawl-like): search → render
|
||||
→ extract → format for top-N results → `{results:[{...,markdown,chunks}], trace}`.
|
||||
- `POST /scrape` — per-URL: render → extract → format for a given URL.
|
||||
- `GET /health`.
|
||||
- Every response includes a `trace` with per-stage timing and cache hit/miss.
|
||||
|
||||
### 6.2 Searcher
|
||||
- **Runtime:** Python / FastAPI (or Node — TBD at impl; Python default).
|
||||
- **Responsibility:** query the SearXNG instance pool, normalize + dedup results,
|
||||
track instance health, serve the config UI.
|
||||
- **Rotation (configurable):**
|
||||
- `failover` (default): one healthy instance per query, fail over on error.
|
||||
- `fanout`: query N instances in parallel, dedup by URL, merge/reconcile rank.
|
||||
Fan-out width is a setting.
|
||||
- **Health tracking:** per-instance success rate, latency, last-failure, in Redis;
|
||||
used for weighted selection and surfaced in the UI.
|
||||
- **Instance list persistence:** mounted YAML/JSON file (git-friendly, hand-editable,
|
||||
survives rebuilds). UI performs CRUD over this file.
|
||||
- **Config UI (v1 scope):** CRUD instance list + live health/status table
|
||||
(last check, success rate, latency). Per-instance engine config / auth = v2.
|
||||
- **Output contract:** `{url, title, snippet, rank, source_instance}`.
|
||||
|
||||
### 6.3 Renderer
|
||||
- **Runtime:** Node / raw Playwright (no external browser service).
|
||||
- **Responsibility:** URL → fully-rendered HTML. Always renders.
|
||||
- **Concurrency control:** single browser, pooled contexts, hard concurrency cap
|
||||
+ request queue.
|
||||
- **Wait policy:** configurable (`networkidle` / fixed delay / selector) with a
|
||||
hard per-page timeout.
|
||||
- **Caching:** rendered HTML cached in Redis keyed by URL with TTL.
|
||||
- **Contract:** `url` → `{html, status, final_url, rendered_at}`.
|
||||
|
||||
### 6.4 Extractor
|
||||
- **Runtime:** Python / Trafilatura.
|
||||
- **Responsibility:** HTML → main content + metadata (boilerplate removal).
|
||||
- **Contract:** `{html, url}` → `{title, text, main_html, metadata}`.
|
||||
|
||||
### 6.5 Formatter
|
||||
- **Runtime:** Python.
|
||||
- **Responsibility:** clean content → LLM-ready Markdown + chunks.
|
||||
- **Chunking:** token-based, configurable size, with overlap; tuned for local LLM
|
||||
context windows. Returns **both** full markdown and chunks.
|
||||
- **Contract:** `{title, text, main_html, metadata}` →
|
||||
`{markdown, chunks: [{text, index, tokens}]}`.
|
||||
|
||||
### 6.6 Redis
|
||||
- Shared cache: search results (short TTL), rendered HTML (medium TTL).
|
||||
- Ephemeral instance-health stats.
|
||||
|
||||
## 7. Inter-Service Contract
|
||||
|
||||
- Transport: synchronous HTTP/REST between services (simplest to debug). Queue
|
||||
deferred to a later version if batch crawling is needed.
|
||||
- Each stage's output schema (Section 6) is the contract; the orchestrator owns
|
||||
sequencing and error handling.
|
||||
|
||||
## 8. Cross-Cutting Requirements
|
||||
|
||||
- **Logging:** structured JSON on every service.
|
||||
- **Health:** `GET /health` on every service; orchestrator aggregates.
|
||||
- **Tracing:** per-stage timings + cache hit/miss returned to caller.
|
||||
- **Config:** env-driven; instance list via mounted file.
|
||||
- **Resource limits:** per-container CPU/RAM limits in compose; renderer
|
||||
concurrency cap enforced.
|
||||
- **Politeness:** per-domain rate limiting; caching to reduce upstream load/bans.
|
||||
|
||||
## 9. Limitations (accepted)
|
||||
|
||||
- Anti-bot walls (Cloudflare/DataDome/CAPTCHA) will block some pages → partial
|
||||
coverage.
|
||||
- "Always render" imposes a RAM/CPU/latency tax; mitigated by concurrency caps
|
||||
+ Redis cache.
|
||||
- Public SearXNG instances are flaky (rate limits, downtime, degraded results);
|
||||
handled by health tracking + rotation.
|
||||
- No answer synthesis in-stack (by design).
|
||||
|
||||
## 10. Open Questions / Future (v2+)
|
||||
|
||||
- Optional message queue for batch crawl jobs.
|
||||
- LLM-powered structured extraction endpoint.
|
||||
- Conditional rendering (fetch-first escalation) as an optimization if always-render
|
||||
proves too heavy.
|
||||
- Per-instance engine config + authenticated private instances in the UI.
|
||||
- Local private-corpus index (hybrid open-web + private).
|
||||
|
||||
## 11. Milestones (proposed)
|
||||
|
||||
1. **M1 — Skeleton:** compose file, 7 services stubbed, `/health` everywhere,
|
||||
end-to-end `/scrape` passing (render → extract → format for one URL).
|
||||
2. **M2 — Search:** searcher with single-instance failover + normalized contract;
|
||||
`/search` working; instance list from file.
|
||||
3. **M3 — Full pipeline:** `/search/contents` wiring all stages; Redis caching;
|
||||
response traces.
|
||||
4. **M4 — Rotation + UI:** fan-out mode, health tracking, config UI.
|
||||
5. **M5 — Hardening:** rate limiting, resource limits, timeouts, docs.
|
||||
Loading…
Add table
Add a link
Reference in a new issue