PRD v4: MCP-first, no in-stack LLM, mechanical extraction only
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
6d7e401188
commit
55317f3f75
1 changed files with 113 additions and 116 deletions
225
PRD.md
225
PRD.md
|
|
@ -1,6 +1,6 @@
|
|||
# PRD — Local Web Search Stack (LWSS)
|
||||
|
||||
**Status:** Draft v2 (MVP-scoped)
|
||||
**Status:** Draft v4 (MVP-scoped, MCP-first, no in-stack LLM)
|
||||
**Owner:** Neil
|
||||
**Last updated:** 2026-07-05
|
||||
|
||||
|
|
@ -12,6 +12,17 @@ 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 primary deliverable is an MCP server** exposing two tools: **web search**
|
||||
and **URL fetch/render**. "Tavily drop-in" means **functional equivalence** — an
|
||||
agent that would call Tavily's search tool gets the same capability from this
|
||||
MCP server — not wire-level API compatibility with Tavily's REST schema.
|
||||
|
||||
**There is no LLM anywhere in the stack.** The consumer of the MCP server *is*
|
||||
an LLM; any judgment calls (reranking results, deciding relevance, summarizing)
|
||||
belong to that calling model. In-stack content cleaning is **purely mechanical**:
|
||||
existing libraries strip HTML/CSS/JS/boilerplate from rendered pages and return
|
||||
pure text/data. This keeps every layer deterministic, fast, and testable.
|
||||
|
||||
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.
|
||||
|
|
@ -21,28 +32,23 @@ in the request hot path.
|
|||
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.
|
||||
The MVP runs **entirely on one local machine** and must be **usable as a
|
||||
functional Tavily replacement via MCP** — that is the acceptance bar.
|
||||
|
||||
## 2. Goals
|
||||
|
||||
- Provide a Serper/Tavily/Firecrawl-equivalent API backed only by
|
||||
self-hostable/free components.
|
||||
- Provide a Serper/Tavily/Firecrawl-equivalent capability, exposed as an **MCP
|
||||
server**, backed only by self-hostable/free components.
|
||||
- **Reliability (MVP priority):** the pipeline doesn't fall over — retries,
|
||||
timeouts, health checks, graceful partial results, caching. No single stage
|
||||
(including the LLM endpoint) is a hard dependency; degrade instead of fail.
|
||||
timeouts, health checks, graceful partial results, caching. No single stage is
|
||||
a hard dependency where degradation is possible.
|
||||
- **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.
|
||||
failures or boilerplate. Mechanical extraction (Trafilatura + friends) strips
|
||||
HTML/CSS/JS/nav/ads and returns clean text/data.
|
||||
- **Deterministic pipeline:** no inference in-stack; every stage is mechanical,
|
||||
reproducible, and cheap to run on modest hardware.
|
||||
- **Modularity:** core layers (`searcher`, `renderer`, `extractor`) as separate
|
||||
containers, each curl-able in isolation.
|
||||
- **Debuggability:** structured logging, `/health` on every service, per-stage
|
||||
timing/trace in orchestrator responses.
|
||||
- **Privacy (end goal, deferred past MVP):** no commercial SaaS sees queries or
|
||||
|
|
@ -55,10 +61,12 @@ on modest hardware.
|
|||
|
||||
## 3. Non-Goals (MVP)
|
||||
|
||||
- Answer synthesis / RAG generation — that is the downstream local LLM's job.
|
||||
- **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.
|
||||
- **Any in-stack LLM usage** — no reranking, no LLM cleaning, no summarization,
|
||||
no structured/schema extraction. The calling LLM does all of that with the
|
||||
clean text this stack returns.
|
||||
- Answer synthesis / RAG generation — the calling LLM's job.
|
||||
- Chunking — the consumer is an MCP client with a large-context model; full
|
||||
cleaned text is returned as-is.
|
||||
- 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.
|
||||
|
|
@ -69,7 +77,7 @@ on modest hardware.
|
|||
|
||||
- **Boundary:** "no SaaS logs my queries/content against my identity," **not**
|
||||
"airgapped." Queries still reach public search engines via SearXNG upstreams.
|
||||
- **MVP:** a **single local self-hosted SearXNG** instance (now a **required**
|
||||
- **MVP:** a **single local self-hosted SearXNG** instance (a **required**
|
||||
container). No rotation, fan-out, or obfuscation yet — but the searcher keeps
|
||||
the **file-based instance-list abstraction** (§6.2) so rotation drops in later
|
||||
with no refactor.
|
||||
|
|
@ -81,61 +89,66 @@ on modest hardware.
|
|||
## 5. Architecture
|
||||
|
||||
```
|
||||
client / local LLM
|
||||
│
|
||||
MCP client (agent / local LLM host)
|
||||
│ MCP (streamable HTTP; stdio optional)
|
||||
▼
|
||||
┌───────────────┐ public API (only exposed port)
|
||||
│ ORCHESTRATOR │ search → LLM rerank → render → extract → LLM clean → format
|
||||
└─┬──┬──┬──┬──┬─┘
|
||||
│ │ │ │ └──────────────────────────────────────┐
|
||||
▼ │ │ │ ▼
|
||||
┌────────┐│ │ │ ┌───────────┐
|
||||
│SEARCHER││ │ │ │ FORMATTER │
|
||||
└───┬────┘│ │ │ │ md+chunk │
|
||||
│ ▼ │ ▼ └───────────┘
|
||||
SearXNG ┌─────────┐ ┌───────────┐
|
||||
(local) │RENDERER │ │ EXTRACTOR │ ┌──────────────────────────┐
|
||||
│Playwright│ │Trafilatura│ │ LLM │
|
||||
└─────────┘ └───────────┘ │ /rerank + /clean │
|
||||
▲ │ OpenAI-compatible client │
|
||||
│ │ (configurable endpoint) │
|
||||
┌─────────┐ └──────────────────────────┘
|
||||
│ REDIS │ shared cache (search + rendered HTML)
|
||||
┌────────────────────────┐
|
||||
│ ORCHESTRATOR + MCP │ pipeline: search → render → extract/clean
|
||||
│ (REST also exposed) │
|
||||
└──┬────────┬────────┬───┘
|
||||
▼ │ │
|
||||
┌────────┐ ▼ ▼
|
||||
│SEARCHER│ ┌─────────┐ ┌───────────┐
|
||||
└───┬────┘ │RENDERER │ │ EXTRACTOR │
|
||||
│ │Playwright│ │Trafilatura│ mechanical clean: strip HTML/CSS/JS/
|
||||
SearXNG └─────────┘ │ + friends │ nav/ads/boilerplate → pure text/data
|
||||
(local) ▲ └───────────┘
|
||||
│
|
||||
┌─────────┐
|
||||
│ REDIS │ shared cache (search + rendered HTML + extracted text)
|
||||
└─────────┘
|
||||
```
|
||||
|
||||
**Containers (8):** orchestrator, searcher, **searxng (required, local)**,
|
||||
renderer, extractor, **llm**, formatter, redis.
|
||||
**Containers (6):** orchestrator (REST + MCP), searcher, **searxng (required,
|
||||
local)**, renderer, extractor, redis.
|
||||
|
||||
**Invariants:**
|
||||
- Workers are stateless and independently testable.
|
||||
- No inference anywhere in the stack; every stage is deterministic.
|
||||
- Only shared state: Redis (cache + ephemeral health) and the searcher's
|
||||
instance-list file.
|
||||
- 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.
|
||||
- Orchestrator is the only externally exposed service (MCP + REST).
|
||||
|
||||
## 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:**
|
||||
### 6.1 Orchestrator (MCP server + API gateway)
|
||||
- **Runtime:** Python / FastAPI + MCP SDK (single container; MCP tools call the
|
||||
same internal pipeline functions as the REST routes).
|
||||
- **Responsibility:** expose the MCP tools and REST API, run the pipeline,
|
||||
aggregate per-stage traces, handle errors/partial results.
|
||||
- **MCP tools (MVP primary interface):**
|
||||
- `web_search` — Tavily-equivalent: `{query, max_results, include_content}` →
|
||||
ranked results, each with `{url, title, snippet}` and (when
|
||||
`include_content`) cleaned full text. Ranking is SearXNG's; the calling LLM
|
||||
reranks/filters as it sees fit.
|
||||
- `fetch_url` — `{url}` → render → extract → cleaned full text + metadata for
|
||||
one page.
|
||||
- **REST endpoints (same pipeline, for curl/debug and non-MCP clients):**
|
||||
- `POST /search` — results only (Serper-like): `{query, options}` →
|
||||
`{results: [{url,title,snippet,rank,source_instance}], trace}`.
|
||||
- `POST /search/contents` — **(MVP primary)** full flow (Tavily-like): search →
|
||||
**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 /search/contents` — full flow (Tavily-like): search → render → extract
|
||||
for top-N results → `{results:[{...,content}], trace}`.
|
||||
- `POST /scrape` — per-URL: render → extract.
|
||||
- `GET /health`.
|
||||
- Every response includes a `trace` with per-stage timing and cache hit/miss.
|
||||
- Every REST response includes a `trace` with per-stage timing, cache hit/miss,
|
||||
and a `degraded` list naming any stage that fell back or partially failed.
|
||||
MCP tool results carry a compact version of the same.
|
||||
- Renders/extracts for the top-N results run **in parallel across URLs**.
|
||||
|
||||
### 6.2 Searcher
|
||||
- **Runtime:** Python / FastAPI (or Node — TBD at impl; Python default).
|
||||
- **Runtime:** Python / FastAPI.
|
||||
- **Responsibility:** query the SearXNG instance pool, normalize + dedup results,
|
||||
track instance health, serve the config UI.
|
||||
track instance health.
|
||||
- **Rotation (configurable):**
|
||||
- `failover` (default, **MVP: only mode**): one healthy instance per query, fail
|
||||
over on error. MVP points at a single local SearXNG, so this is effectively a
|
||||
|
|
@ -147,8 +160,9 @@ renderer, extractor, **llm**, formatter, redis.
|
|||
in Redis; used for weighted selection and surfaced in the UI.
|
||||
- **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.
|
||||
- **SearXNG config note:** the local instance must enable JSON output
|
||||
(`formats: [html, json]` in `settings.yml`) and disable the built-in limiter
|
||||
for internal use.
|
||||
- **Output contract:** `{url, title, snippet, rank, source_instance}`.
|
||||
|
||||
### 6.3 Renderer
|
||||
|
|
@ -161,42 +175,19 @@ renderer, extractor, **llm**, formatter, redis.
|
|||
- **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.4 Extractor (mechanical clean)
|
||||
- **Runtime:** Python / Trafilatura as primary, with library fallbacks
|
||||
(e.g. readability-lxml) when Trafilatura returns empty/thin content.
|
||||
- **Responsibility:** rendered HTML → pure text/data. Strips all markup, CSS,
|
||||
JS, nav, footers, cookie banners, ads, related-links boilerplate. Preserves
|
||||
real content verbatim — including tables/lists/code as text — plus page
|
||||
metadata (title, author, date where available). **No inference, no
|
||||
summarization — deterministic library-based extraction only.**
|
||||
- **Contract:** `{html, url}` → `{title, text, metadata, extractor_used}`.
|
||||
|
||||
### 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 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).
|
||||
### 6.5 Redis
|
||||
- Shared cache: search results (short TTL), rendered HTML (medium TTL),
|
||||
extracted text (medium TTL).
|
||||
- Ephemeral instance-health stats.
|
||||
|
||||
## 7. Inter-Service Contract
|
||||
|
|
@ -210,13 +201,13 @@ renderer, extractor, **llm**, formatter, redis.
|
|||
|
||||
- **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. 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.
|
||||
- **Tracing:** per-stage timings + cache hit/miss + degraded-stage list 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.
|
||||
- **Politeness:** per-domain rate limiting (Redis token bucket, enforced at the
|
||||
renderer); caching to reduce upstream load/bans.
|
||||
|
||||
## 9. Limitations (accepted)
|
||||
|
||||
|
|
@ -225,7 +216,11 @@ renderer, extractor, **llm**, formatter, redis.
|
|||
- "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.
|
||||
handled by health tracking + rotation (post-MVP).
|
||||
- Mechanical extraction is imperfect: some boilerplate survives, some content
|
||||
is lost on unusual layouts. Accepted — the calling LLM is robust to residual
|
||||
noise, and library fallbacks cover the worst cases.
|
||||
- No reranking in-stack: result order is SearXNG's; the calling LLM filters.
|
||||
- No answer synthesis in-stack (by design).
|
||||
|
||||
## 10. Open Questions / Future (post-MVP)
|
||||
|
|
@ -235,22 +230,24 @@ renderer, extractor, **llm**, formatter, redis.
|
|||
and cost distribution across VPSs / friends' hardware.
|
||||
- **Config UI:** instance CRUD + live health table; per-instance engine config +
|
||||
authenticated private instances.
|
||||
- Optional chunking of returned content if small-context consumers appear.
|
||||
- Optional message queue for batch crawl jobs.
|
||||
- LLM-powered **structured/schema** extraction endpoint.
|
||||
- Conditional rendering (fetch-first escalation) as an optimization if always-render
|
||||
proves too heavy.
|
||||
- Local private-corpus index (hybrid open-web + private).
|
||||
|
||||
## 11. Milestones (MVP: reliability + quality first)
|
||||
|
||||
1. **M1 — Scrape spine:** compose up; `/scrape` (render → extract → format for one
|
||||
URL); `/health` everywhere; Redis render cache. Proves the quality path.
|
||||
2. **M2 — LLM clean:** add LLM service `/clean`; wire into `/scrape`; configurable
|
||||
OpenAI-compatible endpoint; graceful fallback to Trafilatura-only.
|
||||
3. **M3 — Search + rerank:** single local SearXNG + searcher (file-based, failover);
|
||||
LLM `/rerank`; `/search` working.
|
||||
4. **M4 — Tavily parity:** `/search/contents` wiring all stages end-to-end with
|
||||
per-stage traces + caching. **MVP acceptance: usable as a Tavily drop-in.**
|
||||
5. **M5 — Hardening:** retries, per-domain rate limiting, resource limits, timeouts,
|
||||
docs.
|
||||
1. **M1 — Scrape spine:** compose up; `/scrape` (render → extract) for one URL;
|
||||
`/health` everywhere; Redis render cache. Proves the quality path.
|
||||
2. **M2 — Extraction quality:** fallback extractors, empty/thin-content
|
||||
detection, metadata capture; extracted-text caching.
|
||||
3. **M3 — Search:** single local SearXNG + searcher (file-based, failover);
|
||||
`/search` working.
|
||||
4. **M4 — Tavily parity + MCP:** `/search/contents` wiring all stages end-to-end
|
||||
(parallel per-URL) with traces + caching; MCP server exposing `web_search` +
|
||||
`fetch_url`. **MVP acceptance: usable as a functional Tavily replacement
|
||||
from an MCP client.**
|
||||
5. **M5 — Hardening:** retries, per-domain rate limiting, resource limits,
|
||||
timeouts, docs.
|
||||
6. **Post-MVP:** rotation/fan-out, VPS obfuscation, config UI (see §10).
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue