Skip to content

Feature: Ollama Web Search Integration — API Key Free Search#210

Merged
nashsu merged 2 commits into
nashsu:mainfrom
naveed949:feature/ollama-web-search
May 24, 2026
Merged

Feature: Ollama Web Search Integration — API Key Free Search#210
nashsu merged 2 commits into
nashsu:mainfrom
naveed949:feature/ollama-web-search

Conversation

@naveed949
Copy link
Copy Markdown
Contributor

Summary

This PR adds Ollama as a new web search provider for Deep Research, enabling users to perform web searches without requiring external API keys (Tavily, SerpApi). Users simply need a local Ollama instance running with a web-search-capable model.

Motivation

Currently, llm_wiki's Deep Research feature requires users to configure a paid API key from Tavily or SerpApi to perform web searches. This creates a barrier for users who:

  • Want to experiment with Deep Research without creating accounts
  • Have privacy concerns about sending queries to third-party services
  • Already have Ollama running locally for LLM inference

By leveraging Ollama's built-in /api/experimental/web_search endpoint, users can get started with web search immediately if they already use Ollama as their LLM provider.

Changes

Type System (src/stores/wiki-store.ts)

  • Added "ollama" to the SearchProvider union type
  • Added ollamaUrl?: string to SearchApiConfig interface
  • Added ollamaUrl?: string to SearchProviderOverride interface
  • Updated SearchProviderConfigs to include "ollama" in the record type

Search Implementation (src/lib/web-search.ts)

  • New function: ollamaSearch(query, ollamaUrl, maxResults) — calls Ollama's /api/experimental/web_search endpoint
  • New function: hasConfiguredSearchProvider() — utility to check if any valid search provider is configured, now includes Ollama in the check
  • Updated resolveSearchConfig() — properly resolves ollama-specific URL configuration with sensible defaults
  • Updated webSearch() switch — added case "ollama" to route searches to the new implementation
  • Uses Tauri's HTTP plugin (getHttpFetch()) for consistent error handling across all providers
  • Implements proper error handling for:
    • Connection refused (Ollama not running)
    • HTTP 401 (requires ollama signin authentication)
    • Other HTTP errors with descriptive messages

UI Changes (src/components/settings/sections/web-search-section.tsx)

  • Added Ollama as the first provider in the search settings UI (promoted as the recommended free option)
  • Ollama card shows:
    • URL field (pre-filled with http://localhost:11434)
    • No API key field (as it's not needed)
    • Helpful hint explaining requirements
  • isLocal: true flag to distinguish local providers from cloud providers in the UI

Internationalization (src/i18n/en.json, src/i18n/zh.json)

  • Added ollamaHint translation key explaining that:
    • Uses local Ollama's built-in web search
    • Requires Ollama running with a web-search-capable model

How It Works

  1. User selects "Ollama (Local)" in Settings → Web Search
  2. URL defaults to http://localhost:11434 (matching the Ollama LLM setting)
  3. Deep Research calls webSearch() which routes to ollamaSearch()
  4. ollamaSearch() POSTs to {ollamaUrl}/api/experimental/web_search with { query, max_results }
  5. Ollama returns JSON with results: [{ title, url, content }]
  6. Results are normalized to WebSearchResult[] format

Requirements

  • Ollama running locally (or at configured URL)
  • A model loaded in Ollama that supports web search (some models may not support this feature)
  • For authenticated searches: ollama signin in terminal

API Reference

Ollama Web Search Endpoint:


POST /api/experimental/web_search
Content-Type: application/json

{
  "query": "search terms",
  "max_results": 5
}

Response:
{
  "results": [
    {
      "title": "Result Title",
      "url": "https://example.com",
      "content": "Snippet text..."
    }
  ]
}

Testing

Added new test cases in src/lib/web-search.test.ts:

  • calls Ollama web search and normalizes results — verifies correct API call and response parsing
  • surfaces Ollama auth errors — verifies 401 handling with actionable message

Screenshots

The new UI shows Ollama as the first (recommended) option:


┌─────────────────────────────────────────────────────┐
│ ┌─────────────────────────────────────────────────┐ │
│ │ ○ Ollama (Local)                      [Active] │ │
│ │ Free web search via your local Ollama instance │ │
│ └─────────────────────────────────────────────────┘ │
│                                                     │
│ ┌─────────────────────────────────────────────────┐ │
│ │ ○ Tavily                                       │ │
│ │ General web search for Deep Research           │ │
│ └─────────────────────────────────────────────────┘ │
│                                                     │
│ ┌─────────────────────────────────────────────────┐ │
│ │ ○ SerpApi                                      │ │
│ │ Google, Bing, DuckDuckGo, Scholar...           │ │
│ └─────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────┘

Comparison with Existing Providers

Provider API Key Required URL Config Notes
Ollama No Yes (default: localhost:11434) Uses local Ollama instance
Tavily Yes No Cloud service
SerpApi Yes No Cloud service
SearXNG No Yes Self-hosted metasearch

Migration Notes

None — this is purely additive. Existing Tavily/SerpApi/SearXNG configurations continue to work unchanged.

Future Enhancements (Out of Scope)

  • webFetch integration for fetching full page content
  • Model capability detection (which models support web search)
  • Auto-detection of Ollama availability on startup

naveed949 added 2 commits May 19, 2026 13:22
- Add 'ollama' as a new SearchProvider type in wiki-store.ts
- Add ollamaUrl field to SearchApiConfig and SearchProviderOverride
- Update SearchProviderConfigs to include 'ollama'
- Implement ollamaSearch() function in web-search.ts using
  GET /api/experimental/web_search endpoint
- Add ollama as first provider in web-search-section.tsx UI
- Add i18n translations for ollamaHint in en.json and zh.json

Users can now do web search without API keys by using their local
Ollama instance's built-in web search capabilities.
- research-panel.tsx: Check resolved config, allow 'ollama' as valid provider
- review-view.tsx: Same fix for deep research validation
- web-search.ts: Improve error message to mention other providers
- web-search.test.ts: Add tests for Ollama search and auth error

Fixes the 'Web Search not configured' popup when Ollama is selected.
@nashsu nashsu merged commit 0335397 into nashsu:main May 24, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants