1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
//! # Fetchium Core Library
//!
//! AI-native search engine for humans and agents.
//!
//! `fetchium-core` contains all algorithms, pipelines, and data structures that power the
//! `fetchium` CLI and MCP/REST API servers. Everything in this crate is designed for both
//! interactive use (humans) and programmatic use (AI agents).
//!
//! ## Architecture
//!
//! The core pipeline runs in this order:
//!
//! ```text
//! Search → Extract (CEP) → Rank (HyperFusion) → Token (QATBE/SCS) →
//! Validate (6 layers) → Citation → Output (markdown/JSON/segments)
//! ↑
//! Research (AMRS) ──┘
//! ```
//!
//! ## Key Algorithms (PRD §8)
//!
//! | Algorithm | Description | PRD |
//! |-----------|-------------|-----|
//! | **CEP** | Content Extraction Protocol — 5-layer cascade | §16 |
//! | **QATBE** | Query-Aware Token-Budgeted Extraction — BM25 + semantic | §17 |
//! | **SCS** | Semantic Content Segmentation — 8 segment types | §18 |
//! | **PDS** | Progressive Detail Streaming — 4 tiers | §19 |
//! | **HyperFusion** | 8-signal ranking: BM25 + semantic + temporal + authority | §21 |
//! | **QADD** | Query-Aware DOM Distillation — 5-step DOM pruning | §15 |
//! | **AMRS** | Adaptive Multi-Agent Research Swarm | §24 |
//! | **PIE** | Persistent Intelligence Engine — cross-session learning | §32 |
//! | **RAR** | Retry-and-Refine — 5-checkpoint self-correction | §44 |
//!
//! ## Quick Example
//!
//! ```rust
//! use fetchium_core::rank::rerank;
//! use fetchium_core::types::{BackendId, ResultItem};
//!
//! // Build some search results
//! let mut results = vec![
//! ResultItem {
//! title: "Rust Programming Language".into(),
//! url: "https://rust-lang.org".into(),
//! snippet: "A language empowering everyone to build reliable software.".into(),
//! rank: 0,
//! backend: BackendId::DuckDuckGo,
//! score: None,
//! published_date: None,
//! },
//! ResultItem {
//! title: "Python is great".into(),
//! url: "https://python.org".into(),
//! snippet: "Python is a versatile scripting language.".into(),
//! rank: 1,
//! backend: BackendId::DuckDuckGo,
//! score: None,
//! published_date: None,
//! },
//! ];
//!
//! // Re-rank with BM25 — the Rust result should score higher for "rust"
//! let ranked = rerank(results, "rust programming language");
//! assert_eq!(ranked[0].url, "https://rust-lang.org");
//! ```
//!
//! ## Feature Flags
//!
//! | Feature | Dependency | What it enables |
//! |---------|-----------|-----------------|
//! | `embeddings` | `fastembed` | Semantic scoring, hybrid QATBE, batch embedding |
//! | `vector-search` | `usearch` | HNSW approximate nearest-neighbor index |
//! | `headless` | `chromiumoxide` | CEP layers 3+5, JS rendering, screenshot OCR |
//! | `mcp` | `rmcp` | MCP protocol support |
//!
//! ## Prelude
//!
//! Import the most commonly used items in one line:
//!
//! ```rust
//! use fetchium_core::prelude::*;
//! ```
// Stylistic lints introduced by newer clippy toolchains; the flagged call sites are
// intentional/borrow-sensitive. Allow crate-wide to keep CI stable across toolchain
// updates; revisit opportunistically.
// Core pipeline modules
// Phase 2: QADD and browser pool
// Phase 3+
// Phase 4+
// Phase 5+ (feature-gated optional subsystems)
// Always-available Phase 5 modules
// Summarization pipeline
// Phase 6+
// Resilience layer — circuit breakers, adaptive rate limiting, bulkhead isolation
// Telemetry — pipeline observability, metrics, health monitoring
// Phase 7+
// Environment setup utilities (Chromium download, path resolution, checks)
// YouTube Intelligence System
// Social Media Intelligence System (Twitter/X, Reddit, TikTok, HackerNews + unified)
/// Re-export commonly used types.