1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Open WebUIでWeb検索のSearXNGをDocker環境で構築

1
Posted at

はじめに

OpenWebUIを構築している中で、最新のインターネット情報を参照しながら回答できる環境を作りたくなりました。

今回は OpenWebUI(v0.9.6)とSearXNGをDocker Composeで構築し、Web検索機能を有効化した際の構成と実際に遭遇したトラブルについてまとめます。

構成

今回の構成は以下です。

利用者
  ↓
OpenWebUI
  ↓
SearXNG
  ↓
Google / Bing / DuckDuckGo 等

OpenWebUIからSearXNGへ検索要求を送り、SearXNGが各検索エンジンから検索結果を取得します。

Docker Compose構成

compose.yaml
services:

  # OpenWebUI
  open-webui:
    image: ghcr.io/open-webui/open-webui:v0.9.6
    ports:
      - "3000:8080"
    depends_on:
      - searxng
    environment:
      # -------------------------------
      # (モデルやDBの指定などは省略)
      # -------------------------------

      # Web検索関連の設定
      ENABLE_WEB_SEARCH: "true"
      WEB_SEARCH_ENGINE: "searxng"
      SEARXNG_QUERY_URL: "http://searxng:8080/search?q=<query>&format=json"
      WEB_SEARCH_RESULT_COUNT: "3"
      WEB_SEARCH_CONCURRENT_REQUESTS: "1"
      # 以下が無いと機能しないので注意
      BYPASS_WEB_SEARCH_EMBEDDING_AND_RETRIEVAL: "true"
    volumes:
      - ./data/open-webui-data:/app/backend/data
    restart: unless-stopped
    depends_on:
      - searxng

  # SearXNG
  searxng:
    image: searxng/searxng:latest
    ports:
      - "8081:8080"
    volumes:
      - ./data/searxng:/etc/searxng
    restart: unless-stopped

SearXNG設定

OpenWebUIから利用するため、JSON形式を有効化します。

search:
  formats:
    - html
    - json

SearXNG設定の編集 ※初回のみ対応&要再起動

OpenWebUIから利用するため、設定ファイルでJSON形式を有効化します。
このファイルは、Docker Composeで一度起動してsettings.ymlを生成してから編集する必要があります。

# 起動
docker compose up -d

# 停止
docker compose down

# ★ローカルの./data/searxng/settings.ymlを編集★

# 起動
docker compose up -d

設定ファイルの編集するポイント配下の通りです。

./data/searxng/settings.yml
search:

  # --- (省略) ---

  # remove format to deny access, use lower case.
  # formats: [html, csv, json, rss]
  formats:
    - html
    - json # ★ここを追加

あとは、検索エンジンによってはエラーが出るケースもあるのですが、今回は検索時にログでエラーとなっていた以下を無効(disabled: true)にします。

対象の検索エンジン

  • duckduckgo
  • startpage

設定ファイルの編集箇所

./data/searxng/settings.yml
engines:

  # --- (省略) ---

  - name: duckduckgo
    engine: duckduckgo
    shortcut: ddg
    disabled: true # ★ここを追加

  - name: duckduckgo web
    engine: duckduckgo_web
    shortcut: ddgw
    disabled: true

  - name: duckduckgo images
    engine: duckduckgo_extra
    categories: [images]
    ddg_category: images
    shortcut: ddi
    disabled: true # ★ここを変更

  - name: duckduckgo videos
    engine: duckduckgo_extra
    categories: [videos]
    ddg_category: videos
    shortcut: ddv
    disabled: true # ★ここを変更

  - name: duckduckgo news
    engine: duckduckgo_extra
    categories: [news]
    ddg_category: news
    shortcut: ddn
    disabled: true # ★ここを変更

# --- (省略) ---

  - name: startpage
    engine: startpage
    shortcut: sp
    startpage_categ: web
    categories: [general, web]
    disabled: true # ★ここを追加

  - name: startpage news
    engine: startpage
    startpage_categ: news
    categories: [news, web]
    shortcut: spn
    disabled: true # ★ここを変更

  - name: startpage images
    engine: startpage
    startpage_categ: images
    categories: [images, web]
    shortcut: spi
    disabled: true # ★ここを変更

OpenWebUI側設定 ※既存環境にWeb検索追加ケース

今回はデフォルトでcompose.yamlで設定値をしていていますが、既存の設定に組み込む場合は管理画面から設定が必要なはずです。

管理画面から以下を設定します。

管理者パネル
↓
設定
↓
ウェブ検索

設定項目

  • ウェブ検索: ON
  • ウェブ検索エンジン: searxng
  • SearXNGクエリURL: http://searxng:8080/search?q=<query>&format=json
  • 検索結果数: 3
  • 同時リクエスト: 1
  • 埋め込みと検索をバイパス: ON

発生した問題

設定後、Web検索自体は実行されるものの、最終的に以下の表示になりました。

チャットで「今日のドル円相場を調べて」と入力
---------------------------------------------
6サイトを検索しました
↓
ドル円相場...
Yahoo Finance...
Investing.com...
↓
照会中...
↓
ソースが見つかりません

ログを見る限りは、Web検索は行われていたのですが原因が不明でした。
こちらは、既存のIssueを調べたらそれっぽい問題ありました。

こちらは、設定「埋め込みと検索をバイパス: ON」で回避するようにしました。
コンテキスト増の可能性はありますが、メリデメを見る限りは問題無いのでOKと考えました。

メリット

  • Web検索が安定する
  • 応答速度が向上する場合がある
  • 最新情報取得用途と相性が良い

デメリット

  • Retrievalによる絞り込みが行われない
  • 大量の検索結果を扱う場合は精度が落ちる可能性がある
  • コンテキスト利用量が増える可能性がある

チームなどでの運用を検討する際の注意事項

この設定は個人や少人数での利用には良いのですが、利用者がチームや組織の場合はWeb検索での失敗が頻発します。
Web検索の失敗の原因は、私の場合はSearXNGのログを確認したところ、検索エンジン側からToo many requestでアクセスが多くて失敗でした。

そのため、チームなどでの運用を行う場合は、有償のAPIを検討することをお勧めします。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?