Add degoog as the search provider, and make it the default

The operator already runs it, so this is the one provider that costs nothing to adopt: no key,
no card, no third party, and no new container. It aggregates several engines and returns them
merged, and its /api/search reply is already the shape everything downstream expects — title,
url, snippet, with content as a fallback for the roughly one result in six that has no snippet.

It is also now the only provider whose response has been read from a live service rather than
from documentation, which is why it is the default.
This commit is contained in:
Gmer4Lfe
2026-08-09 22:50:47 -04:00
parent 613634473a
commit 0c16c6db63
3 changed files with 60 additions and 18 deletions
+55 -16
View File
@@ -5,11 +5,16 @@
// their URLs, for the worker to put in front of the model as context it can cite.
//
// OPERATIONAL MODEL
// One provider at a time, named by AI_WEB_SEARCH_PROVIDER. Three are supported because the
// right answer depends on what the operator is willing to run: a self-hosted SearXNG needs no
// key and no third party, and a hosted API needs no container. They differ only in how the
// request is shaped and where the fields sit in the reply, so everything after parsing is one
// code path.
// One provider at a time, named by AI_WEB_SEARCH_PROVIDER. Four are supported because the right
// answer depends on what the operator already runs: degoog and SearXNG are self-hosted and need
// no key and no third party, while brave and tavily need no container. They differ only in how
// the request is shaped and where the fields sit in the reply, so everything after parsing is
// one code path.
//
// degoog is the default and the one verified here — it was already running on this host, and it
// aggregates several engines and returns them merged. DuckDuckGo is deliberately absent: both
// its scraping endpoints answer a challenge page from this network, and its keyless API returns
// nothing at all for a real question.
//
// DESIGN PRINCIPLES
// Off by default, and not because it is dangerous.
@@ -43,7 +48,7 @@
// ═══════════════════════════════════════════════════════════════════════════════════════════════
require_once __DIR__ . '/ai.php';
const VV_AI_WEB_PROVIDERS = ['searxng', 'brave', 'tavily'];
const VV_AI_WEB_PROVIDERS = ['degoog', 'searxng', 'brave', 'tavily'];
const VV_AI_WEB_MAX_QUERY = 300; // characters sent to the provider
const VV_AI_WEB_MAX_SNIPPET = 400; // characters kept from each result
@@ -53,8 +58,8 @@ function vv_ai_web_enabled(): bool {
}
function vv_ai_web_provider(): string {
$p = strtolower(trim((string)(vv_conf_vars()['AI_WEB_SEARCH_PROVIDER'] ?? 'searxng')));
return in_array($p, VV_AI_WEB_PROVIDERS, true) ? $p : 'searxng';
$p = strtolower(trim((string)(vv_conf_vars()['AI_WEB_SEARCH_PROVIDER'] ?? 'degoog')));
return in_array($p, VV_AI_WEB_PROVIDERS, true) ? $p : 'degoog';
}
function vv_ai_web_results_max(): int {
@@ -71,6 +76,15 @@ function vv_ai_web_searx_url(): string {
return rtrim(trim((string)(vv_conf_vars()[strtoupper(vv_detect_host()) . '_SEARXNG_URL'] ?? '')), '/');
}
function vv_ai_web_degoog_url(): string {
return rtrim(trim((string)(vv_conf_vars()[strtoupper(vv_detect_host()) . '_DEGOOG_URL'] ?? '')), '/');
}
// Which providers need an address on this network rather than a key. Kept as a list because the
// readiness check and the error message both need the same answer and disagreeing about it is how
// a feature reports itself ready and then does nothing.
const VV_AI_WEB_SELF_HOSTED = ['degoog', 'searxng'];
function vv_ai_web_api_key(): string {
return trim((string)(vv_conf_vars()[strtoupper(vv_detect_host()) . '_WEB_SEARCH_API_KEY'] ?? ''));
}
@@ -81,12 +95,17 @@ function vv_ai_web_ready(): array {
if (!vv_ai_web_enabled()) {
return ['ok' => false, 'error' => 'AI_WEB_SEARCH_ENABLED is false'];
}
$p = vv_ai_web_provider();
if ($p === 'searxng' && vv_ai_web_searx_url() === '') {
return ['ok' => false, 'error' => strtoupper(vv_detect_host()) . '_SEARXNG_URL is empty'];
$p = vv_ai_web_provider();
$host = strtoupper(vv_detect_host());
if ($p === 'degoog' && vv_ai_web_degoog_url() === '') {
return ['ok' => false, 'error' => $host . '_DEGOOG_URL is empty'];
}
if ($p !== 'searxng' && vv_ai_web_api_key() === '') {
return ['ok' => false, 'error' => strtoupper(vv_detect_host()) . '_WEB_SEARCH_API_KEY is empty'];
if ($p === 'searxng' && vv_ai_web_searx_url() === '') {
return ['ok' => false, 'error' => $host . '_SEARXNG_URL is empty'];
}
if (!in_array($p, VV_AI_WEB_SELF_HOSTED, true) && vv_ai_web_api_key() === '') {
return ['ok' => false, 'error' => $host . '_WEB_SEARCH_API_KEY is empty'];
}
return ['ok' => true, 'provider' => $p];
}
@@ -144,6 +163,25 @@ function vv_ai_web_normalise(array $rows): array {
// a shape that changes underneath produces zero results rather than wrong ones, because every
// field is read by name and anything missing is dropped by vv_ai_web_normalise().
// Degoog — self-hosted, no key, and the only provider here whose response has been read from a
// live service rather than from documentation. It aggregates several engines and returns them
// already merged, so the ranking is its own.
//
// snippet before content: it fills both, and around one result in six has neither. Those are kept
// anyway — a title and a URL is still a citable source, and dropping them would silently shrink
// the result set the operator asked for.
function vv_ai_web_degoog(string $q): ?array {
$base = vv_ai_web_degoog_url();
if ($base === '') return null;
$d = vv_ai_web_http($base . '/api/search?q=' . rawurlencode($q));
if ($d === null) return null;
return array_map(fn($r) => ['title' => $r['title'] ?? '',
'url' => $r['url'] ?? '',
'snippet' => ($r['snippet'] ?? '') !== '' ? $r['snippet']
: ($r['content'] ?? '')],
array_slice($d['results'] ?? [], 0, vv_ai_web_results_max()));
}
function vv_ai_web_searxng(string $q): ?array {
$base = vv_ai_web_searx_url();
if ($base === '') return null;
@@ -199,9 +237,10 @@ function vv_ai_web_search(string $question): array {
$provider = vv_ai_web_provider();
$raw = match ($provider) {
'brave' => vv_ai_web_brave($q),
'tavily' => vv_ai_web_tavily($q),
default => vv_ai_web_searxng($q),
'brave' => vv_ai_web_brave($q),
'tavily' => vv_ai_web_tavily($q),
'searxng' => vv_ai_web_searxng($q),
default => vv_ai_web_degoog($q),
};
if ($raw === null) {