Deploying SearXNG in Docker: Giving Local AI Agents Private Web Search Capabilities
Overview
Local AI agents (via Open-WebUI or LangChain) often need real-time web search capabilities to ground their responses. Relying on commercial search APIs (like Google Custom Search or Bing API) leaks agent queries and user prompts to third parties.
SearXNG is a privacy-respecting, open-source metasearch engine. Deploying SearXNG in Docker provides local AI agents with a JSON search API while stripping tracking cookies and user logs.
Docker Compose Setup
Create /opt/searxng-stack/docker-compose.yml:
version: "3.8"
services:
searxng:
image: searxng/searxng:latest
container_name: searxng_search
restart: unless-stopped
ports:
- "8080:8080"
volumes:
- ./searxng:/etc/searxng:rw
environment:
- SEARXNG_BASE_URL=http://localhost:8080/
Configure JSON API output in ./searxng/settings.yml:
search:
formats:
- html
- json
Verification & Open-WebUI Integration
Test SearXNG JSON API endpoint:
curl "http://localhost:8080/search?q=OpsNexusAI&format=json"
In Open-WebUI, set Web Search Engine to searxng and URL to http://searxng:8080/search.
Redis Caching Sidecar for High-Performance Search Responses
To prevent rate-limiting from upstream search engines (Google, DuckDuckGo, Wikipedia), deploy a Redis caching sidecar alongside SearXNG.
Complete docker-compose.yml with Redis Cache
version: "3.8"
services:
searxng:
image: searxng/searxng:latest
container_name: searxng_search
restart: unless-stopped
ports:
- "8080:8080"
volumes:
- ./searxng:/etc/searxng:rw
environment:
- SEARXNG_BASE_URL=http://localhost:8080/
depends_on:
- redis
redis:
image: redis:7-alpine
container_name: searxng_redis
restart: unless-stopped
command: redis-server --save 30 1 --loglevel warning
volumes:
- redis_data:/data
volumes:
redis_data:
Architecture: Privacy-Preserving Agentic RAG
AI agents require web search access for real-time information retrieval. However, routing search queries directly to commercial search APIs (Google, Bing) exposes internal prompt contexts, proprietary tokens, and user IP addresses to third parties.
SearXNG acts as an aggressive privacy-preserving meta-search aggregator. It strips tracking IDs, rotates user-agents, pools results from 70+ search engines, and exposes a clean JSON REST API for frameworks like LangChain, LlamaIndex, and AutoGen.
+-------------------------------------------------------------------------+
| Local AI Agent Stack |
| +-------------------------------------------------------------------+ |
| | LangChain / LlamaIndex / AutoGen Agent Framework | |
| +-------------------------------------------------------------------+ |
| | JSON API (SearXNG API Endpoint) |
| \/ |
| +-------------------------------------------------------------------+ |
| | SearXNG Aggregator Engine (Local Docker Container) | |
| +-------------------------------------------------------------------+ |
| || || || |
| \/ \/ \/ |
| +-----------+ +--------------+ +-------------+ |
| | DuckDuckGo| | Wikipedia | | Qwant | |
| +-----------+ +--------------+ +-------------+ |
+-------------------------------------------------------------------------+
Step 1: Production SearXNG Deployment Manifest (docker-compose.yml)
version: "3.8"
services:
searxng:
image: searxng/searxng:latest
container_name: private-searxng
restart: unless-stopped
ports:
- "8080:8080"
volumes:
- ./searxng:/etc/searxng:rw
environment:
- SEARXNG_BASE_URL=http://localhost:8080/
- INSTANCE_NAME=OpsNexus-Private-Search
cap_drop:
- ALL
cap_add:
- CHOWN
- SETGID
- SETUID
redis:
image: redis:7-alpine
container_name: searxng-redis
restart: unless-stopped
command: redis-server --save "" --appendonly no
Step 2: SearXNG Configuration (searxng/settings.yml)
Enable JSON output format for AI agent integration:
use_default_settings: true
server:
port: 8080
bind_address: "0.0.0.0"
secret_key: "GENERATE_SECURE_RANDOM_SECRET_KEY_HERE"
limiter: false
search:
safe_search: 0
autocomplete: ""
formats:
- html
- json
engines:
- name: duckduckgo
engine: duckduckgo
shortcut: ddg
disabled: false
- name: wikipedia
engine: wikipedia
shortcut: wp
disabled: false
Step 3: Python AI Agent Integration Script
Connect SearXNG to a Python AI Agent:
import requests
def searxng_search(query: str, limit: int = 5):
url = "http://localhost:8080/search"
params = {
"q": query,
"format": "json",
"categories": "general"
}
response = requests.get(url, params=params, timeout=5)
data = response.json()
results = []
for item in data.get("results", [])[:limit]:
results.append({
"title": item.get("title"),
"url": item.get("url"),
"snippet": item.get("content")
})
return results
# Example call
search_results = searxng_search("Latest CUDA 12.4 container optimization techniques")
print(search_results) OpsNexusAI Engineering
Verified Lab PublicationOpsNexusAI is a technical laboratory dedicated to sovereign AI infrastructure. Every implementation guide and architectural blueprint published here is tested on physical hardware and isolated networks. Our team specializes in the deployment of private LLMs, network hardening with OPNsense, and enterprise-grade automation patterns.
Join the OpsNexus Brief
Get technical teardowns on sovereign AI architectures delivered to your inbox.