GNAI-023 M8-T4 Fix: Embeddings-Sidecar gegen 501 'does not support embeddings'

gpt-researcher v3.8 rankt Kontext pro Sub-Query per Embeddings, nutzt aber
eine einzige OPENAI_BASE_URL fuer Chat UND Embeddings -> llama.cpp ohne
--embeddings antwortet 501. Loesung: CPU-only llama.cpp-Sidecar
(--embeddings, Alias llama-cpp-embed, nur im Production-Netz) mit
nomic-embed-text-v2-moe Q8_0 (multilingual, sha256-gepinnt im model_store,
Flag model_store_include_embedding nur in Production). Backend erhaelt
EMBEDDING=custom:nomic-embed-text-v2-moe + GNAI_EMBEDDING_BASE_URL; ein
gemountetes sitecustomize.py biegt nur OpenAIEmbeddings auf die Sidecar-URL
um, Chat laeuft weiter auf llama-cpp. Verifiziert: embed_query -> 768-dim
Vektor ueber llama-cpp-embed. research.yml idempotent (changed=0).

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
2026-11-20 20:33:04 +01:00
parent 1c407c28ec
commit c491c0e0bb
10 changed files with 220 additions and 4 deletions
@@ -64,3 +64,10 @@ inference_engine_ctx_size_override: null
# Keycloak OIDC at https://chat.ghostnet.selfhost.eu (NPM proxy host ->
# 10.0.0.90:8081; Keycloak client gnai-openwebui, public + PKCE S256).
open_webui_oidc_enabled: true
# M8 (GNAI-023): the Production environment additionally runs gpt-researcher,
# which needs a multilingual embedding model for its context ranking. The
# model is fetched by model_store (ai.yml) and served by a CPU-only
# llama.cpp --embeddings sidecar rendered by the gpt_researcher role
# (research.yml).
model_store_include_embedding: true
@@ -49,6 +49,29 @@ gpt_researcher_shim_image: docker.io/library/python
gpt_researcher_shim_image_ref: "{{ gpt_researcher_shim_image }}:3.13-alpine"
gpt_researcher_shim_script: "{{ gpt_researcher_data_dir }}/searxng_shim.py"
# Embedding sidecar (GNAI-023 M8-T4, Befund 20.11. "501 embeddings"):
# gpt-researcher v3.8 ranks scraped context via embeddings but reads a single
# OPENAI_BASE_URL for chat AND embeddings, so a dedicated CPU-only llama.cpp
# instance with --embeddings serves /v1/embeddings on the alias
# llama-cpp-embed; the backend's sitecustomize patch redirects only the
# embeddings client there (see files/sitecustomize_gnai.py).
# The image digest is a copy of inference_engine_image_ref (role defaults
# are not visible across plays) — keep in sync with
# roles/inference_engine/defaults/main.yml.
gpt_researcher_embed_engine_image_ref: "ghcr.io/ggml-org/llama.cpp@sha256:4bbbd2e33deb54330fd23edde3a2cdf12b05ce4415139c7e8639a9aebbacdcf2"
gpt_researcher_model_store_root: "{{ model_store_root | default('/var/lib/ghostnet-ai/shared/models') }}"
gpt_researcher_embed_model_directory: nomic-embed-text-v2-moe
gpt_researcher_embed_model_file: nomic-embed-text-v2-moe.Q8_0.gguf
# copy of model_store_embedding_artifact.sha256 (role defaults are not
# visible across plays) — keep in sync with roles/model_store/defaults/main.yml
gpt_researcher_embed_model_sha256: "06e7a7e594a26985523c18383aba4aad39fe6e14f08ffc6ab5b554e1ccdc3cff"
gpt_researcher_embed_model_alias: nomic-embed-text-v2-moe
gpt_researcher_embed_alias: llama-cpp-embed
gpt_researcher_embed_base_url: "http://{{ gpt_researcher_embed_alias }}:8080/v1"
# Mounted over site-packages/sitecustomize.py in the backend container
# (auto-imported at interpreter start; the image ships none).
gpt_researcher_backend_patch_script: "{{ gpt_researcher_data_dir }}/sitecustomize_gnai.py"
# LLM + retriever config (gpt-researcher v3.8 env; LLM names need the
# '<provider>:<model>' form). Token limits stay at upstream defaults
# (FAST=3000/SMART=6000) — fine for a 27B local model.
@@ -63,6 +86,11 @@ gpt_researcher_env:
# v3.8 default scraper is "bs" (requests + bs4) — pin it explicitly so a
# future upstream default change cannot require a browser in the image
SCRAPER: bs
# Embeddings: provider "custom" sends /v1/embeddings to OPENAI_BASE_URL by
# default; sitecustomize_gnai.py redirects only that client to
# GNAI_EMBEDDING_BASE_URL (CPU-only llama-cpp sidecar, alias llama-cpp-embed)
EMBEDDING: "custom:{{ gpt_researcher_embed_model_alias }}"
GNAI_EMBEDDING_BASE_URL: "{{ gpt_researcher_embed_base_url }}"
LLM_TIMEOUT: "600"
LOGGING_LEVEL: INFO
DOC_PATH: /usr/src/app/my-docs
@@ -0,0 +1,32 @@
"""Ghostnet.AI patch for the gpt-researcher backend (GNAI-023 M8-T4).
Mounted read-only over /usr/local/lib/python3.11/site-packages/sitecustomize.py
in the gptr backend container, so Python imports it automatically at
interpreter start (the published image ships no sitecustomize).
gpt-researcher v3.8 reads a single OPENAI_BASE_URL for BOTH the chat LLM
(utils/llm.py) and the embeddings client (memory/embeddings.py, "custom"
provider), so chat and embeddings cannot be split via environment variables
alone. This patch redirects ONLY the embeddings client
(langchain_openai.OpenAIEmbeddings, used exclusively for context ranking) to
GNAI_EMBEDDING_BASE_URL — a CPU-only llama.cpp --embeddings sidecar
(alias llama-cpp-embed). Chat completions keep using OPENAI_BASE_URL
(llama-cpp) untouched.
"""
import os
_base = os.environ.get("GNAI_EMBEDDING_BASE_URL")
if _base:
try:
from langchain_openai import OpenAIEmbeddings as _OE
_orig_init = _OE.__init__
def _patched_init(self, *args, **kwargs):
kwargs["openai_api_base"] = _base
_orig_init(self, *args, **kwargs)
_OE.__init__ = _patched_init
except Exception:
# never break interpreter startup because of the patch
pass
@@ -35,4 +35,5 @@
- backend
- frontend
- searxng-shim
- embed
when: not ansible_check_mode
@@ -30,6 +30,40 @@
- Reload workload user manager
- Restart gptr units
- name: Deploy the backend sitecustomize patch (embeddings split)
ansible.builtin.copy:
src: files/sitecustomize_gnai.py
dest: "{{ gpt_researcher_backend_patch_script }}"
owner: "{{ gpt_researcher_user }}"
group: "{{ gpt_researcher_user }}"
mode: "0644"
notify:
- Reload workload user manager
- Restart gptr units
- name: Ensure the embedding model is present in the shared model store
ansible.builtin.stat:
path: "{{ gpt_researcher_model_store_root }}/{{ gpt_researcher_embed_model_directory }}/{{ gpt_researcher_embed_model_file }}"
checksum_algorithm: sha256
get_checksum: true
register: gptr_embed_model
changed_when: false
failed_when: >-
not gptr_embed_model.stat.exists
or gptr_embed_model.stat.checksum != gpt_researcher_embed_model_sha256
check_mode: false
- name: Explain a missing embedding model
ansible.builtin.assert:
that:
- gptr_embed_model.stat.exists
- gptr_embed_model.stat.checksum == gpt_researcher_embed_model_sha256
fail_msg: >-
The embedding model {{ gpt_researcher_embed_model_file }} is missing or
its checksum mismatches in {{ gpt_researcher_model_store_root }} —
run playbooks/ai.yml for the production inventory first
(model_store_include_embedding: true fetches it).
- name: Check whether the engine API key secret exists
ansible.builtin.command:
argv:
@@ -82,6 +116,7 @@
- "{{ gpt_researcher_backend_image_ref }}"
- "{{ gpt_researcher_frontend_image_ref }}"
- "{{ gpt_researcher_shim_image_ref }}"
- "{{ gpt_researcher_embed_engine_image_ref }}"
register: gptr_images_present
changed_when: false
failed_when: false
@@ -117,6 +152,7 @@
- { src: gptr-backend.container.j2, name: backend }
- { src: gptr-frontend.container.j2, name: frontend }
- { src: gptr-searxng-shim.container.j2, name: searxng-shim }
- { src: gptr-embed.container.j2, name: embed }
notify:
- Reload workload user manager
- Restart gptr units
@@ -157,6 +193,7 @@
- backend
- frontend
- searxng-shim
- embed
register: gptr_unit_states
changed_when: false
failed_when: false
@@ -233,3 +270,47 @@
chdir: "{{ gpt_researcher_home }}"
changed_when: false
when: not ansible_check_mode
- name: Wait for the embedding sidecar (via the backend container)
ansible.builtin.command:
argv:
- /usr/sbin/runuser
- --user
- "{{ gpt_researcher_user }}"
- --
- /usr/bin/env
- HOME={{ gpt_researcher_home }}
- "XDG_RUNTIME_DIR=/run/user/{{ gpt_researcher_uid }}"
- /usr/bin/podman
- exec
- "{{ gpt_researcher_unit_prefix }}-backend"
- /bin/sh
- -c
- "python3 -c \"import urllib.request; urllib.request.urlopen('{{ gpt_researcher_embed_base_url }}/models', timeout=10)\""
chdir: "{{ gpt_researcher_home }}"
register: gptr_embed_health
until: gptr_embed_health.rc == 0
retries: 30
delay: 5
changed_when: false
when: not ansible_check_mode
- name: Verify the embeddings endpoint answers via the sidecar
ansible.builtin.command:
argv:
- /usr/sbin/runuser
- --user
- "{{ gpt_researcher_user }}"
- --
- /usr/bin/env
- HOME={{ gpt_researcher_home }}
- "XDG_RUNTIME_DIR=/run/user/{{ gpt_researcher_uid }}"
- /usr/bin/podman
- exec
- "{{ gpt_researcher_unit_prefix }}-backend"
- /bin/sh
- -c
- "python3 -c \"import json,urllib.request; req=urllib.request.Request('{{ gpt_researcher_embed_base_url }}/embeddings', data=json.dumps({'model':'{{ gpt_researcher_embed_model_alias }}','input':'Hallo Welt'}).encode(), headers={'Content-Type':'application/json'}); d=json.loads(urllib.request.urlopen(req, timeout=60).read()); assert len(d['data'][0]['embedding']) > 100, list(d.keys())\""
chdir: "{{ gpt_researcher_home }}"
changed_when: false
when: not ansible_check_mode
@@ -16,6 +16,9 @@ Secret={{ gpt_researcher_engine_api_key_secret }},type=env,target=OPENAI_API_KEY
Volume={{ gpt_researcher_data_dir }}/my-docs:/usr/src/app/my-docs:rw
Volume={{ gpt_researcher_data_dir }}/outputs:/usr/src/app/outputs:rw
Volume={{ gpt_researcher_data_dir }}/logs:/usr/src/app/logs:rw
# sitecustomize patch: redirects only the embeddings client to
# GNAI_EMBEDDING_BASE_URL (llama-cpp-embed); image ships no sitecustomize
Volume={{ gpt_researcher_backend_patch_script }}:/usr/local/lib/python3.11/site-packages/sitecustomize.py:ro
{% for key, value in gpt_researcher_env.items() %}
Environment="{{ key }}={{ value }}"
{% endfor %}
@@ -0,0 +1,24 @@
[Unit]
Description=Embedding sidecar for gpt-researcher (llama.cpp --embeddings, CPU-only, :8080 internal)
Wants={{ gpt_researcher_network_name }}-network.service
After={{ gpt_researcher_network_name }}-network.service
[Container]
Image={{ gpt_researcher_embed_engine_image_ref }}
Pull=never
ContainerName={{ gpt_researcher_unit_prefix }}-embed
Network={{ gpt_researcher_network_name }}
NetworkAlias={{ gpt_researcher_embed_alias }}
# no PublishPort, no AddDevice: CPU-only (n-gpu-layers 0), reachable only
# inside the workload network as {{ gpt_researcher_embed_alias }}
Volume={{ gpt_researcher_model_store_root }}/{{ gpt_researcher_embed_model_directory }}:/models:ro
# ENTRYPOINT of the pinned image is /app/llama-server, Exec= carries args only
Exec=--host 0.0.0.0 --port 8080 --model /models/{{ gpt_researcher_embed_model_file }} --alias {{ gpt_researcher_embed_model_alias }} --embeddings --n-gpu-layers 0 --ctx-size 8192 --no-webui
[Service]
Restart=on-failure
RestartSec=10
TimeoutStartSec=600
[Install]
WantedBy=default.target
@@ -62,5 +62,24 @@ model_store_vision_artifact:
license: >-
Qwen base model Apache-2.0; Swift changes under Swift Open License 1.0.
# The embedding model is only needed by the Production environment (gpt-
# researcher M8, GNAI-023); Testing does not run a research harness.
model_store_include_embedding: false
model_store_embedding_artifact:
profile: nomic-embed-text-v2-moe-q8
directory: nomic-embed-text-v2-moe
file: nomic-embed-text-v2-moe.Q8_0.gguf
sha256: 06e7a7e594a26985523c18383aba4aad39fe6e14f08ffc6ab5b554e1ccdc3cff
url: https://huggingface.co/nomic-ai/nomic-embed-text-v2-moe-GGUF/resolve/ffbcf4c99e5d617dda10ec8c0e9f75754b0cbb80/nomic-embed-text-v2-moe.Q8_0.gguf
repository: nomic-ai/nomic-embed-text-v2-moe-GGUF
revision: ffbcf4c99e5d617dda10ec8c0e9f75754b0cbb80
origin: >-
Nomic Embed Text v2 MoE, Q8_0 (~488 MiB, ~305M params) — SoTA
multilingual (~100 languages) text embedding model, served by a
CPU-only llama.cpp --embeddings sidecar for gpt-researcher (GNAI-023).
SHA-256 from the Hugging Face LFS blob metadata.
license: Apache-2.0
model_store_directory_mode: "0755"
model_store_file_mode: "0644"
@@ -6,10 +6,8 @@
ansible.builtin.set_fact:
model_store_all_artifacts: >-
{{ model_store_artifacts
+ (model_store_vision_artifact | ternary(
[model_store_vision_artifact], []))
if model_store_include_vision
else model_store_artifacts }}
+ ([model_store_vision_artifact] if model_store_include_vision else [])
+ ([model_store_embedding_artifact] if model_store_include_embedding else []) }}
tags:
- models
- service