This guide explains how to use the Kolosal Server's internet search functionality, which provides a wrapper around SearXNG for web searches.
The internet search endpoint allows you to perform web searches through your server, acting as a proxy to a SearXNG instance. This is useful for integrating web search capabilities into AI applications while maintaining control over the search backend.
Add the following section to your config.yaml file:
search:
enabled: true # Enable/disable internet search endpoint
searxng_url: "http://localhost:4000" # SearXNG instance URL
timeout: 30 # Request timeout in seconds
max_results: 20 # Maximum number of search results
default_engine: "" # Default search engine (empty = SearXNG default)
api_key: "" # Optional API key for authentication
enable_safe_search: true # Enable safe search by default
default_format: "json" # Default output format (json, xml, csv, rss)
default_language: "en" # Default search language
default_category: "general" # Default search categoryYou can also configure the search functionality using command line arguments:
# Enable search
kolosal-server --enable-search --searxng-url "http://localhost:4000"
# Configure search parameters
kolosal-server --enable-search \
--search-url "http://your-searxng-instance:8080" \
--search-timeout 60 \
--search-max-results 50 \
--search-language "en" \
--search-category "general" \
--search-safe-search
# Disable search
kolosal-server --disable-searchThe search functionality is available at these endpoints:
GET /internet_searchPOST /internet_searchGET /v1/internet_searchPOST /v1/internet_searchGET /searchPOST /search
{
"query": "artificial intelligence", // Required: Search query
"engines": "google,bing", // Optional: Comma-separated list of engines
"categories": "general,news", // Optional: Comma-separated list of categories
"language": "en", // Optional: Search language
"format": "json", // Optional: Output format (json, xml, csv, rss)
"results": 10, // Optional: Number of results (1-100)
"safe_search": true, // Optional: Enable safe search
"timeout": 30 // Optional: Request timeout (1-120 seconds)
}GET /internet_search?q=artificial%20intelligence&engines=google,bing&results=10&lang=en
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
query or q |
string | Yes | - | The search query |
engines |
string | No | SearXNG default | Comma-separated list of search engines |
categories |
string | No | general |
Comma-separated list of search categories |
language or lang |
string | No | en |
Search language code |
format |
string | No | json |
Output format: json, xml, csv, rss |
results |
integer | No | 20 | Number of results to return (1-100) |
safe_search or safesearch |
boolean | No | true |
Enable safe search filtering |
timeout |
integer | No | 30 | Request timeout in seconds (1-120) |
The response format depends on the SearXNG instance configuration and the requested format. For JSON format, you'll typically receive:
{
"query": "artificial intelligence",
"number_of_results": 10,
"results": [
{
"title": "Artificial Intelligence - Wikipedia",
"url": "https://en.wikipedia.org/wiki/Artificial_intelligence",
"content": "Artificial intelligence (AI) is intelligence demonstrated by machines...",
"engine": "wikipedia",
"score": 100,
"category": "general"
}
],
"suggestions": ["machine learning", "deep learning"],
"infobox": {
"title": "Artificial Intelligence",
"content": "..."
}
}{
"error": {
"type": "invalid_request",
"message": "Query parameter is required"
}
}curl -X POST http://localhost:8080/internet_search \
-H "Content-Type: application/json" \
-d '{"query": "machine learning tutorials"}'curl -X POST http://localhost:8080/internet_search \
-H "Content-Type: application/json" \
-d '{
"query": "climate change 2024",
"engines": "google,bing,duckduckgo",
"categories": "news,science",
"language": "en",
"results": 15,
"safe_search": true
}'curl "http://localhost:8080/internet_search?q=python%20programming&results=5&lang=en"You need a running SearXNG instance to use this feature. Here's how to set it up:
# Pull and run SearXNG
docker run -d \
--name searxng \
-p 4000:8080 \
-v $(pwd)/searxng:/etc/searxng \
searxng/searxng:latestversion: '3.8'
services:
searxng:
image: searxng/searxng:latest
container_name: searxng
ports:
- "4000:8080"
volumes:
- ./searxng:/etc/searxng
environment:
- SEARXNG_SECRET=your-secret-key-hereCreate a settings.yml file for SearXNG:
use_default_settings: true
server:
port: 8080
bind_address: "0.0.0.0"
secret_key: "your-secret-key-here"
ui:
static_use_hash: true
search:
safe_search: 1
autocomplete: "google"
default_lang: "en"
engines:
- name: google
disabled: false
- name: bing
disabled: false
- name: duckduckgo
disabled: falseThe available search engines depend on your SearXNG configuration. Common engines include:
- Web Search: google, bing, duckduckgo, yahoo, yandex
- News: google news, bing news, reuters, cnn, bbc
- Images: google images, bing images, flickr, unsplash
- Videos: youtube, vimeo, dailymotion
- Academic: google scholar, arxiv, crossref, pubmed
- Maps: google maps, openstreetmap
- Shopping: amazon, ebay, 1337x
- Social: reddit, twitter, mastodon
Common search categories include:
general- General web searchimages- Image searchvideos- Video searchnews- News searchmap- Map/location searchmusic- Music searchit- IT/programming searchscience- Scientific searchsocial media- Social media search
Use standard ISO 639-1 language codes:
en- Englishes- Spanishfr- Frenchde- Germanzh- Chineseja- Japaneseru- Russianpt- Portugueseit- Italianar- Arabic
Structured data format, ideal for programmatic access.
XML format compatible with RSS/Atom readers.
Comma-separated values for data analysis.
RSS feed format for feed readers.
-
Rate Limiting: The search endpoint respects your server's rate limiting configuration.
-
Safe Search: Safe search is enabled by default to filter inappropriate content.
-
Input Validation: All search queries are validated to prevent injection attacks.
-
Timeout Limits: Request timeouts prevent long-running searches from consuming resources.
-
Result Limits: Maximum result count is enforced to prevent excessive resource usage.
The internet search implementation is fully thread-safe and supports concurrent requests:
- Worker Threads: Uses dedicated worker threads for HTTP requests
- Connection Pooling: Efficiently manages connections to the SearXNG instance
- Async Processing: Non-blocking request handling
- Queue Management: Thread-safe request queuing system
Common error types and their meanings:
| Error Type | Description | HTTP Status |
|---|---|---|
feature_disabled |
Search is not enabled | 503 |
invalid_request |
Invalid parameters | 400 |
timeout |
Search request timed out | 504 |
search_failed |
SearXNG returned an error | 502 |
internal_error |
Server internal error | 500 |
-
Caching: Consider implementing caching in your SearXNG instance for frequently searched terms.
-
Connection Pooling: The server uses connection pooling to efficiently handle multiple requests.
-
Timeout Configuration: Adjust timeout values based on your SearXNG instance performance.
-
Result Limiting: Use appropriate result limits to balance between usefulness and performance.
The search endpoint provides detailed logging:
[INFO] [Thread 12345] Received internet search request
[INFO] Making search request to: http://localhost:4000/search?q=example&format=json
[INFO] [Thread 12345] Search request completed successfully
import requests
import json
def search_web(query, max_results=10):
url = "http://localhost:8080/internet_search"
payload = {
"query": query,
"results": max_results,
"format": "json"
}
response = requests.post(url, json=payload)
if response.status_code == 200:
return response.json()
else:
print(f"Search failed: {response.status_code}")
return None
# Usage
results = search_web("machine learning", 5)
if results:
for result in results.get("results", []):
print(f"Title: {result['title']}")
print(f"URL: {result['url']}")
print(f"Content: {result['content'][:100]}...")
print()async function searchWeb(query, maxResults = 10) {
const response = await fetch('http://localhost:8080/internet_search', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
query: query,
results: maxResults,
format: 'json'
})
});
if (response.ok) {
return await response.json();
} else {
console.error('Search failed:', response.status);
return null;
}
}
// Usage
searchWeb('artificial intelligence', 5)
.then(results => {
if (results) {
results.results.forEach(result => {
console.log(`Title: ${result.title}`);
console.log(`URL: ${result.url}`);
console.log(`Content: ${result.content.substring(0, 100)}...`);
console.log();
});
}
});# Basic search
curl -X POST http://localhost:8080/internet_search \
-H "Content-Type: application/json" \
-d '{"query": "OpenAI GPT-4"}'
# Search with specific engines
curl -X POST http://localhost:8080/internet_search \
-H "Content-Type: application/json" \
-d '{"query": "climate change", "engines": "google,bing", "results": 20}'
# News search
curl -X POST http://localhost:8080/internet_search \
-H "Content-Type: application/json" \
-d '{"query": "tech news", "categories": "news", "language": "en"}'
# GET request
curl "http://localhost:8080/internet_search?q=python&results=5"-
"Feature disabled" error
- Enable search in configuration:
search.enabled: true - Restart the server after configuration changes
- Enable search in configuration:
-
"Connection refused" errors
- Verify SearXNG is running and accessible
- Check the
searxng_urlconfiguration - Ensure firewall allows connections
-
Timeout errors
- Increase timeout values in configuration
- Check SearXNG instance performance
- Verify network connectivity
-
Empty results
- Check SearXNG engine configuration
- Verify search engines are enabled
- Try different search categories
-
Invalid format errors
- Use supported formats: json, xml, csv, rss
- Check SearXNG supports the requested format
Enable debug logging to troubleshoot issues:
logging:
level: "DEBUG"This will provide detailed information about search requests and responses.
-
Use Appropriate Timeouts: Set reasonable timeout values based on your use case.
-
Limit Result Count: Request only the number of results you actually need.
-
Cache Results: Implement client-side caching for frequently searched terms.
-
Handle Errors Gracefully: Always check for errors and provide fallback behavior.
-
Use Specific Engines: Specify engines when you know what type of content you're looking for.
-
Respect Rate Limits: Don't overwhelm the search service with too many concurrent requests.
-
Monitor Performance: Keep track of search response times and error rates.
For more information about SearXNG configuration and capabilities, visit the SearXNG documentation.