Skip to content

OpenRAG is a comprehensive, single package Retrieval-Augmented Generation platform built on Langflow, Docling, and Opensearch.

Python

feat: MVP use liteLLM for providers (#2271)

Mike Fortmane7bf66fc8a80
diff --git a/.env.example b/.env.example
index 412b416ec..22983b96c 100644
--- a/.env.example
+++ b/.env.example
@@ -87,6 +87,15 @@ CORS_ALLOWED_ORIGINS=http://localhost:3000
# Set only to override the upstream entirely.
# OPENRAG_BACKEND_ROUTER_UPSTREAM_URL=http://127.0.0.1:8000
+# OpenAI-compatible LLM proxy Langflow calls (must end with /v1). Defaults to
+# OPENRAG_BACKEND_INTERNAL_URL/v1. Override only if Langflow cannot reach that host.
+# OPENRAG_LLM_PROXY_URL=http://openrag-backend:8000/v1
+
+# TTL for the short-lived Langflow LLM hop token (OPENRAG_LLM_TOKEN Langflow
+# sends to /v1/chat/completions and /v1/embeddings). Defaults to the
+# ingest-callback TTL.
+# LANGFLOW_LLM_PROXY_TTL_SECONDS=3900
+
# Base64 AES-256-GCM Master Encryption Key
# If not provided, OpenRAG will automatically generate a secure 32-byte key when you run the TUI or CLI wizard.
# If completely unset during normal execution, the master encryption system will remain inactive.
@@ -320,6 +329,10 @@ LANGFUSE_PUBLIC_KEY=
# Example of self hosting outside of the docker network: LANGFUSE_HOST=http://host.docker.internal:3000
LANGFUSE_HOST=
+# OPENRAG_LLM_TOKEN is seeded to the non-empty string "None" in Langflow
+# (docker-compose OPENRAG_LLM_TOKEN=None). Langflow treats an empty Credential
+# as missing. OpenRAG overwrites the value with a hop token per run.
+
# OPTIONAL: A development-mode only configuration value that allows additional origins (domains/hosts) to make requests to the Next.js dev server (next dev).
# - A list of comma-separate hostnames may be specified
# - e.g. 9.46.110.49,10.21.103.227,openrag.example.com
diff --git a/Dockerfile.langflow b/Dockerfile.langflow
index 181b9654f..ead9e8892 100644
--- a/Dockerfile.langflow
+++ b/Dockerfile.langflow
@@ -32,9 +32,11 @@ COPY custom_components/ /app/custom_components/
# (which owns /app), then switch to root so the entrypoint can correct
# bind-mount permissions at runtime before dropping back to uid=1000.
COPY --chmod=755 scripts/langflow-entrypoint.py /usr/local/bin/langflow-entrypoint
+COPY scripts/patch_langflow_openrag_bundle.py /tmp/patch_langflow_openrag_bundle.py
COPY flows/component_index.json /app/component_index.json
USER root
-RUN rm -f /app/flows/component_index.json
+RUN rm -f /app/flows/component_index.json \
+ && python3 /tmp/patch_langflow_openrag_bundle.py
ENV LANGFLOW_SSRF_ALLOWED_HOSTS=localhost,127.0.0.1,host.docker.internal
ENV LANGFLOW_LOG_TRACE_LOCALS=false
ENV LANGFLOW_BLOCK_CODE_INTERPRETER_COMPONENTS=true
diff --git a/Dockerfile.langflow.dev b/Dockerfile.langflow.dev
index 9829f0676..16e5c3e26 100644
--- a/Dockerfile.langflow.dev
+++ b/Dockerfile.langflow.dev
@@ -34,6 +34,9 @@ RUN pip install --no-cache-dir --upgrade "pip>=26.1.2" \
RUN echo "Cloning ${GIT_REPO} branch ${GIT_BRANCH}..." && \
git clone --depth 1 --branch ${GIT_BRANCH} ${GIT_REPO} /app
+COPY scripts/patch_langflow_openrag_bundle.py /tmp/patch_langflow_openrag_bundle.py
+RUN python3 /tmp/patch_langflow_openrag_bundle.py /app/src/frontend/src/utils/styleUtils.ts
+
# Install backend dependencies
RUN uv sync --frozen --no-install-project --no-editable --extra postgresql
diff --git a/custom_components/__init__.py b/custom_components/__init__.py
new file mode 100644
index 000000000..8b1378917
--- /dev/null
+++ b/custom_components/__init__.py
@@ -0,0 +1 @@
+
diff --git a/custom_components/openrag/__init__.py b/custom_components/openrag/__init__.py
new file mode 100644
index 000000000..8b1378917
--- /dev/null
+++ b/custom_components/openrag/__init__.py
@@ -0,0 +1 @@
+
diff --git a/custom_components/openrag/openai_compatible_embedding.py b/custom_components/openrag/openai_compatible_embedding.py
new file mode 100644
index 000000000..356516d07
--- /dev/null
+++ b/custom_components/openrag/openai_compatible_embedding.py
@@ -0,0 +1,117 @@
+"""OpenAI-compatible embeddings that talk to the OpenRAG `/v1` proxy.
+
+Embeddings work the same way as chat: Langflow never holds upstream vendor
+keys. At runtime OpenRAG injects:
+
+- ``OPENRAG_LLM_TOKEN`` — the same short-lived hop token as chat
+- ``OPENRAG_LLM_BASE_URL`` — the same ``http://<backend>/v1`` base URL
+- ``SELECTED_EMBEDDING_MODEL`` — configured embedding model id
+
+``OpenAIEmbeddings`` posts to ``{base_url}/embeddings``. The backend gateway
+routes by the configured embedding provider (which can differ from the chat
+provider).
+"""
+
+from __future__ import annotations
+
+from typing import Any
+
+from langchain_openai import OpenAIEmbeddings
+from lfx.base.embeddings.model import LCEmbeddingsModel
+from lfx.field_typing import Embeddings
+from lfx.io import IntInput, SecretStrInput, StrInput
+
+# Names must match src/api/settings/langflow_sync.py + src/utils/langflow_headers.py
+OPENRAG_LLM_BASE_URL_VAR = "OPENRAG_LLM_BASE_URL"
+OPENRAG_LLM_TOKEN_VAR = "OPENRAG_LLM_TOKEN"
+SELECTED_EMBEDDING_MODEL_VAR = "SELECTED_EMBEDDING_MODEL"
+
+
+def _as_str(value: object) -> str | None:
+ if value is None:
+ return None
+ getter = getattr(value, "get_secret_value", None)
+ if callable(getter):
+ value = getter()
+ text = str(value).strip()
+ return text or None
+
+
+class OpenAICompatibleEmbeddingComponent(LCEmbeddingsModel):
+ display_name = "OpenRAG Embeddings"
+ description = (
+ "Embeddings via OpenRAG's OpenAI-compatible /v1 proxy. "
+ "Uses the same base URL and hop token as the chat component."
+ )
+ icon = "OpenRAG"
+ name = "OpenAICompatibleEmbedding"
+
+ inputs = [
+ StrInput(
+ name="model_name",
+ display_name="Model Name",
+ info="Embedding model id. Bound to SELECTED_EMBEDDING_MODEL at runtime.",
+ value=SELECTED_EMBEDDING_MODEL_VAR,
+ load_from_db=True,
+ ),
+ SecretStrInput(
+ name="api_key",
+ display_name="OpenRAG LLM Token",
+ info="Hop token from OPENRAG_LLM_TOKEN. Same token as the chat component.",
+ value=OPENRAG_LLM_TOKEN_VAR,
+ required=False,
+ load_from_db=True,
+ ),
+ StrInput(
+ name="api_base",
+ display_name="OpenAI API Base",
+ info=(
+ "Must end with /v1 (for example http://openrag-backend:8000/v1). "
+ "Bound to OPENRAG_LLM_BASE_URL at runtime. Same URL as chat."
+ ),
+ value=OPENRAG_LLM_BASE_URL_VAR,
+ load_from_db=True,
+ ),
+ IntInput(
+ name="dimensions",
+ display_name="Dimensions",
+ info="Output dimensions when the embedding model supports it.",
+ advanced=True,
+ ),
+ IntInput(
+ name="chunk_size",
+ display_name="Chunk Size",
+ advanced=True,
+ value=1000,
+ ),
+ ]
+
+ def build_embeddings(self) -> Embeddings:
+ api_key = _as_str(self.api_key)
+ api_base = _as_str(self.api_base)
+ if api_base:
+ api_base = api_base.rstrip("/")
+
+ kwargs: dict[str, Any] = {
+ "model": self.model_name,
+ # `OpenAIEmbeddings.deployment` defaults to the class-level default of
+ # `model` — the literal "text-embedding-ada-002" — for every instance,
+ # whatever model is actually configured. The OpenSearch component keys
+ # its embedding lookup on `deployment` as well as `model`, so leaving
+ # the default in place registers this object under ada-002 too, and a
+ # 768-dim vector then gets aimed at a 1536-dim ada-002 vector field.
+ # Only Azure reads this field, so pinning it to the real model is inert
+ # at request time and keeps the component's identity honest.
+ "deployment": self.model_name,
+ "api_key": api_key,
+ "base_url": api_base or None,
+ # Skip tiktoken context checks so non-OpenAI model ids still work.
+ "check_embedding_ctx_length": False,
+ }
+ chunk_size = getattr(self, "chunk_size", None)
+ if chunk_size:
+ kwargs["chunk_size"] = chunk_size
+ dimensions = getattr(self, "dimensions", None)
+ if dimensions:
+ kwargs["dimensions"] = dimensions
+ return OpenAIEmbeddings(**kwargs)
diff --git a/custom_components/openrag/openai_compatible_llm.py b/custom_components/openrag/openai_compatible_llm.py
new file mode 100644
index 000000000..de147d013
--- /dev/null
+++ b/custom_components/openrag/openai_compatible_llm.py
@@ -0,0 +1,139 @@
+"""OpenAI-compatible chat model that talks to the OpenRAG `/v1` proxy.
+
+Langflow never holds upstream vendor keys. At runtime OpenRAG injects:
+
+- ``OPENRAG_LLM_TOKEN`` — short-lived hop token (Authorization Bearer)
+- ``OPENRAG_LLM_BASE_URL`` — ``http://<backend>/v1``
+- ``SELECTED_LANGUAGE_MODEL`` — configured chat model id
+
+``ChatOpenAI`` posts to ``{base_url}/chat/completions``. The backend gateway
+then calls the real vendor (OpenAI, Anthropic, Watsonx, Ollama, or any other
+LiteLLM provider). Embeddings use the same base URL and hop token; see
+``openai_compatible_embedding.py``.
+"""
+
+from __future__ import annotations
+
+from typing import Any
+
+from langchain_openai import ChatOpenAI
+from lfx.base.models.model import LCModelComponent
+from lfx.field_typing.constants import LanguageModel
+from lfx.field_typing.range_spec import RangeSpec
+from lfx.inputs.inputs import BoolInput, StrInput
+from lfx.io import IntInput, MessageInput, MultilineInput, SecretStrInput, SliderInput
+
+# Names must match src/api/settings/langflow_sync.py + src/utils/langflow_headers.py
+OPENRAG_LLM_BASE_URL_VAR = "OPENRAG_LLM_BASE_URL"
+OPENRAG_LLM_TOKEN_VAR = "OPENRAG_LLM_TOKEN"
+SELECTED_LANGUAGE_MODEL_VAR = "SELECTED_LANGUAGE_MODEL"
+
+
+def _as_str(value: object) -> str | None:
+ if value is None:
+ return None
+ getter = getattr(value, "get_secret_value", None)
+ if callable(getter):
+ value = getter()
+ text = str(value).strip()
+ return text or None
+
+
+class OpenAICompatibleLLMComponent(LCModelComponent):
+ display_name = "OpenRAG LLM"
+ description = (
+ "Chat model via OpenRAG's OpenAI-compatible /v1 proxy. "
+ "Base URL and hop token come from global variables at runtime."
+ )
+ icon = "OpenRAG"
+ name = "OpenAICompatibleLLM"
+
+ inputs = [
+ MessageInput(
+ name="input_value",
+ display_name="Input",
+ info="The input text to send to the model",
+ ),
+ MultilineInput(
+ name="system_message",
+ display_name="System Message",
+ info="A system message that helps set the behavior of the assistant",
+ advanced=False,
+ ),
+ BoolInput(
+ name="stream",
+ display_name="Stream",
+ info="Whether to stream the response",
+ value=False,
+ advanced=True,
+ ),
+ StrInput(
+ name="model_name",
+ display_name="Model Name",
+ info="Chat model id. Bound to SELECTED_LANGUAGE_MODEL at runtime.",
+ value=SELECTED_LANGUAGE_MODEL_VAR,
+ load_from_db=True,
+ ),
+ SecretStrInput(
+ name="api_key",
+ display_name="OpenRAG LLM Token",
+ info="Hop token from OPENRAG_LLM_TOKEN. OpenRAG injects this per Langflow run.",
+ value=OPENRAG_LLM_TOKEN_VAR,
+ required=False,
+ load_from_db=True,
+ ),
+ StrInput(
+ name="api_base",
+ display_name="OpenAI API Base",
+ info=(
+ "Must end with /v1 (for example http://openrag-backend:8000/v1). "
+ "Bound to OPENRAG_LLM_BASE_URL at runtime. Same URL as embeddings."
+ ),
+ value=OPENRAG_LLM_BASE_URL_VAR,
+ load_from_db=True,
+ ),
+ SliderInput(
+ name="temperature",
+ display_name="Temperature",
+ value=0.1,
+ info="Controls randomness in responses",
+ range_spec=RangeSpec(min=0, max=1, step=0.01),
+ advanced=True,
+ ),
+ IntInput(
+ name="max_tokens",
+ display_name="Max Tokens",
+ info="Maximum number of tokens to generate. Leave empty for the model default.",
+ advanced=True,
+ ),
+ IntInput(
+ name="seed",
+ display_name="Seed",
+ info="The seed controls the reproducibility of the job.",
+ advanced=True,
+ value=1,
+ ),
+ ]
+
+ def build_model(self) -> LanguageModel:
+ api_key = _as_str(self.api_key)
+ api_base = _as_str(self.api_base)
+ if api_base:
+ api_base = api_base.rstrip("/")
+
+ kwargs: dict[str, Any] = {
+ "model": self.model_name,
+ "api_key": api_key,
+ "base_url": api_base or None,
+ "streaming": bool(getattr(self, "stream", False)),
+ }
+ max_tokens = getattr(self, "max_tokens", None)
+ if max_tokens:
+ kwargs["max_tokens"] = max_tokens
+ temperature = getattr(self, "temperature", None)
+ if temperature is not None:
+ kwargs["temperature"] = temperature
+ seed = getattr(self, "seed", None)
+ if seed is not None:
+ kwargs["seed"] = seed
+ return ChatOpenAI(**kwargs)
diff --git a/docker-compose.yml b/docker-compose.yml
index cb902ad35..15e3bc1d2 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -206,11 +206,19 @@ services:
- "host.docker.internal:host-gateway"
environment:
- LANGFLOW_ALLOW_CUSTOM_COMPONENTS=${LANGFLOW_ALLOW_CUSTOM_COMPONENTS:-false}
+ # Prefer the bind-mounted index so `scripts/update_openrag_component_index.py`
+ # takes effect on `docker compose restart langflow` without an image rebuild.
+ - LANGFLOW_COMPONENTS_INDEX_PATH=/app/flows/component_index.json
- LANGFUSE_SECRET_KEY=${LANGFUSE_SECRET_KEY:-}
- LANGFUSE_PUBLIC_KEY=${LANGFUSE_PUBLIC_KEY:-}
- LANGFUSE_HOST=${LANGFUSE_HOST:-}
- LANGFLOW_DEACTIVATE_TRACING
- - OPENAI_API_KEY=${OPENAI_API_KEY}
+ # Hop token is injected per Langflow run. Seed a non-empty placeholder
+ # so load_from_db can resolve OPENRAG_LLM_TOKEN; Langflow treats "" as
+ # missing. Do not pass a vendor key here.
+ - OPENAI_API_KEY=${LANGFLOW_OPENAI_API_KEY:-}
+ - OPENRAG_LLM_TOKEN=None
+ - OPENRAG_LLM_BASE_URL=${OPENRAG_LLM_BASE_URL:-}
- ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY}
- WATSONX_APIKEY=${WATSONX_API_KEY}
- WATSONX_URL=${WATSONX_URL:-${WATSONX_ENDPOINT}}
@@ -250,7 +258,7 @@ services:
- MIMETYPE=None
- FILESIZE=0
- SELECTED_EMBEDDING_MODEL=${SELECTED_EMBEDDING_MODEL:-text-embedding-3-small}
- - LANGFLOW_VARIABLES_TO_GET_FROM_ENVIRONMENT=JWT,OPENRAG-QUERY-FILTER,OPENSEARCH_PASSWORD,OPENSEARCH_URL,DOCLING_SERVE_URL,DOCLING_SERVE_VERIFY_SSL,DOCLING_TASK_ID,OWNER,OWNER_NAME,OWNER_EMAIL,CONNECTOR_TYPE,DOCUMENT_ID,SOURCE_URL,ALLOWED_USERS,ALLOWED_GROUPS,ALLOWED_PRINCIPALS,FILENAME,MIMETYPE,FILESIZE,SELECTED_EMBEDDING_MODEL,OPENAI_API_KEY,ANTHROPIC_API_KEY,WATSONX_APIKEY,WATSONX_URL,WATSONX_PROJECT_ID,OLLAMA_BASE_URL,OPENSEARCH_INDEX_NAME,OPENRAG_INGEST_URL,OPENRAG_INGEST_TOKEN,OPENRAG_INGEST_RUN_ID,OPENRAG_INGEST_BATCH_SIZE
+ - LANGFLOW_VARIABLES_TO_GET_FROM_ENVIRONMENT=JWT,OPENRAG-QUERY-FILTER,OPENSEARCH_PASSWORD,OPENSEARCH_URL,DOCLING_SERVE_URL,DOCLING_SERVE_VERIFY_SSL,DOCLING_TASK_ID,OWNER,OWNER_NAME,OWNER_EMAIL,CONNECTOR_TYPE,DOCUMENT_ID,SOURCE_URL,ALLOWED_USERS,ALLOWED_GROUPS,ALLOWED_PRINCIPALS,FILENAME,MIMETYPE,FILESIZE,SELECTED_EMBEDDING_MODEL,OPENAI_API_KEY,OPENRAG_LLM_TOKEN,OPENRAG_LLM_BASE_URL,ANTHROPIC_API_KEY,WATSONX_APIKEY,WATSONX_URL,WATSONX_PROJECT_ID,OLLAMA_BASE_URL,OPENSEARCH_INDEX_NAME,OPENRAG_INGEST_URL,OPENRAG_INGEST_TOKEN,OPENRAG_INGEST_RUN_ID,OPENRAG_INGEST_BATCH_SIZE
- LANGFLOW_LOG_LEVEL=DEBUG
- LANGFLOW_WORKERS=${LANGFLOW_WORKERS:-1}
- LANGFLOW_RATE_LIMIT_PER_MINUTE=${LANGFLOW_RATE_LIMIT_PER_MINUTE:-100}
diff --git a/flows/ingestion_flow.json b/flows/ingestion_flow.json
index df8bcf034..63b17a306 100644
--- a/flows/ingestion_flow.json
+++ b/flows/ingestion_flow.json
@@ -124,11 +124,10 @@
},
{
"animated": false,
- "className": "",
"data": {
"sourceHandle": {
- "dataType": "EmbeddingModel",
- "id": "EmbeddingModel-d8FQn",
+ "dataType": "OpenAICompatibleEmbedding",
+ "id": "OpenAICompatibleEmbedding-MloZd",
"name": "embeddings",
"output_types": [
"Embeddings"
@@ -136,23 +135,22 @@
},
"targetHandle": {
"fieldName": "embedding",
- "id": "ext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-JFBiL",
+ "id": "OpenSearchVectorStoreComponentMultimodalMultiEmbedding-WaE28",
"inputTypes": [
"Embeddings"
],
"type": "other"
}
},
- "id": "xy-edge__EmbeddingModel-d8FQn{œdataTypeœ:œEmbeddingModelœ,œidœ:œEmbeddingModel-d8FQnœ,œnameœ:œembeddingsœ,œoutput_typesœ:[œEmbeddingsœ]}-ext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-JFBiL{œfieldNameœ:œembeddingœ,œidœ:œext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-JFBiLœ,œinputTypesœ:[œEmbeddingsœ],œtypeœ:œotherœ}",
+ "id": "xy-edge__OpenAICompatibleEmbedding-MloZd{œdataTypeœ:œOpenAICompatibleEmbeddingœ,œidœ:œOpenAICompatibleEmbedding-MloZdœ,œnameœ:œembeddingsœ,œoutput_typesœ:[œEmbeddingsœ]}-OpenSearchVectorStoreComponentMultimodalMultiEmbedding-WaE28{œfieldNameœ:œembeddingœ,œidœ:œOpenSearchVectorStoreComponentMultimodalMultiEmbedding-WaE28œ,œinputTypesœ:[œEmbeddingsœ],œtypeœ:œotherœ}",
"selected": false,
- "source": "EmbeddingModel-d8FQn",
- "sourceHandle": "{œdataTypeœ:œEmbeddingModelœ,œidœ:œEmbeddingModel-d8FQnœ,œnameœ:œembeddingsœ,œoutput_typesœ:[œEmbeddingsœ]}",
- "target": "ext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-JFBiL",
- "targetHandle": "{œfieldNameœ:œembeddingœ,œidœ:œext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-JFBiLœ,œinputTypesœ:[œEmbeddingsœ],œtypeœ:œotherœ}"
+ "source": "OpenAICompatibleEmbedding-MloZd",
+ "sourceHandle": "{œdataTypeœ:œOpenAICompatibleEmbeddingœ,œidœ:œOpenAICompatibleEmbedding-MloZdœ,œnameœ:œembeddingsœ,œoutput_typesœ:[œEmbeddingsœ]}",
+ "target": "OpenSearchVectorStoreComponentMultimodalMultiEmbedding-WaE28",
+ "targetHandle": "{œfieldNameœ:œembeddingœ,œidœ:œOpenSearchVectorStoreComponentMultimodalMultiEmbedding-WaE28œ,œinputTypesœ:[œEmbeddingsœ],œtypeœ:œotherœ}"
},
{
"animated": false,
- "className": "",
"data": {
"sourceHandle": {
"dataType": "SplitText",
@@ -164,7 +162,7 @@
},
"targetHandle": {
"fieldName": "ingest_data",
- "id": "ext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-JFBiL",
+ "id": "OpenSearchVectorStoreComponentMultimodalMultiEmbedding-WaE28",
"inputTypes": [
"Data",
"DataFrame",
@@ -173,12 +171,12 @@
"type": "other"
}
},
- "id": "xy-edge__SplitText-QIKhg{œdataTypeœ:œSplitTextœ,œidœ:œSplitText-QIKhgœ,œnameœ:œdataframeœ,œoutput_typesœ:[œTableœ]}-ext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-JFBiL{œfieldNameœ:œingest_dataœ,œidœ:œext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-JFBiLœ,œinputTypesœ:[œDataœ,œDataFrameœ,œTableœ],œtypeœ:œotherœ}",
+ "id": "xy-edge__SplitText-QIKhg{œdataTypeœ:œSplitTextœ,œidœ:œSplitText-QIKhgœ,œnameœ:œdataframeœ,œoutput_typesœ:[œTableœ]}-OpenSearchVectorStoreComponentMultimodalMultiEmbedding-WaE28{œfieldNameœ:œingest_dataœ,œidœ:œOpenSearchVectorStoreComponentMultimodalMultiEmbedding-WaE28œ,œinputTypesœ:[œDataœ,œDataFrameœ,œTableœ],œtypeœ:œotherœ}",
"selected": false,
"source": "SplitText-QIKhg",
"sourceHandle": "{œdataTypeœ:œSplitTextœ,œidœ:œSplitText-QIKhgœ,œnameœ:œdataframeœ,œoutput_typesœ:[œTableœ]}",
- "target": "ext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-JFBiL",
- "targetHandle": "{œfieldNameœ:œingest_dataœ,œidœ:œext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-JFBiLœ,œinputTypesœ:[œDataœ,œDataFrameœ,œTableœ],œtypeœ:œotherœ}"
+ "target": "OpenSearchVectorStoreComponentMultimodalMultiEmbedding-WaE28",
+ "targetHandle": "{œfieldNameœ:œingest_dataœ,œidœ:œOpenSearchVectorStoreComponentMultimodalMultiEmbedding-WaE28œ,œinputTypesœ:[œDataœ,œDataFrameœ,œTableœ],œtypeœ:œotherœ}"
}
],
"nodes": [
@@ -679,6 +677,10 @@
},
"dragging": false,
"id": "DoclingRemote-Dp3PX",
+ "measured": {
+ "height": 52,
+ "width": 192
+ },
"position": {
"x": 377.3513331245854,
"y": 1841.1174193072818
@@ -951,6 +953,10 @@
},
"dragging": false,
"id": "ExportDoclingDocument-zZdRg",
+ "measured": {
+ "height": 52,
+ "width": 192
+ },
"position": {
"x": 648.3765412475954,
"y": 1839.7464467523132
@@ -2336,6 +2342,10 @@
},
"dragging": false,
"id": "Operations-IC6CD",
+ "measured": {
+ "height": 80,
+ "width": 192
+ },
"position": {
"x": 922.8558031751697,
"y": 1830.0439761689086
@@ -3694,6 +3704,10 @@
},
"dragging": false,
"id": "Operations-VUCJC",
+ "measured": {
+ "height": 80,
+ "width": 192
+ },
"position": {
"x": 1209.814890352602,
"y": 1833.3550221261078
@@ -3965,6 +3979,10 @@
},
"dragging": false,
"id": "SplitText-QIKhg",
+ "measured": {
+ "height": 80,
+ "width": 192
+ },
"position": {
"x": 1483.6566983203961,
"y": 1839.4043723057894
@@ -3974,10 +3992,7 @@
},
{
"data": {
- "_connectionMode": false,
- "description": "Generate embeddings using a specified provider.",
- "display_name": "Embedding Model",
- "id": "EmbeddingModel-d8FQn",
+ "id": "OpenAICompatibleEmbedding-MloZd",
"node": {
"base_classes": [
"Embeddings"
@@ -3985,44 +4000,36 @@
"beta": false,
"conditional_paths": [],
"custom_fields": {},
- "description": "Generate embeddings using a specified provider.",
- "display_name": "Embedding Model",
- "documentation": "https://docs.langflow.org/components-embedding-models",
+ "description": "Embeddings via OpenRAG's OpenAI-compatible /v1 proxy. Uses the same base URL and hop token as the chat component.",
+ "display_name": "OpenRAG Embeddings",
+ "documentation": "",
"edited": false,
"field_order": [
- "model",
"model_name",
- "provider",
"api_key",
"api_base",
- "base_url_ibm_watsonx",
- "project_id",
- "ollama_base_url",
"dimensions",
- "chunk_size",
- "request_timeout",
- "max_retries",
- "show_progress_bar",
- "model_kwargs",
- "truncate_input_tokens",
- "input_text"
+ "chunk_size"
],
"frozen": false,
- "icon": "binary",
- "last_updated": "2026-08-05T16:16:36.111Z",
+ "icon": "OpenRAG",
"legacy": false,
"metadata": {
- "code_hash": "0780e9bbc5fa",
+ "code_hash": "cc257e587747",
"dependencies": {
"dependencies": [
+ {
+ "name": "langchain_openai",
+ "version": "1.5.2"
+ },
{
"name": "lfx",
- "version": "1.11.1rc0"
+ "version": "1.11.2"
}
],
- "total_dependencies": 1
+ "total_dependencies": 2
},
- "module": "custom_components.embedding_model"
+ "module": "custom_components.openrag_embeddings"
},
"minimized": false,
"output_types": [],
@@ -4032,12 +4039,8 @@
"cache": true,
"display_name": "Embedding Model",
"group_outputs": false,
- "hidden": null,
- "loop_types": null,
"method": "build_embeddings",
"name": "embeddings",
- "options": null,
- "required_inputs": null,
"selected": "Embeddings",
"tool_mode": true,
"types": [
@@ -4048,26 +4051,17 @@
],
"pinned": false,
"template": {
- "_frontend_node_flow_id": {
- "value": "5488df7c-b93f-4f87-a446-b67028bc0813"
- },
- "_frontend_node_folder_id": {
- "value": "203c7c12-9e1d-4561-bb14-16102afec154"
- },
"_type": "Component",
"api_base": {
- "_input_type": "MessageTextInput",
- "advanced": true,
+ "_input_type": "StrInput",
+ "advanced": false,
"api_editable": false,
- "display_name": "API Base URL",
+ "display_name": "OpenAI API Base",
"dynamic": false,
- "info": "Base URL for the API. Leave empty for default.",
- "input_types": [
- "Message"
- ],
+ "info": "Must end with /v1 (for example http://openrag-backend:8000/v1). Bound to OPENRAG_LLM_BASE_URL at runtime. Same URL as chat.",
"list": false,
"list_add_label": "Add More",
- "load_from_db": false,
+ "load_from_db": true,
"name": "api_base",
"override_skip": false,
"placeholder": "",
@@ -4075,65 +4069,30 @@
"show": true,
"title_case": false,
"tool_mode": false,
- "trace_as_input": true,
"trace_as_metadata": true,
"track_in_telemetry": false,
"type": "str",
- "value": ""
+ "value": "OPENRAG_LLM_BASE_URL"
},
"api_key": {
"_input_type": "SecretStrInput",
"advanced": false,
"api_editable": false,
- "display_name": "API Key",
+ "display_name": "OpenRAG LLM Token",
"dynamic": false,
- "info": "Overrides global provider settings. Leave blank to use your pre-configured API Key.",
+ "info": "Hop token from OPENRAG_LLM_TOKEN. Same token as the chat component.",
"input_types": [],
- "load_from_db": false,
+ "load_from_db": true,
"name": "api_key",
"override_skip": false,
"password": true,
"placeholder": "",
- "real_time_refresh": true,
"required": false,
"show": true,
"title_case": false,
"track_in_telemetry": false,
"type": "str",
- "value": ""
- },
- "base_url_ibm_watsonx": {
- "_input_type": "DropdownInput",
- "advanced": false,
- "api_editable": false,
- "combobox": true,
- "dialog_inputs": {},
- "display_name": "watsonx API Endpoint",
- "dynamic": false,
- "external_options": {},
- "info": "The base URL of the API (IBM watsonx.ai only)",
- "name": "base_url_ibm_watsonx",
- "options": [
- "https://us-south.ml.cloud.ibm.com",
- "https://eu-de.ml.cloud.ibm.com",
- "https://eu-gb.ml.cloud.ibm.com",
- "https://au-syd.ml.cloud.ibm.com",
- "https://jp-tok.ml.cloud.ibm.com",
- "https://ca-tor.ml.cloud.ibm.com"
- ],
- "options_metadata": [],
- "override_skip": false,
- "placeholder": "",
- "real_time_refresh": true,
- "required": false,
- "show": false,
- "title_case": false,
- "toggle": false,
- "tool_mode": false,
- "trace_as_metadata": true,
- "track_in_telemetry": true,
- "type": "str",
- "value": "https://us-south.ml.cloud.ibm.com"
+ "value": "OPENRAG_LLM_TOKEN"
},
"chunk_size": {
"_input_type": "IntInput",
@@ -4173,7 +4132,7 @@
"show": true,
"title_case": false,
"type": "code",
- "value": "from lfx.base.embeddings.model import LCEmbeddingsModel\nfrom lfx.base.models.unified_models import (\n get_embedding_model_options,\n get_embeddings,\n handle_model_input_update,\n)\nfrom lfx.base.models.watsonx_constants import IBM_WATSONX_URLS\nfrom lfx.components.models_and_agents.model_selection import apply_model_overrides\nfrom lfx.field_typing import Embeddings\nfrom lfx.io import (\n BoolInput,\n DictInput,\n DropdownInput,\n FloatInput,\n IntInput,\n MessageTextInput,\n ModelInput,\n SecretStrInput,\n StrInput,\n)\n\n\nclass EmbeddingModelComponent(LCEmbeddingsModel):\n display_name = \"Embedding Model\"\n description = \"Generate embeddings using a specified provider.\"\n documentation: str = \"https://docs.langflow.org/components-embedding-models\"\n icon = \"binary\"\n name = \"EmbeddingModel\"\n category = \"models\"\n\n def update_build_config(self, build_config: dict, field_value: str, field_name: str | None = None):\n \"\"\"Dynamically update build config with user-filtered model options.\"\"\"\n return handle_model_input_update(\n self,\n dict(build_config),\n field_value,\n field_name,\n cache_key_prefix=\"embedding_model_options\",\n get_options_func=get_embedding_model_options,\n )\n\n inputs = [\n ModelInput(\n name=\"model\",\n display_name=\"Embedding Model\",\n info=\"Select your model provider\",\n real_time_refresh=True,\n required=True,\n model_type=\"embedding\",\n input_types=[\"Embeddings\"], # Override default to accept Embeddings instead of LanguageModel\n ),\n StrInput(\n name=\"model_name\",\n display_name=\"Model Name Override\",\n info=(\n \"Optional embedding model name to use instead of the selected model. \"\n \"Can be set from a global variable for runtime model selection.\"\n ),\n advanced=True,\n load_from_db=False,\n ),\n StrInput(\n name=\"provider\",\n display_name=\"Provider Override\",\n info=(\n \"Optional provider to use with Model Name Override. Leave blank to use the selected model's provider.\"\n ),\n advanced=True,\n load_from_db=False,\n ),\n SecretStrInput(\n name=\"api_key\",\n display_name=\"API Key\",\n info=\"Overrides global provider settings. Leave blank to use your pre-configured API Key.\",\n real_time_refresh=True,\n advanced=True,\n ),\n MessageTextInput(\n name=\"api_base\",\n display_name=\"API Base URL\",\n info=\"Base URL for the API. Leave empty for default.\",\n advanced=True,\n ),\n # Watson-specific inputs\n DropdownInput(\n name=\"base_url_ibm_watsonx\",\n display_name=\"watsonx API Endpoint\",\n info=\"The base URL of the API (IBM watsonx.ai only)\",\n options=IBM_WATSONX_URLS,\n value=IBM_WATSONX_URLS[0],\n combobox=True,\n show=False,\n real_time_refresh=True,\n ),\n MessageTextInput(\n name=\"project_id\",\n display_name=\"Project ID\",\n info=\"IBM watsonx.ai Project ID (required for IBM watsonx.ai)\",\n show=False,\n ),\n # Ollama-specific input\n StrInput(\n name=\"ollama_base_url\",\n display_name=\"Ollama API URL\",\n info=\"Endpoint of the Ollama API (Ollama only)\",\n show=False,\n real_time_refresh=True,\n ),\n IntInput(\n name=\"dimensions\",\n display_name=\"Dimensions\",\n info=\"The number of dimensions the resulting output embeddings should have. \"\n \"Only supported by certain models.\",\n advanced=True,\n ),\n IntInput(\n name=\"chunk_size\",\n display_name=\"Chunk Size\",\n advanced=True,\n value=1000,\n ),\n FloatInput(\n name=\"request_timeout\",\n display_name=\"Request Timeout\",\n advanced=True,\n ),\n IntInput(\n name=\"max_retries\",\n display_name=\"Max Retries\",\n advanced=True,\n value=3,\n ),\n BoolInput(\n name=\"show_progress_bar\",\n display_name=\"Show Progress Bar\",\n advanced=True,\n ),\n DictInput(\n name=\"model_kwargs\",\n display_name=\"Model Kwargs\",\n advanced=True,\n info=(\n \"Additional keyword arguments to pass to the model. Only used by providers that support this parameter \"\n \"(e.g. OpenAI, Google Generative AI). \"\n \"Ignored for providers that do not include it in their parameter mapping.\"\n ),\n ),\n IntInput(\n name=\"truncate_input_tokens\",\n display_name=\"Truncate Input Tokens\",\n advanced=True,\n value=200,\n show=False,\n ),\n BoolInput(\n name=\"input_text\",\n display_name=\"Include the original text in the output\",\n value=True,\n advanced=True,\n show=False,\n ),\n ]\n\n def build_embeddings(self) -> Embeddings:\n \"\"\"Build and return an embeddings instance based on the selected model.\"\"\"\n model = apply_model_overrides(\n self.model,\n model_name=getattr(self, \"model_name\", None),\n provider=getattr(self, \"provider\", None),\n user_id=self.user_id,\n get_options=get_embedding_model_options,\n )\n return get_embeddings(\n model=model,\n user_id=self.user_id,\n api_key=self.api_key,\n api_base=self.api_base,\n dimensions=self.dimensions,\n chunk_size=self.chunk_size,\n request_timeout=self.request_timeout,\n max_retries=self.max_retries,\n show_progress_bar=self.show_progress_bar,\n model_kwargs=self.model_kwargs,\n watsonx_url=getattr(self, \"base_url_ibm_watsonx\", None),\n watsonx_project_id=getattr(self, \"project_id\", None),\n watsonx_truncate_input_tokens=getattr(self, \"truncate_input_tokens\", None),\n watsonx_input_text=getattr(self, \"input_text\", None),\n ollama_base_url=getattr(self, \"ollama_base_url\", None),\n )\n"
+ "value": "\"\"\"OpenAI-compatible embeddings that talk to the OpenRAG `/v1` proxy.\n\nEmbeddings work the same way as chat: Langflow never holds upstream vendor\nkeys. At runtime OpenRAG injects:\n\n- ``OPENRAG_LLM_TOKEN`` — the same short-lived hop token as chat\n- ``OPENRAG_LLM_BASE_URL`` — the same ``http://<backend>/v1`` base URL\n- ``SELECTED_EMBEDDING_MODEL`` — configured embedding model id\n\n``OpenAIEmbeddings`` posts to ``{base_url}/embeddings``. The backend gateway\nroutes by the configured embedding provider (which can differ from the chat\nprovider).\n\"\"\"\n\nfrom __future__ import annotations\n\nfrom typing import Any\n\nfrom langchain_openai import OpenAIEmbeddings\nfrom lfx.base.embeddings.model import LCEmbeddingsModel\nfrom lfx.field_typing import Embeddings\nfrom lfx.io import IntInput, SecretStrInput, StrInput\n\n# Names must match src/api/settings/langflow_sync.py + src/utils/langflow_headers.py\nOPENRAG_LLM_BASE_URL_VAR = \"OPENRAG_LLM_BASE_URL\"\nOPENRAG_LLM_TOKEN_VAR = \"OPENRAG_LLM_TOKEN\"\nSELECTED_EMBEDDING_MODEL_VAR = \"SELECTED_EMBEDDING_MODEL\"\n\n\ndef _as_str(value: object) -> str | None:\n if value is None:\n return None\n getter = getattr(value, \"get_secret_value\", None)\n if callable(getter):\n value = getter()\n text = str(value).strip()\n return text or None\n\n\nclass OpenAICompatibleEmbeddingComponent(LCEmbeddingsModel):\n display_name = \"OpenRAG Embeddings\"\n description = (\n \"Embeddings via OpenRAG's OpenAI-compatible /v1 proxy. \"\n \"Uses the same base URL and hop token as the chat component.\"\n )\n icon = \"OpenRAG\"\n name = \"OpenAICompatibleEmbedding\"\n\n inputs = [\n StrInput(\n name=\"model_name\",\n display_name=\"Model Name\",\n info=\"Embedding model id. Bound to SELECTED_EMBEDDING_MODEL at runtime.\",\n value=SELECTED_EMBEDDING_MODEL_VAR,\n load_from_db=True,\n ),\n SecretStrInput(\n name=\"api_key\",\n display_name=\"OpenRAG LLM Token\",\n info=\"Hop token from OPENRAG_LLM_TOKEN. Same token as the chat component.\",\n value=OPENRAG_LLM_TOKEN_VAR,\n required=False,\n load_from_db=True,\n ),\n StrInput(\n name=\"api_base\",\n display_name=\"OpenAI API Base\",\n info=(\n \"Must end with /v1 (for example http://openrag-backend:8000/v1). \"\n \"Bound to OPENRAG_LLM_BASE_URL at runtime. Same URL as chat.\"\n ),\n value=OPENRAG_LLM_BASE_URL_VAR,\n load_from_db=True,\n ),\n IntInput(\n name=\"dimensions\",\n display_name=\"Dimensions\",\n info=\"Output dimensions when the embedding model supports it.\",\n advanced=True,\n ),\n IntInput(\n name=\"chunk_size\",\n display_name=\"Chunk Size\",\n advanced=True,\n value=1000,\n ),\n ]\n\n def build_embeddings(self) -> Embeddings:\n api_key = _as_str(self.api_key)\n api_base = _as_str(self.api_base)\n if api_base:\n api_base = api_base.rstrip(\"/\")\n\n kwargs: dict[str, Any] = {\n \"model\": self.model_name,\n # `OpenAIEmbeddings.deployment` defaults to the class-level default of\n # `model` — the literal \"text-embedding-ada-002\" — for every instance,\n # whatever model is actually configured. The OpenSearch component keys\n # its embedding lookup on `deployment` as well as `model`, so leaving\n # the default in place registers this object under ada-002 too, and a\n # 768-dim vector then gets aimed at a 1536-dim ada-002 vector field.\n # Only Azure reads this field, so pinning it to the real model is inert\n # at request time and keeps the component's identity honest.\n \"deployment\": self.model_name,\n \"api_key\": api_key,\n \"base_url\": api_base or None,\n # Skip tiktoken context checks so non-OpenAI model ids still work.\n \"check_embedding_ctx_length\": False,\n }\n chunk_size = getattr(self, \"chunk_size\", None)\n if chunk_size:\n kwargs[\"chunk_size\"] = chunk_size\n dimensions = getattr(self, \"dimensions\", None)\n if dimensions:\n kwargs[\"dimensions\"] = dimensions\n return OpenAIEmbeddings(**kwargs)\n"
},
"dimensions": {
"_input_type": "IntInput",
@@ -4181,7 +4140,7 @@
"api_editable": false,
"display_name": "Dimensions",
"dynamic": false,
- "info": "The number of dimensions the resulting output embeddings should have. Only supported by certain models.",
+ "info": "Output dimensions when the embedding model supports it.",
"list": false,
"list_add_label": "Add More",
"name": "dimensions",
@@ -4196,274 +4155,13 @@
"type": "int",
"value": 0
},
- "input_text": {
- "_input_type": "BoolInput",
- "advanced": true,
- "api_editable": false,
- "display_name": "Include the original text in the output",
- "dynamic": false,
- "info": "",
- "list": false,
- "list_add_label": "Add More",
- "name": "input_text",
- "override_skip": false,
- "placeholder": "",
- "required": false,
- "show": false,
- "title_case": false,
- "tool_mode": false,
- "trace_as_metadata": true,
- "track_in_telemetry": true,
- "type": "bool",
- "value": true
- },
- "is_refresh": false,
- "max_retries": {
- "_input_type": "IntInput",
- "advanced": true,
- "api_editable": false,
- "display_name": "Max Retries",
- "dynamic": false,
- "info": "",
- "list": false,
- "list_add_label": "Add More",
- "name": "max_retries",
- "override_skip": false,
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_metadata": true,
- "track_in_telemetry": true,
- "type": "int",
- "value": 3
- },
- "model": {
- "_input_type": "ModelInput",
- "advanced": true,
- "api_editable": false,
- "display_name": "Embedding Model",
- "dynamic": false,
- "external_options": {
- "fields": {
- "data": {
- "node": {
- "display_name": "Connect other models",
- "icon": "CornerDownLeft",
- "name": "connect_other_models"
- }
- }
- }
- },
- "info": "Select your model provider",
- "input_types": [
- "Embeddings"
- ],
- "list": false,
- "list_add_label": "Add More",
- "load_from_db": false,
- "model_type": "embedding",
- "name": "model",
- "options": [
- {
- "category": "OpenAI",
- "icon": "OpenAI",
- "metadata": {
- "embedding_class": "OpenAIEmbeddings",
- "model_type": "embeddings",
- "param_mapping": {
- "api_base": "base_url",
- "api_key": "api_key",
- "chunk_size": "chunk_size",
- "dimensions": "dimensions",
- "max_retries": "max_retries",
- "model": "model",
- "model_kwargs": "model_kwargs",
- "request_timeout": "timeout",
- "show_progress_bar": "show_progress_bar"
- }
- },
- "name": "text-embedding-3-large",
- "provider": "OpenAI"
- },
- {
- "category": "OpenAI",
- "icon": "OpenAI",
- "metadata": {
- "embedding_class": "OpenAIEmbeddings",
- "model_type": "embeddings",
- "param_mapping": {
- "api_base": "base_url",
- "api_key": "api_key",
- "chunk_size": "chunk_size",
- "dimensions": "dimensions",
- "max_retries": "max_retries",
- "model": "model",
- "model_kwargs": "model_kwargs",
- "request_timeout": "timeout",
- "show_progress_bar": "show_progress_bar"
- }
- },
- "name": "text-embedding-3-small",
- "provider": "OpenAI"
- },
- {
- "category": "OpenAI",
- "icon": "OpenAI",
- "metadata": {
- "embedding_class": "OpenAIEmbeddings",
- "model_type": "embeddings",
- "param_mapping": {
- "api_base": "base_url",
- "api_key": "api_key",
- "chunk_size": "chunk_size",
- "dimensions": "dimensions",
- "max_retries": "max_retries",
- "model": "model",
- "model_kwargs": "model_kwargs",
- "request_timeout": "timeout",
- "show_progress_bar": "show_progress_bar"
- }
- },
- "name": "text-embedding-ada-002",
- "provider": "OpenAI"
- },
- {
- "category": "IBM WatsonX",
- "icon": "WatsonxAI",
- "metadata": {
- "embedding_class": "WatsonxEmbeddings",
- "model_type": "embeddings",
- "param_mapping": {
- "api_key": "apikey",
- "model_id": "model_id",
- "project_id": "project_id",
- "request_timeout": "request_timeout",
- "space_id": "space_id",
- "url": "url"
- }
- },
- "name": "ibm/granite-embedding-278m-multilingual",
- "provider": "IBM WatsonX"
- },
- {
- "category": "IBM WatsonX",
- "icon": "WatsonxAI",
- "metadata": {
- "embedding_class": "WatsonxEmbeddings",
- "model_type": "embeddings",
- "param_mapping": {
- "api_key": "apikey",
- "model_id": "model_id",
- "project_id": "project_id",
- "request_timeout": "request_timeout",
- "space_id": "space_id",
- "url": "url"
- }
- },
- "name": "ibm/slate-125m-english-rtrvr-v2",
- "provider": "IBM WatsonX"
- },
- {
- "category": "IBM WatsonX",
- "icon": "WatsonxAI",
- "metadata": {
- "embedding_class": "WatsonxEmbeddings",
- "model_type": "embeddings",
- "param_mapping": {
- "api_key": "apikey",
- "model_id": "model_id",
- "project_id": "project_id",
- "request_timeout": "request_timeout",
- "space_id": "space_id",
- "url": "url"
- }
- },
- "name": "ibm/slate-30m-english-rtrvr-v2",
- "provider": "IBM WatsonX"
- },
- {
- "category": "IBM WatsonX",
- "icon": "WatsonxAI",
- "metadata": {
- "embedding_class": "WatsonxEmbeddings",
- "model_type": "embeddings",
- "param_mapping": {
- "api_key": "apikey",
- "model_id": "model_id",
- "project_id": "project_id",
- "request_timeout": "request_timeout",
- "space_id": "space_id",
- "url": "url"
- }
- },
- "name": "intfloat/multilingual-e5-large",
- "provider": "IBM WatsonX"
- }
- ],
- "override_skip": false,
- "placeholder": "Setup Provider",
- "real_time_refresh": true,
- "refresh_button": true,
- "required": true,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_input": true,
- "track_in_telemetry": false,
- "type": "model",
- "value": [
- {
- "icon": "OpenAI",
- "metadata": {
- "embedding_class": "OpenAIEmbeddings",
- "model_type": "embeddings",
- "param_mapping": {
- "api_base": "base_url",
- "api_key": "api_key",
- "chunk_size": "chunk_size",
- "dimensions": "dimensions",
- "max_retries": "max_retries",
- "model": "model",
- "model_kwargs": "model_kwargs",
- "request_timeout": "timeout",
- "show_progress_bar": "show_progress_bar"
- }
- },
- "name": "text-embedding-3-small",
- "provider": "OpenAI"
- }
- ]
- },
- "model_kwargs": {
- "_input_type": "DictInput",
- "advanced": true,
- "api_editable": false,
- "display_name": "Model Kwargs",
- "dynamic": false,
- "info": "Additional keyword arguments to pass to the model. Only used by providers that support this parameter (e.g. OpenAI, Google Generative AI). Ignored for providers that do not include it in their parameter mapping.",
- "list": false,
- "list_add_label": "Add More",
- "name": "model_kwargs",
- "override_skip": false,
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_input": true,
- "track_in_telemetry": false,
- "type": "dict",
- "value": {}
- },
"model_name": {
"_input_type": "StrInput",
"advanced": false,
"api_editable": false,
- "display_name": "Model Name Override",
+ "display_name": "Model Name",
"dynamic": false,
- "info": "Optional embedding model name to use instead of the selected model. Can be set from a global variable for runtime model selection.",
+ "info": "Embedding model id. Bound to SELECTED_EMBEDDING_MODEL at runtime.",
"list": false,
"list_add_label": "Add More",
"load_from_db": true,
@@ -4478,174 +4176,41 @@
"track_in_telemetry": false,
"type": "str",
"value": "SELECTED_EMBEDDING_MODEL"
- },
- "ollama_base_url": {
- "_input_type": "StrInput",
- "advanced": false,
- "api_editable": false,
- "display_name": "Ollama API URL",
- "dynamic": false,
- "info": "Endpoint of the Ollama API (Ollama only)",
- "list": false,
- "list_add_label": "Add More",
- "load_from_db": false,
- "name": "ollama_base_url",
- "override_skip": false,
- "placeholder": "",
- "real_time_refresh": true,
- "required": false,
- "show": false,
- "title_case": false,
- "tool_mode": false,
- "trace_as_metadata": true,
- "track_in_telemetry": false,
- "type": "str",
- "value": "http://localhost:11434"
- },
- "project_id": {
- "_input_type": "MessageTextInput",
- "advanced": false,
- "api_editable": false,
- "display_name": "Project ID",
- "dynamic": false,
- "info": "IBM watsonx.ai Project ID (required for IBM watsonx.ai)",
- "input_types": [
- "Message"
- ],
- "list": false,
- "list_add_label": "Add More",
- "load_from_db": true,
- "name": "project_id",
- "override_skip": false,
- "placeholder": "",
- "required": false,
- "show": false,
- "title_case": false,
- "tool_mode": false,
- "trace_as_input": true,
- "trace_as_metadata": true,
- "track_in_telemetry": false,
- "type": "str",
- "value": "WATSONX_PROJECT_ID"
- },
- "provider": {
- "_input_type": "StrInput",
- "advanced": false,
- "api_editable": false,
- "display_name": "Provider Override",
- "dynamic": false,
- "info": "Optional provider to use with Model Name Override. Leave blank to use the selected model's provider.",
- "list": false,
- "list_add_label": "Add More",
- "load_from_db": true,
- "name": "provider",
- "override_skip": false,
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_metadata": true,
- "track_in_telemetry": false,
- "type": "str",
- "value": "SELECTED_EMBEDDING_MODEL_PROVIDER"
- },
- "request_timeout": {
- "_input_type": "FloatInput",
- "advanced": true,
- "api_editable": false,
- "display_name": "Request Timeout",
- "dynamic": false,
- "info": "",
- "list": false,
- "list_add_label": "Add More",
- "name": "request_timeout",
- "override_skip": false,
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_metadata": true,
- "track_in_telemetry": true,
- "type": "float",
- "value": ""
- },
- "show_progress_bar": {
- "_input_type": "BoolInput",
- "advanced": true,
- "api_editable": false,
- "display_name": "Show Progress Bar",
- "dynamic": false,
- "info": "",
- "list": false,
- "list_add_label": "Add More",
- "name": "show_progress_bar",
- "override_skip": false,
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_metadata": true,
- "track_in_telemetry": true,
- "type": "bool",
- "value": false
- },
- "truncate_input_tokens": {
- "_input_type": "IntInput",
- "advanced": true,
- "api_editable": false,
- "display_name": "Truncate Input Tokens",
- "dynamic": false,
- "info": "",
- "list": false,
- "list_add_label": "Add More",
- "name": "truncate_input_tokens",
- "override_skip": false,
- "placeholder": "",
- "required": false,
- "show": false,
- "title_case": false,
- "tool_mode": false,
- "trace_as_metadata": true,
- "track_in_telemetry": true,
- "type": "int",
- "value": 200
}
},
"tool_mode": false
},
"showNode": false,
- "type": "EmbeddingModel"
+ "type": "OpenAICompatibleEmbedding"
},
"dragging": false,
- "id": "EmbeddingModel-d8FQn",
+ "id": "OpenAICompatibleEmbedding-MloZd",
+ "measured": {
+ "height": 52,
+ "width": 192
+ },
"position": {
- "x": 1489.0121472829765,
- "y": 1954.4725071351013
+ "x": 1481.2824937463324,
+ "y": 1946.082713977874
},
"selected": false,
"type": "genericNode"
},
{
"data": {
- "id": "ext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-JFBiL",
+ "id": "OpenSearchVectorStoreComponentMultimodalMultiEmbedding-WaE28",
"node": {
"base_classes": [
"JSON",
"VectorStore"
],
"beta": false,
- "bundle": "openrag",
"conditional_paths": [],
"custom_fields": {},
"description": "Store and search documents using OpenSearch with multi-model hybrid semantic and keyword search. To search use the tools search_documents and raw_search. Search documents takes a query for vector search, for example\n {search_query: \"components in openrag\"}",
"display_name": "OpenSearch (Multi-Model Multi-Embedding)",
"documentation": "",
"edited": false,
- "extension": "openrag",
- "extension_version": "0.0.0",
"field_order": [
"docs_metadata",
"opensearch_url",
@@ -4680,7 +4245,7 @@
],
"frozen": false,
"icon": "OpenSearch",
- "last_updated": "2026-08-05T16:17:08.465Z",
+ "last_updated": "2026-08-18T22:46:55.693Z",
"legacy": false,
"metadata": {
"code_hash": "6c375fdaa9e7",
@@ -4712,8 +4277,6 @@
"module": "_lfx_ext.extra.openrag.opensearch_multimodal"
},
"minimized": false,
- "name": "OpenSearchVectorStoreComponentMultimodalMultiEmbedding",
- "namespaced_id": "ext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra",
"output_types": [],
"outputs": [
{
@@ -4775,7 +4338,7 @@
"value": "5488df7c-b93f-4f87-a446-b67028bc0813"
},
"_frontend_node_folder_id": {
- "value": "203c7c12-9e1d-4561-bb14-16102afec154"
+ "value": "e861a230-a49b-41ef-82de-5f825ea9ab51"
},
"_type": "Component",
"auth_mode": {
@@ -5521,23 +5084,27 @@
"tool_mode": false
},
"selected_output": "search_results",
- "showNode": true,
+ "showNode": false,
"type": "ext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra"
},
"dragging": false,
- "id": "ext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-JFBiL",
+ "id": "OpenSearchVectorStoreComponentMultimodalMultiEmbedding-WaE28",
+ "measured": {
+ "height": 188,
+ "width": 192
+ },
"position": {
- "x": 1752.0967918395147,
- "y": 1398.644564559221
+ "x": 1782.4529230544917,
+ "y": 1889.4261474579816
},
"selected": false,
"type": "genericNode"
}
],
"viewport": {
- "x": -115.6622907391245,
- "y": -755.3420396053712,
- "zoom": 0.6041897381141127
+ "x": -1244.045984357672,
+ "y": -1687.476697445286,
+ "zoom": 1.0133085834963953
}
},
"description": "Load your data for chat context with Retrieval Augmented Generation.",
@@ -5545,7 +5112,7 @@
"id": "5488df7c-b93f-4f87-a446-b67028bc0813",
"is_component": false,
"last_tested_version": "0.11.2",
- "locked": true,
+ "locked": false,
"name": "OpenSearch Ingestion Flow",
"tags": [
"openai",
diff --git a/flows/openrag_agent.json b/flows/openrag_agent.json
index fc02d956d..8a5fe6041 100644
--- a/flows/openrag_agent.json
+++ b/flows/openrag_agent.json
@@ -113,6 +113,34 @@
"target": "Prompt Template-7kZsI",
"targetHandle": "{œfieldNameœ:œfilterœ,œidœ:œPrompt Template-7kZsIœ,œinputTypesœ:[œMessageœ],œtypeœ:œstrœ}"
},
+ {
+ "animated": false,
+ "className": "",
+ "data": {
+ "sourceHandle": {
+ "dataType": "TextInput",
+ "id": "TextInput-i0a3P",
+ "name": "text",
+ "output_types": [
+ "Message"
+ ]
+ },
+ "targetHandle": {
+ "fieldName": "filter_expression",
+ "id": "OpenSearchVectorStoreComponentMultimodalMultiEmbedding-3x7Ll",
+ "inputTypes": [
+ "Message"
+ ],
+ "type": "str"
+ }
+ },
+ "id": "xy-edge__TextInput-i0a3P{œdataTypeœ:œTextInputœ,œidœ:œTextInput-i0a3Pœ,œnameœ:œtextœ,œoutput_typesœ:[œMessageœ]}-OpenSearchVectorStoreComponentMultimodalMultiEmbedding-3x7Ll{œfieldNameœ:œfilter_expressionœ,œidœ:œOpenSearchVectorStoreComponentMultimodalMultiEmbedding-3x7Llœ,œinputTypesœ:[œMessageœ],œtypeœ:œstrœ}",
+ "selected": false,
+ "source": "TextInput-i0a3P",
+ "sourceHandle": "{œdataTypeœ:œTextInputœ,œidœ:œTextInput-i0a3Pœ,œnameœ:œtextœ,œoutput_typesœ:[œMessageœ]}",
+ "target": "OpenSearchVectorStoreComponentMultimodalMultiEmbedding-3x7Ll",
+ "targetHandle": "{œfieldNameœ:œfilter_expressionœ,œidœ:œOpenSearchVectorStoreComponentMultimodalMultiEmbedding-3x7Llœ,œinputTypesœ:[œMessageœ],œtypeœ:œstrœ}"
+ },
{
"animated": false,
"className": "",
@@ -178,35 +206,8 @@
"className": "",
"data": {
"sourceHandle": {
- "dataType": "LanguageModelComponent",
- "id": "LanguageModelComponent-MfLsT",
- "name": "model_output",
- "output_types": [
- "LanguageModel"
- ]
- },
- "targetHandle": {
- "fieldName": "model",
- "id": "Agent-Nfw7u",
- "inputTypes": [
- "LanguageModel"
- ],
- "type": "model"
- }
- },
- "id": "xy-edge__LanguageModelComponent-MfLsT{œdataTypeœ:œLanguageModelComponentœ,œidœ:œLanguageModelComponent-MfLsTœ,œnameœ:œmodel_outputœ,œoutput_typesœ:[œLanguageModelœ]}-Agent-Nfw7u{œfieldNameœ:œmodelœ,œidœ:œAgent-Nfw7uœ,œinputTypesœ:[œLanguageModelœ],œtypeœ:œmodelœ}",
- "selected": false,
- "source": "LanguageModelComponent-MfLsT",
- "sourceHandle": "{œdataTypeœ:œLanguageModelComponentœ,œidœ:œLanguageModelComponent-MfLsTœ,œnameœ:œmodel_outputœ,œoutput_typesœ:[œLanguageModelœ]}",
- "target": "Agent-Nfw7u",
- "targetHandle": "{œfieldNameœ:œmodelœ,œidœ:œAgent-Nfw7uœ,œinputTypesœ:[œLanguageModelœ],œtypeœ:œmodelœ}"
- },
- {
- "className": "",
- "data": {
- "sourceHandle": {
- "dataType": "EmbeddingModel",
- "id": "EmbeddingModel-zLHKs",
+ "dataType": "OpenAICompatibleEmbedding",
+ "id": "OpenAICompatibleEmbedding-ix4WD",
"name": "embeddings",
"output_types": [
"Embeddings"
@@ -214,51 +215,55 @@
},
"targetHandle": {
"fieldName": "embedding",
- "id": "ext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-Ji9kZ",
+ "id": "OpenSearchVectorStoreComponentMultimodalMultiEmbedding-3x7Ll",
"inputTypes": [
"Embeddings"
],
"type": "other"
}
},
- "id": "xy-edge__EmbeddingModel-zLHKs{œdataTypeœ:œEmbeddingModelœ,œidœ:œEmbeddingModel-zLHKsœ,œnameœ:œembeddingsœ,œoutput_typesœ:[œEmbeddingsœ]}-ext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-Ji9kZ{œfieldNameœ:œembeddingœ,œidœ:œext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-Ji9kZœ,œinputTypesœ:[œEmbeddingsœ],œtypeœ:œotherœ}",
- "source": "EmbeddingModel-zLHKs",
- "sourceHandle": "{œdataTypeœ:œEmbeddingModelœ,œidœ:œEmbeddingModel-zLHKsœ,œnameœ:œembeddingsœ,œoutput_typesœ:[œEmbeddingsœ]}",
- "target": "ext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-Ji9kZ",
- "targetHandle": "{œfieldNameœ:œembeddingœ,œidœ:œext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-Ji9kZœ,œinputTypesœ:[œEmbeddingsœ],œtypeœ:œotherœ}"
+ "id": "xy-edge__OpenAICompatibleEmbedding-ix4WD{œdataTypeœ:œOpenAICompatibleEmbeddingœ,œidœ:œOpenAICompatibleEmbedding-ix4WDœ,œnameœ:œembeddingsœ,œoutput_typesœ:[œEmbeddingsœ]}-OpenSearchVectorStoreComponentMultimodalMultiEmbedding-3x7Ll{œfieldNameœ:œembeddingœ,œidœ:œOpenSearchVectorStoreComponentMultimodalMultiEmbedding-3x7Llœ,œinputTypesœ:[œEmbeddingsœ],œtypeœ:œotherœ}",
+ "selected": false,
+ "source": "OpenAICompatibleEmbedding-ix4WD",
+ "sourceHandle": "{œdataTypeœ:œOpenAICompatibleEmbeddingœ,œidœ:œOpenAICompatibleEmbedding-ix4WDœ,œnameœ:œembeddingsœ,œoutput_typesœ:[œEmbeddingsœ]}",
+ "target": "OpenSearchVectorStoreComponentMultimodalMultiEmbedding-3x7Ll",
+ "targetHandle": "{œfieldNameœ:œembeddingœ,œidœ:œOpenSearchVectorStoreComponentMultimodalMultiEmbedding-3x7Llœ,œinputTypesœ:[œEmbeddingsœ],œtypeœ:œotherœ}"
},
{
+ "animated": false,
"className": "",
"data": {
"sourceHandle": {
- "dataType": "TextInput",
- "id": "TextInput-i0a3P",
- "name": "text",
+ "dataType": "OpenAICompatibleLLM",
+ "id": "OpenAICompatibleLLM-u2sHy",
+ "name": "model_output",
"output_types": [
- "Message"
+ "LanguageModel"
]
},
"targetHandle": {
- "fieldName": "filter_expression",
- "id": "ext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-Ji9kZ",
+ "fieldName": "model",
+ "id": "Agent-Nfw7u",
"inputTypes": [
- "Message"
+ "LanguageModel"
],
- "type": "str"
+ "type": "model"
}
},
- "id": "xy-edge__TextInput-i0a3P{œdataTypeœ:œTextInputœ,œidœ:œTextInput-i0a3Pœ,œnameœ:œtextœ,œoutput_typesœ:[œMessageœ]}-ext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-Ji9kZ{œfieldNameœ:œfilter_expressionœ,œidœ:œext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-Ji9kZœ,œinputTypesœ:[œMessageœ],œtypeœ:œstrœ}",
- "source": "TextInput-i0a3P",
- "sourceHandle": "{œdataTypeœ:œTextInputœ,œidœ:œTextInput-i0a3Pœ,œnameœ:œtextœ,œoutput_typesœ:[œMessageœ]}",
- "target": "ext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-Ji9kZ",
- "targetHandle": "{œfieldNameœ:œfilter_expressionœ,œidœ:œext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-Ji9kZœ,œinputTypesœ:[œMessageœ],œtypeœ:œstrœ}"
+ "id": "xy-edge__OpenAICompatibleLLM-u2sHy{œdataTypeœ:œOpenAICompatibleLLMœ,œidœ:œOpenAICompatibleLLM-u2sHyœ,œnameœ:œmodel_outputœ,œoutput_typesœ:[œLanguageModelœ]}-Agent-Nfw7u{œfieldNameœ:œmodelœ,œidœ:œAgent-Nfw7uœ,œinputTypesœ:[œLanguageModelœ],œtypeœ:œmodelœ}",
+ "selected": false,
+ "source": "OpenAICompatibleLLM-u2sHy",
+ "sourceHandle": "{œdataTypeœ:œOpenAICompatibleLLMœ,œidœ:œOpenAICompatibleLLM-u2sHyœ,œnameœ:œmodel_outputœ,œoutput_typesœ:[œLanguageModelœ]}",
+ "target": "Agent-Nfw7u",
+ "targetHandle": "{œfieldNameœ:œmodelœ,œidœ:œAgent-Nfw7uœ,œinputTypesœ:[œLanguageModelœ],œtypeœ:œmodelœ}"
},
{
+ "animated": false,
"className": "",
"data": {
"sourceHandle": {
"dataType": "ext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra",
- "id": "ext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-Ji9kZ",
+ "id": "OpenSearchVectorStoreComponentMultimodalMultiEmbedding-3x7Ll",
"name": "component_as_tool",
"output_types": [
"Tool"
@@ -273,9 +278,10 @@
"type": "other"
}
},
- "id": "xy-edge__ext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-Ji9kZ{œdataTypeœ:œext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extraœ,œidœ:œext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-Ji9kZœ,œnameœ:œcomponent_as_toolœ,œoutput_typesœ:[œToolœ]}-Agent-Nfw7u{œfieldNameœ:œtoolsœ,œidœ:œAgent-Nfw7uœ,œinputTypesœ:[œToolœ],œtypeœ:œotherœ}",
- "source": "ext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-Ji9kZ",
- "sourceHandle": "{œdataTypeœ:œext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extraœ,œidœ:œext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-Ji9kZœ,œnameœ:œcomponent_as_toolœ,œoutput_typesœ:[œToolœ]}",
+ "id": "xy-edge__OpenSearchVectorStoreComponentMultimodalMultiEmbedding-3x7Ll{œdataTypeœ:œext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extraœ,œidœ:œOpenSearchVectorStoreComponentMultimodalMultiEmbedding-3x7Llœ,œnameœ:œcomponent_as_toolœ,œoutput_typesœ:[œToolœ]}-Agent-Nfw7u{œfieldNameœ:œtoolsœ,œidœ:œAgent-Nfw7uœ,œinputTypesœ:[œToolœ],œtypeœ:œotherœ}",
+ "selected": false,
+ "source": "OpenSearchVectorStoreComponentMultimodalMultiEmbedding-3x7Ll",
+ "sourceHandle": "{œdataTypeœ:œext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extraœ,œidœ:œOpenSearchVectorStoreComponentMultimodalMultiEmbedding-3x7Llœ,œnameœ:œcomponent_as_toolœ,œoutput_typesœ:[œToolœ]}",
"target": "Agent-Nfw7u",
"targetHandle": "{œfieldNameœ:œtoolsœ,œidœ:œAgent-Nfw7uœ,œinputTypesœ:[œToolœ],œtypeœ:œotherœ}"
}
@@ -597,9 +603,13 @@
},
"dragging": false,
"id": "ChatInput-ci8VE",
+ "measured": {
+ "height": 52,
+ "width": 192
+ },
"position": {
- "x": 1136.2811923974275,
- "y": 2503.9876597481666
+ "x": 566.8287104227669,
+ "y": 2025.1942793814123
},
"selected": false,
"type": "genericNode"
@@ -898,9 +908,13 @@
},
"dragging": false,
"id": "ChatOutput-gWl8E",
+ "measured": {
+ "height": 52,
+ "width": 192
+ },
"position": {
- "x": 2458.4563028144366,
- "y": 2074.662957908784
+ "x": 2154.9337551440794,
+ "y": 1638.6504092712073
},
"selected": false,
"type": "genericNode"
@@ -945,6 +959,7 @@
],
"frozen": false,
"icon": "bot",
+ "last_updated": "2026-08-18T22:52:17.781Z",
"legacy": false,
"metadata": {
"code_hash": "e3c6d36a2020",
@@ -1014,6 +1029,14 @@
],
"pinned": false,
"template": {
+ "_frontend_node_flow_id": {
+ "input_types": [],
+ "value": "1098eea1-6649-4e1d-aed1-b77249fb8dd0"
+ },
+ "_frontend_node_folder_id": {
+ "input_types": [],
+ "value": "501d7212-c442-4593-a43a-e987cc095eb4"
+ },
"_type": "Component",
"add_calculator_tool": {
"_input_type": "BoolInput",
@@ -1022,6 +1045,7 @@
"display_name": "Calculator",
"dynamic": false,
"info": "If true, adds a zero-config arithmetic calculator tool to the agent (safe: only +, -, *, /, ** operators via AST).",
+ "input_types": [],
"list": false,
"list_add_label": "Add More",
"name": "add_calculator_tool",
@@ -1043,6 +1067,7 @@
"display_name": "Current Date",
"dynamic": false,
"info": "If true, will add a tool to the agent that returns the current date.",
+ "input_types": [],
"list": false,
"list_add_label": "Add More",
"name": "add_current_date_tool",
@@ -1088,6 +1113,7 @@
"dynamic": false,
"external_options": {},
"info": "The base URL of the API (IBM watsonx.ai only)",
+ "input_types": [],
"name": "base_url_ibm_watsonx",
"options": [
"https://us-south.ml.cloud.ibm.com",
@@ -1118,6 +1144,7 @@
"fileTypes": [],
"file_path": "",
"info": "",
+ "input_types": [],
"list": false,
"load_from_db": false,
"multiline": true,
@@ -1193,6 +1220,7 @@
"display_name": "Handle Parse Errors",
"dynamic": false,
"info": "Adds tool-execution retry as a safety net. `create_agent` already feeds tool-call validation errors back to the LLM automatically; this flag layers `ToolRetryMiddleware` on top so transient tool runtime failures are retried (max 2 retries).",
+ "input_types": [],
"list": false,
"list_add_label": "Add More",
"name": "handle_parsing_errors",
@@ -1233,6 +1261,7 @@
"type": "str",
"value": ""
},
+ "is_refresh": true,
"max_iterations": {
"_input_type": "IntInput",
"advanced": true,
@@ -1240,6 +1269,7 @@
"display_name": "Max Iterations",
"dynamic": false,
"info": "Maximum number of model calls the agent can make before stopping (maps to `ModelCallLimitMiddleware.run_limit` on the create_agent path). Must be at least 1 — it is a safety cap, never 'unlimited'.",
+ "input_types": [],
"list": false,
"list_add_label": "Add More",
"name": "max_iterations",
@@ -1267,6 +1297,7 @@
"display_name": "Max Tokens",
"dynamic": false,
"info": "Maximum number of tokens to generate. Field name varies by provider.",
+ "input_types": [],
"list": false,
"list_add_label": "Add More",
"load_from_db": false,
@@ -1317,6 +1348,26 @@
"load_from_db": false,
"model_type": "language",
"name": "model",
+ "options": [
+ {
+ "category": "Anthropic",
+ "icon": "Anthropic",
+ "metadata": {
+ "api_key_param": "api_key",
+ "context_length": 128000,
+ "max_tokens_field_name": "max_tokens",
+ "model_class": "ChatAnthropic",
+ "model_name_param": "model",
+ "not_enabled_locally": true,
+ "reasoning": true,
+ "reasoning_models": [
+ "claude-opus-5"
+ ]
+ },
+ "name": "claude-opus-5",
+ "provider": "Anthropic"
+ }
+ ],
"override_skip": false,
"placeholder": "Setup Provider",
"real_time_refresh": true,
@@ -1355,6 +1406,7 @@
"display_name": "Number of Chat History Messages",
"dynamic": false,
"info": "Number of chat history messages to retrieve.",
+ "input_types": [],
"list": false,
"list_add_label": "Add More",
"name": "n_messages",
@@ -1445,6 +1497,7 @@
"display_name": "watsonx Project ID",
"dynamic": false,
"info": "The project ID associated with the foundation model (IBM watsonx.ai only)",
+ "input_types": [],
"list": false,
"list_add_label": "Add More",
"load_from_db": true,
@@ -1467,6 +1520,7 @@
"display_name": "Stream",
"dynamic": false,
"info": "Stream the response from the model. Streaming works only in Chat.",
+ "input_types": [],
"list": false,
"list_add_label": "Add More",
"name": "stream",
@@ -1538,14 +1592,18 @@
"tool_mode": false
},
"selected_output": "response",
- "showNode": true,
+ "showNode": false,
"type": "Agent"
},
"dragging": false,
"id": "Agent-Nfw7u",
+ "measured": {
+ "height": 116,
+ "width": 192
+ },
"position": {
- "x": 2064.9341782775937,
- "y": 1693.5833129555906
+ "x": 1852.9501767300426,
+ "y": 1606.8625850497745
},
"selected": false,
"type": "genericNode"
@@ -1571,7 +1629,7 @@
],
"frozen": false,
"icon": "calculator",
- "last_updated": "2026-08-05T16:17:33.195Z",
+ "last_updated": "2026-08-20T18:09:22.934Z",
"legacy": false,
"metadata": {
"code_hash": "d0b2936e74fa",
@@ -1614,7 +1672,7 @@
"value": "1098eea1-6649-4e1d-aed1-b77249fb8dd0"
},
"_frontend_node_folder_id": {
- "value": "203c7c12-9e1d-4561-bb14-16102afec154"
+ "value": "503f5216-7f2c-4998-9010-b1a0eafbd500"
},
"_type": "Component",
"code": {
@@ -1707,69 +1765,63 @@
},
"tool_mode": true
},
- "showNode": true,
+ "showNode": false,
"type": "CalculatorComponent"
},
"dragging": false,
"id": "CalculatorComponent-KrlMH",
+ "measured": {
+ "height": 52,
+ "width": 192
+ },
"position": {
- "x": 1498.151476724705,
- "y": 1719.4446700170724
+ "x": 1354.9559315259569,
+ "y": 1572.0374911360082
},
"selected": false,
"type": "genericNode"
},
{
"data": {
- "_connectionMode": false,
- "description": "Generate embeddings using a specified provider.",
- "display_name": "Embedding Model",
- "id": "EmbeddingModel-zLHKs",
+ "description": "Create a prompt template with dynamic variables.",
+ "display_name": "Prompt Template",
+ "id": "Prompt Template-7kZsI",
"node": {
"base_classes": [
- "Embeddings"
+ "Message"
],
"beta": false,
"conditional_paths": [],
- "custom_fields": {},
- "description": "Generate embeddings using a specified provider.",
- "display_name": "Embedding Model",
- "documentation": "https://docs.langflow.org/components-embedding-models",
+ "custom_fields": {
+ "template": [
+ "filter",
+ "input"
+ ]
+ },
+ "description": "Create a prompt template with dynamic variables.",
+ "display_name": "Prompt Template",
+ "documentation": "https://docs.langflow.org/components-prompts",
"edited": false,
"field_order": [
- "model",
- "model_name",
- "provider",
- "api_key",
- "api_base",
- "base_url_ibm_watsonx",
- "project_id",
- "ollama_base_url",
- "dimensions",
- "chunk_size",
- "request_timeout",
- "max_retries",
- "show_progress_bar",
- "model_kwargs",
- "truncate_input_tokens",
- "input_text"
+ "template",
+ "use_double_brackets",
+ "tool_placeholder"
],
"frozen": false,
- "icon": "binary",
- "last_updated": "2026-07-29T14:25:25.832Z",
+ "icon": "prompts",
"legacy": false,
"metadata": {
- "code_hash": "0780e9bbc5fa",
+ "code_hash": "3d3fd7b8a36f",
"dependencies": {
"dependencies": [
{
"name": "lfx",
- "version": "1.11.1rc0"
+ "version": "0.4.0"
}
],
"total_dependencies": 1
},
- "module": "custom_components.embedding_model"
+ "module": "custom_components.prompt_template"
},
"minimized": false,
"output_types": [],
@@ -1777,136 +1829,245 @@
{
"allows_loop": false,
"cache": true,
- "display_name": "Embedding Model",
+ "display_name": "Prompt",
"group_outputs": false,
"hidden": null,
"loop_types": null,
- "method": "build_embeddings",
- "name": "embeddings",
+ "method": "build_prompt",
+ "name": "prompt",
"options": null,
"required_inputs": null,
- "selected": "Embeddings",
+ "selected": "Message",
"tool_mode": true,
"types": [
- "Embeddings"
+ "Message"
],
"value": "__UNDEFINED__"
}
],
"pinned": false,
"template": {
- "_frontend_node_flow_id": {
- "value": "1098eea1-6649-4e1d-aed1-b77249fb8dd0"
- },
- "_frontend_node_folder_id": {
- "value": "203c7c12-9e1d-4561-bb14-16102afec154"
- },
"_type": "Component",
- "api_base": {
- "_input_type": "MessageTextInput",
+ "code": {
"advanced": true,
- "api_editable": false,
- "display_name": "API Base URL",
+ "dynamic": true,
+ "fileTypes": [],
+ "file_path": "",
+ "info": "",
+ "list": false,
+ "load_from_db": false,
+ "multiline": true,
+ "name": "code",
+ "password": false,
+ "placeholder": "",
+ "required": true,
+ "show": true,
+ "title_case": false,
+ "type": "code",
+ "value": "from typing import Any\n\nfrom lfx.base.prompts.api_utils import process_prompt_template\nfrom lfx.custom.custom_component.component import Component\nfrom lfx.inputs.input_mixin import FieldTypes\nfrom lfx.inputs.inputs import DefaultPromptField\nfrom lfx.io import BoolInput, MessageTextInput, Output, PromptInput\nfrom lfx.log.logger import logger\nfrom lfx.schema.dotdict import dotdict\nfrom lfx.schema.message import Message\nfrom lfx.template.utils import update_template_values\nfrom lfx.utils.mustache_security import validate_mustache_template\n\n\nclass PromptComponent(Component):\n display_name: str = \"Prompt Template\"\n description: str = \"Create a prompt template with dynamic variables.\"\n documentation: str = \"https://docs.langflow.org/components-prompts\"\n icon = \"prompts\"\n trace_type = \"prompt\"\n name = \"Prompt Template\"\n\n inputs = [\n PromptInput(name=\"template\", display_name=\"Template\"),\n BoolInput(\n name=\"use_double_brackets\",\n display_name=\"Use Double Brackets\",\n value=False,\n advanced=True,\n info=\"Use {{variable}} syntax instead of {variable}.\",\n real_time_refresh=True,\n ),\n MessageTextInput(\n name=\"tool_placeholder\",\n display_name=\"Tool Placeholder\",\n tool_mode=True,\n advanced=True,\n show=False,\n info=\"A placeholder input for tool mode.\",\n ),\n ]\n\n outputs = [\n Output(display_name=\"Prompt\", name=\"prompt\", method=\"build_prompt\"),\n ]\n\n def update_build_config(self, build_config: dotdict, field_value: Any, field_name: str | None = None) -> dotdict:\n \"\"\"Update the template field type based on the selected mode.\"\"\"\n if field_name == \"use_double_brackets\":\n # Change the template field type based on mode\n is_mustache = field_value is True\n if is_mustache:\n build_config[\"template\"][\"type\"] = FieldTypes.MUSTACHE_PROMPT.value\n else:\n build_config[\"template\"][\"type\"] = FieldTypes.PROMPT.value\n\n # Re-process the template to update variables when mode changes\n template_value = build_config.get(\"template\", {}).get(\"value\", \"\")\n if template_value:\n # Ensure custom_fields is properly initialized\n if \"custom_fields\" not in build_config:\n build_config[\"custom_fields\"] = {}\n\n # Clean up fields from the OLD mode before processing with NEW mode\n # This ensures we don't keep fields with wrong syntax even if validation fails\n old_custom_fields = build_config[\"custom_fields\"].get(\"template\", [])\n for old_field in list(old_custom_fields):\n # Remove the field from custom_fields and template\n if old_field in old_custom_fields:\n old_custom_fields.remove(old_field)\n build_config.pop(old_field, None)\n\n # Try to process template with new mode to add new variables\n # If validation fails, at least we cleaned up old fields\n try:\n # Validate mustache templates for security\n if is_mustache:\n validate_mustache_template(template_value)\n\n # Re-process template with new mode to add new variables\n _ = process_prompt_template(\n template=template_value,\n name=\"template\",\n custom_fields=build_config[\"custom_fields\"],\n frontend_node_template=build_config,\n is_mustache=is_mustache,\n )\n except ValueError as e:\n # If validation fails, we still updated the mode and cleaned old fields\n # User will see error when they try to save\n logger.debug(f\"Template validation failed during mode switch: {e}\")\n return build_config\n\n async def build_prompt(self) -> Message:\n use_double_brackets = self.use_double_brackets if hasattr(self, \"use_double_brackets\") else False\n template_format = \"mustache\" if use_double_brackets else \"f-string\"\n prompt = await Message.from_template_and_variables(template_format=template_format, **self._attributes)\n self.status = prompt.text\n return prompt\n\n def _update_template(self, frontend_node: dict):\n prompt_template = frontend_node[\"template\"][\"template\"][\"value\"]\n use_double_brackets = frontend_node[\"template\"].get(\"use_double_brackets\", {}).get(\"value\", False)\n is_mustache = use_double_brackets is True\n\n try:\n # Validate mustache templates for security\n if is_mustache:\n validate_mustache_template(prompt_template)\n\n custom_fields = frontend_node[\"custom_fields\"]\n frontend_node_template = frontend_node[\"template\"]\n _ = process_prompt_template(\n template=prompt_template,\n name=\"template\",\n custom_fields=custom_fields,\n frontend_node_template=frontend_node_template,\n is_mustache=is_mustache,\n )\n except ValueError as e:\n # If validation fails, don't add variables but allow component to be created\n logger.debug(f\"Template validation failed in _update_template: {e}\")\n return frontend_node\n\n async def update_frontend_node(self, new_frontend_node: dict, current_frontend_node: dict):\n \"\"\"This function is called after the code validation is done.\"\"\"\n frontend_node = await super().update_frontend_node(new_frontend_node, current_frontend_node)\n template = frontend_node[\"template\"][\"template\"][\"value\"]\n use_double_brackets = frontend_node[\"template\"].get(\"use_double_brackets\", {}).get(\"value\", False)\n is_mustache = use_double_brackets is True\n\n try:\n # Validate mustache templates for security\n if is_mustache:\n validate_mustache_template(template)\n\n # Kept it duplicated for backwards compatibility\n _ = process_prompt_template(\n template=template,\n name=\"template\",\n custom_fields=frontend_node[\"custom_fields\"],\n frontend_node_template=frontend_node[\"template\"],\n is_mustache=is_mustache,\n )\n except ValueError as e:\n # If validation fails, don't add variables but allow component to be updated\n logger.debug(f\"Template validation failed in update_frontend_node: {e}\")\n # Now that template is updated, we need to grab any values that were set in the current_frontend_node\n # and update the frontend_node with those values\n update_template_values(new_template=frontend_node, previous_template=current_frontend_node[\"template\"])\n return frontend_node\n\n def _get_fallback_input(self, **kwargs):\n return DefaultPromptField(**kwargs)\n"
+ },
+ "filter": {
+ "advanced": false,
+ "display_name": "filter",
"dynamic": false,
- "info": "Base URL for the API. Leave empty for default.",
+ "field_type": "str",
+ "fileTypes": [],
+ "file_path": "",
+ "info": "",
"input_types": [
"Message"
],
"list": false,
- "list_add_label": "Add More",
"load_from_db": false,
- "name": "api_base",
- "override_skip": false,
+ "multiline": true,
+ "name": "filter",
"placeholder": "",
"required": false,
"show": true,
"title_case": false,
- "tool_mode": false,
- "trace_as_input": true,
- "trace_as_metadata": true,
- "track_in_telemetry": false,
"type": "str",
"value": ""
},
- "api_key": {
- "_input_type": "SecretStrInput",
- "advanced": true,
- "api_editable": false,
- "display_name": "API Key",
+ "input": {
+ "advanced": false,
+ "display_name": "input",
"dynamic": false,
- "info": "Overrides global provider settings. Leave blank to use your pre-configured API Key.",
- "input_types": [],
+ "field_type": "str",
+ "fileTypes": [],
+ "file_path": "",
+ "info": "",
+ "input_types": [
+ "Message"
+ ],
+ "list": false,
"load_from_db": false,
- "name": "api_key",
- "override_skip": false,
- "password": true,
+ "multiline": true,
+ "name": "input",
"placeholder": "",
- "real_time_refresh": true,
"required": false,
"show": true,
"title_case": false,
- "track_in_telemetry": false,
"type": "str",
"value": ""
},
- "base_url_ibm_watsonx": {
- "_input_type": "DropdownInput",
+ "template": {
+ "_input_type": "PromptInput",
"advanced": false,
- "api_editable": false,
- "combobox": true,
- "dialog_inputs": {},
- "display_name": "watsonx API Endpoint",
+ "display_name": "Template",
"dynamic": false,
- "external_options": {},
- "info": "The base URL of the API (IBM watsonx.ai only)",
+ "info": "",
+ "list": false,
+ "list_add_label": "Add More",
"load_from_db": false,
- "name": "base_url_ibm_watsonx",
- "options": [
- "https://us-south.ml.cloud.ibm.com",
- "https://eu-de.ml.cloud.ibm.com",
- "https://eu-gb.ml.cloud.ibm.com",
- "https://au-syd.ml.cloud.ibm.com",
- "https://jp-tok.ml.cloud.ibm.com",
- "https://ca-tor.ml.cloud.ibm.com"
- ],
- "options_metadata": [],
+ "name": "template",
"override_skip": false,
"placeholder": "",
- "real_time_refresh": true,
"required": false,
- "show": false,
+ "show": true,
"title_case": false,
- "toggle": false,
"tool_mode": false,
- "trace_as_metadata": true,
- "track_in_telemetry": true,
+ "trace_as_input": true,
+ "track_in_telemetry": false,
+ "type": "prompt",
+ "value": "This is Knowledge filter - use it as a context of what to search on the database, unless it's empty: {filter}\n\nChat input: {input}"
+ },
+ "tool_placeholder": {
+ "_input_type": "MessageTextInput",
+ "advanced": true,
+ "display_name": "Tool Placeholder",
+ "dynamic": false,
+ "info": "A placeholder input for tool mode.",
+ "input_types": [
+ "Message"
+ ],
+ "list": false,
+ "list_add_label": "Add More",
+ "load_from_db": false,
+ "name": "tool_placeholder",
+ "override_skip": false,
+ "placeholder": "",
+ "required": false,
+ "show": false,
+ "title_case": false,
+ "tool_mode": true,
+ "trace_as_input": true,
+ "trace_as_metadata": true,
+ "track_in_telemetry": false,
"type": "str",
"value": ""
},
- "chunk_size": {
- "_input_type": "IntInput",
+ "use_double_brackets": {
+ "_input_type": "BoolInput",
"advanced": true,
- "api_editable": false,
- "display_name": "Chunk Size",
+ "display_name": "Use Double Brackets",
"dynamic": false,
- "info": "",
+ "info": "Use {{variable}} syntax instead of {variable}.",
"list": false,
"list_add_label": "Add More",
- "name": "chunk_size",
+ "name": "use_double_brackets",
"override_skip": false,
"placeholder": "",
+ "real_time_refresh": true,
"required": false,
"show": true,
"title_case": false,
"tool_mode": false,
"trace_as_metadata": true,
"track_in_telemetry": true,
- "type": "int",
- "value": 1000
+ "type": "bool",
+ "value": false
+ }
+ },
+ "tool_mode": false
+ },
+ "showNode": false,
+ "type": "Prompt Template"
+ },
+ "dragging": false,
+ "id": "Prompt Template-7kZsI",
+ "measured": {
+ "height": 80,
+ "width": 192
+ },
+ "position": {
+ "x": 998.1664626584457,
+ "y": 2010.5977206525736
+ },
+ "selected": false,
+ "type": "genericNode"
+ },
+ {
+ "data": {
+ "description": "Get user text inputs.",
+ "display_name": "Text Input",
+ "id": "TextInput-i0a3P",
+ "node": {
+ "base_classes": [
+ "Message"
+ ],
+ "beta": false,
+ "conditional_paths": [],
+ "custom_fields": {},
+ "description": "Get user text inputs.",
+ "display_name": "Text Input",
+ "documentation": "https://docs.langflow.org/text-input-and-output",
+ "edited": false,
+ "field_order": [
+ "input_value",
+ "use_global_variable"
+ ],
+ "frozen": false,
+ "icon": "type",
+ "last_updated": "2026-07-16T18:29:01.639Z",
+ "legacy": true,
+ "metadata": {
+ "code_hash": "2811c0e0496f",
+ "dependencies": {
+ "dependencies": [
+ {
+ "name": "lfx",
+ "version": "1.11.0.dev45"
+ }
+ ],
+ "total_dependencies": 1
+ },
+ "module": "custom_components.text_input"
+ },
+ "minimized": false,
+ "output_types": [],
+ "outputs": [
+ {
+ "allows_loop": false,
+ "cache": true,
+ "display_name": "Output Text",
+ "group_outputs": false,
+ "loop_types": null,
+ "method": "text_response",
+ "name": "text",
+ "options": null,
+ "required_inputs": null,
+ "selected": "Message",
+ "tool_mode": true,
+ "types": [
+ "Message"
+ ],
+ "value": "__UNDEFINED__"
+ }
+ ],
+ "pinned": false,
+ "replacement": [
+ "input_output.ChatInput"
+ ],
+ "template": {
+ "_frontend_node_flow_id": {
+ "value": "1098eea1-6649-4e1d-aed1-b77249fb8dd0"
},
+ "_frontend_node_folder_id": {
+ "value": "521f03bb-1efd-4936-904d-7440a72ec14b"
+ },
+ "_type": "Component",
"code": {
"advanced": true,
- "api_editable": false,
"dynamic": true,
"fileTypes": [],
"file_path": "",
@@ -1921,1345 +2082,125 @@
"show": true,
"title_case": false,
"type": "code",
- "value": "from lfx.base.embeddings.model import LCEmbeddingsModel\nfrom lfx.base.models.unified_models import (\n get_embedding_model_options,\n get_embeddings,\n handle_model_input_update,\n)\nfrom lfx.base.models.watsonx_constants import IBM_WATSONX_URLS\nfrom lfx.components.models_and_agents.model_selection import apply_model_overrides\nfrom lfx.field_typing import Embeddings\nfrom lfx.io import (\n BoolInput,\n DictInput,\n DropdownInput,\n FloatInput,\n IntInput,\n MessageTextInput,\n ModelInput,\n SecretStrInput,\n StrInput,\n)\n\n\nclass EmbeddingModelComponent(LCEmbeddingsModel):\n display_name = \"Embedding Model\"\n description = \"Generate embeddings using a specified provider.\"\n documentation: str = \"https://docs.langflow.org/components-embedding-models\"\n icon = \"binary\"\n name = \"EmbeddingModel\"\n category = \"models\"\n\n def update_build_config(self, build_config: dict, field_value: str, field_name: str | None = None):\n \"\"\"Dynamically update build config with user-filtered model options.\"\"\"\n return handle_model_input_update(\n self,\n dict(build_config),\n field_value,\n field_name,\n cache_key_prefix=\"embedding_model_options\",\n get_options_func=get_embedding_model_options,\n )\n\n inputs = [\n ModelInput(\n name=\"model\",\n display_name=\"Embedding Model\",\n info=\"Select your model provider\",\n real_time_refresh=True,\n required=True,\n model_type=\"embedding\",\n input_types=[\"Embeddings\"], # Override default to accept Embeddings instead of LanguageModel\n ),\n StrInput(\n name=\"model_name\",\n display_name=\"Model Name Override\",\n info=(\n \"Optional embedding model name to use instead of the selected model. \"\n \"Can be set from a global variable for runtime model selection.\"\n ),\n advanced=True,\n load_from_db=False,\n ),\n StrInput(\n name=\"provider\",\n display_name=\"Provider Override\",\n info=(\n \"Optional provider to use with Model Name Override. Leave blank to use the selected model's provider.\"\n ),\n advanced=True,\n load_from_db=False,\n ),\n SecretStrInput(\n name=\"api_key\",\n display_name=\"API Key\",\n info=\"Overrides global provider settings. Leave blank to use your pre-configured API Key.\",\n real_time_refresh=True,\n advanced=True,\n ),\n MessageTextInput(\n name=\"api_base\",\n display_name=\"API Base URL\",\n info=\"Base URL for the API. Leave empty for default.\",\n advanced=True,\n ),\n # Watson-specific inputs\n DropdownInput(\n name=\"base_url_ibm_watsonx\",\n display_name=\"watsonx API Endpoint\",\n info=\"The base URL of the API (IBM watsonx.ai only)\",\n options=IBM_WATSONX_URLS,\n value=IBM_WATSONX_URLS[0],\n combobox=True,\n show=False,\n real_time_refresh=True,\n ),\n MessageTextInput(\n name=\"project_id\",\n display_name=\"Project ID\",\n info=\"IBM watsonx.ai Project ID (required for IBM watsonx.ai)\",\n show=False,\n ),\n # Ollama-specific input\n StrInput(\n name=\"ollama_base_url\",\n display_name=\"Ollama API URL\",\n info=\"Endpoint of the Ollama API (Ollama only)\",\n show=False,\n real_time_refresh=True,\n ),\n IntInput(\n name=\"dimensions\",\n display_name=\"Dimensions\",\n info=\"The number of dimensions the resulting output embeddings should have. \"\n \"Only supported by certain models.\",\n advanced=True,\n ),\n IntInput(\n name=\"chunk_size\",\n display_name=\"Chunk Size\",\n advanced=True,\n value=1000,\n ),\n FloatInput(\n name=\"request_timeout\",\n display_name=\"Request Timeout\",\n advanced=True,\n ),\n IntInput(\n name=\"max_retries\",\n display_name=\"Max Retries\",\n advanced=True,\n value=3,\n ),\n BoolInput(\n name=\"show_progress_bar\",\n display_name=\"Show Progress Bar\",\n advanced=True,\n ),\n DictInput(\n name=\"model_kwargs\",\n display_name=\"Model Kwargs\",\n advanced=True,\n info=(\n \"Additional keyword arguments to pass to the model. Only used by providers that support this parameter \"\n \"(e.g. OpenAI, Google Generative AI). \"\n \"Ignored for providers that do not include it in their parameter mapping.\"\n ),\n ),\n IntInput(\n name=\"truncate_input_tokens\",\n display_name=\"Truncate Input Tokens\",\n advanced=True,\n value=200,\n show=False,\n ),\n BoolInput(\n name=\"input_text\",\n display_name=\"Include the original text in the output\",\n value=True,\n advanced=True,\n show=False,\n ),\n ]\n\n def build_embeddings(self) -> Embeddings:\n \"\"\"Build and return an embeddings instance based on the selected model.\"\"\"\n model = apply_model_overrides(\n self.model,\n model_name=getattr(self, \"model_name\", None),\n provider=getattr(self, \"provider\", None),\n user_id=self.user_id,\n get_options=get_embedding_model_options,\n )\n return get_embeddings(\n model=model,\n user_id=self.user_id,\n api_key=self.api_key,\n api_base=self.api_base,\n dimensions=self.dimensions,\n chunk_size=self.chunk_size,\n request_timeout=self.request_timeout,\n max_retries=self.max_retries,\n show_progress_bar=self.show_progress_bar,\n model_kwargs=self.model_kwargs,\n watsonx_url=getattr(self, \"base_url_ibm_watsonx\", None),\n watsonx_project_id=getattr(self, \"project_id\", None),\n watsonx_truncate_input_tokens=getattr(self, \"truncate_input_tokens\", None),\n watsonx_input_text=getattr(self, \"input_text\", None),\n ollama_base_url=getattr(self, \"ollama_base_url\", None),\n )\n"
+ "value": "from typing import Any\n\nfrom lfx.base.io.text import TextComponent\nfrom lfx.io import BoolInput, MultilineInput, Output\nfrom lfx.schema.message import Message\n\n\nclass TextInputComponent(TextComponent):\n display_name = \"Text Input\"\n description = \"Get user text inputs.\"\n documentation: str = \"https://docs.langflow.org/text-input-and-output\"\n icon = \"type\"\n name = \"TextInput\"\n legacy = True\n replacement = [\"input_output.ChatInput\"]\n\n inputs = [\n MultilineInput(\n name=\"input_value\",\n display_name=\"Text\",\n info=\"Text to be passed as input.\",\n ),\n BoolInput(\n name=\"use_global_variable\",\n display_name=\"Use Global Variable\",\n info=\"Enable to select from global variables (shows globe icon). Disables multiline editing.\",\n value=False,\n advanced=True,\n real_time_refresh=True,\n ),\n ]\n outputs = [\n Output(display_name=\"Output Text\", name=\"text\", method=\"text_response\"),\n ]\n\n def update_build_config(self, build_config: dict, field_value: Any, field_name: str | None = None) -> dict:\n if field_name == \"use_global_variable\":\n if field_value:\n # Enable global variable mode: single-line with password masking and globe dropdown\n build_config[\"input_value\"][\"multiline\"] = False\n build_config[\"input_value\"][\"password\"] = True\n else:\n # Default mode: multiline text editing\n build_config[\"input_value\"][\"multiline\"] = True\n build_config[\"input_value\"][\"password\"] = False\n return build_config\n\n def text_response(self) -> Message:\n return Message(\n text=self.input_value,\n )\n"
},
- "dimensions": {
- "_input_type": "IntInput",
- "advanced": true,
- "api_editable": false,
- "display_name": "Dimensions",
+ "input_value": {
+ "_input_type": "MultilineInput",
+ "advanced": false,
+ "ai_enabled": false,
+ "copy_field": false,
+ "display_name": "Text",
"dynamic": false,
- "info": "The number of dimensions the resulting output embeddings should have. Only supported by certain models.",
+ "info": "Text to be passed as input.",
+ "input_types": [
+ "Message"
+ ],
"list": false,
"list_add_label": "Add More",
- "load_from_db": false,
- "name": "dimensions",
+ "load_from_db": true,
+ "multiline": false,
+ "name": "input_value",
"override_skip": false,
+ "password": true,
"placeholder": "",
"required": false,
"show": true,
"title_case": false,
"tool_mode": false,
+ "trace_as_input": true,
"trace_as_metadata": true,
- "track_in_telemetry": true,
- "type": "int",
- "value": ""
+ "track_in_telemetry": false,
+ "type": "str",
+ "value": "OPENRAG-QUERY-FILTER"
},
- "input_text": {
+ "is_refresh": false,
+ "use_global_variable": {
"_input_type": "BoolInput",
"advanced": true,
- "api_editable": false,
- "display_name": "Include the original text in the output",
+ "display_name": "Use Global Variable",
"dynamic": false,
- "info": "",
+ "info": "Enable to select from global variables (shows globe icon). Disables multiline editing.",
"list": false,
"list_add_label": "Add More",
- "name": "input_text",
+ "load_from_db": false,
+ "name": "use_global_variable",
"override_skip": false,
"placeholder": "",
+ "real_time_refresh": true,
"required": false,
- "show": false,
+ "show": true,
"title_case": false,
"tool_mode": false,
"trace_as_metadata": true,
"track_in_telemetry": true,
"type": "bool",
"value": true
+ }
+ },
+ "tool_mode": false
+ },
+ "showNode": false,
+ "type": "TextInput"
+ },
+ "dragging": false,
+ "id": "TextInput-i0a3P",
+ "measured": {
+ "height": 129,
+ "width": 192
+ },
+ "position": {
+ "x": 564.9101816547212,
+ "y": 1824.034735248319
+ },
+ "selected": false,
+ "type": "genericNode"
+ },
+ {
+ "data": {
+ "id": "MCPTools-uu7m3",
+ "node": {
+ "base_classes": [
+ "Table"
+ ],
+ "beta": false,
+ "conditional_paths": [],
+ "custom_fields": {},
+ "description": "Connect to an MCP server to use its tools.",
+ "display_name": "MCP Tools",
+ "documentation": "https://docs.langflow.org/mcp-tools",
+ "edited": true,
+ "field_order": [
+ "mcp_server",
+ "use_cache",
+ "verify_ssl",
+ "headers",
+ "tool",
+ "tool_placeholder"
+ ],
+ "frozen": false,
+ "icon": "Mcp",
+ "last_updated": "2026-08-20T18:11:46.489Z",
+ "legacy": false,
+ "metadata": {
+ "code_hash": "ccd98ac0a0fb",
+ "dependencies": {
+ "dependencies": [
+ {
+ "name": "langchain_core",
+ "version": "1.2.29"
+ },
+ {
+ "name": "lfx",
+ "version": "0.4.0"
+ },
+ {
+ "name": "langflow",
+ "version": "1.9.0"
+ }
+ ],
+ "total_dependencies": 3
},
- "is_refresh": true,
- "max_retries": {
- "_input_type": "IntInput",
- "advanced": true,
- "api_editable": false,
- "display_name": "Max Retries",
- "dynamic": false,
- "info": "",
- "list": false,
- "list_add_label": "Add More",
- "name": "max_retries",
- "override_skip": false,
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_metadata": true,
- "track_in_telemetry": true,
- "type": "int",
- "value": 3
- },
- "model": {
- "_input_type": "ModelInput",
- "advanced": true,
- "api_editable": false,
- "display_name": "Embedding Model",
- "dynamic": false,
- "external_options": {
- "fields": {
- "data": {
- "node": {
- "display_name": "Connect other models",
- "icon": "CornerDownLeft",
- "name": "connect_other_models"
- }
- }
- }
- },
- "info": "Select your model provider",
- "input_types": [
- "Embeddings"
- ],
- "list": false,
- "list_add_label": "Add More",
- "load_from_db": false,
- "model_type": "embedding",
- "name": "model",
- "options": [
- {
- "category": "OpenAI",
- "icon": "OpenAI",
- "metadata": {
- "embedding_class": "OpenAIEmbeddings",
- "model_type": "embeddings",
- "param_mapping": {
- "api_base": "base_url",
- "api_key": "api_key",
- "chunk_size": "chunk_size",
- "dimensions": "dimensions",
- "max_retries": "max_retries",
- "model": "model",
- "model_kwargs": "model_kwargs",
- "request_timeout": "timeout",
- "show_progress_bar": "show_progress_bar"
- }
- },
- "name": "text-embedding-3-large",
- "provider": "OpenAI"
- },
- {
- "category": "OpenAI",
- "icon": "OpenAI",
- "metadata": {
- "embedding_class": "OpenAIEmbeddings",
- "model_type": "embeddings",
- "param_mapping": {
- "api_base": "base_url",
- "api_key": "api_key",
- "chunk_size": "chunk_size",
- "dimensions": "dimensions",
- "max_retries": "max_retries",
- "model": "model",
- "model_kwargs": "model_kwargs",
- "request_timeout": "timeout",
- "show_progress_bar": "show_progress_bar"
- }
- },
- "name": "text-embedding-3-small",
- "provider": "OpenAI"
- },
- {
- "category": "OpenAI",
- "icon": "OpenAI",
- "metadata": {
- "embedding_class": "OpenAIEmbeddings",
- "model_type": "embeddings",
- "param_mapping": {
- "api_base": "base_url",
- "api_key": "api_key",
- "chunk_size": "chunk_size",
- "dimensions": "dimensions",
- "max_retries": "max_retries",
- "model": "model",
- "model_kwargs": "model_kwargs",
- "request_timeout": "timeout",
- "show_progress_bar": "show_progress_bar"
- }
- },
- "name": "text-embedding-ada-002",
- "provider": "OpenAI"
- },
- {
- "category": "IBM WatsonX",
- "icon": "WatsonxAI",
- "metadata": {
- "embedding_class": "WatsonxEmbeddings",
- "model_type": "embeddings",
- "param_mapping": {
- "api_key": "apikey",
- "model_id": "model_id",
- "project_id": "project_id",
- "request_timeout": "request_timeout",
- "space_id": "space_id",
- "url": "url"
- }
- },
- "name": "ibm/granite-embedding-278m-multilingual",
- "provider": "IBM WatsonX"
- },
- {
- "category": "IBM WatsonX",
- "icon": "WatsonxAI",
- "metadata": {
- "embedding_class": "WatsonxEmbeddings",
- "model_type": "embeddings",
- "param_mapping": {
- "api_key": "apikey",
- "model_id": "model_id",
- "project_id": "project_id",
- "request_timeout": "request_timeout",
- "space_id": "space_id",
- "url": "url"
- }
- },
- "name": "ibm/slate-125m-english-rtrvr-v2",
- "provider": "IBM WatsonX"
- },
- {
- "category": "IBM WatsonX",
- "icon": "WatsonxAI",
- "metadata": {
- "embedding_class": "WatsonxEmbeddings",
- "model_type": "embeddings",
- "param_mapping": {
- "api_key": "apikey",
- "model_id": "model_id",
- "project_id": "project_id",
- "request_timeout": "request_timeout",
- "space_id": "space_id",
- "url": "url"
- }
- },
- "name": "ibm/slate-30m-english-rtrvr-v2",
- "provider": "IBM WatsonX"
- },
- {
- "category": "IBM WatsonX",
- "icon": "WatsonxAI",
- "metadata": {
- "embedding_class": "WatsonxEmbeddings",
- "model_type": "embeddings",
- "param_mapping": {
- "api_key": "apikey",
- "model_id": "model_id",
- "project_id": "project_id",
- "request_timeout": "request_timeout",
- "space_id": "space_id",
- "url": "url"
- }
- },
- "name": "intfloat/multilingual-e5-large",
- "provider": "IBM WatsonX"
- }
- ],
- "override_skip": false,
- "placeholder": "Setup Provider",
- "real_time_refresh": true,
- "refresh_button": true,
- "required": true,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_input": true,
- "track_in_telemetry": false,
- "type": "model",
- "value": [
- {
- "category": "OpenAI",
- "icon": "OpenAI",
- "metadata": {
- "embedding_class": "OpenAIEmbeddings",
- "model_type": "embeddings",
- "param_mapping": {
- "api_base": "base_url",
- "api_key": "api_key",
- "chunk_size": "chunk_size",
- "dimensions": "dimensions",
- "max_retries": "max_retries",
- "model": "model",
- "model_kwargs": "model_kwargs",
- "request_timeout": "timeout",
- "show_progress_bar": "show_progress_bar"
- }
- },
- "name": "text-embedding-3-small",
- "provider": "OpenAI"
- }
- ]
- },
- "model_kwargs": {
- "_input_type": "DictInput",
- "advanced": true,
- "api_editable": false,
- "display_name": "Model Kwargs",
- "dynamic": false,
- "info": "Additional keyword arguments to pass to the model. Only used by providers that support this parameter (e.g. OpenAI, Google Generative AI). Ignored for providers that do not include it in their parameter mapping.",
- "list": false,
- "list_add_label": "Add More",
- "name": "model_kwargs",
- "override_skip": false,
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_input": true,
- "track_in_telemetry": false,
- "type": "dict",
- "value": {}
- },
- "model_name": {
- "_input_type": "StrInput",
- "advanced": false,
- "api_editable": false,
- "display_name": "Model Name Override",
- "dynamic": false,
- "info": "Optional embedding model name to use instead of the selected model. Can be set from a global variable for runtime model selection.",
- "list": false,
- "list_add_label": "Add More",
- "load_from_db": true,
- "name": "model_name",
- "override_skip": false,
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_metadata": true,
- "track_in_telemetry": false,
- "type": "str",
- "value": "SELECTED_EMBEDDING_MODEL"
- },
- "ollama_base_url": {
- "_input_type": "StrInput",
- "advanced": false,
- "api_editable": false,
- "display_name": "Ollama API URL",
- "dynamic": false,
- "info": "Endpoint of the Ollama API (Ollama only)",
- "list": false,
- "list_add_label": "Add More",
- "load_from_db": false,
- "name": "ollama_base_url",
- "override_skip": false,
- "placeholder": "",
- "real_time_refresh": true,
- "required": false,
- "show": false,
- "title_case": false,
- "tool_mode": false,
- "trace_as_metadata": true,
- "track_in_telemetry": false,
- "type": "str",
- "value": ""
- },
- "project_id": {
- "_input_type": "MessageTextInput",
- "advanced": false,
- "api_editable": false,
- "display_name": "Project ID",
- "dynamic": false,
- "info": "IBM watsonx.ai Project ID (required for IBM watsonx.ai)",
- "input_types": [
- "Message"
- ],
- "list": false,
- "list_add_label": "Add More",
- "load_from_db": false,
- "name": "project_id",
- "override_skip": false,
- "placeholder": "",
- "required": false,
- "show": false,
- "title_case": false,
- "tool_mode": false,
- "trace_as_input": true,
- "trace_as_metadata": true,
- "track_in_telemetry": false,
- "type": "str",
- "value": ""
- },
- "provider": {
- "_input_type": "StrInput",
- "advanced": false,
- "api_editable": false,
- "display_name": "Provider Override",
- "dynamic": false,
- "info": "Optional provider to use with Model Name Override. Leave blank to use the selected model's provider.",
- "list": false,
- "list_add_label": "Add More",
- "load_from_db": true,
- "name": "provider",
- "override_skip": false,
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_metadata": true,
- "track_in_telemetry": false,
- "type": "str",
- "value": "SELECTED_EMBEDDING_MODEL_PROVIDER"
- },
- "request_timeout": {
- "_input_type": "FloatInput",
- "advanced": true,
- "api_editable": false,
- "display_name": "Request Timeout",
- "dynamic": false,
- "info": "",
- "list": false,
- "list_add_label": "Add More",
- "name": "request_timeout",
- "override_skip": false,
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_metadata": true,
- "track_in_telemetry": true,
- "type": "float",
- "value": ""
- },
- "show_progress_bar": {
- "_input_type": "BoolInput",
- "advanced": true,
- "api_editable": false,
- "display_name": "Show Progress Bar",
- "dynamic": false,
- "info": "",
- "list": false,
- "list_add_label": "Add More",
- "name": "show_progress_bar",
- "override_skip": false,
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_metadata": true,
- "track_in_telemetry": true,
- "type": "bool",
- "value": false
- },
- "truncate_input_tokens": {
- "_input_type": "IntInput",
- "advanced": true,
- "api_editable": false,
- "display_name": "Truncate Input Tokens",
- "dynamic": false,
- "info": "",
- "list": false,
- "list_add_label": "Add More",
- "name": "truncate_input_tokens",
- "override_skip": false,
- "placeholder": "",
- "required": false,
- "show": false,
- "title_case": false,
- "tool_mode": false,
- "trace_as_metadata": true,
- "track_in_telemetry": true,
- "type": "int",
- "value": 200
- }
- },
- "tool_mode": false
- },
- "showNode": false,
- "type": "EmbeddingModel"
- },
- "dragging": false,
- "id": "EmbeddingModel-zLHKs",
- "position": {
- "x": 665.0615885834427,
- "y": 1838.806979140434
- },
- "selected": false,
- "type": "genericNode"
- },
- {
- "data": {
- "description": "Create a prompt template with dynamic variables.",
- "display_name": "Prompt Template",
- "id": "Prompt Template-7kZsI",
- "node": {
- "base_classes": [
- "Message"
- ],
- "beta": false,
- "conditional_paths": [],
- "custom_fields": {
- "template": [
- "filter",
- "input"
- ]
- },
- "description": "Create a prompt template with dynamic variables.",
- "display_name": "Prompt Template",
- "documentation": "https://docs.langflow.org/components-prompts",
- "edited": false,
- "field_order": [
- "template",
- "use_double_brackets",
- "tool_placeholder"
- ],
- "frozen": false,
- "icon": "prompts",
- "legacy": false,
- "metadata": {
- "code_hash": "3d3fd7b8a36f",
- "dependencies": {
- "dependencies": [
- {
- "name": "lfx",
- "version": "0.4.0"
- }
- ],
- "total_dependencies": 1
- },
- "module": "custom_components.prompt_template"
- },
- "minimized": false,
- "output_types": [],
- "outputs": [
- {
- "allows_loop": false,
- "cache": true,
- "display_name": "Prompt",
- "group_outputs": false,
- "hidden": null,
- "loop_types": null,
- "method": "build_prompt",
- "name": "prompt",
- "options": null,
- "required_inputs": null,
- "selected": "Message",
- "tool_mode": true,
- "types": [
- "Message"
- ],
- "value": "__UNDEFINED__"
- }
- ],
- "pinned": false,
- "template": {
- "_type": "Component",
- "code": {
- "advanced": true,
- "dynamic": true,
- "fileTypes": [],
- "file_path": "",
- "info": "",
- "list": false,
- "load_from_db": false,
- "multiline": true,
- "name": "code",
- "password": false,
- "placeholder": "",
- "required": true,
- "show": true,
- "title_case": false,
- "type": "code",
- "value": "from typing import Any\n\nfrom lfx.base.prompts.api_utils import process_prompt_template\nfrom lfx.custom.custom_component.component import Component\nfrom lfx.inputs.input_mixin import FieldTypes\nfrom lfx.inputs.inputs import DefaultPromptField\nfrom lfx.io import BoolInput, MessageTextInput, Output, PromptInput\nfrom lfx.log.logger import logger\nfrom lfx.schema.dotdict import dotdict\nfrom lfx.schema.message import Message\nfrom lfx.template.utils import update_template_values\nfrom lfx.utils.mustache_security import validate_mustache_template\n\n\nclass PromptComponent(Component):\n display_name: str = \"Prompt Template\"\n description: str = \"Create a prompt template with dynamic variables.\"\n documentation: str = \"https://docs.langflow.org/components-prompts\"\n icon = \"prompts\"\n trace_type = \"prompt\"\n name = \"Prompt Template\"\n\n inputs = [\n PromptInput(name=\"template\", display_name=\"Template\"),\n BoolInput(\n name=\"use_double_brackets\",\n display_name=\"Use Double Brackets\",\n value=False,\n advanced=True,\n info=\"Use {{variable}} syntax instead of {variable}.\",\n real_time_refresh=True,\n ),\n MessageTextInput(\n name=\"tool_placeholder\",\n display_name=\"Tool Placeholder\",\n tool_mode=True,\n advanced=True,\n show=False,\n info=\"A placeholder input for tool mode.\",\n ),\n ]\n\n outputs = [\n Output(display_name=\"Prompt\", name=\"prompt\", method=\"build_prompt\"),\n ]\n\n def update_build_config(self, build_config: dotdict, field_value: Any, field_name: str | None = None) -> dotdict:\n \"\"\"Update the template field type based on the selected mode.\"\"\"\n if field_name == \"use_double_brackets\":\n # Change the template field type based on mode\n is_mustache = field_value is True\n if is_mustache:\n build_config[\"template\"][\"type\"] = FieldTypes.MUSTACHE_PROMPT.value\n else:\n build_config[\"template\"][\"type\"] = FieldTypes.PROMPT.value\n\n # Re-process the template to update variables when mode changes\n template_value = build_config.get(\"template\", {}).get(\"value\", \"\")\n if template_value:\n # Ensure custom_fields is properly initialized\n if \"custom_fields\" not in build_config:\n build_config[\"custom_fields\"] = {}\n\n # Clean up fields from the OLD mode before processing with NEW mode\n # This ensures we don't keep fields with wrong syntax even if validation fails\n old_custom_fields = build_config[\"custom_fields\"].get(\"template\", [])\n for old_field in list(old_custom_fields):\n # Remove the field from custom_fields and template\n if old_field in old_custom_fields:\n old_custom_fields.remove(old_field)\n build_config.pop(old_field, None)\n\n # Try to process template with new mode to add new variables\n # If validation fails, at least we cleaned up old fields\n try:\n # Validate mustache templates for security\n if is_mustache:\n validate_mustache_template(template_value)\n\n # Re-process template with new mode to add new variables\n _ = process_prompt_template(\n template=template_value,\n name=\"template\",\n custom_fields=build_config[\"custom_fields\"],\n frontend_node_template=build_config,\n is_mustache=is_mustache,\n )\n except ValueError as e:\n # If validation fails, we still updated the mode and cleaned old fields\n # User will see error when they try to save\n logger.debug(f\"Template validation failed during mode switch: {e}\")\n return build_config\n\n async def build_prompt(self) -> Message:\n use_double_brackets = self.use_double_brackets if hasattr(self, \"use_double_brackets\") else False\n template_format = \"mustache\" if use_double_brackets else \"f-string\"\n prompt = await Message.from_template_and_variables(template_format=template_format, **self._attributes)\n self.status = prompt.text\n return prompt\n\n def _update_template(self, frontend_node: dict):\n prompt_template = frontend_node[\"template\"][\"template\"][\"value\"]\n use_double_brackets = frontend_node[\"template\"].get(\"use_double_brackets\", {}).get(\"value\", False)\n is_mustache = use_double_brackets is True\n\n try:\n # Validate mustache templates for security\n if is_mustache:\n validate_mustache_template(prompt_template)\n\n custom_fields = frontend_node[\"custom_fields\"]\n frontend_node_template = frontend_node[\"template\"]\n _ = process_prompt_template(\n template=prompt_template,\n name=\"template\",\n custom_fields=custom_fields,\n frontend_node_template=frontend_node_template,\n is_mustache=is_mustache,\n )\n except ValueError as e:\n # If validation fails, don't add variables but allow component to be created\n logger.debug(f\"Template validation failed in _update_template: {e}\")\n return frontend_node\n\n async def update_frontend_node(self, new_frontend_node: dict, current_frontend_node: dict):\n \"\"\"This function is called after the code validation is done.\"\"\"\n frontend_node = await super().update_frontend_node(new_frontend_node, current_frontend_node)\n template = frontend_node[\"template\"][\"template\"][\"value\"]\n use_double_brackets = frontend_node[\"template\"].get(\"use_double_brackets\", {}).get(\"value\", False)\n is_mustache = use_double_brackets is True\n\n try:\n # Validate mustache templates for security\n if is_mustache:\n validate_mustache_template(template)\n\n # Kept it duplicated for backwards compatibility\n _ = process_prompt_template(\n template=template,\n name=\"template\",\n custom_fields=frontend_node[\"custom_fields\"],\n frontend_node_template=frontend_node[\"template\"],\n is_mustache=is_mustache,\n )\n except ValueError as e:\n # If validation fails, don't add variables but allow component to be updated\n logger.debug(f\"Template validation failed in update_frontend_node: {e}\")\n # Now that template is updated, we need to grab any values that were set in the current_frontend_node\n # and update the frontend_node with those values\n update_template_values(new_template=frontend_node, previous_template=current_frontend_node[\"template\"])\n return frontend_node\n\n def _get_fallback_input(self, **kwargs):\n return DefaultPromptField(**kwargs)\n"
- },
- "filter": {
- "advanced": false,
- "display_name": "filter",
- "dynamic": false,
- "field_type": "str",
- "fileTypes": [],
- "file_path": "",
- "info": "",
- "input_types": [
- "Message"
- ],
- "list": false,
- "load_from_db": false,
- "multiline": true,
- "name": "filter",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "type": "str",
- "value": ""
- },
- "input": {
- "advanced": false,
- "display_name": "input",
- "dynamic": false,
- "field_type": "str",
- "fileTypes": [],
- "file_path": "",
- "info": "",
- "input_types": [
- "Message"
- ],
- "list": false,
- "load_from_db": false,
- "multiline": true,
- "name": "input",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "type": "str",
- "value": ""
- },
- "template": {
- "_input_type": "PromptInput",
- "advanced": false,
- "display_name": "Template",
- "dynamic": false,
- "info": "",
- "list": false,
- "list_add_label": "Add More",
- "load_from_db": false,
- "name": "template",
- "override_skip": false,
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_input": true,
- "track_in_telemetry": false,
- "type": "prompt",
- "value": "This is Knowledge filter - use it as a context of what to search on the database, unless it's empty: {filter}\n\nChat input: {input}"
- },
- "tool_placeholder": {
- "_input_type": "MessageTextInput",
- "advanced": true,
- "display_name": "Tool Placeholder",
- "dynamic": false,
- "info": "A placeholder input for tool mode.",
- "input_types": [
- "Message"
- ],
- "list": false,
- "list_add_label": "Add More",
- "load_from_db": false,
- "name": "tool_placeholder",
- "override_skip": false,
- "placeholder": "",
- "required": false,
- "show": false,
- "title_case": false,
- "tool_mode": true,
- "trace_as_input": true,
- "trace_as_metadata": true,
- "track_in_telemetry": false,
- "type": "str",
- "value": ""
- },
- "use_double_brackets": {
- "_input_type": "BoolInput",
- "advanced": true,
- "display_name": "Use Double Brackets",
- "dynamic": false,
- "info": "Use {{variable}} syntax instead of {variable}.",
- "list": false,
- "list_add_label": "Add More",
- "name": "use_double_brackets",
- "override_skip": false,
- "placeholder": "",
- "real_time_refresh": true,
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_metadata": true,
- "track_in_telemetry": true,
- "type": "bool",
- "value": false
- }
- },
- "tool_mode": false
- },
- "showNode": true,
- "type": "Prompt Template"
- },
- "dragging": false,
- "id": "Prompt Template-7kZsI",
- "position": {
- "x": 1496.7915215019298,
- "y": 2019.0970114283145
- },
- "selected": false,
- "type": "genericNode"
- },
- {
- "data": {
- "description": "Get user text inputs.",
- "display_name": "Text Input",
- "id": "TextInput-i0a3P",
- "node": {
- "base_classes": [
- "Message"
- ],
- "beta": false,
- "conditional_paths": [],
- "custom_fields": {},
- "description": "Get user text inputs.",
- "display_name": "Text Input",
- "documentation": "https://docs.langflow.org/text-input-and-output",
- "edited": false,
- "field_order": [
- "input_value",
- "use_global_variable"
- ],
- "frozen": false,
- "icon": "type",
- "last_updated": "2026-07-16T18:29:01.639Z",
- "legacy": true,
- "metadata": {
- "code_hash": "2811c0e0496f",
- "dependencies": {
- "dependencies": [
- {
- "name": "lfx",
- "version": "1.11.0.dev45"
- }
- ],
- "total_dependencies": 1
- },
- "module": "custom_components.text_input"
- },
- "minimized": false,
- "output_types": [],
- "outputs": [
- {
- "allows_loop": false,
- "cache": true,
- "display_name": "Output Text",
- "group_outputs": false,
- "loop_types": null,
- "method": "text_response",
- "name": "text",
- "options": null,
- "required_inputs": null,
- "selected": "Message",
- "tool_mode": true,
- "types": [
- "Message"
- ],
- "value": "__UNDEFINED__"
- }
- ],
- "pinned": false,
- "replacement": [
- "input_output.ChatInput"
- ],
- "template": {
- "_frontend_node_flow_id": {
- "value": "1098eea1-6649-4e1d-aed1-b77249fb8dd0"
- },
- "_frontend_node_folder_id": {
- "value": "521f03bb-1efd-4936-904d-7440a72ec14b"
- },
- "_type": "Component",
- "code": {
- "advanced": true,
- "dynamic": true,
- "fileTypes": [],
- "file_path": "",
- "info": "",
- "list": false,
- "load_from_db": false,
- "multiline": true,
- "name": "code",
- "password": false,
- "placeholder": "",
- "required": true,
- "show": true,
- "title_case": false,
- "type": "code",
- "value": "from typing import Any\n\nfrom lfx.base.io.text import TextComponent\nfrom lfx.io import BoolInput, MultilineInput, Output\nfrom lfx.schema.message import Message\n\n\nclass TextInputComponent(TextComponent):\n display_name = \"Text Input\"\n description = \"Get user text inputs.\"\n documentation: str = \"https://docs.langflow.org/text-input-and-output\"\n icon = \"type\"\n name = \"TextInput\"\n legacy = True\n replacement = [\"input_output.ChatInput\"]\n\n inputs = [\n MultilineInput(\n name=\"input_value\",\n display_name=\"Text\",\n info=\"Text to be passed as input.\",\n ),\n BoolInput(\n name=\"use_global_variable\",\n display_name=\"Use Global Variable\",\n info=\"Enable to select from global variables (shows globe icon). Disables multiline editing.\",\n value=False,\n advanced=True,\n real_time_refresh=True,\n ),\n ]\n outputs = [\n Output(display_name=\"Output Text\", name=\"text\", method=\"text_response\"),\n ]\n\n def update_build_config(self, build_config: dict, field_value: Any, field_name: str | None = None) -> dict:\n if field_name == \"use_global_variable\":\n if field_value:\n # Enable global variable mode: single-line with password masking and globe dropdown\n build_config[\"input_value\"][\"multiline\"] = False\n build_config[\"input_value\"][\"password\"] = True\n else:\n # Default mode: multiline text editing\n build_config[\"input_value\"][\"multiline\"] = True\n build_config[\"input_value\"][\"password\"] = False\n return build_config\n\n def text_response(self) -> Message:\n return Message(\n text=self.input_value,\n )\n"
- },
- "input_value": {
- "_input_type": "MultilineInput",
- "advanced": false,
- "ai_enabled": false,
- "copy_field": false,
- "display_name": "Text",
- "dynamic": false,
- "info": "Text to be passed as input.",
- "input_types": [
- "Message"
- ],
- "list": false,
- "list_add_label": "Add More",
- "load_from_db": true,
- "multiline": false,
- "name": "input_value",
- "override_skip": false,
- "password": true,
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_input": true,
- "trace_as_metadata": true,
- "track_in_telemetry": false,
- "type": "str",
- "value": "OPENRAG-QUERY-FILTER"
- },
- "is_refresh": false,
- "use_global_variable": {
- "_input_type": "BoolInput",
- "advanced": true,
- "display_name": "Use Global Variable",
- "dynamic": false,
- "info": "Enable to select from global variables (shows globe icon). Disables multiline editing.",
- "list": false,
- "list_add_label": "Add More",
- "load_from_db": false,
- "name": "use_global_variable",
- "override_skip": false,
- "placeholder": "",
- "real_time_refresh": true,
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_metadata": true,
- "track_in_telemetry": true,
- "type": "bool",
- "value": true
- }
- },
- "tool_mode": false
- },
- "showNode": true,
- "type": "TextInput"
- },
- "dragging": false,
- "id": "TextInput-i0a3P",
- "position": {
- "x": 471.417983121568,
- "y": 2079.013458520555
- },
- "selected": false,
- "type": "genericNode"
- },
- {
- "data": {
- "id": "MCPTools-uu7m3",
- "node": {
- "base_classes": [
- "Table"
- ],
- "beta": false,
- "conditional_paths": [],
- "custom_fields": {},
- "description": "Connect to an MCP server to use its tools.",
- "display_name": "MCP Tools",
- "documentation": "https://docs.langflow.org/mcp-tools",
- "edited": true,
- "field_order": [
- "mcp_server",
- "use_cache",
- "verify_ssl",
- "headers",
- "tool",
- "tool_placeholder"
- ],
- "frozen": false,
- "icon": "Mcp",
- "last_updated": "2026-08-05T16:17:33.205Z",
- "legacy": false,
- "metadata": {
- "code_hash": "ccd98ac0a0fb",
- "dependencies": {
- "dependencies": [
- {
- "name": "langchain_core",
- "version": "1.2.29"
- },
- {
- "name": "lfx",
- "version": "0.4.0"
- },
- {
- "name": "langflow",
- "version": "1.9.0"
- }
- ],
- "total_dependencies": 3
- },
- "module": "custom_components.mcp_tools"
- },
- "minimized": false,
- "output_types": [],
- "outputs": [
- {
- "allows_loop": false,
- "cache": true,
- "display_name": "Toolset",
- "group_outputs": false,
- "hidden": null,
- "loop_types": null,
- "method": "to_toolkit",
- "name": "component_as_tool",
- "options": null,
- "required_inputs": null,
- "selected": "Tool",
- "tool_mode": true,
- "types": [
- "Tool"
- ],
- "value": "__UNDEFINED__"
- }
- ],
- "pinned": false,
- "template": {
- "_frontend_node_flow_id": {
- "value": "1098eea1-6649-4e1d-aed1-b77249fb8dd0"
- },
- "_frontend_node_folder_id": {
- "value": "203c7c12-9e1d-4561-bb14-16102afec154"
- },
- "_type": "Component",
- "code": {
- "advanced": true,
- "dynamic": true,
- "fileTypes": [],
- "file_path": "",
- "info": "",
- "list": false,
- "load_from_db": false,
- "multiline": true,
- "name": "code",
- "password": false,
- "placeholder": "",
- "required": true,
- "show": true,
- "title_case": false,
- "type": "code",
- "value": "from __future__ import annotations\n\nimport asyncio\nimport json\nimport uuid\n\nfrom langchain_core.tools import StructuredTool # noqa: TC002\n\nfrom lfx.base.agents.utils import maybe_unflatten_dict, safe_cache_get, safe_cache_set\nfrom lfx.base.mcp.util import (\n MCPStdioClient,\n MCPStreamableHttpClient,\n create_input_schema_from_json_schema,\n update_tools,\n)\nfrom lfx.custom.custom_component.component_with_cache import ComponentWithCache\nfrom lfx.inputs.inputs import InputTypes # noqa: TC001\nfrom lfx.io import BoolInput, DictInput, DropdownInput, McpInput, MessageTextInput, Output, TableInput\nfrom lfx.io.schema import flatten_schema, schema_to_langflow_inputs\nfrom lfx.log.logger import logger\nfrom lfx.schema.dataframe import DataFrame\nfrom lfx.schema.message import Message\nfrom lfx.services.deps import get_storage_service, session_scope\n\n\ndef resolve_mcp_config(\n server_name: str, # noqa: ARG001\n server_config_from_value: dict | None,\n server_config_from_db: dict | None,\n) -> dict | None:\n \"\"\"Resolve MCP server config with proper precedence.\n\n Resolves the configuration for an MCP server with the following precedence:\n 1. Database config (takes priority) - ensures edits are reflected\n 2. Config from value/tweaks (fallback) - allows REST API to provide config for new servers\n\n Args:\n server_name: Name of the MCP server\n server_config_from_value: Config provided via value/tweaks (optional)\n server_config_from_db: Config from database (optional)\n\n Returns:\n Final config to use (DB takes priority, falls back to value)\n Returns None if no config found in either location\n \"\"\"\n if server_config_from_db:\n return server_config_from_db\n return server_config_from_value\n\n\nclass MCPToolsComponent(ComponentWithCache):\n schema_inputs: list = []\n tools: list[StructuredTool] = []\n _not_load_actions: bool = False\n _tool_cache: dict = {}\n _last_selected_server: str | None = None # Cache for the last selected server\n\n def __init__(self, **data) -> None:\n super().__init__(**data)\n # Initialize cache keys to avoid CacheMiss when accessing them\n self._ensure_cache_structure()\n\n # Initialize clients with access to the component cache\n self.stdio_client: MCPStdioClient = MCPStdioClient(component_cache=self._shared_component_cache)\n self.streamable_http_client: MCPStreamableHttpClient = MCPStreamableHttpClient(\n component_cache=self._shared_component_cache\n )\n\n def _ensure_cache_structure(self):\n \"\"\"Ensure the cache has the required structure.\"\"\"\n # Check if servers key exists and is not CacheMiss\n servers_value = safe_cache_get(self._shared_component_cache, \"servers\")\n if servers_value is None:\n safe_cache_set(self._shared_component_cache, \"servers\", {})\n\n # Check if last_selected_server key exists and is not CacheMiss\n last_server_value = safe_cache_get(self._shared_component_cache, \"last_selected_server\")\n if last_server_value is None:\n safe_cache_set(self._shared_component_cache, \"last_selected_server\", \"\")\n\n default_keys: list[str] = [\n \"code\",\n \"_type\",\n \"tool_mode\",\n \"tool_placeholder\",\n \"mcp_server\",\n \"tool\",\n \"use_cache\",\n \"verify_ssl\",\n \"headers\",\n ]\n\n display_name = \"MCP Tools\"\n description = \"Connect to an MCP server to use its tools.\"\n documentation: str = \"https://docs.langflow.org/mcp-tools\"\n icon = \"Mcp\"\n name = \"MCPTools\"\n\n inputs = [\n McpInput(\n name=\"mcp_server\",\n display_name=\"MCP Server\",\n info=\"Select the MCP Server that will be used by this component\",\n real_time_refresh=True,\n ),\n BoolInput(\n name=\"use_cache\",\n display_name=\"Use Cached Server\",\n info=(\n \"Enable caching of MCP Server and tools to improve performance. \"\n \"Disable to always fetch fresh tools and server updates.\"\n ),\n value=False,\n advanced=True,\n ),\n BoolInput(\n name=\"verify_ssl\",\n display_name=\"Verify SSL Certificate\",\n info=(\n \"Enable SSL certificate verification for HTTPS connections. \"\n \"Disable only for development/testing with self-signed certificates.\"\n ),\n value=True,\n advanced=True,\n ),\n TableInput(\n name=\"headers\",\n display_name=\"Headers\",\n info=(\n \"HTTP headers to include with MCP server requests. \"\n \"Useful for authentication (e.g., Authorization header). \"\n \"These headers override any headers configured in the MCP server settings.\"\n ),\n advanced=True,\n table_schema=[\n {\n \"name\": \"key\",\n \"display_name\": \"Key\",\n \"type\": \"string\",\n \"description\": \"Key name\",\n },\n {\n \"name\": \"value\",\n \"display_name\": \"Value\",\n \"load_from_db\": True,\n \"type\": \"string\",\n \"description\": \"Value of the header\",\n },\n ],\n value={},\n input_types=[\"Data\", \"JSON\"],\n ),\n DropdownInput(\n name=\"tool\",\n display_name=\"Tool\",\n options=[],\n value=\"\",\n info=\"Select the tool to execute\",\n show=False,\n required=True,\n real_time_refresh=True,\n refresh_button=True,\n ),\n MessageTextInput(\n name=\"tool_placeholder\",\n display_name=\"Tool Placeholder\",\n info=\"Placeholder for the tool\",\n value=\"\",\n show=False,\n tool_mode=False,\n ),\n ]\n\n outputs = [\n Output(display_name=\"Response\", name=\"response\", method=\"build_output\"),\n ]\n\n async def _validate_schema_inputs(self, tool_obj) -> list[InputTypes]:\n \"\"\"Validate and process schema inputs for a tool.\"\"\"\n try:\n if not tool_obj or not hasattr(tool_obj, \"args_schema\"):\n msg = \"Invalid tool object or missing input schema\"\n raise ValueError(msg)\n\n flat_schema = flatten_schema(tool_obj.args_schema.schema())\n input_schema = create_input_schema_from_json_schema(flat_schema)\n if not input_schema:\n msg = f\"Empty input schema for tool '{tool_obj.name}'\"\n raise ValueError(msg)\n\n schema_inputs = schema_to_langflow_inputs(input_schema)\n if not schema_inputs:\n msg = f\"No input parameters defined for tool '{tool_obj.name}'\"\n await logger.awarning(msg)\n return []\n\n except Exception as e:\n msg = f\"Error validating schema inputs: {e!s}\"\n await logger.aexception(msg)\n raise ValueError(msg) from e\n else:\n return schema_inputs\n\n async def update_tool_list(self, mcp_server_value=None):\n # Accepts mcp_server_value as dict {name, config} or uses self.mcp_server\n mcp_server = mcp_server_value if mcp_server_value is not None else getattr(self, \"mcp_server\", None)\n server_name = None\n server_config_from_value = None\n if isinstance(mcp_server, dict):\n server_name = mcp_server.get(\"name\")\n server_config_from_value = mcp_server.get(\"config\")\n else:\n server_name = mcp_server\n if not server_name:\n self.tools = []\n return [], {\"name\": server_name, \"config\": server_config_from_value}\n\n # Check if caching is enabled, default to False\n use_cache = getattr(self, \"use_cache\", False)\n\n # Use shared cache if available and caching is enabled\n cached = None\n if use_cache:\n servers_cache = safe_cache_get(self._shared_component_cache, \"servers\", {})\n cached = servers_cache.get(server_name) if isinstance(servers_cache, dict) else None\n\n if cached is not None:\n try:\n self.tools = cached[\"tools\"]\n self.tool_names = cached[\"tool_names\"]\n self._tool_cache = cached[\"tool_cache\"]\n server_config_from_value = cached[\"config\"]\n except (TypeError, KeyError, AttributeError) as e:\n # Handle corrupted cache data by clearing it and continuing to fetch fresh tools\n msg = f\"Unable to use cached data for MCP Server{server_name}: {e}\"\n await logger.awarning(msg)\n # Clear the corrupted cache entry\n current_servers_cache = safe_cache_get(self._shared_component_cache, \"servers\", {})\n if isinstance(current_servers_cache, dict) and server_name in current_servers_cache:\n current_servers_cache.pop(server_name)\n safe_cache_set(self._shared_component_cache, \"servers\", current_servers_cache)\n else:\n return self.tools, {\"name\": server_name, \"config\": server_config_from_value}\n\n try:\n # Try to fetch from database first to ensure we have the latest config\n # This ensures database updates (like editing a server) take effect\n try:\n from langflow.api.v2.mcp import get_server\n from langflow.services.database.models.user.crud import get_user_by_id\n\n from lfx.services.deps import get_settings_service\n except ImportError as e:\n msg = (\n \"Langflow MCP server functionality is not available. \"\n \"This feature requires the full Langflow installation.\"\n )\n raise ImportError(msg) from e\n\n server_config_from_db = None\n async with session_scope() as db:\n if not self.user_id:\n msg = \"User ID is required for fetching MCP tools.\"\n raise ValueError(msg)\n current_user = await get_user_by_id(db, self.user_id)\n\n # Try to get server config from DB/API\n server_config_from_db = await get_server(\n server_name,\n current_user,\n db,\n storage_service=get_storage_service(),\n settings_service=get_settings_service(),\n )\n\n # Resolve config with proper precedence: DB takes priority, falls back to value\n server_config = resolve_mcp_config(\n server_name=server_name,\n server_config_from_value=server_config_from_value,\n server_config_from_db=server_config_from_db,\n )\n\n if not server_config:\n self.tools = []\n return [], {\"name\": server_name, \"config\": server_config}\n\n # Add verify_ssl option to server config if not present\n if \"verify_ssl\" not in server_config:\n verify_ssl = getattr(self, \"verify_ssl\", True)\n server_config[\"verify_ssl\"] = verify_ssl\n\n # Merge headers from component input with server config headers\n # Component headers take precedence over server config headers\n component_headers = getattr(self, \"headers\", None)\n if component_headers:\n # Convert list of {\"key\": k, \"value\": v}, Data objects, or dicts to dict\n component_headers_dict = {}\n\n # TableInput.validate_value normalizes single items to lists\n items = component_headers if isinstance(component_headers, list) else [component_headers]\n\n for item in items:\n if not item:\n continue\n\n # Case 1: Data object (Langflow standard)\n if hasattr(item, \"data\") and isinstance(item.data, dict):\n data = item.data\n if \"key\" in data and \"value\" in data:\n component_headers_dict[str(data[\"key\"])] = str(data[\"value\"])\n else:\n # Fallback: merge all keys from Data object (excluding internal keys)\n for k, v in data.items():\n if k not in (\"text_key\", \"default_value\"):\n component_headers_dict[str(k)] = str(v)\n\n # Case 2: Dictionary (Table row or direct JSON)\n elif isinstance(item, dict):\n if \"key\" in item and \"value\" in item:\n component_headers_dict[str(item[\"key\"])] = str(item[\"value\"])\n else:\n # Fallback: merge all keys\n for k, v in item.items():\n component_headers_dict[str(k)] = str(v)\n\n # Case 3: Message object\n elif hasattr(item, \"text\") and isinstance(item.text, str):\n try:\n parsed = json.loads(item.text)\n if isinstance(parsed, dict):\n for k, v in parsed.items():\n component_headers_dict[str(k)] = str(v)\n except json.JSONDecodeError:\n pass\n\n if component_headers_dict:\n existing_headers = server_config.get(\"headers\", {}) or {}\n # Ensure existing_headers is a dict (convert from list if needed)\n if isinstance(existing_headers, list):\n existing_dict = {}\n for item in existing_headers:\n if isinstance(item, dict) and \"key\" in item and \"value\" in item:\n existing_dict[item[\"key\"]] = item[\"value\"]\n existing_headers = existing_dict\n merged_headers = {**existing_headers, **component_headers_dict}\n server_config[\"headers\"] = merged_headers\n # Get request_variables from graph context for global variable resolution\n request_variables = None\n if hasattr(self, \"graph\") and self.graph and hasattr(self.graph, \"context\"):\n request_variables = self.graph.context.get(\"request_variables\")\n\n # Only load global variables from database if we have headers that might use them\n # This avoids unnecessary database queries when headers are empty\n has_headers = server_config.get(\"headers\") and len(server_config.get(\"headers\", {})) > 0\n if not request_variables and has_headers:\n try:\n from lfx.services.deps import get_variable_service\n\n variable_service = get_variable_service()\n if variable_service:\n async with session_scope() as db:\n request_variables = await variable_service.get_all_decrypted_variables(\n user_id=self.user_id, session=db\n )\n except Exception as e: # noqa: BLE001\n await logger.awarning(f\"Failed to load global variables for MCP component: {e}\")\n\n _, tool_list, tool_cache = await update_tools(\n server_name=server_name,\n server_config=server_config,\n mcp_stdio_client=self.stdio_client,\n mcp_streamable_http_client=self.streamable_http_client,\n request_variables=request_variables,\n )\n\n self.tool_names = [tool.name for tool in tool_list if hasattr(tool, \"name\")]\n self._tool_cache = tool_cache\n self.tools = tool_list\n\n # Cache the result only if caching is enabled\n if use_cache:\n cache_data = {\n \"tools\": tool_list,\n \"tool_names\": self.tool_names,\n \"tool_cache\": tool_cache,\n \"config\": server_config,\n }\n\n # Safely update the servers cache\n current_servers_cache = safe_cache_get(self._shared_component_cache, \"servers\", {})\n if isinstance(current_servers_cache, dict):\n current_servers_cache[server_name] = cache_data\n safe_cache_set(self._shared_component_cache, \"servers\", current_servers_cache)\n\n except (TimeoutError, asyncio.TimeoutError) as e:\n msg = f\"Timeout updating tool list: {e!s}\"\n await logger.aexception(msg)\n raise TimeoutError(msg) from e\n except Exception as e:\n msg = f\"Error updating tool list: {e!s}\"\n await logger.aexception(msg)\n raise ValueError(msg) from e\n else:\n return tool_list, {\"name\": server_name, \"config\": server_config}\n\n async def update_build_config(self, build_config: dict, field_value: str, field_name: str | None = None) -> dict:\n \"\"\"Toggle the visibility of connection-specific fields based on the selected mode.\"\"\"\n try:\n if field_name == \"tool\":\n try:\n # Always refresh tools when cache is disabled, or when tools list is empty\n # This ensures database edits are reflected immediately when cache is disabled\n use_cache = getattr(self, \"use_cache\", False)\n if len(self.tools) == 0 or not use_cache:\n try:\n self.tools, build_config[\"mcp_server\"][\"value\"] = await self.update_tool_list()\n build_config[\"tool\"][\"options\"] = [tool.name for tool in self.tools]\n build_config[\"tool\"][\"placeholder\"] = \"Select a tool\"\n except (TimeoutError, asyncio.TimeoutError) as e:\n msg = f\"Timeout updating tool list: {e!s}\"\n await logger.aexception(msg)\n if not build_config[\"tools_metadata\"][\"show\"]:\n build_config[\"tool\"][\"show\"] = True\n build_config[\"tool\"][\"options\"] = []\n build_config[\"tool\"][\"value\"] = \"\"\n build_config[\"tool\"][\"placeholder\"] = \"Timeout on MCP server\"\n else:\n build_config[\"tool\"][\"show\"] = False\n except ValueError:\n if not build_config[\"tools_metadata\"][\"show\"]:\n build_config[\"tool\"][\"show\"] = True\n build_config[\"tool\"][\"options\"] = []\n build_config[\"tool\"][\"value\"] = \"\"\n build_config[\"tool\"][\"placeholder\"] = \"Error on MCP Server\"\n else:\n build_config[\"tool\"][\"show\"] = False\n\n if field_value == \"\":\n return build_config\n tool_obj = None\n for tool in self.tools:\n if tool.name == field_value:\n tool_obj = tool\n break\n if tool_obj is None:\n msg = f\"Tool {field_value} not found in available tools: {self.tools}\"\n await logger.awarning(msg)\n return build_config\n await self._update_tool_config(build_config, field_value)\n except Exception as e:\n build_config[\"tool\"][\"options\"] = []\n msg = f\"Failed to update tools: {e!s}\"\n raise ValueError(msg) from e\n else:\n return build_config\n elif field_name == \"mcp_server\":\n if not field_value:\n build_config[\"tool\"][\"show\"] = False\n build_config[\"tool\"][\"options\"] = []\n build_config[\"tool\"][\"value\"] = \"\"\n build_config[\"tool\"][\"placeholder\"] = \"\"\n build_config[\"tool_placeholder\"][\"tool_mode\"] = False\n self.remove_non_default_keys(build_config)\n return build_config\n\n build_config[\"tool_placeholder\"][\"tool_mode\"] = True\n\n current_server_name = field_value.get(\"name\") if isinstance(field_value, dict) else field_value\n _last_selected_server = safe_cache_get(self._shared_component_cache, \"last_selected_server\", \"\")\n # Only treat as a server change if there was a previous server selection.\n # Cold cache (_last_selected_server=\"\") on initial flow load is NOT a server change —\n # the user didn't switch anything, the backend just hasn't seen this component yet.\n server_changed = bool(_last_selected_server and current_server_name != _last_selected_server)\n\n # Determine if \"Tool Mode\" is active by checking if the tool dropdown is hidden.\n is_in_tool_mode = build_config[\"tools_metadata\"][\"show\"]\n\n # Get use_cache setting to determine if we should use cached data\n use_cache = getattr(self, \"use_cache\", False)\n\n # Fast path: if server didn't change and we already have options, keep them as-is\n # BUT only if caching is enabled, we're in tool mode, or it's the initial load\n existing_options = build_config.get(\"tool\", {}).get(\"options\") or []\n if not server_changed and existing_options:\n # In non-tool mode with cache disabled, skip the fast path to force refresh\n # BUT on initial load (cold cache), always preserve saved options from the flow\n if not is_in_tool_mode and not use_cache and _last_selected_server:\n pass # Continue to refresh logic below (user-initiated with cache disabled)\n else:\n if not is_in_tool_mode:\n build_config[\"tool\"][\"show\"] = True\n safe_cache_set(self._shared_component_cache, \"last_selected_server\", current_server_name)\n return build_config\n\n # To avoid unnecessary updates, only proceed if the server has actually changed\n # OR if caching is disabled (to force refresh in non-tool mode)\n if (_last_selected_server in (current_server_name, \"\")) and build_config[\"tool\"][\"show\"] and use_cache:\n if current_server_name:\n servers_cache = safe_cache_get(self._shared_component_cache, \"servers\", {})\n if isinstance(servers_cache, dict):\n cached = servers_cache.get(current_server_name)\n if cached is not None and cached.get(\"tool_names\"):\n cached_tools = cached[\"tool_names\"]\n current_tools = build_config[\"tool\"][\"options\"]\n if current_tools == cached_tools:\n return build_config\n else:\n return build_config\n safe_cache_set(self._shared_component_cache, \"last_selected_server\", current_server_name)\n\n # When cache is disabled, clear any cached data for this server\n # This ensures we always fetch fresh data from the database\n if not use_cache and current_server_name:\n servers_cache = safe_cache_get(self._shared_component_cache, \"servers\", {})\n if isinstance(servers_cache, dict) and current_server_name in servers_cache:\n servers_cache.pop(current_server_name)\n safe_cache_set(self._shared_component_cache, \"servers\", servers_cache)\n\n # Check if tools are already cached for this server before clearing\n cached_tools = None\n if current_server_name and use_cache:\n servers_cache = safe_cache_get(self._shared_component_cache, \"servers\", {})\n if isinstance(servers_cache, dict):\n cached = servers_cache.get(current_server_name)\n if cached is not None:\n try:\n cached_tools = cached[\"tools\"]\n self.tools = cached_tools\n self.tool_names = cached[\"tool_names\"]\n self._tool_cache = cached[\"tool_cache\"]\n except (TypeError, KeyError, AttributeError) as e:\n # Handle corrupted cache data by ignoring it\n msg = f\"Unable to use cached data for MCP Server,{current_server_name}: {e}\"\n await logger.awarning(msg)\n cached_tools = None\n\n # Clear tools when cache is disabled OR when we don't have cached tools\n # This ensures fresh tools are fetched after database edits\n if not cached_tools or not use_cache:\n self.tools = [] # Clear previous tools to force refresh\n\n # Clear previous tool inputs if:\n # 1. Server actually changed\n # 2. Cache is disabled (meaning tool list will be refreshed)\n if server_changed or not use_cache:\n self.remove_non_default_keys(build_config)\n\n # Only show the tool dropdown if not in tool_mode\n if not is_in_tool_mode:\n build_config[\"tool\"][\"show\"] = True\n if cached_tools:\n # Use cached tools to populate options immediately\n build_config[\"tool\"][\"options\"] = [tool.name for tool in cached_tools]\n build_config[\"tool\"][\"placeholder\"] = \"Select a tool\"\n else:\n # Actually fetch tools now instead of deferring to a frontend callback.\n # The frontend has no reliable mechanism to trigger a second\n # update_build_config call for the \"tool\" field after this response,\n # so we must populate the options here.\n try:\n self.tools, build_config[\"mcp_server\"][\"value\"] = await self.update_tool_list(\n mcp_server_value=field_value\n )\n build_config[\"tool\"][\"options\"] = [tool.name for tool in self.tools]\n build_config[\"tool\"][\"placeholder\"] = \"Select a tool\"\n except (TimeoutError, asyncio.TimeoutError) as e:\n msg = f\"Timeout loading tools for MCP server: {e!s}\"\n await logger.awarning(msg)\n build_config[\"tool\"][\"options\"] = []\n build_config[\"tool\"][\"placeholder\"] = \"Timeout on MCP server\"\n except (ValueError, ImportError, ConnectionError, OSError, RuntimeError) as e:\n msg = f\"Error loading tools for MCP server: {e!s}\"\n await logger.awarning(msg)\n build_config[\"tool\"][\"options\"] = []\n build_config[\"tool\"][\"placeholder\"] = \"Error on MCP Server\"\n # Force a value refresh only when the user genuinely switched servers.\n # server_changed is only True for real user-initiated changes (not initial load).\n if server_changed:\n build_config[\"tool\"][\"value\"] = uuid.uuid4()\n else:\n # Keep the tool dropdown hidden if in tool_mode\n self._not_load_actions = True\n build_config[\"tool\"][\"show\"] = False\n\n elif field_name == \"tool_mode\":\n build_config[\"tool\"][\"placeholder\"] = \"\"\n build_config[\"tool\"][\"show\"] = not bool(field_value) and bool(build_config[\"mcp_server\"])\n self.remove_non_default_keys(build_config)\n self.tool = build_config[\"tool\"][\"value\"]\n if field_value:\n self._not_load_actions = True\n else:\n build_config[\"tool\"][\"value\"] = uuid.uuid4()\n build_config[\"tool\"][\"show\"] = True\n # Fetch tools immediately instead of showing \"Loading tools...\"\n try:\n self.tools, build_config[\"mcp_server\"][\"value\"] = await self.update_tool_list()\n build_config[\"tool\"][\"options\"] = [tool.name for tool in self.tools]\n build_config[\"tool\"][\"placeholder\"] = \"Select a tool\"\n except (TimeoutError, asyncio.TimeoutError) as e:\n msg = f\"Timeout loading tools when toggling tool mode: {e!s}\"\n await logger.awarning(msg)\n build_config[\"tool\"][\"options\"] = []\n build_config[\"tool\"][\"placeholder\"] = \"Timeout on MCP server\"\n except (ValueError, ImportError, ConnectionError, OSError, RuntimeError) as e:\n msg = f\"Error loading tools when toggling tool mode: {e!s}\"\n await logger.awarning(msg)\n build_config[\"tool\"][\"options\"] = []\n build_config[\"tool\"][\"placeholder\"] = \"Error on MCP Server\"\n elif field_name == \"tools_metadata\":\n self._not_load_actions = False\n\n except Exception as e:\n msg = f\"Error in update_build_config: {e!s}\"\n await logger.aexception(msg)\n raise ValueError(msg) from e\n else:\n return build_config\n\n def get_inputs_for_all_tools(self, tools: list) -> dict:\n \"\"\"Get input schemas for all tools.\"\"\"\n inputs = {}\n for tool in tools:\n if not tool or not hasattr(tool, \"name\"):\n continue\n try:\n flat_schema = flatten_schema(tool.args_schema.schema())\n input_schema = create_input_schema_from_json_schema(flat_schema)\n langflow_inputs = schema_to_langflow_inputs(input_schema)\n inputs[tool.name] = langflow_inputs\n except (AttributeError, ValueError, TypeError, KeyError) as e:\n msg = f\"Error getting inputs for tool {getattr(tool, 'name', 'unknown')}: {e!s}\"\n logger.exception(msg)\n continue\n return inputs\n\n def remove_non_default_keys(self, build_config: dict) -> None:\n \"\"\"Remove non-default keys from the build config.\"\"\"\n for key in list(build_config.keys()):\n if key not in self.default_keys:\n build_config.pop(key)\n\n async def _update_tool_config(self, build_config: dict, tool_name: str) -> None:\n \"\"\"Update tool configuration with proper error handling.\"\"\"\n if not self.tools:\n self.tools, build_config[\"mcp_server\"][\"value\"] = await self.update_tool_list()\n\n if not tool_name:\n return\n\n tool_obj = next((tool for tool in self.tools if tool.name == tool_name), None)\n if not tool_obj:\n msg = f\"Tool {tool_name} not found in available tools: {self.tools}\"\n self.remove_non_default_keys(build_config)\n build_config[\"tool\"][\"value\"] = \"\"\n await logger.awarning(msg)\n return\n\n try:\n # Store current values before removing inputs (only for the current tool)\n current_values = {}\n for key, value in build_config.items():\n if key not in self.default_keys and isinstance(value, dict) and \"value\" in value:\n current_values[key] = value[\"value\"]\n\n # Remove ALL non-default keys (all previous tool inputs)\n self.remove_non_default_keys(build_config)\n\n # Get and validate new inputs for the selected tool\n self.schema_inputs = await self._validate_schema_inputs(tool_obj)\n if not self.schema_inputs:\n msg = f\"No input parameters to configure for tool '{tool_name}'\"\n await logger.ainfo(msg)\n return\n\n # Add new inputs to build config for the selected tool only\n for schema_input in self.schema_inputs:\n if not schema_input or not hasattr(schema_input, \"name\"):\n msg = \"Invalid schema input detected, skipping\"\n await logger.awarning(msg)\n continue\n\n try:\n name = schema_input.name\n input_dict = schema_input.to_dict()\n input_dict.setdefault(\"value\", None)\n input_dict.setdefault(\"required\", True)\n\n build_config[name] = input_dict\n\n # Preserve existing value if the parameter name exists in current_values\n if name in current_values:\n build_config[name][\"value\"] = current_values[name]\n\n except (AttributeError, KeyError, TypeError) as e:\n msg = f\"Error processing schema input {schema_input}: {e!s}\"\n await logger.aexception(msg)\n continue\n except ValueError as e:\n msg = f\"Schema validation error for tool {tool_name}: {e!s}\"\n await logger.aexception(msg)\n self.schema_inputs = []\n return\n except (AttributeError, KeyError, TypeError) as e:\n msg = f\"Error updating tool config: {e!s}\"\n await logger.aexception(msg)\n raise ValueError(msg) from e\n\n async def build_output(self) -> DataFrame:\n \"\"\"Build output with improved error handling and validation.\"\"\"\n try:\n self.tools, _ = await self.update_tool_list()\n if self.tool != \"\":\n # Set session context for persistent MCP sessions using Langflow session ID\n session_context = self._get_session_context()\n if session_context:\n self.stdio_client.set_session_context(session_context)\n self.streamable_http_client.set_session_context(session_context)\n exec_tool = self._tool_cache[self.tool]\n tool_args = self.get_inputs_for_all_tools(self.tools)[self.tool]\n kwargs = {}\n for arg in tool_args:\n value = getattr(self, arg.name, None)\n if value is not None:\n if isinstance(value, Message):\n kwargs[arg.name] = value.text\n else:\n kwargs[arg.name] = value\n\n unflattened_kwargs = maybe_unflatten_dict(kwargs)\n\n output = await exec_tool.coroutine(**unflattened_kwargs)\n tool_content = []\n for item in output.content:\n item_dict = item.model_dump()\n item_dict = self.process_output_item(item_dict)\n tool_content.append(item_dict)\n\n if isinstance(tool_content, list) and all(isinstance(x, dict) for x in tool_content):\n return DataFrame(tool_content)\n return DataFrame(data=tool_content)\n return DataFrame(data=[{\"error\": \"You must select a tool\"}])\n except Exception as e:\n msg = f\"Error in build_output: {e!s}\"\n await logger.aexception(msg)\n raise ValueError(msg) from e\n\n def process_output_item(self, item_dict):\n \"\"\"Process the output of a tool.\"\"\"\n if item_dict.get(\"type\") == \"text\":\n text = item_dict.get(\"text\")\n try:\n parsed = json.loads(text)\n # Ensure we always return a dictionary for DataFrame compatibility\n if isinstance(parsed, dict):\n return parsed\n # Wrap non-dict parsed values in a dictionary\n return {\"text\": text, \"parsed_value\": parsed, \"type\": \"text\"} # noqa: TRY300\n except json.JSONDecodeError:\n return item_dict\n return item_dict\n\n def _get_session_context(self) -> str | None:\n \"\"\"Get the Langflow session ID for MCP session caching.\"\"\"\n # Try to get session ID from the component's execution context\n if hasattr(self, \"graph\") and hasattr(self.graph, \"session_id\"):\n session_id = self.graph.session_id\n # Include server name to ensure different servers get different sessions\n server_name = \"\"\n mcp_server = getattr(self, \"mcp_server\", None)\n if isinstance(mcp_server, dict):\n server_name = mcp_server.get(\"name\", \"\")\n elif mcp_server:\n server_name = str(mcp_server)\n return f\"{session_id}_{server_name}\" if session_id else None\n return None\n\n async def _get_tools(self):\n \"\"\"Get cached tools or update if necessary.\"\"\"\n mcp_server = getattr(self, \"mcp_server\", None)\n if not self._not_load_actions:\n tools, _ = await self.update_tool_list(mcp_server)\n return tools\n return []\n"
- },
- "headers": {
- "_input_type": "TableInput",
- "advanced": true,
- "display_name": "Headers",
- "dynamic": false,
- "info": "HTTP headers to include with MCP server requests. Useful for authentication (e.g., Authorization header). These headers override any headers configured in the MCP server settings.",
- "input_types": [
- "Data",
- "JSON"
- ],
- "is_list": true,
- "list_add_label": "Add More",
- "load_from_db": false,
- "name": "headers",
- "override_skip": false,
- "placeholder": "",
- "required": false,
- "show": true,
- "table_icon": "Table",
- "table_schema": [
- {
- "description": "Key name",
- "display_name": "Key",
- "formatter": "text",
- "name": "key",
- "type": "string"
- },
- {
- "description": "Value of the header",
- "display_name": "Value",
- "formatter": "text",
- "load_from_db": true,
- "name": "value",
- "type": "string"
- }
- ],
- "title_case": false,
- "tool_mode": false,
- "trace_as_metadata": true,
- "track_in_telemetry": false,
- "trigger_icon": "Table",
- "trigger_text": "Open table",
- "type": "table",
- "value": [
- {
- "": "",
- "__load_from_db_fields": {
- "value": true
- },
- "key": "X-Langflow-Global-Var-JWT",
- "value": "JWT"
- },
- {
- "__load_from_db_fields": {
- "value": true
- },
- "key": "X-Langflow-Global-Var-OPENAI_API_KEY",
- "value": "OPENAI_API_KEY"
- },
- {
- "__load_from_db_fields": {
- "value": true
- },
- "key": "X-Langflow-Global-Var-OPENSEARCH_URL",
- "value": "OPENSEARCH_URL"
- },
- {
- "__load_from_db_fields": {
- "value": true
- },
- "key": "X-Langflow-Global-Var-OPENSEARCH_INDEX_NAME",
- "value": "OPENSEARCH_INDEX_NAME"
- },
- {
- "__load_from_db_fields": {
- "value": true
- },
- "key": "X-Langflow-Global-Var-WATSONX_PROJECT_ID",
- "value": "WATSONX_PROJECT_ID"
- },
- {
- "__load_from_db_fields": {
- "value": true
- },
- "key": "X-Langflow-Global-Var-WATSONX_APIKEY",
- "value": "WATSONX_APIKEY"
- },
- {
- "__load_from_db_fields": {
- "value": true
- },
- "key": "X-Langflow-Global-Var-SELECTED_EMBEDDING_MODEL",
- "value": "SELECTED_EMBEDDING_MODEL"
- },
- {
- "__load_from_db_fields": {
- "value": true
- },
- "key": "X-Langflow-Global-Var-OPENRAG_INGEST_URL",
- "value": "OPENRAG_INGEST_URL"
- },
- {
- "__load_from_db_fields": {
- "value": true
- },
- "key": "X-Langflow-Global-Var-OPENRAG_INGEST_RUN_ID",
- "value": "OPENRAG_INGEST_RUN_ID"
- },
- {
- "__load_from_db_fields": {
- "value": true
- },
- "key": "X-Langflow-Global-Var-OPENRAG_INGEST_BATCH_SIZE",
- "value": "OPENRAG_INGEST_BATCH_SIZE"
- },
- {
- "__load_from_db_fields": {
- "value": true
- },
- "key": "X-Langflow-Global-Var-OPENRAG_INGEST_TOKEN",
- "value": "OPENRAG_INGEST_TOKEN"
- },
- {
- "__load_from_db_fields": {
- "value": true
- },
- "key": "X-Langflow-Global-Var-WATSONX_URL",
- "value": "WATSONX_URL"
- },
- {
- "__load_from_db_fields": {
- "value": true
- },
- "key": "X-Langflow-Global-Var-SELECTED_EMBEDDING_MODEL",
- "value": "SELECTED_EMBEDDING_MODEL"
- },
- {
- "__load_from_db_fields": {
- "value": true
- },
- "key": "X-Langflow-Global-Var-SELECTED_EMBEDDING_MODEL_PROVIDER",
- "value": "SELECTED_EMBEDDING_MODEL_PROVIDER"
- }
- ]
- },
- "is_refresh": false,
- "mcp_server": {
- "_input_type": "McpInput",
- "advanced": false,
- "display_name": "MCP Server",
- "dynamic": false,
- "info": "Select the MCP Server that will be used by this component",
- "load_from_db": false,
- "name": "mcp_server",
- "override_skip": false,
- "placeholder": "",
- "real_time_refresh": true,
- "required": false,
- "show": true,
- "title_case": false,
- "trace_as_metadata": true,
- "track_in_telemetry": false,
- "type": "mcp",
- "value": {
- "config": {},
- "name": "lf-starter_project"
- }
- },
- "tool": {
- "_input_type": "DropdownInput",
- "advanced": false,
- "combobox": false,
- "dialog_inputs": {},
- "display_name": "Tool",
- "dynamic": false,
- "external_options": {},
- "info": "Select the tool to execute",
- "name": "tool",
- "options": [
- "opensearch_url_ingestion_flow"
- ],
- "options_metadata": [],
- "override_skip": false,
- "placeholder": "",
- "real_time_refresh": true,
- "refresh_button": true,
- "required": true,
- "show": false,
- "title_case": false,
- "toggle": false,
- "tool_mode": false,
- "trace_as_metadata": true,
- "track_in_telemetry": true,
- "type": "str",
- "value": ""
- },
- "tool_placeholder": {
- "_input_type": "MessageTextInput",
- "advanced": false,
- "display_name": "Tool Placeholder",
- "dynamic": false,
- "info": "Placeholder for the tool",
- "input_types": [
- "Message"
- ],
- "list": false,
- "list_add_label": "Add More",
- "load_from_db": false,
- "name": "tool_placeholder",
- "override_skip": false,
- "placeholder": "",
- "required": false,
- "show": false,
- "title_case": false,
- "tool_mode": true,
- "trace_as_input": true,
- "trace_as_metadata": true,
- "track_in_telemetry": false,
- "type": "str",
- "value": ""
- },
- "tools_metadata": {
- "_input_type": "ToolsInput",
- "advanced": false,
- "api_editable": false,
- "display_name": "Actions",
- "dynamic": false,
- "info": "Modify tool names and descriptions to help agents understand when to use each tool.",
- "is_list": true,
- "list_add_label": "Add More",
- "name": "tools_metadata",
- "override_skip": false,
- "placeholder": "",
- "real_time_refresh": true,
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_metadata": true,
- "track_in_telemetry": false,
- "type": "tools",
- "value": [
- {
- "approval_actions": [],
- "args": {
- "input_value": {
- "anyOf": [
- {
- "type": "string"
- },
- {
- "type": "null"
- }
- ],
- "default": null,
- "description": "Message to be passed as input.",
- "title": "Input Value"
- },
- "session_id": {
- "anyOf": [
- {
- "type": "string"
- },
- {
- "type": "null"
- }
- ],
- "default": null,
- "description": "Optional session identifier used to persist conversation history across tool calls. Omit to start a new session.",
- "title": "Session Id"
- }
- },
- "description": "This flow is to ingest the URL to open search.",
- "display_description": "This flow is to ingest the URL to open search.",
- "display_name": "opensearch_url_ingestion_flow",
- "name": "opensearch_url_ingestion_flow",
- "readonly": false,
- "status": true,
- "tags": [
- "opensearch_url_ingestion_flow"
- ]
- },
- {
- "approval_actions": [],
- "args": {
- "session_id": {
- "anyOf": [
- {
- "type": "string"
- },
- {
- "type": "null"
- }
- ],
- "default": null,
- "description": "Optional session identifier used to persist conversation history across tool calls. Omit to start a new session.",
- "title": "Session Id"
- }
- },
- "description": "Unlock the Power of AI in Your Business Conversations.",
- "display_description": "Unlock the Power of AI in Your Business Conversations.",
- "display_name": "new_flow",
- "name": "new_flow",
- "readonly": false,
- "status": true,
- "tags": [
- "new_flow"
- ]
- }
- ]
- },
- "use_cache": {
- "_input_type": "BoolInput",
- "advanced": true,
- "display_name": "Use Cached Server",
- "dynamic": false,
- "info": "Enable caching of MCP Server and tools to improve performance. Disable to always fetch fresh tools and server updates.",
- "list": false,
- "list_add_label": "Add More",
- "name": "use_cache",
- "override_skip": false,
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_metadata": true,
- "track_in_telemetry": true,
- "type": "bool",
- "value": false
- },
- "verify_ssl": {
- "_input_type": "BoolInput",
- "advanced": true,
- "display_name": "Verify SSL Certificate",
- "dynamic": false,
- "info": "Enable SSL certificate verification for HTTPS connections. Disable only for development/testing with self-signed certificates.",
- "list": false,
- "list_add_label": "Add More",
- "name": "verify_ssl",
- "override_skip": false,
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_metadata": true,
- "track_in_telemetry": true,
- "type": "bool",
- "value": true
- }
- },
- "tool_mode": true
- },
- "showNode": true,
- "type": "MCPTools"
- },
- "dragging": false,
- "id": "MCPTools-uu7m3",
- "position": {
- "x": 1499.1989099237799,
- "y": 1358.0838292705346
- },
- "selected": false,
- "type": "genericNode"
- },
- {
- "data": {
- "_connectionMode": false,
- "description": "Runs a language model given a specified provider.",
- "display_name": "Language Model",
- "id": "LanguageModelComponent-MfLsT",
- "node": {
- "base_classes": [
- "LanguageModel",
- "Message"
- ],
- "beta": false,
- "conditional_paths": [],
- "custom_fields": {},
- "description": "Runs a language model given a specified provider.",
- "display_name": "Language Model",
- "documentation": "https://docs.langflow.org/components-models",
- "edited": false,
- "field_order": [
- "model",
- "model_name",
- "provider",
- "api_key",
- "base_url_ibm_watsonx",
- "project_id",
- "ollama_base_url",
- "input_value",
- "system_message",
- "stream",
- "temperature",
- "max_tokens"
- ],
- "frozen": false,
- "icon": "brain-circuit",
- "last_updated": "2026-07-29T14:25:05.187Z",
- "legacy": false,
- "metadata": {
- "code_hash": "c1f16fbd02f1",
- "dependencies": {
- "dependencies": [
- {
- "name": "lfx",
- "version": "1.11.1rc0"
- }
- ],
- "total_dependencies": 1
- },
- "keywords": [
- "model",
- "llm",
- "language model",
- "large language model"
- ],
- "module": "custom_components.language_model"
+ "module": "custom_components.mcp_tools"
},
"minimized": false,
"output_types": [],
@@ -3267,36 +2208,18 @@
{
"allows_loop": false,
"cache": true,
- "display_name": "Model Response",
- "group_outputs": false,
- "hidden": null,
- "loop_types": null,
- "method": "text_response",
- "name": "text_output",
- "options": null,
- "required_inputs": null,
- "selected": "Message",
- "tool_mode": true,
- "types": [
- "Message"
- ],
- "value": "__UNDEFINED__"
- },
- {
- "allows_loop": false,
- "cache": true,
- "display_name": "Language Model",
+ "display_name": "Toolset",
"group_outputs": false,
"hidden": null,
"loop_types": null,
- "method": "build_model",
- "name": "model_output",
+ "method": "to_toolkit",
+ "name": "component_as_tool",
"options": null,
"required_inputs": null,
- "selected": "LanguageModel",
+ "selected": "Tool",
"tool_mode": true,
"types": [
- "LanguageModel"
+ "Tool"
],
"value": "__UNDEFINED__"
}
@@ -3307,467 +2230,334 @@
"value": "1098eea1-6649-4e1d-aed1-b77249fb8dd0"
},
"_frontend_node_folder_id": {
- "value": "203c7c12-9e1d-4561-bb14-16102afec154"
+ "value": "503f5216-7f2c-4998-9010-b1a0eafbd500"
},
"_type": "Component",
- "api_key": {
- "_input_type": "SecretStrInput",
- "advanced": true,
- "api_editable": false,
- "display_name": "API Key",
- "dynamic": false,
- "info": "Overrides global provider settings. Leave blank to use your pre-configured API Key.",
- "input_types": [],
- "load_from_db": false,
- "name": "api_key",
- "override_skip": false,
- "password": true,
- "placeholder": "",
- "real_time_refresh": true,
- "required": false,
- "show": true,
- "title_case": false,
- "track_in_telemetry": false,
- "type": "str",
- "value": ""
- },
- "base_url_ibm_watsonx": {
- "_input_type": "DropdownInput",
- "advanced": false,
- "api_editable": false,
- "combobox": true,
- "dialog_inputs": {},
- "display_name": "watsonx API Endpoint",
- "dynamic": false,
- "external_options": {},
- "info": "The base URL of the API (IBM watsonx.ai only)",
- "name": "base_url_ibm_watsonx",
- "options": [
- "https://us-south.ml.cloud.ibm.com",
- "https://eu-de.ml.cloud.ibm.com",
- "https://eu-gb.ml.cloud.ibm.com",
- "https://au-syd.ml.cloud.ibm.com",
- "https://jp-tok.ml.cloud.ibm.com",
- "https://ca-tor.ml.cloud.ibm.com"
- ],
- "options_metadata": [],
- "override_skip": false,
- "placeholder": "",
- "real_time_refresh": true,
- "required": false,
- "show": false,
- "title_case": false,
- "toggle": false,
- "tool_mode": false,
- "trace_as_metadata": true,
- "track_in_telemetry": true,
- "type": "str",
- "value": "https://us-south.ml.cloud.ibm.com"
- },
"code": {
"advanced": true,
- "api_editable": false,
"dynamic": true,
"fileTypes": [],
"file_path": "",
- "info": "",
- "list": false,
- "load_from_db": false,
- "multiline": true,
- "name": "code",
- "password": false,
- "placeholder": "",
- "required": true,
- "show": true,
- "title_case": false,
- "type": "code",
- "value": "from lfx.base.models.model import LCModelComponent\nfrom lfx.base.models.unified_models import (\n get_language_model_options,\n get_llm,\n handle_model_input_update,\n)\nfrom lfx.base.models.watsonx_constants import IBM_WATSONX_URLS\nfrom lfx.components.models_and_agents.model_selection import apply_model_overrides\nfrom lfx.field_typing.constants import LanguageModel\nfrom lfx.field_typing.range_spec import RangeSpec\nfrom lfx.inputs.inputs import BoolInput, DropdownInput, StrInput\nfrom lfx.io import IntInput, MessageInput, ModelInput, MultilineInput, SecretStrInput, SliderInput\n\n\nclass LanguageModelComponent(LCModelComponent):\n display_name = \"Language Model\"\n description = \"Runs a language model given a specified provider.\"\n documentation: str = \"https://docs.langflow.org/components-models\"\n icon = \"brain-circuit\"\n category = \"models\"\n\n inputs = [\n ModelInput(\n name=\"model\",\n display_name=\"Language Model\",\n info=\"Select your model provider\",\n real_time_refresh=True,\n required=True,\n ),\n StrInput(\n name=\"model_name\",\n display_name=\"Model Name Override\",\n info=(\n \"Optional model name to use instead of the selected model. \"\n \"Can be set from a global variable for runtime model selection.\"\n ),\n advanced=True,\n load_from_db=False,\n ),\n StrInput(\n name=\"provider\",\n display_name=\"Provider Override\",\n info=(\n \"Optional provider to use with Model Name Override. Leave blank to use the selected model's provider.\"\n ),\n advanced=True,\n load_from_db=False,\n ),\n SecretStrInput(\n name=\"api_key\",\n display_name=\"API Key\",\n info=\"Overrides global provider settings. Leave blank to use your pre-configured API Key.\",\n required=False,\n show=True,\n real_time_refresh=True,\n advanced=True,\n ),\n DropdownInput(\n name=\"base_url_ibm_watsonx\",\n display_name=\"watsonx API Endpoint\",\n info=\"The base URL of the API (IBM watsonx.ai only)\",\n options=IBM_WATSONX_URLS,\n value=IBM_WATSONX_URLS[0],\n combobox=True,\n show=False,\n real_time_refresh=True,\n ),\n StrInput(\n name=\"project_id\",\n display_name=\"watsonx Project ID\",\n info=\"The project ID associated with the foundation model (IBM watsonx.ai only)\",\n show=False,\n required=False,\n ),\n StrInput(\n name=\"ollama_base_url\",\n display_name=\"Ollama API URL\",\n info=\"Endpoint of the Ollama API (Ollama only)\",\n show=False,\n real_time_refresh=True,\n ),\n MessageInput(\n name=\"input_value\",\n display_name=\"Input\",\n info=\"The input text to send to the model\",\n ),\n MultilineInput(\n name=\"system_message\",\n display_name=\"System Message\",\n info=\"A system message that helps set the behavior of the assistant\",\n advanced=False,\n ),\n BoolInput(\n name=\"stream\",\n display_name=\"Stream\",\n info=\"Whether to stream the response\",\n value=False,\n advanced=True,\n ),\n SliderInput(\n name=\"temperature\",\n display_name=\"Temperature\",\n value=0.1,\n info=\"Controls randomness in responses\",\n range_spec=RangeSpec(min=0, max=1, step=0.01),\n advanced=True,\n ),\n IntInput(\n name=\"max_tokens\",\n display_name=\"Max Tokens\",\n info=\"Maximum number of tokens to generate. Field name varies by provider.\",\n advanced=True,\n range_spec=RangeSpec(min=1, max=128000, step=1, step_type=\"int\"),\n ),\n ]\n\n def build_model(self) -> LanguageModel:\n model = apply_model_overrides(\n self.model,\n model_name=getattr(self, \"model_name\", None),\n provider=getattr(self, \"provider\", None),\n user_id=self.user_id,\n get_options=get_language_model_options,\n )\n return get_llm(\n model=model,\n user_id=self.user_id,\n api_key=self.api_key,\n temperature=self.temperature,\n stream=self.stream,\n max_tokens=getattr(self, \"max_tokens\", None),\n watsonx_url=getattr(self, \"base_url_ibm_watsonx\", None),\n watsonx_project_id=getattr(self, \"project_id\", None),\n ollama_base_url=getattr(self, \"ollama_base_url\", None),\n )\n\n def update_build_config(self, build_config: dict, field_value: str, field_name: str | None = None):\n \"\"\"Dynamically update build config with user-filtered model options.\"\"\"\n return handle_model_input_update(self, build_config, field_value, field_name)\n"
- },
- "input_value": {
- "_input_type": "MessageInput",
- "advanced": true,
- "api_editable": false,
- "display_name": "Input",
- "dynamic": false,
- "info": "The input text to send to the model",
- "input_types": [
- "Message"
- ],
- "list": false,
- "list_add_label": "Add More",
- "load_from_db": false,
- "name": "input_value",
- "override_skip": false,
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_input": true,
- "trace_as_metadata": true,
- "track_in_telemetry": false,
- "type": "str",
- "value": ""
- },
- "is_refresh": true,
- "max_tokens": {
- "_input_type": "IntInput",
- "advanced": true,
- "api_editable": false,
- "display_name": "Max Tokens",
- "dynamic": false,
- "info": "Maximum number of tokens to generate. Field name varies by provider.",
+ "info": "",
"list": false,
- "list_add_label": "Add More",
- "name": "max_tokens",
- "override_skip": false,
+ "load_from_db": false,
+ "multiline": true,
+ "name": "code",
+ "password": false,
"placeholder": "",
- "range_spec": {
- "max": 128000,
- "min": 1,
- "step": 1,
- "step_type": "int"
- },
- "required": false,
+ "required": true,
"show": true,
"title_case": false,
- "tool_mode": false,
- "trace_as_metadata": true,
- "track_in_telemetry": true,
- "type": "int",
- "value": 0
+ "type": "code",
+ "value": "from __future__ import annotations\n\nimport asyncio\nimport json\nimport uuid\n\nfrom langchain_core.tools import StructuredTool # noqa: TC002\n\nfrom lfx.base.agents.utils import maybe_unflatten_dict, safe_cache_get, safe_cache_set\nfrom lfx.base.mcp.util import (\n MCPStdioClient,\n MCPStreamableHttpClient,\n create_input_schema_from_json_schema,\n update_tools,\n)\nfrom lfx.custom.custom_component.component_with_cache import ComponentWithCache\nfrom lfx.inputs.inputs import InputTypes # noqa: TC001\nfrom lfx.io import BoolInput, DictInput, DropdownInput, McpInput, MessageTextInput, Output, TableInput\nfrom lfx.io.schema import flatten_schema, schema_to_langflow_inputs\nfrom lfx.log.logger import logger\nfrom lfx.schema.dataframe import DataFrame\nfrom lfx.schema.message import Message\nfrom lfx.services.deps import get_storage_service, session_scope\n\n\ndef resolve_mcp_config(\n server_name: str, # noqa: ARG001\n server_config_from_value: dict | None,\n server_config_from_db: dict | None,\n) -> dict | None:\n \"\"\"Resolve MCP server config with proper precedence.\n\n Resolves the configuration for an MCP server with the following precedence:\n 1. Database config (takes priority) - ensures edits are reflected\n 2. Config from value/tweaks (fallback) - allows REST API to provide config for new servers\n\n Args:\n server_name: Name of the MCP server\n server_config_from_value: Config provided via value/tweaks (optional)\n server_config_from_db: Config from database (optional)\n\n Returns:\n Final config to use (DB takes priority, falls back to value)\n Returns None if no config found in either location\n \"\"\"\n if server_config_from_db:\n return server_config_from_db\n return server_config_from_value\n\n\nclass MCPToolsComponent(ComponentWithCache):\n schema_inputs: list = []\n tools: list[StructuredTool] = []\n _not_load_actions: bool = False\n _tool_cache: dict = {}\n _last_selected_server: str | None = None # Cache for the last selected server\n\n def __init__(self, **data) -> None:\n super().__init__(**data)\n # Initialize cache keys to avoid CacheMiss when accessing them\n self._ensure_cache_structure()\n\n # Initialize clients with access to the component cache\n self.stdio_client: MCPStdioClient = MCPStdioClient(component_cache=self._shared_component_cache)\n self.streamable_http_client: MCPStreamableHttpClient = MCPStreamableHttpClient(\n component_cache=self._shared_component_cache\n )\n\n def _ensure_cache_structure(self):\n \"\"\"Ensure the cache has the required structure.\"\"\"\n # Check if servers key exists and is not CacheMiss\n servers_value = safe_cache_get(self._shared_component_cache, \"servers\")\n if servers_value is None:\n safe_cache_set(self._shared_component_cache, \"servers\", {})\n\n # Check if last_selected_server key exists and is not CacheMiss\n last_server_value = safe_cache_get(self._shared_component_cache, \"last_selected_server\")\n if last_server_value is None:\n safe_cache_set(self._shared_component_cache, \"last_selected_server\", \"\")\n\n default_keys: list[str] = [\n \"code\",\n \"_type\",\n \"tool_mode\",\n \"tool_placeholder\",\n \"mcp_server\",\n \"tool\",\n \"use_cache\",\n \"verify_ssl\",\n \"headers\",\n ]\n\n display_name = \"MCP Tools\"\n description = \"Connect to an MCP server to use its tools.\"\n documentation: str = \"https://docs.langflow.org/mcp-tools\"\n icon = \"Mcp\"\n name = \"MCPTools\"\n\n inputs = [\n McpInput(\n name=\"mcp_server\",\n display_name=\"MCP Server\",\n info=\"Select the MCP Server that will be used by this component\",\n real_time_refresh=True,\n ),\n BoolInput(\n name=\"use_cache\",\n display_name=\"Use Cached Server\",\n info=(\n \"Enable caching of MCP Server and tools to improve performance. \"\n \"Disable to always fetch fresh tools and server updates.\"\n ),\n value=False,\n advanced=True,\n ),\n BoolInput(\n name=\"verify_ssl\",\n display_name=\"Verify SSL Certificate\",\n info=(\n \"Enable SSL certificate verification for HTTPS connections. \"\n \"Disable only for development/testing with self-signed certificates.\"\n ),\n value=True,\n advanced=True,\n ),\n TableInput(\n name=\"headers\",\n display_name=\"Headers\",\n info=(\n \"HTTP headers to include with MCP server requests. \"\n \"Useful for authentication (e.g., Authorization header). \"\n \"These headers override any headers configured in the MCP server settings.\"\n ),\n advanced=True,\n table_schema=[\n {\n \"name\": \"key\",\n \"display_name\": \"Key\",\n \"type\": \"string\",\n \"description\": \"Key name\",\n },\n {\n \"name\": \"value\",\n \"display_name\": \"Value\",\n \"load_from_db\": True,\n \"type\": \"string\",\n \"description\": \"Value of the header\",\n },\n ],\n value={},\n input_types=[\"Data\", \"JSON\"],\n ),\n DropdownInput(\n name=\"tool\",\n display_name=\"Tool\",\n options=[],\n value=\"\",\n info=\"Select the tool to execute\",\n show=False,\n required=True,\n real_time_refresh=True,\n refresh_button=True,\n ),\n MessageTextInput(\n name=\"tool_placeholder\",\n display_name=\"Tool Placeholder\",\n info=\"Placeholder for the tool\",\n value=\"\",\n show=False,\n tool_mode=False,\n ),\n ]\n\n outputs = [\n Output(display_name=\"Response\", name=\"response\", method=\"build_output\"),\n ]\n\n async def _validate_schema_inputs(self, tool_obj) -> list[InputTypes]:\n \"\"\"Validate and process schema inputs for a tool.\"\"\"\n try:\n if not tool_obj or not hasattr(tool_obj, \"args_schema\"):\n msg = \"Invalid tool object or missing input schema\"\n raise ValueError(msg)\n\n flat_schema = flatten_schema(tool_obj.args_schema.schema())\n input_schema = create_input_schema_from_json_schema(flat_schema)\n if not input_schema:\n msg = f\"Empty input schema for tool '{tool_obj.name}'\"\n raise ValueError(msg)\n\n schema_inputs = schema_to_langflow_inputs(input_schema)\n if not schema_inputs:\n msg = f\"No input parameters defined for tool '{tool_obj.name}'\"\n await logger.awarning(msg)\n return []\n\n except Exception as e:\n msg = f\"Error validating schema inputs: {e!s}\"\n await logger.aexception(msg)\n raise ValueError(msg) from e\n else:\n return schema_inputs\n\n async def update_tool_list(self, mcp_server_value=None):\n # Accepts mcp_server_value as dict {name, config} or uses self.mcp_server\n mcp_server = mcp_server_value if mcp_server_value is not None else getattr(self, \"mcp_server\", None)\n server_name = None\n server_config_from_value = None\n if isinstance(mcp_server, dict):\n server_name = mcp_server.get(\"name\")\n server_config_from_value = mcp_server.get(\"config\")\n else:\n server_name = mcp_server\n if not server_name:\n self.tools = []\n return [], {\"name\": server_name, \"config\": server_config_from_value}\n\n # Check if caching is enabled, default to False\n use_cache = getattr(self, \"use_cache\", False)\n\n # Use shared cache if available and caching is enabled\n cached = None\n if use_cache:\n servers_cache = safe_cache_get(self._shared_component_cache, \"servers\", {})\n cached = servers_cache.get(server_name) if isinstance(servers_cache, dict) else None\n\n if cached is not None:\n try:\n self.tools = cached[\"tools\"]\n self.tool_names = cached[\"tool_names\"]\n self._tool_cache = cached[\"tool_cache\"]\n server_config_from_value = cached[\"config\"]\n except (TypeError, KeyError, AttributeError) as e:\n # Handle corrupted cache data by clearing it and continuing to fetch fresh tools\n msg = f\"Unable to use cached data for MCP Server{server_name}: {e}\"\n await logger.awarning(msg)\n # Clear the corrupted cache entry\n current_servers_cache = safe_cache_get(self._shared_component_cache, \"servers\", {})\n if isinstance(current_servers_cache, dict) and server_name in current_servers_cache:\n current_servers_cache.pop(server_name)\n safe_cache_set(self._shared_component_cache, \"servers\", current_servers_cache)\n else:\n return self.tools, {\"name\": server_name, \"config\": server_config_from_value}\n\n try:\n # Try to fetch from database first to ensure we have the latest config\n # This ensures database updates (like editing a server) take effect\n try:\n from langflow.api.v2.mcp import get_server\n from langflow.services.database.models.user.crud import get_user_by_id\n\n from lfx.services.deps import get_settings_service\n except ImportError as e:\n msg = (\n \"Langflow MCP server functionality is not available. \"\n \"This feature requires the full Langflow installation.\"\n )\n raise ImportError(msg) from e\n\n server_config_from_db = None\n async with session_scope() as db:\n if not self.user_id:\n msg = \"User ID is required for fetching MCP tools.\"\n raise ValueError(msg)\n current_user = await get_user_by_id(db, self.user_id)\n\n # Try to get server config from DB/API\n server_config_from_db = await get_server(\n server_name,\n current_user,\n db,\n storage_service=get_storage_service(),\n settings_service=get_settings_service(),\n )\n\n # Resolve config with proper precedence: DB takes priority, falls back to value\n server_config = resolve_mcp_config(\n server_name=server_name,\n server_config_from_value=server_config_from_value,\n server_config_from_db=server_config_from_db,\n )\n\n if not server_config:\n self.tools = []\n return [], {\"name\": server_name, \"config\": server_config}\n\n # Add verify_ssl option to server config if not present\n if \"verify_ssl\" not in server_config:\n verify_ssl = getattr(self, \"verify_ssl\", True)\n server_config[\"verify_ssl\"] = verify_ssl\n\n # Merge headers from component input with server config headers\n # Component headers take precedence over server config headers\n component_headers = getattr(self, \"headers\", None)\n if component_headers:\n # Convert list of {\"key\": k, \"value\": v}, Data objects, or dicts to dict\n component_headers_dict = {}\n\n # TableInput.validate_value normalizes single items to lists\n items = component_headers if isinstance(component_headers, list) else [component_headers]\n\n for item in items:\n if not item:\n continue\n\n # Case 1: Data object (Langflow standard)\n if hasattr(item, \"data\") and isinstance(item.data, dict):\n data = item.data\n if \"key\" in data and \"value\" in data:\n component_headers_dict[str(data[\"key\"])] = str(data[\"value\"])\n else:\n # Fallback: merge all keys from Data object (excluding internal keys)\n for k, v in data.items():\n if k not in (\"text_key\", \"default_value\"):\n component_headers_dict[str(k)] = str(v)\n\n # Case 2: Dictionary (Table row or direct JSON)\n elif isinstance(item, dict):\n if \"key\" in item and \"value\" in item:\n component_headers_dict[str(item[\"key\"])] = str(item[\"value\"])\n else:\n # Fallback: merge all keys\n for k, v in item.items():\n component_headers_dict[str(k)] = str(v)\n\n # Case 3: Message object\n elif hasattr(item, \"text\") and isinstance(item.text, str):\n try:\n parsed = json.loads(item.text)\n if isinstance(parsed, dict):\n for k, v in parsed.items():\n component_headers_dict[str(k)] = str(v)\n except json.JSONDecodeError:\n pass\n\n if component_headers_dict:\n existing_headers = server_config.get(\"headers\", {}) or {}\n # Ensure existing_headers is a dict (convert from list if needed)\n if isinstance(existing_headers, list):\n existing_dict = {}\n for item in existing_headers:\n if isinstance(item, dict) and \"key\" in item and \"value\" in item:\n existing_dict[item[\"key\"]] = item[\"value\"]\n existing_headers = existing_dict\n merged_headers = {**existing_headers, **component_headers_dict}\n server_config[\"headers\"] = merged_headers\n # Get request_variables from graph context for global variable resolution\n request_variables = None\n if hasattr(self, \"graph\") and self.graph and hasattr(self.graph, \"context\"):\n request_variables = self.graph.context.get(\"request_variables\")\n\n # Only load global variables from database if we have headers that might use them\n # This avoids unnecessary database queries when headers are empty\n has_headers = server_config.get(\"headers\") and len(server_config.get(\"headers\", {})) > 0\n if not request_variables and has_headers:\n try:\n from lfx.services.deps import get_variable_service\n\n variable_service = get_variable_service()\n if variable_service:\n async with session_scope() as db:\n request_variables = await variable_service.get_all_decrypted_variables(\n user_id=self.user_id, session=db\n )\n except Exception as e: # noqa: BLE001\n await logger.awarning(f\"Failed to load global variables for MCP component: {e}\")\n\n _, tool_list, tool_cache = await update_tools(\n server_name=server_name,\n server_config=server_config,\n mcp_stdio_client=self.stdio_client,\n mcp_streamable_http_client=self.streamable_http_client,\n request_variables=request_variables,\n )\n\n self.tool_names = [tool.name for tool in tool_list if hasattr(tool, \"name\")]\n self._tool_cache = tool_cache\n self.tools = tool_list\n\n # Cache the result only if caching is enabled\n if use_cache:\n cache_data = {\n \"tools\": tool_list,\n \"tool_names\": self.tool_names,\n \"tool_cache\": tool_cache,\n \"config\": server_config,\n }\n\n # Safely update the servers cache\n current_servers_cache = safe_cache_get(self._shared_component_cache, \"servers\", {})\n if isinstance(current_servers_cache, dict):\n current_servers_cache[server_name] = cache_data\n safe_cache_set(self._shared_component_cache, \"servers\", current_servers_cache)\n\n except (TimeoutError, asyncio.TimeoutError) as e:\n msg = f\"Timeout updating tool list: {e!s}\"\n await logger.aexception(msg)\n raise TimeoutError(msg) from e\n except Exception as e:\n msg = f\"Error updating tool list: {e!s}\"\n await logger.aexception(msg)\n raise ValueError(msg) from e\n else:\n return tool_list, {\"name\": server_name, \"config\": server_config}\n\n async def update_build_config(self, build_config: dict, field_value: str, field_name: str | None = None) -> dict:\n \"\"\"Toggle the visibility of connection-specific fields based on the selected mode.\"\"\"\n try:\n if field_name == \"tool\":\n try:\n # Always refresh tools when cache is disabled, or when tools list is empty\n # This ensures database edits are reflected immediately when cache is disabled\n use_cache = getattr(self, \"use_cache\", False)\n if len(self.tools) == 0 or not use_cache:\n try:\n self.tools, build_config[\"mcp_server\"][\"value\"] = await self.update_tool_list()\n build_config[\"tool\"][\"options\"] = [tool.name for tool in self.tools]\n build_config[\"tool\"][\"placeholder\"] = \"Select a tool\"\n except (TimeoutError, asyncio.TimeoutError) as e:\n msg = f\"Timeout updating tool list: {e!s}\"\n await logger.aexception(msg)\n if not build_config[\"tools_metadata\"][\"show\"]:\n build_config[\"tool\"][\"show\"] = True\n build_config[\"tool\"][\"options\"] = []\n build_config[\"tool\"][\"value\"] = \"\"\n build_config[\"tool\"][\"placeholder\"] = \"Timeout on MCP server\"\n else:\n build_config[\"tool\"][\"show\"] = False\n except ValueError:\n if not build_config[\"tools_metadata\"][\"show\"]:\n build_config[\"tool\"][\"show\"] = True\n build_config[\"tool\"][\"options\"] = []\n build_config[\"tool\"][\"value\"] = \"\"\n build_config[\"tool\"][\"placeholder\"] = \"Error on MCP Server\"\n else:\n build_config[\"tool\"][\"show\"] = False\n\n if field_value == \"\":\n return build_config\n tool_obj = None\n for tool in self.tools:\n if tool.name == field_value:\n tool_obj = tool\n break\n if tool_obj is None:\n msg = f\"Tool {field_value} not found in available tools: {self.tools}\"\n await logger.awarning(msg)\n return build_config\n await self._update_tool_config(build_config, field_value)\n except Exception as e:\n build_config[\"tool\"][\"options\"] = []\n msg = f\"Failed to update tools: {e!s}\"\n raise ValueError(msg) from e\n else:\n return build_config\n elif field_name == \"mcp_server\":\n if not field_value:\n build_config[\"tool\"][\"show\"] = False\n build_config[\"tool\"][\"options\"] = []\n build_config[\"tool\"][\"value\"] = \"\"\n build_config[\"tool\"][\"placeholder\"] = \"\"\n build_config[\"tool_placeholder\"][\"tool_mode\"] = False\n self.remove_non_default_keys(build_config)\n return build_config\n\n build_config[\"tool_placeholder\"][\"tool_mode\"] = True\n\n current_server_name = field_value.get(\"name\") if isinstance(field_value, dict) else field_value\n _last_selected_server = safe_cache_get(self._shared_component_cache, \"last_selected_server\", \"\")\n # Only treat as a server change if there was a previous server selection.\n # Cold cache (_last_selected_server=\"\") on initial flow load is NOT a server change —\n # the user didn't switch anything, the backend just hasn't seen this component yet.\n server_changed = bool(_last_selected_server and current_server_name != _last_selected_server)\n\n # Determine if \"Tool Mode\" is active by checking if the tool dropdown is hidden.\n is_in_tool_mode = build_config[\"tools_metadata\"][\"show\"]\n\n # Get use_cache setting to determine if we should use cached data\n use_cache = getattr(self, \"use_cache\", False)\n\n # Fast path: if server didn't change and we already have options, keep them as-is\n # BUT only if caching is enabled, we're in tool mode, or it's the initial load\n existing_options = build_config.get(\"tool\", {}).get(\"options\") or []\n if not server_changed and existing_options:\n # In non-tool mode with cache disabled, skip the fast path to force refresh\n # BUT on initial load (cold cache), always preserve saved options from the flow\n if not is_in_tool_mode and not use_cache and _last_selected_server:\n pass # Continue to refresh logic below (user-initiated with cache disabled)\n else:\n if not is_in_tool_mode:\n build_config[\"tool\"][\"show\"] = True\n safe_cache_set(self._shared_component_cache, \"last_selected_server\", current_server_name)\n return build_config\n\n # To avoid unnecessary updates, only proceed if the server has actually changed\n # OR if caching is disabled (to force refresh in non-tool mode)\n if (_last_selected_server in (current_server_name, \"\")) and build_config[\"tool\"][\"show\"] and use_cache:\n if current_server_name:\n servers_cache = safe_cache_get(self._shared_component_cache, \"servers\", {})\n if isinstance(servers_cache, dict):\n cached = servers_cache.get(current_server_name)\n if cached is not None and cached.get(\"tool_names\"):\n cached_tools = cached[\"tool_names\"]\n current_tools = build_config[\"tool\"][\"options\"]\n if current_tools == cached_tools:\n return build_config\n else:\n return build_config\n safe_cache_set(self._shared_component_cache, \"last_selected_server\", current_server_name)\n\n # When cache is disabled, clear any cached data for this server\n # This ensures we always fetch fresh data from the database\n if not use_cache and current_server_name:\n servers_cache = safe_cache_get(self._shared_component_cache, \"servers\", {})\n if isinstance(servers_cache, dict) and current_server_name in servers_cache:\n servers_cache.pop(current_server_name)\n safe_cache_set(self._shared_component_cache, \"servers\", servers_cache)\n\n # Check if tools are already cached for this server before clearing\n cached_tools = None\n if current_server_name and use_cache:\n servers_cache = safe_cache_get(self._shared_component_cache, \"servers\", {})\n if isinstance(servers_cache, dict):\n cached = servers_cache.get(current_server_name)\n if cached is not None:\n try:\n cached_tools = cached[\"tools\"]\n self.tools = cached_tools\n self.tool_names = cached[\"tool_names\"]\n self._tool_cache = cached[\"tool_cache\"]\n except (TypeError, KeyError, AttributeError) as e:\n # Handle corrupted cache data by ignoring it\n msg = f\"Unable to use cached data for MCP Server,{current_server_name}: {e}\"\n await logger.awarning(msg)\n cached_tools = None\n\n # Clear tools when cache is disabled OR when we don't have cached tools\n # This ensures fresh tools are fetched after database edits\n if not cached_tools or not use_cache:\n self.tools = [] # Clear previous tools to force refresh\n\n # Clear previous tool inputs if:\n # 1. Server actually changed\n # 2. Cache is disabled (meaning tool list will be refreshed)\n if server_changed or not use_cache:\n self.remove_non_default_keys(build_config)\n\n # Only show the tool dropdown if not in tool_mode\n if not is_in_tool_mode:\n build_config[\"tool\"][\"show\"] = True\n if cached_tools:\n # Use cached tools to populate options immediately\n build_config[\"tool\"][\"options\"] = [tool.name for tool in cached_tools]\n build_config[\"tool\"][\"placeholder\"] = \"Select a tool\"\n else:\n # Actually fetch tools now instead of deferring to a frontend callback.\n # The frontend has no reliable mechanism to trigger a second\n # update_build_config call for the \"tool\" field after this response,\n # so we must populate the options here.\n try:\n self.tools, build_config[\"mcp_server\"][\"value\"] = await self.update_tool_list(\n mcp_server_value=field_value\n )\n build_config[\"tool\"][\"options\"] = [tool.name for tool in self.tools]\n build_config[\"tool\"][\"placeholder\"] = \"Select a tool\"\n except (TimeoutError, asyncio.TimeoutError) as e:\n msg = f\"Timeout loading tools for MCP server: {e!s}\"\n await logger.awarning(msg)\n build_config[\"tool\"][\"options\"] = []\n build_config[\"tool\"][\"placeholder\"] = \"Timeout on MCP server\"\n except (ValueError, ImportError, ConnectionError, OSError, RuntimeError) as e:\n msg = f\"Error loading tools for MCP server: {e!s}\"\n await logger.awarning(msg)\n build_config[\"tool\"][\"options\"] = []\n build_config[\"tool\"][\"placeholder\"] = \"Error on MCP Server\"\n # Force a value refresh only when the user genuinely switched servers.\n # server_changed is only True for real user-initiated changes (not initial load).\n if server_changed:\n build_config[\"tool\"][\"value\"] = uuid.uuid4()\n else:\n # Keep the tool dropdown hidden if in tool_mode\n self._not_load_actions = True\n build_config[\"tool\"][\"show\"] = False\n\n elif field_name == \"tool_mode\":\n build_config[\"tool\"][\"placeholder\"] = \"\"\n build_config[\"tool\"][\"show\"] = not bool(field_value) and bool(build_config[\"mcp_server\"])\n self.remove_non_default_keys(build_config)\n self.tool = build_config[\"tool\"][\"value\"]\n if field_value:\n self._not_load_actions = True\n else:\n build_config[\"tool\"][\"value\"] = uuid.uuid4()\n build_config[\"tool\"][\"show\"] = True\n # Fetch tools immediately instead of showing \"Loading tools...\"\n try:\n self.tools, build_config[\"mcp_server\"][\"value\"] = await self.update_tool_list()\n build_config[\"tool\"][\"options\"] = [tool.name for tool in self.tools]\n build_config[\"tool\"][\"placeholder\"] = \"Select a tool\"\n except (TimeoutError, asyncio.TimeoutError) as e:\n msg = f\"Timeout loading tools when toggling tool mode: {e!s}\"\n await logger.awarning(msg)\n build_config[\"tool\"][\"options\"] = []\n build_config[\"tool\"][\"placeholder\"] = \"Timeout on MCP server\"\n except (ValueError, ImportError, ConnectionError, OSError, RuntimeError) as e:\n msg = f\"Error loading tools when toggling tool mode: {e!s}\"\n await logger.awarning(msg)\n build_config[\"tool\"][\"options\"] = []\n build_config[\"tool\"][\"placeholder\"] = \"Error on MCP Server\"\n elif field_name == \"tools_metadata\":\n self._not_load_actions = False\n\n except Exception as e:\n msg = f\"Error in update_build_config: {e!s}\"\n await logger.aexception(msg)\n raise ValueError(msg) from e\n else:\n return build_config\n\n def get_inputs_for_all_tools(self, tools: list) -> dict:\n \"\"\"Get input schemas for all tools.\"\"\"\n inputs = {}\n for tool in tools:\n if not tool or not hasattr(tool, \"name\"):\n continue\n try:\n flat_schema = flatten_schema(tool.args_schema.schema())\n input_schema = create_input_schema_from_json_schema(flat_schema)\n langflow_inputs = schema_to_langflow_inputs(input_schema)\n inputs[tool.name] = langflow_inputs\n except (AttributeError, ValueError, TypeError, KeyError) as e:\n msg = f\"Error getting inputs for tool {getattr(tool, 'name', 'unknown')}: {e!s}\"\n logger.exception(msg)\n continue\n return inputs\n\n def remove_non_default_keys(self, build_config: dict) -> None:\n \"\"\"Remove non-default keys from the build config.\"\"\"\n for key in list(build_config.keys()):\n if key not in self.default_keys:\n build_config.pop(key)\n\n async def _update_tool_config(self, build_config: dict, tool_name: str) -> None:\n \"\"\"Update tool configuration with proper error handling.\"\"\"\n if not self.tools:\n self.tools, build_config[\"mcp_server\"][\"value\"] = await self.update_tool_list()\n\n if not tool_name:\n return\n\n tool_obj = next((tool for tool in self.tools if tool.name == tool_name), None)\n if not tool_obj:\n msg = f\"Tool {tool_name} not found in available tools: {self.tools}\"\n self.remove_non_default_keys(build_config)\n build_config[\"tool\"][\"value\"] = \"\"\n await logger.awarning(msg)\n return\n\n try:\n # Store current values before removing inputs (only for the current tool)\n current_values = {}\n for key, value in build_config.items():\n if key not in self.default_keys and isinstance(value, dict) and \"value\" in value:\n current_values[key] = value[\"value\"]\n\n # Remove ALL non-default keys (all previous tool inputs)\n self.remove_non_default_keys(build_config)\n\n # Get and validate new inputs for the selected tool\n self.schema_inputs = await self._validate_schema_inputs(tool_obj)\n if not self.schema_inputs:\n msg = f\"No input parameters to configure for tool '{tool_name}'\"\n await logger.ainfo(msg)\n return\n\n # Add new inputs to build config for the selected tool only\n for schema_input in self.schema_inputs:\n if not schema_input or not hasattr(schema_input, \"name\"):\n msg = \"Invalid schema input detected, skipping\"\n await logger.awarning(msg)\n continue\n\n try:\n name = schema_input.name\n input_dict = schema_input.to_dict()\n input_dict.setdefault(\"value\", None)\n input_dict.setdefault(\"required\", True)\n\n build_config[name] = input_dict\n\n # Preserve existing value if the parameter name exists in current_values\n if name in current_values:\n build_config[name][\"value\"] = current_values[name]\n\n except (AttributeError, KeyError, TypeError) as e:\n msg = f\"Error processing schema input {schema_input}: {e!s}\"\n await logger.aexception(msg)\n continue\n except ValueError as e:\n msg = f\"Schema validation error for tool {tool_name}: {e!s}\"\n await logger.aexception(msg)\n self.schema_inputs = []\n return\n except (AttributeError, KeyError, TypeError) as e:\n msg = f\"Error updating tool config: {e!s}\"\n await logger.aexception(msg)\n raise ValueError(msg) from e\n\n async def build_output(self) -> DataFrame:\n \"\"\"Build output with improved error handling and validation.\"\"\"\n try:\n self.tools, _ = await self.update_tool_list()\n if self.tool != \"\":\n # Set session context for persistent MCP sessions using Langflow session ID\n session_context = self._get_session_context()\n if session_context:\n self.stdio_client.set_session_context(session_context)\n self.streamable_http_client.set_session_context(session_context)\n exec_tool = self._tool_cache[self.tool]\n tool_args = self.get_inputs_for_all_tools(self.tools)[self.tool]\n kwargs = {}\n for arg in tool_args:\n value = getattr(self, arg.name, None)\n if value is not None:\n if isinstance(value, Message):\n kwargs[arg.name] = value.text\n else:\n kwargs[arg.name] = value\n\n unflattened_kwargs = maybe_unflatten_dict(kwargs)\n\n output = await exec_tool.coroutine(**unflattened_kwargs)\n tool_content = []\n for item in output.content:\n item_dict = item.model_dump()\n item_dict = self.process_output_item(item_dict)\n tool_content.append(item_dict)\n\n if isinstance(tool_content, list) and all(isinstance(x, dict) for x in tool_content):\n return DataFrame(tool_content)\n return DataFrame(data=tool_content)\n return DataFrame(data=[{\"error\": \"You must select a tool\"}])\n except Exception as e:\n msg = f\"Error in build_output: {e!s}\"\n await logger.aexception(msg)\n raise ValueError(msg) from e\n\n def process_output_item(self, item_dict):\n \"\"\"Process the output of a tool.\"\"\"\n if item_dict.get(\"type\") == \"text\":\n text = item_dict.get(\"text\")\n try:\n parsed = json.loads(text)\n # Ensure we always return a dictionary for DataFrame compatibility\n if isinstance(parsed, dict):\n return parsed\n # Wrap non-dict parsed values in a dictionary\n return {\"text\": text, \"parsed_value\": parsed, \"type\": \"text\"} # noqa: TRY300\n except json.JSONDecodeError:\n return item_dict\n return item_dict\n\n def _get_session_context(self) -> str | None:\n \"\"\"Get the Langflow session ID for MCP session caching.\"\"\"\n # Try to get session ID from the component's execution context\n if hasattr(self, \"graph\") and hasattr(self.graph, \"session_id\"):\n session_id = self.graph.session_id\n # Include server name to ensure different servers get different sessions\n server_name = \"\"\n mcp_server = getattr(self, \"mcp_server\", None)\n if isinstance(mcp_server, dict):\n server_name = mcp_server.get(\"name\", \"\")\n elif mcp_server:\n server_name = str(mcp_server)\n return f\"{session_id}_{server_name}\" if session_id else None\n return None\n\n async def _get_tools(self):\n \"\"\"Get cached tools or update if necessary.\"\"\"\n mcp_server = getattr(self, \"mcp_server\", None)\n if not self._not_load_actions:\n tools, _ = await self.update_tool_list(mcp_server)\n return tools\n return []\n"
},
- "model": {
- "_input_type": "ModelInput",
- "advanced": true,
- "api_editable": false,
- "display_name": "Language Model",
+ "headers": {
+ "_input_type": "TableInput",
+ "advanced": false,
+ "display_name": "Headers",
"dynamic": false,
- "external_options": {
- "fields": {
- "data": {
- "node": {
- "display_name": "Connect other models",
- "icon": "CornerDownLeft",
- "name": "connect_other_models"
- }
- }
- }
- },
- "info": "Select your model provider",
+ "info": "HTTP headers to include with MCP server requests. Useful for authentication (e.g., Authorization header). These headers override any headers configured in the MCP server settings.",
"input_types": [
- "LanguageModel"
+ "Data",
+ "JSON"
],
- "list": false,
+ "is_list": true,
"list_add_label": "Add More",
"load_from_db": false,
- "model_type": "language",
- "name": "model",
- "options": [
+ "name": "headers",
+ "override_skip": false,
+ "placeholder": "",
+ "required": false,
+ "show": true,
+ "table_icon": "Table",
+ "table_schema": [
{
- "category": "Anthropic",
- "icon": "Anthropic",
- "metadata": {
- "api_key_param": "api_key",
- "context_length": 128000,
- "max_tokens_field_name": "max_tokens",
- "model_class": "ChatAnthropic",
- "model_name_param": "model",
- "reasoning": true,
- "reasoning_models": [
- "claude-opus-5"
- ]
+ "description": "Key name",
+ "display_name": "Key",
+ "formatter": "text",
+ "name": "key",
+ "type": "string"
+ },
+ {
+ "description": "Value of the header",
+ "display_name": "Value",
+ "formatter": "text",
+ "load_from_db": true,
+ "name": "value",
+ "type": "string"
+ }
+ ],
+ "title_case": false,
+ "tool_mode": false,
+ "trace_as_metadata": true,
+ "track_in_telemetry": false,
+ "trigger_icon": "Table",
+ "trigger_text": "Open table",
+ "type": "table",
+ "value": [
+ {
+ "": "",
+ "__load_from_db_fields": {
+ "value": true
},
- "name": "claude-opus-5",
- "provider": "Anthropic"
+ "key": "X-Langflow-Global-Var-JWT",
+ "value": "JWT"
},
{
- "category": "Anthropic",
- "icon": "Anthropic",
- "metadata": {
- "api_key_param": "api_key",
- "context_length": 128000,
- "max_tokens_field_name": "max_tokens",
- "model_class": "ChatAnthropic",
- "model_name_param": "model",
- "reasoning": true,
- "reasoning_models": [
- "claude-sonnet-5"
- ]
+ "__load_from_db_fields": {
+ "value": false
},
- "name": "claude-sonnet-5",
- "provider": "Anthropic"
+ "key": "X-Langflow-Global-Var-OPENAI_API_KEY",
+ "value": ""
},
{
- "category": "Anthropic",
- "icon": "Anthropic",
- "metadata": {
- "api_key_param": "api_key",
- "context_length": 128000,
- "max_tokens_field_name": "max_tokens",
- "model_class": "ChatAnthropic",
- "model_name_param": "model",
- "reasoning": true,
- "reasoning_models": [
- "claude-fable-5"
- ]
+ "__load_from_db_fields": {
+ "value": true
},
- "name": "claude-fable-5",
- "provider": "Anthropic"
+ "key": "X-Langflow-Global-Var-OPENSEARCH_URL",
+ "value": "OPENSEARCH_URL"
},
{
- "category": "Anthropic",
- "icon": "Anthropic",
- "metadata": {
- "api_key_param": "api_key",
- "context_length": 128000,
- "max_tokens_field_name": "max_tokens",
- "model_class": "ChatAnthropic",
- "model_name_param": "model",
- "reasoning": true,
- "reasoning_models": [
- "claude-opus-4-8"
- ]
+ "__load_from_db_fields": {
+ "value": true
},
- "name": "claude-opus-4-8",
- "provider": "Anthropic"
+ "key": "X-Langflow-Global-Var-OPENSEARCH_INDEX_NAME",
+ "value": "OPENSEARCH_INDEX_NAME"
},
{
- "category": "Anthropic",
- "icon": "Anthropic",
- "metadata": {
- "api_key_param": "api_key",
- "context_length": 128000,
- "max_tokens_field_name": "max_tokens",
- "model_class": "ChatAnthropic",
- "model_name_param": "model",
- "reasoning": true,
- "reasoning_models": [
- "claude-opus-4-7"
- ]
+ "__load_from_db_fields": {
+ "value": true
},
- "name": "claude-opus-4-7",
- "provider": "Anthropic"
+ "key": "X-Langflow-Global-Var-WATSONX_PROJECT_ID",
+ "value": "WATSONX_PROJECT_ID"
},
{
- "category": "OpenAI",
- "icon": "OpenAI",
- "metadata": {
- "api_key_param": "api_key",
- "context_length": 128000,
- "max_tokens_field_name": "max_tokens",
- "model_class": "ChatOpenAI",
- "model_name_param": "model",
- "reasoning": true,
- "reasoning_models": [
- "gpt-5.6-sol"
- ]
+ "__load_from_db_fields": {
+ "value": true
},
- "name": "gpt-5.6-sol",
- "provider": "OpenAI"
+ "key": "X-Langflow-Global-Var-WATSONX_APIKEY",
+ "value": "WATSONX_APIKEY"
},
{
- "category": "OpenAI",
- "icon": "OpenAI",
- "metadata": {
- "api_key_param": "api_key",
- "context_length": 128000,
- "max_tokens_field_name": "max_tokens",
- "model_class": "ChatOpenAI",
- "model_name_param": "model",
- "reasoning": true,
- "reasoning_models": [
- "gpt-5.6-luna"
- ]
+ "__load_from_db_fields": {
+ "value": true
},
- "name": "gpt-5.6-luna",
- "provider": "OpenAI"
+ "key": "X-Langflow-Global-Var-SELECTED_EMBEDDING_MODEL",
+ "value": "SELECTED_EMBEDDING_MODEL"
},
{
- "category": "OpenAI",
- "icon": "OpenAI",
- "metadata": {
- "api_key_param": "api_key",
- "context_length": 128000,
- "max_tokens_field_name": "max_tokens",
- "model_class": "ChatOpenAI",
- "model_name_param": "model",
- "reasoning": true,
- "reasoning_models": [
- "gpt-5.6"
- ]
+ "__load_from_db_fields": {
+ "value": true
},
- "name": "gpt-5.6",
- "provider": "OpenAI"
+ "key": "X-Langflow-Global-Var-OPENRAG_INGEST_URL",
+ "value": "OPENRAG_INGEST_URL"
},
{
- "category": "OpenAI",
- "icon": "OpenAI",
- "metadata": {
- "api_key_param": "api_key",
- "context_length": 128000,
- "max_tokens_field_name": "max_tokens",
- "model_class": "ChatOpenAI",
- "model_name_param": "model",
- "reasoning": true,
- "reasoning_models": [
- "gpt-5.6-terra"
- ]
+ "__load_from_db_fields": {
+ "value": true
},
- "name": "gpt-5.6-terra",
- "provider": "OpenAI"
+ "key": "X-Langflow-Global-Var-OPENRAG_INGEST_RUN_ID",
+ "value": "OPENRAG_INGEST_RUN_ID"
},
{
- "category": "OpenAI",
- "icon": "OpenAI",
- "metadata": {
- "api_key_param": "api_key",
- "context_length": 128000,
- "max_tokens_field_name": "max_tokens",
- "model_class": "ChatOpenAI",
- "model_name_param": "model",
- "reasoning": true,
- "reasoning_models": [
- "gpt-realtime-2.1"
- ]
+ "__load_from_db_fields": {
+ "value": true
},
- "name": "gpt-realtime-2.1",
- "provider": "OpenAI"
+ "key": "X-Langflow-Global-Var-OPENRAG_INGEST_BATCH_SIZE",
+ "value": "OPENRAG_INGEST_BATCH_SIZE"
},
{
- "category": "IBM WatsonX",
- "icon": "WatsonxAI",
- "metadata": {
- "api_key_param": "apikey",
- "context_length": 128000,
- "max_tokens_field_name": "max_tokens",
- "model_class": "ChatWatsonx",
- "model_name_param": "model_id",
- "project_id_param": "project_id",
- "url_param": "url"
+ "__load_from_db_fields": {
+ "value": true
},
- "name": "ibm/granite-4-h-small",
- "provider": "IBM WatsonX"
+ "key": "X-Langflow-Global-Var-OPENRAG_INGEST_TOKEN",
+ "value": "OPENRAG_INGEST_TOKEN"
},
{
- "category": "IBM WatsonX",
- "icon": "WatsonxAI",
- "metadata": {
- "api_key_param": "apikey",
- "context_length": 128000,
- "max_tokens_field_name": "max_tokens",
- "model_class": "ChatWatsonx",
- "model_name_param": "model_id",
- "project_id_param": "project_id",
- "url_param": "url"
+ "__load_from_db_fields": {
+ "value": true
},
- "name": "ibm/granite-8b-code-instruct",
- "provider": "IBM WatsonX"
+ "key": "X-Langflow-Global-Var-WATSONX_URL",
+ "value": "WATSONX_URL"
},
{
- "category": "IBM WatsonX",
- "icon": "WatsonxAI",
- "metadata": {
- "api_key_param": "apikey",
- "context_length": 128000,
- "max_tokens_field_name": "max_tokens",
- "model_class": "ChatWatsonx",
- "model_name_param": "model_id",
- "project_id_param": "project_id",
- "url_param": "url"
+ "__load_from_db_fields": {
+ "value": true
},
- "name": "ibm/granite-guardian-3-8b",
- "provider": "IBM WatsonX"
+ "key": "X-Langflow-Global-Var-SELECTED_EMBEDDING_MODEL",
+ "value": "SELECTED_EMBEDDING_MODEL"
},
{
- "category": "IBM WatsonX",
- "icon": "WatsonxAI",
- "metadata": {
- "api_key_param": "apikey",
- "context_length": 128000,
- "max_tokens_field_name": "max_tokens",
- "model_class": "ChatWatsonx",
- "model_name_param": "model_id",
- "project_id_param": "project_id",
- "url_param": "url"
+ "__load_from_db_fields": {
+ "value": true
},
- "name": "meta-llama/llama-3-3-70b-instruct",
- "provider": "IBM WatsonX"
+ "key": "X-Langflow-Global-Var-SELECTED_EMBEDDING_MODEL_PROVIDER",
+ "value": "SELECTED_EMBEDDING_MODEL_PROVIDER"
},
{
- "category": "IBM WatsonX",
- "icon": "WatsonxAI",
- "metadata": {
- "api_key_param": "apikey",
- "context_length": 128000,
- "max_tokens_field_name": "max_tokens",
- "model_class": "ChatWatsonx",
- "model_name_param": "model_id",
- "project_id_param": "project_id",
- "url_param": "url"
+ "__load_from_db_fields": {
+ "value": true
},
- "name": "meta-llama/llama-4-maverick-17b-128e-instruct-fp8",
- "provider": "IBM WatsonX"
+ "key": "X-Langflow-Global-Var-OPENRAG_LLM_BASE_URL",
+ "value": "OPENRAG_LLM_BASE_URL"
},
{
- "icon": "OpenAI",
- "metadata": {
- "api_key_param": "api_key",
- "context_length": 128000,
- "max_tokens_field_name": "max_tokens",
- "model_class": "ChatOpenAI",
- "model_name_param": "model",
- "not_enabled_locally": true,
- "reasoning": true,
- "reasoning_models": [
- "gpt-5.4-mini"
- ]
+ "__load_from_db_fields": {
+ "value": true
},
- "name": "gpt-5.4-mini",
- "provider": "OpenAI"
+ "key": "X-Langflow-Global-Var-OPENRAG_LLM_TOKEN",
+ "value": "OPENRAG_LLM_TOKEN"
}
+ ]
+ },
+ "is_refresh": false,
+ "mcp_server": {
+ "_input_type": "McpInput",
+ "advanced": false,
+ "display_name": "MCP Server",
+ "dynamic": false,
+ "info": "Select the MCP Server that will be used by this component",
+ "load_from_db": false,
+ "name": "mcp_server",
+ "override_skip": false,
+ "placeholder": "",
+ "real_time_refresh": true,
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "trace_as_metadata": true,
+ "track_in_telemetry": false,
+ "type": "mcp",
+ "value": {
+ "config": {},
+ "name": "lf-starter_project"
+ }
+ },
+ "tool": {
+ "_input_type": "DropdownInput",
+ "advanced": false,
+ "combobox": false,
+ "dialog_inputs": {},
+ "display_name": "Tool",
+ "dynamic": false,
+ "external_options": {},
+ "info": "Select the tool to execute",
+ "name": "tool",
+ "options": [
+ "opensearch_url_ingestion_flow"
],
+ "options_metadata": [],
"override_skip": false,
- "placeholder": "Setup Provider",
+ "placeholder": "",
"real_time_refresh": true,
"refresh_button": true,
"required": true,
- "show": true,
+ "show": false,
"title_case": false,
+ "toggle": false,
"tool_mode": false,
+ "trace_as_metadata": true,
+ "track_in_telemetry": true,
+ "type": "str",
+ "value": ""
+ },
+ "tool_placeholder": {
+ "_input_type": "MessageTextInput",
+ "advanced": false,
+ "display_name": "Tool Placeholder",
+ "dynamic": false,
+ "info": "Placeholder for the tool",
+ "input_types": [
+ "Message"
+ ],
+ "list": false,
+ "list_add_label": "Add More",
+ "load_from_db": false,
+ "name": "tool_placeholder",
+ "override_skip": false,
+ "placeholder": "",
+ "required": false,
+ "show": false,
+ "title_case": false,
+ "tool_mode": true,
"trace_as_input": true,
+ "trace_as_metadata": true,
"track_in_telemetry": false,
- "type": "model",
+ "type": "str",
+ "value": ""
+ },
+ "tools_metadata": {
+ "_input_type": "ToolsInput",
+ "advanced": false,
+ "api_editable": false,
+ "display_name": "Actions",
+ "dynamic": false,
+ "info": "Modify tool names and descriptions to help agents understand when to use each tool.",
+ "is_list": true,
+ "list_add_label": "Add More",
+ "name": "tools_metadata",
+ "override_skip": false,
+ "placeholder": "",
+ "real_time_refresh": true,
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "tool_mode": false,
+ "trace_as_metadata": true,
+ "track_in_telemetry": false,
+ "type": "tools",
"value": [
{
- "icon": "OpenAI",
- "metadata": {
- "api_key_param": "api_key",
- "context_length": 128000,
- "max_tokens_field_name": "max_tokens",
- "model_class": "ChatOpenAI",
- "model_name_param": "model",
- "reasoning": true,
- "reasoning_models": [
- "gpt-5.4-mini"
- ]
+ "approval_actions": [],
+ "args": {
+ "input_value": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Message to be passed as input.",
+ "title": "Input Value"
+ },
+ "session_id": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Optional session identifier used to persist conversation history across tool calls. Omit to start a new session.",
+ "title": "Session Id"
+ }
},
- "name": "gpt-5.4-mini",
- "provider": "OpenAI"
+ "description": "This flow is to ingest the URL to open search.",
+ "display_description": "This flow is to ingest the URL to open search.",
+ "display_name": "opensearch_url_ingestion_flow",
+ "name": "opensearch_url_ingestion_flow",
+ "readonly": false,
+ "status": true,
+ "tags": [
+ "opensearch_url_ingestion_flow"
+ ]
}
]
},
- "model_name": {
- "_input_type": "StrInput",
- "advanced": false,
- "api_editable": false,
- "display_name": "Model Name Override",
+ "use_cache": {
+ "_input_type": "BoolInput",
+ "advanced": true,
+ "display_name": "Use Cached Server",
"dynamic": false,
- "info": "Optional model name to use instead of the selected model. Can be set from a global variable for runtime model selection.",
+ "info": "Enable caching of MCP Server and tools to improve performance. Disable to always fetch fresh tools and server updates.",
"list": false,
"list_add_label": "Add More",
- "load_from_db": true,
- "name": "model_name",
+ "name": "use_cache",
"override_skip": false,
"placeholder": "",
"required": false,
@@ -3775,87 +2565,163 @@
"title_case": false,
"tool_mode": false,
"trace_as_metadata": true,
- "track_in_telemetry": false,
- "type": "str",
- "value": "SELECTED_LANGUAGE_MODEL"
+ "track_in_telemetry": true,
+ "type": "bool",
+ "value": false
},
- "ollama_base_url": {
- "_input_type": "StrInput",
- "advanced": false,
- "api_editable": false,
- "display_name": "Ollama API URL",
+ "verify_ssl": {
+ "_input_type": "BoolInput",
+ "advanced": true,
+ "display_name": "Verify SSL Certificate",
"dynamic": false,
- "info": "Endpoint of the Ollama API (Ollama only)",
+ "info": "Enable SSL certificate verification for HTTPS connections. Disable only for development/testing with self-signed certificates.",
"list": false,
"list_add_label": "Add More",
- "load_from_db": false,
- "name": "ollama_base_url",
+ "name": "verify_ssl",
"override_skip": false,
"placeholder": "",
- "real_time_refresh": true,
"required": false,
- "show": false,
+ "show": true,
"title_case": false,
"tool_mode": false,
"trace_as_metadata": true,
- "track_in_telemetry": false,
- "type": "str",
- "value": "http://localhost:11434"
+ "track_in_telemetry": true,
+ "type": "bool",
+ "value": true
+ }
+ },
+ "tool_mode": true
+ },
+ "showNode": false,
+ "type": "MCPTools"
+ },
+ "dragging": false,
+ "id": "MCPTools-uu7m3",
+ "measured": {
+ "height": 52,
+ "width": 192
+ },
+ "position": {
+ "x": 1349.4716085842726,
+ "y": 1384.8440085751042
+ },
+ "selected": true,
+ "type": "genericNode"
+ },
+ {
+ "data": {
+ "id": "OpenAICompatibleEmbedding-ix4WD",
+ "node": {
+ "base_classes": [
+ "Embeddings"
+ ],
+ "beta": false,
+ "conditional_paths": [],
+ "custom_fields": {},
+ "description": "Embeddings via OpenRAG's OpenAI-compatible /v1 proxy. Uses the same base URL and hop token as the chat component.",
+ "display_name": "OpenRAG Embeddings",
+ "documentation": "",
+ "edited": false,
+ "field_order": [
+ "model_name",
+ "api_key",
+ "api_base",
+ "dimensions",
+ "chunk_size"
+ ],
+ "frozen": false,
+ "icon": "OpenRAG",
+ "legacy": false,
+ "metadata": {
+ "code_hash": "cc257e587747",
+ "dependencies": {
+ "dependencies": [
+ {
+ "name": "langchain_openai",
+ "version": "1.5.2"
+ },
+ {
+ "name": "lfx",
+ "version": "1.11.2"
+ }
+ ],
+ "total_dependencies": 2
},
- "project_id": {
+ "module": "custom_components.openrag_embeddings"
+ },
+ "minimized": false,
+ "output_types": [],
+ "outputs": [
+ {
+ "allows_loop": false,
+ "cache": true,
+ "display_name": "Embedding Model",
+ "group_outputs": false,
+ "method": "build_embeddings",
+ "name": "embeddings",
+ "selected": "Embeddings",
+ "tool_mode": true,
+ "types": [
+ "Embeddings"
+ ],
+ "value": "__UNDEFINED__"
+ }
+ ],
+ "pinned": false,
+ "template": {
+ "_type": "Component",
+ "api_base": {
"_input_type": "StrInput",
"advanced": false,
"api_editable": false,
- "display_name": "watsonx Project ID",
+ "display_name": "OpenAI API Base",
"dynamic": false,
- "info": "The project ID associated with the foundation model (IBM watsonx.ai only)",
+ "info": "Must end with /v1 (for example http://openrag-backend:8000/v1). Bound to OPENRAG_LLM_BASE_URL at runtime. Same URL as chat.",
"list": false,
"list_add_label": "Add More",
- "load_from_db": false,
- "name": "project_id",
+ "load_from_db": true,
+ "name": "api_base",
"override_skip": false,
"placeholder": "",
"required": false,
- "show": false,
+ "show": true,
"title_case": false,
"tool_mode": false,
"trace_as_metadata": true,
"track_in_telemetry": false,
"type": "str",
- "value": ""
+ "value": "OPENRAG_LLM_BASE_URL"
},
- "provider": {
- "_input_type": "StrInput",
+ "api_key": {
+ "_input_type": "SecretStrInput",
"advanced": false,
"api_editable": false,
- "display_name": "Provider Override",
+ "display_name": "OpenRAG LLM Token",
"dynamic": false,
- "info": "Optional provider to use with Model Name Override. Leave blank to use the selected model's provider.",
- "list": false,
- "list_add_label": "Add More",
+ "info": "Hop token from OPENRAG_LLM_TOKEN. Same token as the chat component.",
+ "input_types": [],
"load_from_db": true,
- "name": "provider",
+ "name": "api_key",
"override_skip": false,
+ "password": true,
"placeholder": "",
"required": false,
"show": true,
"title_case": false,
- "tool_mode": false,
- "trace_as_metadata": true,
"track_in_telemetry": false,
"type": "str",
- "value": "SELECTED_LANGUAGE_MODEL_PROVIDER"
+ "value": "OPENRAG_LLM_TOKEN"
},
- "stream": {
- "_input_type": "BoolInput",
+ "chunk_size": {
+ "_input_type": "IntInput",
"advanced": true,
"api_editable": false,
- "display_name": "Stream",
+ "display_name": "Chunk Size",
"dynamic": false,
- "info": "Whether to stream the response",
+ "info": "",
"list": false,
"list_add_label": "Add More",
- "name": "stream",
+ "name": "chunk_size",
"override_skip": false,
"placeholder": "",
"required": false,
@@ -3864,104 +2730,105 @@
"tool_mode": false,
"trace_as_metadata": true,
"track_in_telemetry": true,
- "type": "bool",
- "value": false
+ "type": "int",
+ "value": 1000
},
- "system_message": {
- "_input_type": "MultilineInput",
+ "code": {
"advanced": true,
- "ai_enabled": false,
"api_editable": false,
- "copy_field": false,
- "display_name": "System Message",
- "dynamic": false,
- "info": "A system message that helps set the behavior of the assistant",
- "input_types": [
- "Message"
- ],
+ "dynamic": true,
+ "fileTypes": [],
+ "file_path": "",
+ "info": "",
"list": false,
- "list_add_label": "Add More",
"load_from_db": false,
"multiline": true,
- "name": "system_message",
- "override_skip": false,
+ "name": "code",
"password": false,
"placeholder": "",
+ "required": true,
+ "show": true,
+ "title_case": false,
+ "type": "code",
+ "value": "\"\"\"OpenAI-compatible embeddings that talk to the OpenRAG `/v1` proxy.\n\nEmbeddings work the same way as chat: Langflow never holds upstream vendor\nkeys. At runtime OpenRAG injects:\n\n- ``OPENRAG_LLM_TOKEN`` — the same short-lived hop token as chat\n- ``OPENRAG_LLM_BASE_URL`` — the same ``http://<backend>/v1`` base URL\n- ``SELECTED_EMBEDDING_MODEL`` — configured embedding model id\n\n``OpenAIEmbeddings`` posts to ``{base_url}/embeddings``. The backend gateway\nroutes by the configured embedding provider (which can differ from the chat\nprovider).\n\"\"\"\n\nfrom __future__ import annotations\n\nfrom typing import Any\n\nfrom langchain_openai import OpenAIEmbeddings\nfrom lfx.base.embeddings.model import LCEmbeddingsModel\nfrom lfx.field_typing import Embeddings\nfrom lfx.io import IntInput, SecretStrInput, StrInput\n\n# Names must match src/api/settings/langflow_sync.py + src/utils/langflow_headers.py\nOPENRAG_LLM_BASE_URL_VAR = \"OPENRAG_LLM_BASE_URL\"\nOPENRAG_LLM_TOKEN_VAR = \"OPENRAG_LLM_TOKEN\"\nSELECTED_EMBEDDING_MODEL_VAR = \"SELECTED_EMBEDDING_MODEL\"\n\n\ndef _as_str(value: object) -> str | None:\n if value is None:\n return None\n getter = getattr(value, \"get_secret_value\", None)\n if callable(getter):\n value = getter()\n text = str(value).strip()\n return text or None\n\n\nclass OpenAICompatibleEmbeddingComponent(LCEmbeddingsModel):\n display_name = \"OpenRAG Embeddings\"\n description = (\n \"Embeddings via OpenRAG's OpenAI-compatible /v1 proxy. \"\n \"Uses the same base URL and hop token as the chat component.\"\n )\n icon = \"OpenRAG\"\n name = \"OpenAICompatibleEmbedding\"\n\n inputs = [\n StrInput(\n name=\"model_name\",\n display_name=\"Model Name\",\n info=\"Embedding model id. Bound to SELECTED_EMBEDDING_MODEL at runtime.\",\n value=SELECTED_EMBEDDING_MODEL_VAR,\n load_from_db=True,\n ),\n SecretStrInput(\n name=\"api_key\",\n display_name=\"OpenRAG LLM Token\",\n info=\"Hop token from OPENRAG_LLM_TOKEN. Same token as the chat component.\",\n value=OPENRAG_LLM_TOKEN_VAR,\n required=False,\n load_from_db=True,\n ),\n StrInput(\n name=\"api_base\",\n display_name=\"OpenAI API Base\",\n info=(\n \"Must end with /v1 (for example http://openrag-backend:8000/v1). \"\n \"Bound to OPENRAG_LLM_BASE_URL at runtime. Same URL as chat.\"\n ),\n value=OPENRAG_LLM_BASE_URL_VAR,\n load_from_db=True,\n ),\n IntInput(\n name=\"dimensions\",\n display_name=\"Dimensions\",\n info=\"Output dimensions when the embedding model supports it.\",\n advanced=True,\n ),\n IntInput(\n name=\"chunk_size\",\n display_name=\"Chunk Size\",\n advanced=True,\n value=1000,\n ),\n ]\n\n def build_embeddings(self) -> Embeddings:\n api_key = _as_str(self.api_key)\n api_base = _as_str(self.api_base)\n if api_base:\n api_base = api_base.rstrip(\"/\")\n\n kwargs: dict[str, Any] = {\n \"model\": self.model_name,\n # `OpenAIEmbeddings.deployment` defaults to the class-level default of\n # `model` — the literal \"text-embedding-ada-002\" — for every instance,\n # whatever model is actually configured. The OpenSearch component keys\n # its embedding lookup on `deployment` as well as `model`, so leaving\n # the default in place registers this object under ada-002 too, and a\n # 768-dim vector then gets aimed at a 1536-dim ada-002 vector field.\n # Only Azure reads this field, so pinning it to the real model is inert\n # at request time and keeps the component's identity honest.\n \"deployment\": self.model_name,\n \"api_key\": api_key,\n \"base_url\": api_base or None,\n # Skip tiktoken context checks so non-OpenAI model ids still work.\n \"check_embedding_ctx_length\": False,\n }\n chunk_size = getattr(self, \"chunk_size\", None)\n if chunk_size:\n kwargs[\"chunk_size\"] = chunk_size\n dimensions = getattr(self, \"dimensions\", None)\n if dimensions:\n kwargs[\"dimensions\"] = dimensions\n return OpenAIEmbeddings(**kwargs)\n"
+ },
+ "dimensions": {
+ "_input_type": "IntInput",
+ "advanced": true,
+ "api_editable": false,
+ "display_name": "Dimensions",
+ "dynamic": false,
+ "info": "Output dimensions when the embedding model supports it.",
+ "list": false,
+ "list_add_label": "Add More",
+ "name": "dimensions",
+ "override_skip": false,
+ "placeholder": "",
"required": false,
"show": true,
"title_case": false,
"tool_mode": false,
- "trace_as_input": true,
"trace_as_metadata": true,
- "track_in_telemetry": false,
- "type": "str",
- "value": ""
+ "track_in_telemetry": true,
+ "type": "int",
+ "value": 0
},
- "temperature": {
- "_input_type": "SliderInput",
- "advanced": true,
+ "model_name": {
+ "_input_type": "StrInput",
+ "advanced": false,
"api_editable": false,
- "display_name": "Temperature",
+ "display_name": "Model Name",
"dynamic": false,
- "info": "Controls randomness in responses",
- "max_label": "",
- "max_label_icon": "",
- "min_label": "",
- "min_label_icon": "",
- "name": "temperature",
+ "info": "Embedding model id. Bound to SELECTED_EMBEDDING_MODEL at runtime.",
+ "list": false,
+ "list_add_label": "Add More",
+ "load_from_db": true,
+ "name": "model_name",
"override_skip": false,
"placeholder": "",
- "range_spec": {
- "max": 1,
- "min": 0,
- "step": 0.01,
- "step_type": "float"
- },
"required": false,
"show": true,
- "slider_buttons": false,
- "slider_buttons_options": [],
- "slider_input": false,
"title_case": false,
"tool_mode": false,
+ "trace_as_metadata": true,
"track_in_telemetry": false,
- "type": "slider",
- "value": 0.1
+ "type": "str",
+ "value": "SELECTED_EMBEDDING_MODEL"
}
},
"tool_mode": false
},
- "selected_output": "model_output",
"showNode": false,
- "type": "LanguageModelComponent"
+ "type": "OpenAICompatibleEmbedding"
},
"dragging": false,
- "id": "LanguageModelComponent-MfLsT",
+ "id": "OpenAICompatibleEmbedding-ix4WD",
+ "measured": {
+ "height": 52,
+ "width": 192
+ },
"position": {
- "x": 1832.8173400251,
- "y": 1806.741236642841
+ "x": 564.5974527712519,
+ "y": 1726.63184778373
},
"selected": false,
"type": "genericNode"
},
{
"data": {
- "id": "ext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-Ji9kZ",
+ "id": "OpenSearchVectorStoreComponentMultimodalMultiEmbedding-3x7Ll",
"node": {
"base_classes": [
"JSON",
"VectorStore"
],
"beta": false,
- "bundle": "openrag",
"conditional_paths": [],
"custom_fields": {},
"description": "Store and search documents using OpenSearch with multi-model hybrid semantic and keyword search. To search use the tools search_documents and raw_search. Search documents takes a query for vector search, for example\n {search_query: \"components in openrag\"}",
"display_name": "OpenSearch (Multi-Model Multi-Embedding)",
"documentation": "",
"edited": false,
- "extension": "openrag",
- "extension_version": "0.0.0",
"field_order": [
"docs_metadata",
"opensearch_url",
@@ -3996,7 +2863,7 @@
],
"frozen": false,
"icon": "OpenSearch",
- "last_updated": "2026-08-05T16:18:15.206Z",
+ "last_updated": "2026-08-20T18:09:22.941Z",
"legacy": false,
"metadata": {
"code_hash": "6c375fdaa9e7",
@@ -4028,8 +2895,6 @@
"module": "_lfx_ext.extra.openrag.opensearch_multimodal"
},
"minimized": false,
- "name": "OpenSearchVectorStoreComponentMultimodalMultiEmbedding",
- "namespaced_id": "ext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra",
"output_types": [],
"outputs": [
{
@@ -4048,38 +2913,218 @@
"types": [
"Tool"
],
- "value": "__UNDEFINED__"
- }
- ],
- "pinned": false,
- "template": {
- "_frontend_node_flow_id": {
- "value": "1098eea1-6649-4e1d-aed1-b77249fb8dd0"
+ "value": "__UNDEFINED__"
+ }
+ ],
+ "pinned": false,
+ "template": {
+ "_frontend_node_flow_id": {
+ "value": "1098eea1-6649-4e1d-aed1-b77249fb8dd0"
+ },
+ "_frontend_node_folder_id": {
+ "value": "503f5216-7f2c-4998-9010-b1a0eafbd500"
+ },
+ "_type": "Component",
+ "auth_mode": {
+ "_input_type": "DropdownInput",
+ "advanced": false,
+ "api_editable": false,
+ "combobox": false,
+ "dialog_inputs": {},
+ "display_name": "Authentication Mode",
+ "dynamic": false,
+ "external_options": {},
+ "info": "Authentication method: 'basic' for username/password authentication, 'jwt' for JSON Web Token (Bearer) authentication, or 'openrag' to delegate writes to the OpenRAG backend ingest callback (no direct OpenSearch credentials required — only OPENRAG_* fields).",
+ "name": "auth_mode",
+ "options": [
+ "basic",
+ "jwt",
+ "openrag"
+ ],
+ "options_metadata": [],
+ "override_skip": false,
+ "placeholder": "",
+ "real_time_refresh": true,
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "toggle": false,
+ "tool_mode": false,
+ "trace_as_metadata": true,
+ "track_in_telemetry": true,
+ "type": "str",
+ "value": "jwt"
+ },
+ "bearer_prefix": {
+ "_input_type": "BoolInput",
+ "advanced": true,
+ "api_editable": false,
+ "display_name": "Prefix 'Bearer '",
+ "dynamic": false,
+ "info": "",
+ "list": false,
+ "list_add_label": "Add More",
+ "name": "bearer_prefix",
+ "override_skip": false,
+ "placeholder": "",
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "tool_mode": false,
+ "trace_as_metadata": true,
+ "track_in_telemetry": true,
+ "type": "bool",
+ "value": false
+ },
+ "code": {
+ "advanced": true,
+ "api_editable": false,
+ "dynamic": true,
+ "fileTypes": [],
+ "file_path": "",
+ "info": "",
+ "list": false,
+ "load_from_db": false,
+ "multiline": true,
+ "name": "code",
+ "password": false,
+ "placeholder": "",
+ "required": true,
+ "show": true,
+ "title_case": false,
+ "type": "code",
+ "value": "from __future__ import annotations\n\nimport copy\nimport json\nimport uuid\nfrom concurrent.futures import ThreadPoolExecutor, as_completed\nfrom typing import Any\n\nimport httpx\nfrom lfx.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store\nfrom lfx.base.vectorstores.vector_store_connection_decorator import vector_store_connection\nfrom lfx.io import (\n BoolInput,\n DropdownInput,\n HandleInput,\n IntInput,\n MultilineInput,\n Output,\n SecretStrInput,\n StrInput,\n TableInput,\n)\nfrom lfx.log import logger\nfrom lfx.schema.data import Data\nfrom lfx.schema.dataframe import Table\nfrom opensearchpy import OpenSearch, helpers\nfrom opensearchpy.exceptions import OpenSearchException, RequestError\n\nREQUEST_TIMEOUT = 60\nMAX_RETRIES = 5\n\n# watsonx.ai surfaces rate-limit state via these (mostly non-standard) response\n# headers. The IBM SDK acts on the x-requests-limit-* family directly; we log\n# them on a failed embedding call to aid plan/region tuning.\n_WATSONX_RATE_LIMIT_HEADERS = (\n \"x-requests-limit-rate\",\n \"x-requests-limit-remaining\",\n \"x-requests-limit-reset\",\n \"Retry-After\",\n)\n\n\ndef _log_watsonx_rate_limit_headers(error: Exception) -> None:\n \"\"\"Best-effort diagnostic: log watsonx rate-limit headers from a failed call.\n\n The watsonx SDK raises ``ApiRequestFailure``, which carries the originating\n httpx/requests ``Response`` as ``.response``. On a 429 exhaustion we surface\n the documented rate-limit headers so operators can tune throughput.\n \"\"\"\n try:\n response = getattr(error, \"response\", None)\n headers = getattr(response, \"headers\", None)\n if not headers:\n return\n status = getattr(response, \"status_code\", \"unknown\")\n observed = {h: headers.get(h) for h in _WATSONX_RATE_LIMIT_HEADERS if headers.get(h) is not None}\n if str(status) == \"429\" or observed:\n logger.warning(f\"watsonx rate-limit response (status={status}): {observed}\")\n except Exception as log_error: # never let diagnostics mask the real error\n logger.debug(f\"Could not extract watsonx rate-limit headers: {log_error}\")\n\n\ndef normalize_model_name(model_name: str) -> str:\n \"\"\"Normalize embedding model name for use as field suffix.\n\n Converts model names to valid OpenSearch field names by replacing\n special characters and ensuring alphanumeric format.\n\n Args:\n model_name: Original embedding model name (e.g., \"text-embedding-3-small\")\n\n Returns:\n Normalized field suffix (e.g., \"text_embedding_3_small\")\n \"\"\"\n normalized = model_name.lower()\n # Replace common separators with underscores\n normalized = normalized.replace(\"-\", \"_\").replace(\":\", \"_\").replace(\"/\", \"_\").replace(\".\", \"_\")\n # Remove any non-alphanumeric characters except underscores\n normalized = \"\".join(c if c.isalnum() or c == \"_\" else \"_\" for c in normalized)\n # Remove duplicate underscores\n while \"__\" in normalized:\n normalized = normalized.replace(\"__\", \"_\")\n return normalized.strip(\"_\")\n\n\ndef get_embedding_field_name(model_name: str) -> str:\n \"\"\"Get the dynamic embedding field name for a model.\n\n Args:\n model_name: Embedding model name\n\n Returns:\n Field name in format: chunk_embedding_{normalized_model_name}\n \"\"\"\n logger.info(f\"chunk_embedding_{normalize_model_name(model_name)}\")\n return f\"chunk_embedding_{normalize_model_name(model_name)}\"\n\n\nUNTRUSTED_CHUNK_FENCE_START = \"<<<UNTRUSTED_DOC_CHUNK>>>\"\nUNTRUSTED_CHUNK_FENCE_END = \"<<<END_UNTRUSTED_DOC_CHUNK>>>\"\n\n\ndef fence_untrusted_text(text: str) -> str:\n \"\"\"Wrap retrieved document text in delimiters marking it as untrusted data.\n\n Retrieved chunk text can contain attacker-controlled natural-language\n instructions (indirect prompt injection, VULN-13906). Fencing it lets the\n system prompt tell the LLM to treat anything between these markers as\n data only, never as instructions or tool directives.\n\n Any literal fence markers already present in `text` are escaped first, so\n a poisoned chunk can't embed a fake end-of-fence marker to break out of\n the untrusted section and have its continuation misread as trusted.\n \"\"\"\n if not text:\n return text\n escaped = text.replace(\n UNTRUSTED_CHUNK_FENCE_START, \"\\\\\" + UNTRUSTED_CHUNK_FENCE_START\n ).replace(UNTRUSTED_CHUNK_FENCE_END, \"\\\\\" + UNTRUSTED_CHUNK_FENCE_END)\n return f\"{UNTRUSTED_CHUNK_FENCE_START}\\n{escaped}\\n{UNTRUSTED_CHUNK_FENCE_END}\"\n\n\n@vector_store_connection\nclass OpenSearchVectorStoreComponentMultimodalMultiEmbedding(LCVectorStoreComponent):\n \"\"\"OpenSearch Vector Store Component with Multi-Model Hybrid Search Capabilities.\n\n This component provides vector storage and retrieval using OpenSearch, combining semantic\n similarity search (KNN) with keyword-based search for optimal results. It supports:\n - Multiple embedding models per index with dynamic field names\n - Automatic detection and querying of all available embedding models\n - Parallel embedding generation for multi-model search\n - Document ingestion with model tracking\n - Advanced filtering and aggregations\n - Flexible authentication options\n\n Features:\n - Multi-model vector storage with dynamic fields (chunk_embedding_{model_name})\n - Hybrid search combining multiple KNN queries (dis_max) + keyword matching\n - Auto-detection of available models in the index\n - Parallel query embedding generation for all detected models\n - Vector storage with configurable engines (jvector, nmslib, faiss, lucene)\n - Flexible authentication (Basic auth, JWT tokens)\n\n Model Name Resolution:\n - Priority: deployment > model > model_name attributes\n - This ensures correct matching between embedding objects and index fields\n - When multiple embeddings are provided, specify embedding_model_name to select which one to use\n - During search, each detected model in the index is matched to its corresponding embedding object\n \"\"\"\n\n display_name: str = \"OpenSearch (Multi-Model Multi-Embedding)\"\n icon: str = \"OpenSearch\"\n description: str = (\n \"Store and search documents using OpenSearch with multi-model hybrid semantic and keyword search. \"\n \"To search use the tools search_documents and raw_search. \"\n \"Search documents takes a query for vector search, for example\\n\"\n ' {search_query: \"components in openrag\"}'\n )\n\n # Keys we consider baseline\n default_keys: list[str] = [\n \"opensearch_url\",\n \"index_name\",\n *[i.name for i in LCVectorStoreComponent.inputs], # search_query, add_documents, etc.\n \"embedding\",\n \"embedding_model_name\",\n \"vector_field\",\n \"number_of_results\",\n \"auth_mode\",\n \"username\",\n \"password\",\n \"jwt_token\",\n \"jwt_header\",\n \"bearer_prefix\",\n \"use_ssl\",\n \"verify_certs\",\n \"filter_expression\",\n \"engine\",\n \"space_type\",\n \"ef_construction\",\n \"m\",\n \"num_candidates\",\n \"docs_metadata\",\n \"request_timeout\",\n \"max_retries\",\n \"openrag_ingest_url\",\n \"openrag_ingest_token\",\n \"openrag_ingest_run_id\",\n \"openrag_ingest_batch_size\",\n ]\n _openrag_ingest_global_placeholders = {\n \"openrag_ingest_url\": \"OPENRAG_INGEST_URL\",\n \"openrag_ingest_token\": \"OPENRAG_INGEST_TOKEN\",\n \"openrag_ingest_run_id\": \"OPENRAG_INGEST_RUN_ID\",\n }\n\n inputs = [\n TableInput(\n name=\"docs_metadata\",\n display_name=\"Document Metadata\",\n info=(\n \"Additional metadata key-value pairs to be added to all ingested documents. \"\n \"Useful for tagging documents with source information, categories, or other custom attributes.\"\n ),\n table_schema=[\n {\n \"name\": \"key\",\n \"display_name\": \"Key\",\n \"type\": \"str\",\n \"description\": \"Key name\",\n },\n {\n \"name\": \"value\",\n \"display_name\": \"Value\",\n \"type\": \"str\",\n \"description\": \"Value of the metadata\",\n },\n ],\n value=[],\n input_types=[\"Data\", \"JSON\"],\n ),\n StrInput(\n name=\"opensearch_url\",\n display_name=\"OpenSearch URL\",\n value=\"http://localhost:9200\",\n info=(\n \"The connection URL for your OpenSearch cluster \"\n \"(e.g., http://localhost:9200 for local development or your cloud endpoint).\"\n ),\n ),\n StrInput(\n name=\"index_name\",\n display_name=\"Index Name\",\n value=\"langflow\",\n info=(\n \"The OpenSearch index name where documents will be stored and searched. \"\n \"Will be created automatically if it doesn't exist.\"\n ),\n ),\n DropdownInput(\n name=\"engine\",\n display_name=\"Vector Engine\",\n options=[\"nmslib\", \"faiss\", \"lucene\", \"jvector\"],\n value=\"jvector\",\n info=(\n \"Vector search engine for similarity calculations. 'nmslib' works with standard \"\n \"OpenSearch. 'jvector' requires OpenSearch 2.9+. 'lucene' requires index.knn: true. \"\n \"Amazon OpenSearch Serverless only supports 'nmslib' or 'faiss'.\"\n ),\n advanced=True,\n ),\n DropdownInput(\n name=\"space_type\",\n display_name=\"Distance Metric\",\n options=[\"l2\", \"l1\", \"cosinesimil\", \"linf\", \"innerproduct\"],\n value=\"l2\",\n info=(\n \"Distance metric for calculating vector similarity. 'l2' (Euclidean) is most common, \"\n \"'cosinesimil' for cosine similarity, 'innerproduct' for dot product.\"\n ),\n advanced=True,\n ),\n IntInput(\n name=\"ef_construction\",\n display_name=\"EF Construction\",\n value=512,\n info=(\n \"Size of the dynamic candidate list during index construction. \"\n \"Higher values improve recall but increase indexing time and memory usage.\"\n ),\n advanced=True,\n ),\n IntInput(\n name=\"m\",\n display_name=\"M Parameter\",\n value=16,\n info=(\n \"Number of bidirectional connections for each vector in the HNSW graph. \"\n \"Higher values improve search quality but increase memory usage and indexing time.\"\n ),\n advanced=True,\n ),\n IntInput(\n name=\"num_candidates\",\n display_name=\"Candidate Pool Size\",\n value=1000,\n info=(\n \"Number of approximate neighbors to consider for each KNN query. \"\n \"Some OpenSearch deployments do not support this parameter; set to 0 to disable.\"\n ),\n advanced=True,\n ),\n *LCVectorStoreComponent.inputs, # includes search_query, add_documents, etc.\n HandleInput(\n name=\"embedding\", display_name=\"Embedding\", input_types=[\"Embeddings\"], is_list=True\n ),\n StrInput(\n name=\"embedding_model_name\",\n display_name=\"Embedding Model Name\",\n value=\"\",\n info=(\n \"Name of the embedding model to use for ingestion. This selects which embedding from the list \"\n \"will be used to embed documents. Matches on deployment, model, model_id, or model_name. \"\n \"For duplicate deployments, use combined format: 'deployment:model' \"\n \"(e.g., 'text-embedding-ada-002:text-embedding-3-large'). \"\n \"Leave empty to use the first embedding. Error message will show all available identifiers.\"\n ),\n advanced=False,\n ),\n StrInput(\n name=\"vector_field\",\n display_name=\"Legacy Vector Field Name\",\n value=\"chunk_embedding\",\n advanced=True,\n info=(\n \"Legacy field name for backward compatibility. New documents use dynamic fields \"\n \"(chunk_embedding_{model_name}) based on the embedding_model_name.\"\n ),\n ),\n IntInput(\n name=\"number_of_results\",\n display_name=\"Default Result Limit\",\n value=10,\n advanced=True,\n info=(\n \"Default maximum number of search results to return when no limit is \"\n \"specified in the filter expression.\"\n ),\n ),\n MultilineInput(\n name=\"filter_expression\",\n display_name=\"Search Filters (JSON)\",\n value=\"\",\n info=(\n \"Optional JSON configuration for search filtering, result limits, and score thresholds.\\n\\n\"\n \"Format 1 - Explicit filters:\\n\"\n '{\"filter\": [{\"term\": {\"filename\":\"doc.pdf\"}}, '\n '{\"terms\":{\"owner\":[\"user1\",\"user2\"]}}], \"limit\": 10, \"score_threshold\": 1.6}\\n\\n'\n \"Format 2 - Context-style mapping:\\n\"\n '{\"data_sources\":[\"file.pdf\"], \"document_types\":[\"application/pdf\"], \"owners\":[\"user123\"]}\\n\\n'\n \"Use __IMPOSSIBLE_VALUE__ as placeholder to ignore specific filters.\"\n ),\n ),\n # ----- Auth controls (dynamic) -----\n DropdownInput(\n name=\"auth_mode\",\n display_name=\"Authentication Mode\",\n value=\"openrag\",\n options=[\"basic\", \"jwt\", \"openrag\"],\n info=(\n \"Authentication method: 'basic' for username/password authentication, \"\n \"'jwt' for JSON Web Token (Bearer) authentication, or 'openrag' to \"\n \"delegate writes to the OpenRAG backend ingest callback (no direct \"\n \"OpenSearch credentials required — only OPENRAG_* fields).\"\n ),\n real_time_refresh=True,\n advanced=False,\n ),\n StrInput(\n name=\"username\",\n display_name=\"Username\",\n value=\"admin\",\n show=True,\n ),\n SecretStrInput(\n name=\"password\",\n display_name=\"OpenSearch Password\",\n value=\"OPENSEARCH_PASSWORD\",\n load_from_db=True,\n show=True,\n ),\n SecretStrInput(\n name=\"jwt_token\",\n display_name=\"JWT Token\",\n value=\"JWT\",\n load_from_db=False,\n show=False,\n info=(\n \"Valid JSON Web Token for authentication. \"\n \"Will be sent in the Authorization header (with optional 'Bearer ' prefix).\"\n ),\n required=False\n ),\n StrInput(\n name=\"jwt_header\",\n display_name=\"JWT Header Name\",\n value=\"Authorization\",\n show=False,\n advanced=True,\n ),\n BoolInput(\n name=\"bearer_prefix\",\n display_name=\"Prefix 'Bearer '\",\n value=False,\n show=False,\n advanced=True,\n ),\n # ----- TLS -----\n BoolInput(\n name=\"use_ssl\",\n display_name=\"Use SSL/TLS\",\n value=True,\n advanced=True,\n info=\"Enable SSL/TLS encryption for secure connections to OpenSearch.\",\n ),\n BoolInput(\n name=\"verify_certs\",\n display_name=\"Verify SSL Certificates\",\n value=False,\n advanced=True,\n info=(\n \"Verify SSL certificates when connecting. \"\n \"Disable for self-signed certificates in development environments.\"\n ),\n ),\n # ----- Timeout / Retry -----\n StrInput(\n name=\"request_timeout\",\n display_name=\"Request Timeout (seconds)\",\n value=\"60\",\n advanced=True,\n info=(\n \"Time in seconds to wait for a response from OpenSearch. \"\n \"Increase for large bulk ingestion or complex hybrid queries.\"\n ),\n ),\n StrInput(\n name=\"max_retries\",\n display_name=\"Max Retries\",\n value=\"3\",\n advanced=True,\n info=\"Number of retries for failed connections before raising an error.\",\n ),\n StrInput(\n name=\"openrag_ingest_url\",\n display_name=\"OpenRAG Ingest URL\",\n value=\"OPENRAG_INGEST_URL\",\n load_from_db=True,\n input_types=[\"Text\", \"Message\"],\n advanced=True,\n info=\"Internal OpenRAG callback URL for backend-owned document indexing.\",\n ),\n SecretStrInput(\n name=\"openrag_ingest_token\",\n display_name=\"OpenRAG Ingest Token\",\n value=\"OPENRAG_INGEST_TOKEN\",\n load_from_db=True,\n input_types=[\"Text\", \"Message\"],\n advanced=True,\n info=\"Short-lived token used only for OpenRAG ingest callbacks.\",\n ),\n StrInput(\n name=\"openrag_ingest_run_id\",\n display_name=\"OpenRAG Ingest Run ID\",\n value=\"OPENRAG_INGEST_RUN_ID\",\n load_from_db=True,\n input_types=[\"Text\", \"Message\"],\n advanced=True,\n ),\n IntInput(\n name=\"openrag_ingest_batch_size\",\n display_name=\"OpenRAG Ingest Batch Size\",\n value=100,\n advanced=True,\n ),\n ]\n outputs = [\n Output(\n display_name=\"Search Results\",\n name=\"search_results\",\n method=\"search_documents\",\n ),\n Output(display_name=\"Raw Search\", name=\"raw_search\", method=\"raw_search\"),\n ]\n\n def raw_search(self, query: str | dict | None = None) -> Data:\n \"\"\"Execute a raw OpenSearch query against the target index.\n\n Args:\n query (dict[str, Any]): The OpenSearch query DSL dictionary.\n\n Returns:\n Data: Search results as a Data object.\n\n Raises:\n ValueError: If 'query' is not a valid OpenSearch query (must be a non-empty dict).\n \"\"\"\n raw_query = query if query is not None else self.search_query\n\n if raw_query is None or (isinstance(raw_query, str) and not raw_query.strip()):\n self.log(\"No query provided for raw search - returning empty results\")\n return Data(data={})\n\n if isinstance(raw_query, dict):\n query_body = copy.deepcopy(raw_query)\n elif isinstance(raw_query, str):\n s = raw_query.strip()\n\n # First, optimistically try to parse as JSON DSL\n try:\n query_body = json.loads(s)\n except json.JSONDecodeError:\n # Fallback: treat as a basic text query over common fields\n query_body = {\n \"query\": {\n \"multi_match\": {\n \"query\": s,\n \"fields\": [\"text^2\", \"filename^1.5\"],\n \"type\": \"best_fields\",\n \"fuzziness\": \"AUTO\",\n }\n }\n }\n else:\n msg = f\"Unsupported raw_search query type: {type(raw_query)!r}\"\n raise TypeError(msg)\n\n filter_obj = self._parse_filter_expression()\n filter_clauses = self._coerce_filter_clauses(filter_obj)\n\n if filter_clauses:\n if \"query\" in query_body:\n original_query = query_body[\"query\"]\n query_body[\"query\"] = {\n \"bool\": {\n \"must\": [original_query],\n \"filter\": filter_clauses,\n }\n }\n else:\n query_body[\"query\"] = {\n \"bool\": {\n \"must\": [{\"match_all\": {}}],\n \"filter\": filter_clauses,\n }\n }\n\n if filter_obj:\n # Apply limit if not already set in the raw query\n if \"size\" not in query_body:\n limit = self._resolve_limit(filter_obj, default_limit=None)\n if limit is not None:\n query_body[\"size\"] = limit\n\n # Apply score_threshold / scoreThreshold as min_score if not already set\n if \"min_score\" not in query_body:\n\n score_threshold = self._resolve_score_threshold(filter_obj)\n if score_threshold is not None:\n\n query_body[\"min_score\"] = score_threshold\n\n client = self.build_client()\n logger.info(f\"query: {query_body}\")\n resp = client.search(\n index=self.index_name,\n body=query_body,\n params={\"terminate_after\": 0},\n )\n # Remove any _source keys whose value is a list of floats (embedding vectors)\n # Minimum length threshold to identify embedding vectors\n min_vector_length = 100\n\n def is_vector(val):\n # Accepts if it's a list of numbers (float or int) and has reasonable vector length\n return (\n isinstance(val, list)\n and len(val) > min_vector_length\n and all(isinstance(x, (float, int)) for x in val)\n )\n\n if \"hits\" in resp and \"hits\" in resp[\"hits\"]:\n for hit in resp[\"hits\"][\"hits\"]:\n source = hit.get(\"_source\")\n if isinstance(source, dict):\n keys_to_remove = [k for k, v in source.items() if is_vector(v)]\n for k in keys_to_remove:\n source.pop(k)\n if \"text\" in source:\n source[\"text\"] = fence_untrusted_text(source[\"text\"])\n logger.info(f\"Raw search response (all embedding vectors removed): {resp}\")\n return Data(**resp)\n\n def _get_embedding_model_name(self, embedding_obj=None) -> str:\n \"\"\"Get the embedding model name from component config or embedding object.\n\n Priority: deployment > model > model_id > model_name\n This ensures we use the actual model being deployed, not just the configured model.\n Supports multiple embedding providers (OpenAI, Watsonx, Cohere, etc.)\n\n Args:\n embedding_obj: Specific embedding object to get name from (optional)\n\n Returns:\n Embedding model name\n\n Raises:\n ValueError: If embedding model name cannot be determined\n \"\"\"\n # First try explicit embedding_model_name input\n if hasattr(self, \"embedding_model_name\") and self.embedding_model_name:\n return self.embedding_model_name.strip()\n\n # Try to get from provided embedding object\n if embedding_obj:\n # Priority: deployment > model > model_id > model_name\n if hasattr(embedding_obj, \"deployment\") and embedding_obj.deployment:\n return str(embedding_obj.deployment)\n if hasattr(embedding_obj, \"model\") and embedding_obj.model:\n return str(embedding_obj.model)\n if hasattr(embedding_obj, \"model_id\") and embedding_obj.model_id:\n return str(embedding_obj.model_id)\n if hasattr(embedding_obj, \"model_name\") and embedding_obj.model_name:\n return str(embedding_obj.model_name)\n\n # Try to get from embedding component (legacy single embedding)\n if hasattr(self, \"embedding\") and self.embedding:\n # Handle list of embeddings\n if isinstance(self.embedding, list) and len(self.embedding) > 0:\n first_emb = self.embedding[0]\n if hasattr(first_emb, \"deployment\") and first_emb.deployment:\n return str(first_emb.deployment)\n if hasattr(first_emb, \"model\") and first_emb.model:\n return str(first_emb.model)\n if hasattr(first_emb, \"model_id\") and first_emb.model_id:\n return str(first_emb.model_id)\n if hasattr(first_emb, \"model_name\") and first_emb.model_name:\n return str(first_emb.model_name)\n # Handle single embedding\n elif not isinstance(self.embedding, list):\n if hasattr(self.embedding, \"deployment\") and self.embedding.deployment:\n return str(self.embedding.deployment)\n if hasattr(self.embedding, \"model\") and self.embedding.model:\n return str(self.embedding.model)\n if hasattr(self.embedding, \"model_id\") and self.embedding.model_id:\n return str(self.embedding.model_id)\n if hasattr(self.embedding, \"model_name\") and self.embedding.model_name:\n return str(self.embedding.model_name)\n\n msg = (\n \"Could not determine embedding model name. \"\n \"Please set the 'embedding_model_name' field or ensure the embedding component \"\n \"has a 'deployment', 'model', 'model_id', or 'model_name' attribute.\"\n )\n raise ValueError(msg)\n\n # ---------- helper functions for index management ----------\n def _default_text_mapping(\n self,\n dim: int,\n engine: str = \"jvector\",\n space_type: str = \"l2\",\n ef_search: int = 512,\n ef_construction: int = 100,\n m: int = 16,\n vector_field: str = \"vector_field\",\n ) -> dict[str, Any]:\n \"\"\"Create the default OpenSearch index mapping for vector search.\n\n This method generates the index configuration with k-NN settings optimized\n for approximate nearest neighbor search using the specified vector engine.\n Includes the embedding_model keyword field for tracking which model was used.\n\n Args:\n dim: Dimensionality of the vector embeddings\n engine: Vector search engine (jvector, nmslib, faiss, lucene)\n space_type: Distance metric for similarity calculation\n ef_search: Size of dynamic list used during search\n ef_construction: Size of dynamic list used during index construction\n m: Number of bidirectional links for each vector\n vector_field: Name of the field storing vector embeddings\n\n Returns:\n Dictionary containing OpenSearch index mapping configuration\n \"\"\"\n return {\n \"settings\": {\"index\": {\"knn\": True, \"knn.algo_param.ef_search\": ef_search}},\n \"mappings\": {\n \"properties\": {\n vector_field: {\n \"type\": \"knn_vector\",\n \"dimension\": dim,\n \"method\": {\n \"name\": \"disk_ann\",\n \"space_type\": space_type,\n \"engine\": engine,\n \"parameters\": {\"ef_construction\": ef_construction, \"m\": m},\n },\n },\n \"embedding_model\": {\"type\": \"keyword\"}, # Track which model was used\n \"embedding_dimensions\": {\"type\": \"integer\"},\n }\n },\n }\n\n def _ensure_embedding_field_mapping(\n self,\n client: OpenSearch,\n index_name: str,\n field_name: str,\n dim: int,\n engine: str,\n space_type: str,\n ef_construction: int,\n m: int,\n ) -> None:\n \"\"\"Lazily add a dynamic embedding field to the index if it doesn't exist.\n\n This allows adding new embedding models without recreating the entire index.\n Also ensures the embedding_model tracking field exists.\n\n Note: Some OpenSearch versions/configurations have issues with dynamically adding\n knn_vector mappings (NullPointerException). This method checks if the field\n already exists before attempting to add it, and gracefully skips if the field\n is already properly configured.\n\n Args:\n client: OpenSearch client instance\n index_name: Target index name\n field_name: Dynamic field name for this embedding model\n dim: Vector dimensionality\n engine: Vector search engine\n space_type: Distance metric\n ef_construction: Construction parameter\n m: HNSW parameter\n \"\"\"\n # First, check if the field already exists and is properly mapped\n properties = self._get_index_properties(client)\n if self._is_knn_vector_field(properties, field_name):\n # Field already exists as knn_vector - verify dimensions match\n existing_dim = self._get_field_dimension(properties, field_name)\n if existing_dim is not None and existing_dim != dim:\n logger.warning(\n f\"Field '{field_name}' exists with dimension {existing_dim}, \"\n f\"but current embedding has dimension {dim}. Using existing mapping.\"\n )\n else:\n logger.info(\n f\"[OpenSearchMultimodel] Field '{field_name}' already exists\"\n f\"as knn_vector with matching dimensions - skipping mapping update\"\n )\n return\n\n # Field doesn't exist, try to add the mapping\n try:\n mapping = {\n \"properties\": {\n field_name: {\n \"type\": \"knn_vector\",\n \"dimension\": dim,\n \"method\": {\n \"name\": \"disk_ann\",\n \"space_type\": space_type,\n \"engine\": engine,\n \"parameters\": {\"ef_construction\": ef_construction, \"m\": m},\n },\n },\n # Also ensure the embedding_model tracking field exists as keyword\n \"embedding_model\": {\"type\": \"keyword\"},\n \"embedding_dimensions\": {\"type\": \"integer\"},\n }\n }\n client.indices.put_mapping(index=index_name, body=mapping)\n logger.info(f\"Added/updated embedding field mapping: {field_name}\")\n except RequestError as e:\n error_str = str(e).lower()\n if \"invalid engine\" in error_str and \"jvector\" in error_str:\n msg = (\n \"The 'jvector' engine is not available in your OpenSearch installation. \"\n \"Use 'nmslib' or 'faiss' for standard OpenSearch, or upgrade to OpenSearch 2.9+.\"\n )\n raise ValueError(msg) from e\n if \"index.knn\" in error_str:\n msg = (\n \"The index has index.knn: false. Delete the existing index and let the \"\n \"component recreate it, or create a new index with a different name.\"\n )\n raise ValueError(msg) from e\n raise\n except Exception as e:\n # Check if this is the known OpenSearch k-NN NullPointerException issue\n error_str = str(e).lower()\n if \"null\" in error_str or \"nullpointerexception\" in error_str:\n logger.warning(\n f\"[OpenSearchMultimodel] Could not add embedding field mapping for {field_name}\"\n f\"due to OpenSearch k-NN plugin issue: {e}. \"\n f\"This is a known issue with some OpenSearch versions. \"\n f\"[OpenSearchMultimodel] Skipping mapping update. \"\n f\"Please ensure the index has the correct mapping for KNN search to work.\"\n )\n # Skip and continue - ingestion will proceed, but KNN search may fail if mapping doesn't exist\n return\n logger.warning(\n f\"[OpenSearchMultimodel] Could not add embedding field mapping for {field_name}: {e}\"\n )\n raise\n\n # Verify the field was added correctly\n properties = self._get_index_properties(client)\n if not self._is_knn_vector_field(properties, field_name):\n msg = f\"Field '{field_name}' is not mapped as knn_vector. Current mapping: {properties.get(field_name)}\"\n logger.error(msg)\n raise ValueError(msg)\n\n def _validate_aoss_with_engines(self, *, is_aoss: bool, engine: str) -> None:\n \"\"\"Validate engine compatibility with Amazon OpenSearch Serverless (AOSS).\n\n Amazon OpenSearch Serverless has restrictions on which vector engines\n can be used. This method ensures the selected engine is compatible.\n\n Args:\n is_aoss: Whether the connection is to Amazon OpenSearch Serverless\n engine: The selected vector search engine\n\n Raises:\n ValueError: If AOSS is used with an incompatible engine\n \"\"\"\n if is_aoss and engine not in {\"nmslib\", \"faiss\"}:\n msg = \"Amazon OpenSearch Service Serverless only supports `nmslib` or `faiss` engines\"\n raise ValueError(msg)\n\n def _is_aoss_enabled(self, http_auth: Any) -> bool:\n \"\"\"Determine if Amazon OpenSearch Serverless (AOSS) is being used.\n\n Args:\n http_auth: The HTTP authentication object\n\n Returns:\n True if AOSS is enabled, False otherwise\n \"\"\"\n return (\n http_auth is not None and hasattr(http_auth, \"service\") and http_auth.service == \"aoss\"\n )\n\n @staticmethod\n def _openrag_input_to_str(value: Any) -> str:\n if value is None:\n return \"\"\n if hasattr(value, \"get_secret_value\"):\n value = value.get_secret_value()\n if hasattr(value, \"text\"):\n value = value.text\n return str(value or \"\").strip()\n\n def _openrag_callback_value(self, attr_name: str) -> str:\n value = self._openrag_input_to_str(getattr(self, attr_name, \"\"))\n if value == self._openrag_ingest_global_placeholders.get(attr_name):\n return \"\"\n return value\n\n def _openrag_ingest_callback_config(self) -> tuple[str, str, str] | None:\n url = self._openrag_callback_value(\"openrag_ingest_url\")\n token = self._openrag_callback_value(\"openrag_ingest_token\")\n ingest_run_id = self._openrag_callback_value(\"openrag_ingest_run_id\")\n\n if not url and not token and not ingest_run_id:\n return None\n if not url or not token or not ingest_run_id:\n msg = \"OpenRAG ingest callback requires url, token, and ingest_run_id.\"\n raise ValueError(msg)\n\n logger.debug(\n \"[OpenRAG callback config] configured for ingest_run_id=%s (url_len=%d, token_len=%d)\",\n ingest_run_id,\n len(url),\n len(token),\n )\n return url, token, ingest_run_id\n\n def _post_openrag_ingest_batches(\n self,\n *,\n requests: list[dict],\n vector_field: str,\n text_field: str,\n ) -> None:\n callback_config = self._openrag_ingest_callback_config()\n if callback_config is None:\n return\n\n url, token, ingest_run_id = callback_config\n batch_size = max(self._parse_int_param(\"openrag_ingest_batch_size\", 100), 1)\n timeout = self._parse_int_param(\"request_timeout\", REQUEST_TIMEOUT)\n headers = {\"Authorization\": f\"Bearer {token}\"}\n\n logger.debug(\n f\"[OpenRAG ingest POST] total_chunks={len(requests)} batch_size={batch_size} timeout_s={timeout}\"\n )\n\n with httpx.Client(timeout=timeout) as client:\n total_batches = (len(requests) + batch_size - 1) // batch_size\n for batch_number, start in enumerate(range(0, len(requests), batch_size), start=1):\n batch = requests[start : start + batch_size]\n final = batch_number == total_batches\n payload = {\n \"ingest_run_id\": ingest_run_id,\n \"batch_id\": batch_number,\n \"final\": final,\n \"chunks\": [\n self._openrag_chunk_payload(\n request,\n vector_field=vector_field,\n text_field=text_field,\n )\n for request in batch\n ],\n }\n logger.debug(\n f\"[OpenRAG ingest POST] -> batch={batch_number}/{total_batches} \"\n f\"chunks={len(payload['chunks'])} final={final}\"\n )\n response = client.post(url, json=payload, headers=headers)\n logger.debug(f\"[OpenRAG ingest POST resp] batch={batch_number} status={response.status_code}\")\n if response.status_code >= 400:\n msg = (\n \"OpenRAG ingest callback failed \"\n f\"(batch={batch_number}, status={response.status_code})\"\n )\n logger.warning(msg)\n raise RuntimeError(msg)\n\n logger.debug(f\"Posted {len(requests)} chunks to OpenRAG backend ingest callback.\")\n\n @staticmethod\n def _openrag_chunk_payload(\n request: dict,\n *,\n vector_field: str,\n text_field: str,\n ) -> dict:\n metadata = {\n key: value\n for key, value in request.items()\n if key not in {\"_op_type\", \"_index\", \"_id\", \"id\", vector_field, text_field}\n }\n page = metadata.get(\"page\")\n if isinstance(page, str) and page.isdigit():\n page = int(page)\n return {\n \"id\": request.get(\"_id\") or request.get(\"id\"),\n \"text\": request.get(text_field, \"\"),\n \"vector\": request[vector_field],\n \"page\": page if isinstance(page, int) else None,\n \"metadata\": metadata,\n }\n\n def _bulk_ingest_embeddings(\n self,\n client: OpenSearch,\n index_name: str,\n embeddings: list[list[float]],\n texts: list[str],\n metadatas: list[dict] | None = None,\n ids: list[str] | None = None,\n vector_field: str = \"vector_field\",\n text_field: str = \"text\",\n embedding_model: str = \"unknown\",\n mapping: dict | None = None,\n max_chunk_bytes: int | None = 1 * 1024 * 1024,\n *,\n is_aoss: bool = False,\n ) -> list[str]:\n \"\"\"Efficiently ingest multiple documents with embeddings into OpenSearch.\n\n This method uses bulk operations to insert documents with their vector\n embeddings and metadata into the specified OpenSearch index. Each document\n is tagged with the embedding_model name for tracking.\n\n Args:\n client: OpenSearch client instance\n index_name: Target index for document storage\n embeddings: List of vector embeddings for each document\n texts: List of document texts\n metadatas: Optional metadata dictionaries for each document\n ids: Optional document IDs (UUIDs generated if not provided)\n vector_field: Field name for storing vector embeddings\n text_field: Field name for storing document text\n embedding_model: Name of the embedding model used\n mapping: Optional index mapping configuration\n max_chunk_bytes: Maximum size per bulk request chunk\n is_aoss: Whether using Amazon OpenSearch Serverless\n\n Returns:\n List of document IDs that were successfully ingested\n \"\"\"\n logger.debug(f\"[OpenSearchMultimodel] Bulk ingesting embeddings for {index_name}\")\n if not mapping:\n mapping = {}\n\n requests = []\n return_ids = []\n vector_dimensions = len(embeddings[0]) if embeddings else None\n\n for i, text in enumerate(texts):\n metadata = metadatas[i] if metadatas else {}\n if vector_dimensions is not None and \"embedding_dimensions\" not in metadata:\n metadata = {**metadata, \"embedding_dimensions\": vector_dimensions}\n\n # Normalize ACL fields that may arrive as JSON strings from flows\n for key in (\"allowed_users\", \"allowed_groups\", \"allowed_principals\"):\n value = metadata.get(key)\n if isinstance(value, str):\n try:\n parsed = json.loads(value)\n if isinstance(parsed, list):\n metadata[key] = parsed\n except (json.JSONDecodeError, TypeError):\n # Leave value as-is if it isn't valid JSON\n pass\n\n metadata_document_id = str(metadata.get(\"document_id\") or \"\").strip()\n if metadata_document_id and metadata_document_id.lower() != \"none\":\n generated_id = f\"{metadata_document_id}_{i}\"\n else:\n generated_id = str(uuid.uuid4())\n _id = ids[i] if ids else generated_id\n request = {\n \"_op_type\": \"index\",\n \"_index\": index_name,\n vector_field: embeddings[i],\n text_field: text,\n \"embedding_model\": embedding_model, # Track which model was used\n **metadata,\n }\n if is_aoss:\n request[\"id\"] = _id\n else:\n request[\"_id\"] = _id\n requests.append(request)\n return_ids.append(_id)\n if metadatas:\n self.log(f\"Sample metadata: {metadatas[0] if metadatas else {}}\")\n if self._openrag_ingest_callback_config() is not None:\n self._post_openrag_ingest_batches(\n requests=requests,\n vector_field=vector_field,\n text_field=text_field,\n )\n return return_ids\n try:\n helpers.bulk(client, requests, max_chunk_bytes=max_chunk_bytes)\n except Exception as bulk_error:\n if \"Unsupported request type for filter level DLS\" not in str(bulk_error):\n raise\n logger.warning(\n \"[OpenSearchMultimodel] Bulk ingest is blocked by filter-level DLS; \"\n \"falling back to per-document index requests.\"\n )\n self._index_embeddings_individually(client, requests)\n return return_ids\n\n def _index_embeddings_individually(\n self,\n client: OpenSearch,\n requests: list[dict],\n ) -> None:\n \"\"\"Index documents one at a time when OpenSearch DLS rejects bulk writes.\"\"\"\n for request in requests:\n document_id = request.get(\"_id\") or request.get(\"id\")\n body = {\n key: value\n for key, value in request.items()\n if key not in {\"_op_type\", \"_index\", \"_id\", \"id\"}\n }\n client.index(index=request[\"_index\"], id=document_id, body=body)\n\n def _log_index_admin_skip(self, operation: str, error: Exception) -> None:\n \"\"\"Log index-admin operations that may be blocked under filter-level DLS.\"\"\"\n logger.warning(\n f\"[OpenSearchMultimodel] Could not run index-admin operation '{operation}': {error}. \"\n \"Assuming the backend pre-created the required index/mapping and continuing.\"\n )\n\n # ---------- param helpers ----------\n def _parse_int_param(self, attr_name: str, default: int) -> int:\n \"\"\"Parse a string attribute to int, returning *default* on failure.\"\"\"\n raw = getattr(self, attr_name, None)\n if raw is None or str(raw).strip() == \"\":\n return default\n try:\n value = int(str(raw).strip())\n except ValueError:\n logger.warning(\n f\"Invalid integer value '{raw}' for {attr_name}, using default {default}\"\n )\n return default\n\n if value < 0:\n logger.warning(f\"Negative value '{raw}' for {attr_name}, using default {default}\")\n return default\n\n return value\n\n # ---------- auth / client ----------\n def _build_auth_kwargs(self) -> dict[str, Any]:\n \"\"\"Build authentication configuration for OpenSearch client.\n\n Constructs the appropriate authentication parameters based on the\n selected auth mode (basic username/password or JWT token).\n\n Returns:\n Dictionary containing authentication configuration\n\n Raises:\n ValueError: If required authentication parameters are missing\n \"\"\"\n mode = (self.auth_mode or \"basic\").strip().lower()\n if mode == \"jwt\":\n token = (self.jwt_token or \"\").strip()\n if not token:\n msg = \"Auth Mode is 'jwt' but no jwt_token was provided.\"\n raise ValueError(msg)\n header_name = (self.jwt_header or \"Authorization\").strip()\n header_value = f\"Bearer {token}\" if self.bearer_prefix else token\n return {\"headers\": {header_name: header_value}}\n if mode == \"openrag\":\n # Writes are delegated to the OpenRAG backend ingest callback,\n # so no direct OpenSearch credentials are needed. Only the\n # OPENRAG_* fields are required for ingestion to function.\n url = self._openrag_callback_value(\"openrag_ingest_url\")\n token = self._openrag_callback_value(\"openrag_ingest_token\")\n ingest_run_id = self._openrag_callback_value(\"openrag_ingest_run_id\")\n missing = [\n name\n for name, value in (\n (\"openrag_ingest_url\", url),\n (\"openrag_ingest_token\", token),\n (\"openrag_ingest_run_id\", ingest_run_id),\n )\n if not (value or \"\").strip()\n ]\n if missing:\n msg = (\n \"Auth Mode is 'openrag' but required OPENRAG_* fields are \"\n f\"missing: {', '.join(missing)}.\"\n )\n raise ValueError(msg)\n return {}\n user = (self.username or \"\").strip()\n pwd = (self._openrag_input_to_str(self.password) or \"\").strip()\n if pwd == \"OPENSEARCH_PASSWORD\" or not pwd:\n from config.settings import get_opensearch_password\n pwd = get_opensearch_password() or \"\"\n if not user or not pwd:\n msg = \"Auth Mode is 'basic' but username/password are missing.\"\n raise ValueError(msg)\n return {\"http_auth\": (user, pwd)}\n\n def build_client(self) -> OpenSearch:\n \"\"\"Create and configure an OpenSearch client instance.\n\n Returns:\n Configured OpenSearch client ready for operations\n \"\"\"\n logger.debug(\"[OpenSearchMultimodel] Building OpenSearch client\")\n auth_kwargs = self._build_auth_kwargs()\n return OpenSearch(\n hosts=[self.opensearch_url],\n use_ssl=self.use_ssl,\n verify_certs=self.verify_certs,\n ssl_assert_hostname=False,\n ssl_show_warn=False,\n timeout=self._parse_int_param(\"request_timeout\", REQUEST_TIMEOUT),\n max_retries=self._parse_int_param(\"max_retries\", MAX_RETRIES),\n retry_on_timeout=True,\n **auth_kwargs,\n )\n\n @check_cached_vector_store\n def build_vector_store(self) -> OpenSearch:\n # Return raw OpenSearch client as our \"vector store.\"\n client = self.build_client()\n\n # Check if we're in ingestion-only mode (no search query)\n has_search_query = bool((self.search_query or \"\").strip())\n if not has_search_query:\n logger.debug(\n \"[OpenSearchMultimodel] Ingestion-only mode activated: search operations will be skipped\"\n )\n logger.debug(\"[OpenSearchMultimodel] Starting ingestion mode...\")\n\n logger.debug(f\"[OpenSearchMultimodel] Embedding: {self.embedding}\")\n self._add_documents_to_vector_store(client=client)\n return client\n\n # ---------- ingest ----------\n def _add_documents_to_vector_store(self, client: OpenSearch) -> None:\n \"\"\"Process and ingest documents into the OpenSearch vector store.\n\n This method handles the complete document ingestion pipeline:\n - Prepares document data and metadata\n - Generates vector embeddings using the selected model\n - Creates appropriate index mappings with dynamic field names\n - Bulk inserts documents with vectors and model tracking\n\n Args:\n client: OpenSearch client for performing operations\n \"\"\"\n logger.debug(\"[OpenSearchMultimodel][INGESTION] _add_documents_to_vector_store called\")\n # Convert DataFrame to Data if needed using parent's method\n self.ingest_data = self._prepare_ingest_data()\n\n logger.debug(\n f\"[OpenSearchMultimodel][INGESTION] ingest_data type: \"\n f\"{type(self.ingest_data)}, length: {len(self.ingest_data) if self.ingest_data else 0}\"\n )\n logger.debug(\n f\"[OpenSearchMultimodel][INGESTION] ingest_data content: \"\n f\"{self.ingest_data[:2] if self.ingest_data and len(self.ingest_data) > 0 else 'empty'}\"\n )\n\n docs = self.ingest_data or []\n if not docs:\n logger.debug(\"Ingestion complete: No documents provided\")\n return\n\n if not self.embedding:\n msg = \"Embedding handle is required to embed documents.\"\n raise ValueError(msg)\n\n # Normalize embedding to list first\n embeddings_list = self.embedding if isinstance(self.embedding, list) else [self.embedding]\n\n # Filter out None values (fail-safe mode) - do this BEFORE checking if empty\n embeddings_list = [e for e in embeddings_list if e is not None]\n\n # NOW check if we have any valid embeddings left after filtering\n if not embeddings_list:\n logger.warning(\n \"All embeddings returned None (fail-safe mode enabled). Skipping document ingestion.\"\n )\n self.log(\n \"Embedding returned None (fail-safe mode enabled). Skipping document ingestion.\"\n )\n return\n\n logger.debug(\n f\"[OpenSearchMultimodel][INGESTION] Valid embeddings after filtering: {len(embeddings_list)}\"\n )\n self.log(\n f\"[OpenSearchMultimodel][INGESTION] Available embedding models: {len(embeddings_list)}\"\n )\n\n # Select the embedding to use for ingestion\n selected_embedding = None\n embedding_model = None\n\n # If embedding_model_name is specified, find matching embedding\n if (\n hasattr(self, \"embedding_model_name\")\n and self.embedding_model_name\n and self.embedding_model_name.strip()\n ):\n target_model_name = self.embedding_model_name.strip()\n self.log(f\"Looking for embedding model: {target_model_name}\")\n\n for emb_obj in embeddings_list:\n # Check all possible model identifiers (deployment, model, model_id, model_name)\n # Also check available_models list from EmbeddingsWithModels\n possible_names = []\n deployment = getattr(emb_obj, \"deployment\", None)\n model = getattr(emb_obj, \"model\", None)\n model_id = getattr(emb_obj, \"model_id\", None)\n model_name = getattr(emb_obj, \"model_name\", None)\n available_models_attr = getattr(emb_obj, \"available_models\", None)\n\n if deployment:\n possible_names.append(str(deployment))\n if model:\n possible_names.append(str(model))\n if model_id:\n possible_names.append(str(model_id))\n if model_name:\n possible_names.append(str(model_name))\n\n # Also add combined identifier\n if deployment and model and deployment != model:\n possible_names.append(f\"{deployment}:{model}\")\n\n # Add all models from available_models dict\n if available_models_attr and isinstance(available_models_attr, dict):\n possible_names.extend(\n str(model_key).strip()\n for model_key in available_models_attr\n if model_key and str(model_key).strip()\n )\n\n # Match if target matches any of the possible names\n if target_model_name in possible_names:\n # Check if target is in available_models dict - use dedicated instance\n if (\n available_models_attr\n and isinstance(available_models_attr, dict)\n and target_model_name in available_models_attr\n ):\n # Use the dedicated embedding instance from the dict\n selected_embedding = available_models_attr[target_model_name]\n embedding_model = target_model_name\n self.log(\n f\"Found dedicated embedding instance for '{embedding_model}' in available_models dict\"\n )\n else:\n # Traditional identifier match\n selected_embedding = emb_obj\n embedding_model = self._get_embedding_model_name(emb_obj)\n self.log(\n f\"Found matching embedding model: {embedding_model} (matched on: {target_model_name})\"\n )\n break\n\n if not selected_embedding:\n # Build detailed list of available embeddings with all their identifiers\n available_info = []\n for idx, emb in enumerate(embeddings_list):\n emb_type = type(emb).__name__\n identifiers = []\n deployment = getattr(emb, \"deployment\", None)\n model = getattr(emb, \"model\", None)\n model_id = getattr(emb, \"model_id\", None)\n model_name = getattr(emb, \"model_name\", None)\n available_models_attr = getattr(emb, \"available_models\", None)\n\n if deployment:\n identifiers.append(f\"deployment='{deployment}'\")\n if model:\n identifiers.append(f\"model='{model}'\")\n if model_id:\n identifiers.append(f\"model_id='{model_id}'\")\n if model_name:\n identifiers.append(f\"model_name='{model_name}'\")\n\n # Add combined identifier as an option\n if deployment and model and deployment != model:\n identifiers.append(f\"combined='{deployment}:{model}'\")\n\n # Add available_models dict if present\n if available_models_attr and isinstance(available_models_attr, dict):\n identifiers.append(f\"available_models={list(available_models_attr.keys())}\")\n\n available_info.append(\n f\" [{idx}] {emb_type}: {', '.join(identifiers) if identifiers else 'No identifiers'}\"\n )\n\n msg = (\n f\"Embedding model '{target_model_name}' not found in available embeddings.\\n\\n\"\n f\"Available embeddings:\\n\" + \"\\n\".join(available_info) + \"\\n\\n\"\n \"Please set 'embedding_model_name' to one of the identifier values shown above \"\n \"(use the value after the '=' sign, without quotes).\\n\"\n \"For duplicate deployments, use the 'combined' format.\\n\"\n \"Or leave it empty to use the first embedding.\"\n )\n raise ValueError(msg)\n else:\n # Use first embedding if no model name specified\n selected_embedding = embeddings_list[0]\n embedding_model = self._get_embedding_model_name(selected_embedding)\n self.log(f\"No embedding_model_name specified, using first embedding: {embedding_model}\")\n\n dynamic_field_name = get_embedding_field_name(embedding_model)\n\n logger.info(f\"Selected embedding model for ingestion: '{embedding_model}'\")\n self.log(f\"Using embedding model for ingestion: {embedding_model}\")\n self.log(f\"Dynamic vector field: {dynamic_field_name}\")\n\n # Log embedding details for debugging\n if hasattr(selected_embedding, \"deployment\"):\n logger.info(f\"Embedding deployment: {selected_embedding.deployment}\")\n if hasattr(selected_embedding, \"model\"):\n logger.info(f\"Embedding model: {selected_embedding.model}\")\n if hasattr(selected_embedding, \"model_id\"):\n logger.info(f\"Embedding model_id: {selected_embedding.model_id}\")\n if hasattr(selected_embedding, \"dimensions\"):\n logger.info(f\"Embedding dimensions: {selected_embedding.dimensions}\")\n if hasattr(selected_embedding, \"available_models\"):\n logger.info(f\"Embedding available_models: {selected_embedding.available_models}\")\n\n # No model switching needed - each model in available_models has its own dedicated instance\n # The selected_embedding is already configured correctly for the target model\n logger.info(\n f\"Using embedding instance for '{embedding_model}' - pre-configured and ready to use\"\n )\n\n # Extract texts and metadata from documents\n texts = []\n metadatas = []\n # Process docs_metadata table input into a dict\n additional_metadata = {}\n logger.debug(f\"[LF] Docs metadata {self.docs_metadata}\")\n if hasattr(self, \"docs_metadata\") and self.docs_metadata:\n logger.info(f\"[LF] Docs metadata {self.docs_metadata}\")\n if isinstance(self.docs_metadata[-1], Data):\n logger.info(f\"[LF] Docs metadata is a Data object {self.docs_metadata}\")\n self.docs_metadata = self.docs_metadata[-1].data\n logger.info(f\"[LF] Docs metadata is a Data object {self.docs_metadata}\")\n additional_metadata.update(self.docs_metadata)\n else:\n for item in self.docs_metadata:\n if isinstance(item, dict) and \"key\" in item and \"value\" in item:\n additional_metadata[item[\"key\"]] = item[\"value\"]\n # Replace string \"None\" values with actual None\n for key, value in additional_metadata.items():\n if value == \"None\":\n additional_metadata[key] = None\n logger.info(f\"[LF] Additional metadata {additional_metadata}\")\n for doc_obj in docs:\n data_copy = json.loads(doc_obj.model_dump_json())\n text = data_copy.pop(doc_obj.text_key, doc_obj.default_value)\n texts.append(text)\n\n # Merge additional metadata from table input\n data_copy.update(additional_metadata)\n\n metadatas.append(data_copy)\n self.log(metadatas)\n\n # Determine whether the selected embedding is watsonx/IBM. The watsonx\n # SDK ships its own rate-limit machinery (input batching, proactive\n # x-requests-limit-* TokenBucket throttling, and jittered exponential\n # backoff on 429), so we lean on it instead of retrying on top of it.\n # The type-name check also covers watsonx-hosted, non-\"ibm/\" models\n # (e.g. intfloat/multilingual-e5-large).\n is_ibm = (embedding_model and \"ibm\" in str(embedding_model).lower()) or (\n selected_embedding and \"watsonx\" in type(selected_embedding).__name__.lower()\n )\n logger.debug(f\"Is IBM/watsonx embedding: {is_ibm}\")\n\n if is_ibm:\n\n # Hand the full batch to the SDK and let it batch/throttle/retry.\n # Retry attempts and base backoff are tunable via the SDK's own\n # WATSONX_MAX_RETRIES / WATSONX_DELAY_TIME environment variables.\n logger.info(\n f\"Embedding {len(texts)} chunks via watsonx SDK batch (SDK-managed throttle + 429 retry)\"\n )\n try:\n vectors: list[list[float]] = selected_embedding.embed_documents(texts)\n logger.info(f\"Successfully embedded {len(vectors)} chunks via watsonx SDK\")\n except Exception as embed_error:\n _log_watsonx_rate_limit_headers(embed_error)\n logger.error(\n f\"Failed to embed {len(texts)} chunks via watsonx SDK. Error: {embed_error}\",\n )\n raise\n\n else:\n # Non-watsonx providers (OpenAI, Ollama) lack the watsonx SDK's\n # built-in rate-limit handling, so embed per chunk in parallel with\n # a generic rate-limit-aware tenacity retry.\n vectors: list[list[float]] = [None] * len(texts)\n from tenacity import (\n retry,\n retry_if_exception,\n stop_after_attempt,\n wait_exponential,\n )\n\n def is_rate_limit_error(exception: Exception) -> bool:\n \"\"\"Check if exception is a rate limit error (429).\"\"\"\n error_str = str(exception).lower()\n return \"429\" in error_str or \"rate_limit\" in error_str or \"rate limit\" in error_str\n\n def is_other_retryable_error(exception: Exception) -> bool:\n \"\"\"Check if exception is a transient network error worth retrying.\"\"\"\n if is_rate_limit_error(exception):\n return False\n return isinstance(exception, (ConnectionError, TimeoutError, OSError))\n\n # Retry decorator for rate limit errors (longer backoff)\n retry_on_rate_limit = retry(\n retry=retry_if_exception(is_rate_limit_error),\n stop=stop_after_attempt(5),\n wait=wait_exponential(multiplier=2, min=2, max=30),\n reraise=True,\n before_sleep=lambda retry_state: logger.warning(\n f\"Rate limit hit for chunk (attempt {retry_state.attempt_number}/5), \"\n f\"backing off for {retry_state.next_action.sleep:.1f}s\"\n ),\n )\n\n # Retry decorator for other errors (shorter backoff)\n retry_on_other_errors = retry(\n retry=retry_if_exception(is_other_retryable_error),\n stop=stop_after_attempt(3),\n wait=wait_exponential(multiplier=1, min=1, max=8),\n reraise=True,\n before_sleep=lambda retry_state: logger.warning(\n f\"Error embedding chunk (attempt {retry_state.attempt_number}/3), \"\n f\"retrying in {retry_state.next_action.sleep:.1f}s: {retry_state.outcome.exception()}\"\n ),\n )\n\n def embed_chunk_with_retry(chunk_text: str, chunk_idx: int) -> list[float]:\n \"\"\"Embed a single chunk with rate-limit-aware retry logic.\"\"\"\n\n @retry_on_rate_limit\n @retry_on_other_errors\n def _embed(text: str) -> list[float]:\n return selected_embedding.embed_documents([text])[0]\n\n try:\n return _embed(chunk_text)\n except Exception as e:\n logger.error(\n f\"Failed to embed chunk {chunk_idx} after all retries: {e}\",\n error=str(e),\n )\n raise\n\n max_workers = min(max(len(texts), 1), 8)\n logger.debug(f\"Using parallel processing with {max_workers} workers\")\n\n with ThreadPoolExecutor(max_workers=max_workers) as executor:\n futures = {\n executor.submit(embed_chunk_with_retry, chunk, idx): idx\n for idx, chunk in enumerate(texts)\n }\n for future in as_completed(futures):\n idx = futures[future]\n vectors[idx] = future.result()\n\n if not vectors:\n self.log(f\"No vectors generated from documents for model {embedding_model}.\")\n return\n\n # Get vector dimension for mapping\n dim = len(vectors[0]) if vectors else 768 # default fallback\n use_openrag_ingest_callback = self._openrag_ingest_callback_config() is not None\n\n is_aoss = False\n mapping: dict | None = None\n\n engine = getattr(self, \"engine\", \"jvector\")\n\n if use_openrag_ingest_callback:\n self.log(\"Using OpenRAG backend ingest callback; skipping direct OpenSearch writes.\")\n else:\n # Check for AOSS\n auth_kwargs = self._build_auth_kwargs()\n is_aoss = self._is_aoss_enabled(auth_kwargs.get(\"http_auth\"))\n\n # Validate engine with AOSS\n self._validate_aoss_with_engines(is_aoss=is_aoss, engine=engine)\n\n # Create mapping with proper KNN settings\n space_type = getattr(self, \"space_type\", \"l2\")\n ef_construction = getattr(self, \"ef_construction\", 512)\n m = getattr(self, \"m\", 16)\n\n mapping = self._default_text_mapping(\n dim=dim,\n engine=engine,\n space_type=space_type,\n ef_construction=ef_construction,\n m=m,\n vector_field=dynamic_field_name, # Use dynamic field name\n )\n\n # Ensure index exists with baseline mapping (index.knn: true is required for vector search)\n index_exists = True\n try:\n index_exists = bool(client.indices.exists(index=self.index_name))\n except OpenSearchException as exists_error:\n self._log_index_admin_skip(\"indices.exists\", exists_error)\n\n try:\n if not index_exists:\n self.log(f\"Creating index '{self.index_name}' with base mapping\")\n client.indices.create(index=self.index_name, body=mapping)\n except RequestError as creation_error:\n if creation_error.error == \"resource_already_exists_exception\":\n pass # Index was created concurrently\n else:\n error_msg = str(creation_error).lower()\n if \"invalid engine\" in error_msg or \"illegal_argument\" in error_msg:\n if \"jvector\" in error_msg:\n msg = (\n \"The 'jvector' engine is not available in your OpenSearch installation. \"\n \"Use 'nmslib' or 'faiss' for standard OpenSearch, or upgrade to 2.9+.\"\n )\n raise ValueError(msg) from creation_error\n if \"index.knn\" in error_msg:\n msg = (\n \"The index has index.knn: false. Delete the existing index and let the \"\n \"component recreate it, or create a new index with a different name.\"\n )\n raise ValueError(msg) from creation_error\n logger.warning(f\"Failed to create index '{self.index_name}': {creation_error}\")\n raise\n\n # Ensure the dynamic field exists in the index\n self._ensure_embedding_field_mapping(\n client=client,\n index_name=self.index_name,\n field_name=dynamic_field_name,\n dim=dim,\n engine=engine,\n space_type=space_type,\n ef_construction=ef_construction,\n m=m,\n )\n\n self.log(\n f\"Indexing {len(texts)} documents into '{self.index_name}' with model '{embedding_model}'...\"\n )\n logger.info(f\"Will store embeddings in field: {dynamic_field_name}\")\n logger.info(f\"Will tag documents with embedding_model: {embedding_model}\")\n\n # Use the bulk ingestion with model tracking\n return_ids = self._bulk_ingest_embeddings(\n client=client,\n index_name=self.index_name,\n embeddings=vectors,\n texts=texts,\n metadatas=metadatas,\n vector_field=dynamic_field_name, # Use dynamic field name\n text_field=\"text\",\n embedding_model=embedding_model, # Track the model\n mapping=mapping,\n is_aoss=is_aoss,\n )\n self.log(metadatas)\n\n logger.info(\n f\"Ingestion complete: Successfully indexed {len(return_ids)} documents with model '{embedding_model}'\"\n )\n self.log(f\"Successfully indexed {len(return_ids)} documents with model {embedding_model}.\")\n\n # ---------- helpers for filters ----------\n def _is_placeholder_term(self, term_obj: dict) -> bool:\n # term_obj like {\"filename\": \"__IMPOSSIBLE_VALUE__\"}\n return any(v == \"__IMPOSSIBLE_VALUE__\" for v in term_obj.values())\n\n def _coerce_filter_clauses(self, filter_obj: dict | None) -> list[dict]:\n \"\"\"Convert filter expressions into OpenSearch-compatible filter clauses.\n\n This method accepts two filter formats and converts them to standardized\n OpenSearch query clauses:\n\n Format A - Explicit filters:\n {\"filter\": [{\"term\": {\"field\": \"value\"}}, {\"terms\": {\"field\": [\"val1\", \"val2\"]}}],\n \"limit\": 10, \"score_threshold\": 1.5}\n\n Format B - Context-style mapping:\n {\"data_sources\": [\"file1.pdf\"], \"document_types\": [\"pdf\"], \"owners\": [\"user1\"]}\n\n Args:\n filter_obj: Filter configuration dictionary or None\n\n Returns:\n List of OpenSearch filter clauses (term/terms objects)\n Placeholder values with \"__IMPOSSIBLE_VALUE__\" are ignored\n \"\"\"\n if not filter_obj:\n return []\n\n # If it is a string, try to parse it once\n if isinstance(filter_obj, str):\n try:\n filter_obj = json.loads(filter_obj)\n except json.JSONDecodeError:\n # Not valid JSON - treat as no filters\n return []\n\n # Case A: already an explicit list/dict under \"filter\"\n if \"filter\" in filter_obj:\n raw = filter_obj[\"filter\"]\n if isinstance(raw, dict):\n raw = [raw]\n explicit_clauses: list[dict] = []\n for f in raw or []:\n if (\n \"term\" in f\n and isinstance(f[\"term\"], dict)\n and not self._is_placeholder_term(f[\"term\"])\n ):\n explicit_clauses.append(f)\n elif \"terms\" in f and isinstance(f[\"terms\"], dict):\n field, vals = next(iter(f[\"terms\"].items()))\n if isinstance(vals, list) and len(vals) > 0:\n explicit_clauses.append(f)\n return explicit_clauses\n\n # Case B: convert context-style maps into clauses\n field_mapping = {\n \"data_sources\": \"filename\",\n \"document_types\": \"mimetype\",\n \"owners\": \"owner\",\n }\n context_clauses: list[dict] = []\n for k, values in filter_obj.items():\n if not isinstance(values, list):\n continue\n field = field_mapping.get(k, k)\n if len(values) == 0:\n # Match-nothing placeholder (kept to mirror your tool semantics)\n context_clauses.append({\"term\": {field: \"__IMPOSSIBLE_VALUE__\"}})\n elif len(values) == 1:\n if values[0] != \"__IMPOSSIBLE_VALUE__\":\n context_clauses.append({\"term\": {field: values[0]}})\n else:\n context_clauses.append({\"terms\": {field: values}})\n return context_clauses\n\n\n def _parse_filter_expression(self) -> dict | None:\n \"\"\"Parse and validate optional filter_expression JSON.\n\n Returns:\n Parsed JSON object as a dict, or None when unset/blank.\n\n Raises:\n ValueError: If JSON is invalid or does not decode to an object.\n \"\"\"\n filter_expression = getattr(self, \"filter_expression\", \"\")\n if not isinstance(filter_expression, str) or not filter_expression.strip():\n return None\n try:\n filter_obj = json.loads(filter_expression)\n except json.JSONDecodeError as e:\n msg = f\"Invalid filter_expression JSON: {e}\"\n raise ValueError(msg) from e\n\n if not isinstance(filter_obj, dict):\n msg = \"Invalid filter_expression JSON type: expected a JSON object.\"\n raise TypeError(msg)\n return filter_obj\n\n def _resolve_limit(self, filter_obj: dict | None, default_limit: int | None) -> int | None:\n \"\"\"Resolve an integer result limit from filter settings.\"\"\"\n if not filter_obj:\n return default_limit\n raw_limit = filter_obj.get(\"limit\", default_limit)\n if raw_limit is None:\n return None\n if isinstance(raw_limit, bool):\n msg = \"Invalid filter_expression.limit: expected a positive integer.\"\n raise TypeError(msg)\n try:\n limit = int(raw_limit)\n except (TypeError, ValueError) as e:\n msg = \"Invalid filter_expression.limit: expected a positive integer.\"\n raise ValueError(msg) from e\n if limit <= 0:\n msg = \"Invalid filter_expression.limit: expected a positive integer.\"\n raise ValueError(msg)\n return limit\n\n def _resolve_score_threshold(self, filter_obj: dict | None) -> float | None:\n \"\"\"Resolve optional positive min score from filter settings.\"\"\"\n if not filter_obj:\n return None\n score_threshold = filter_obj.get(\"score_threshold\")\n if score_threshold is None:\n score_threshold = filter_obj.get(\"scoreThreshold\")\n if not isinstance(score_threshold, (int, float)) or score_threshold <= 0:\n return None\n return float(score_threshold)\n\n def _detect_available_models(self, client: OpenSearch, filter_clauses: list[dict] | None = None) -> list[str]:\n\n \"\"\"Detect which embedding models have documents in the index.\n\n Uses aggregation to find all unique embedding_model values, optionally\n filtered to only documents matching the user's filter criteria.\n\n Args:\n client: OpenSearch client instance\n filter_clauses: Optional filter clauses to scope model detection\n\n Returns:\n List of embedding model names found in the index\n \"\"\"\n try:\n agg_query = {\n \"size\": 0,\n \"aggs\": {\"embedding_models\": {\"terms\": {\"field\": \"embedding_model\", \"size\": 10}}},\n }\n\n # Apply filters to model detection if any exist\n if filter_clauses:\n agg_query[\"query\"] = {\"bool\": {\"filter\": filter_clauses}}\n\n logger.debug(f\"Model detection query: {agg_query}\")\n result = client.search(\n index=self.index_name,\n body=agg_query,\n params={\"terminate_after\": 0},\n )\n buckets = result.get(\"aggregations\", {}).get(\"embedding_models\", {}).get(\"buckets\", [])\n models = [b[\"key\"] for b in buckets if b[\"key\"]]\n\n # Log detailed bucket info for debugging\n logger.info(\n f\"Detected embedding models in corpus: {models}\"\n + (f\" (with {len(filter_clauses)} filters)\" if filter_clauses else \"\")\n )\n if not models:\n total_hits = result.get(\"hits\", {}).get(\"total\", {})\n total_count = (\n total_hits.get(\"value\", 0) if isinstance(total_hits, dict) else total_hits\n )\n logger.warning(\n f\"No embedding_model values found in index '{self.index_name}'. \"\n f\"Total docs in index: {total_count}. \"\n f\"This may indicate documents were indexed without the embedding_model field.\"\n )\n except (OpenSearchException, KeyError, ValueError) as e:\n logger.warning(f\"Failed to detect embedding models: {e}\")\n # Fallback to current model\n fallback_model = self._get_embedding_model_name()\n logger.info(f\"Using fallback model: {fallback_model}\")\n return [fallback_model]\n else:\n return models\n\n def _get_index_properties(self, client: OpenSearch) -> dict[str, Any] | None:\n \"\"\"Retrieve flattened mapping properties for the current index.\"\"\"\n try:\n mapping = client.indices.get_mapping(index=self.index_name)\n except OpenSearchException as e:\n logger.warning(\n f\"Failed to fetch mapping for index '{self.index_name}': {e}. Proceeding without mapping metadata.\"\n )\n return None\n\n properties: dict[str, Any] = {}\n for index_data in mapping.values():\n props = index_data.get(\"mappings\", {}).get(\"properties\", {})\n if isinstance(props, dict):\n properties.update(props)\n return properties\n\n def _is_knn_vector_field(self, properties: dict[str, Any] | None, field_name: str) -> bool:\n \"\"\"Check whether the field is mapped as a knn_vector.\"\"\"\n if not field_name:\n return False\n if properties is None:\n logger.warning(\n f\"Mapping metadata unavailable; assuming field '{field_name}' is usable.\"\n )\n return True\n field_def = properties.get(field_name)\n if not isinstance(field_def, dict):\n return False\n if field_def.get(\"type\") == \"knn_vector\":\n return True\n\n nested_props = field_def.get(\"properties\")\n return bool(isinstance(nested_props, dict) and nested_props.get(\"type\") == \"knn_vector\")\n\n def _get_field_dimension(\n self, properties: dict[str, Any] | None, field_name: str\n ) -> int | None:\n \"\"\"Get the dimension of a knn_vector field from the index mapping.\n\n Args:\n properties: Index properties from mapping\n field_name: Name of the vector field\n\n Returns:\n Dimension of the field, or None if not found\n \"\"\"\n if not field_name or properties is None:\n return None\n\n field_def = properties.get(field_name)\n if not isinstance(field_def, dict):\n return None\n\n # Check direct knn_vector field\n if field_def.get(\"type\") == \"knn_vector\":\n return field_def.get(\"dimension\")\n\n # Check nested properties\n nested_props = field_def.get(\"properties\")\n if isinstance(nested_props, dict) and nested_props.get(\"type\") == \"knn_vector\":\n return nested_props.get(\"dimension\")\n\n return None\n\n def _get_filename_agg_field(self, index_properties: dict[str, Any] | None) -> str:\n \"\"\"Choose the appropriate field for filename aggregations.\"\"\"\n if not index_properties:\n return \"filename.keyword\"\n\n filename_def = index_properties.get(\"filename\")\n if not isinstance(filename_def, dict):\n return \"filename.keyword\"\n\n field_type = filename_def.get(\"type\")\n fields_def = filename_def.get(\"fields\", {})\n\n # Top-level keyword with no subfields\n if field_type == \"keyword\" and not isinstance(fields_def, dict):\n return \"filename\"\n\n # Text field with keyword subfield\n if isinstance(fields_def, dict) and \"keyword\" in fields_def:\n return \"filename.keyword\"\n\n # Fallback: aggregate on filename directly\n return \"filename\"\n\n # ---------- search (multi-model hybrid) ----------\n def search(self, query: str | None = None) -> list[dict[str, Any]]:\n \"\"\"Perform multi-model hybrid search combining multiple vector similarities and keyword matching.\n\n This method executes a sophisticated search that:\n 1. Auto-detects all embedding models present in the index\n 2. Generates query embeddings for ALL detected models in parallel\n 3. Combines multiple KNN queries using dis_max (picks best match)\n 4. Adds keyword search with fuzzy matching (30% weight)\n 5. Applies optional filtering and score thresholds\n 6. Returns aggregations for faceted search\n\n Search weights:\n - Semantic search (dis_max across all models): 70%\n - Keyword search: 30%\n\n Args:\n query: Search query string (used for both vector embedding and keyword search)\n\n Returns:\n List of search results with page_content, metadata, and relevance scores\n\n Raises:\n ValueError: If embedding component is not provided or filter JSON is invalid\n \"\"\"\n logger.info(self.ingest_data)\n client = self.build_client()\n q = (query or \"\").strip()\n\n # Parse optional filter expression\n filter_obj = self._parse_filter_expression()\n\n if not self.embedding:\n msg = \"Embedding is required to run hybrid search (KNN + keyword).\"\n raise ValueError(msg)\n\n # Check if embedding is None (fail-safe mode)\n if self.embedding is None or (\n isinstance(self.embedding, list) and all(e is None for e in self.embedding)\n ):\n logger.error(\"Embedding returned None (fail-safe mode enabled). Cannot perform search.\")\n return []\n\n # Build filter clauses first so we can use them in model detection\n filter_clauses = self._coerce_filter_clauses(filter_obj)\n\n # Detect available embedding models in the index (scoped by filters)\n available_models = self._detect_available_models(client, filter_clauses)\n\n if not available_models:\n logger.warning(\"No embedding models found in index, using current model\")\n available_models = [self._get_embedding_model_name()]\n\n # Generate embeddings for ALL detected models\n query_embeddings = {}\n\n # Normalize embedding to list\n embeddings_list = self.embedding if isinstance(self.embedding, list) else [self.embedding]\n # Filter out None values (fail-safe mode)\n embeddings_list = [e for e in embeddings_list if e is not None]\n\n if not embeddings_list:\n logger.error(\n \"No valid embeddings available after filtering None values (fail-safe mode). Cannot perform search.\"\n )\n return []\n\n # Create a comprehensive map of model names to embedding objects\n # Check all possible identifiers (deployment, model, model_id, model_name)\n # Also leverage available_models list from EmbeddingsWithModels\n # Handle duplicate identifiers by creating combined keys\n embedding_by_model = {}\n identifier_conflicts = {} # Track which identifiers have conflicts\n\n for idx, emb_obj in enumerate(embeddings_list):\n # Get all possible identifiers for this embedding\n identifiers = []\n deployment = getattr(emb_obj, \"deployment\", None)\n model = getattr(emb_obj, \"model\", None)\n model_id = getattr(emb_obj, \"model_id\", None)\n model_name = getattr(emb_obj, \"model_name\", None)\n dimensions = getattr(emb_obj, \"dimensions\", None)\n available_models_attr = getattr(emb_obj, \"available_models\", None)\n\n logger.info(\n f\"Embedding object {idx}: deployment={deployment}, model={model}, \"\n f\"model_id={model_id}, model_name={model_name}, dimensions={dimensions}, \"\n f\"available_models={available_models_attr}\"\n )\n\n # If this embedding has available_models dict, map all models to their dedicated instances\n if available_models_attr and isinstance(available_models_attr, dict):\n logger.info(\n f\"Embedding object {idx} provides {len(available_models_attr)} models via available_models dict\"\n )\n for model_name_key, dedicated_embedding in available_models_attr.items():\n if model_name_key and str(model_name_key).strip():\n model_str = str(model_name_key).strip()\n if model_str not in embedding_by_model:\n # Use the dedicated embedding instance from the dict\n embedding_by_model[model_str] = dedicated_embedding\n logger.info(\n f\"Mapped available model '{model_str}' to dedicated embedding instance\"\n )\n else:\n # Conflict detected - track it\n if model_str not in identifier_conflicts:\n identifier_conflicts[model_str] = [embedding_by_model[model_str]]\n identifier_conflicts[model_str].append(dedicated_embedding)\n logger.warning(\n f\"Available model '{model_str}' has conflict - used by multiple embeddings\"\n )\n\n # Also map traditional identifiers (for backward compatibility)\n if deployment:\n identifiers.append(str(deployment))\n if model:\n identifiers.append(str(model))\n if model_id:\n identifiers.append(str(model_id))\n if model_name:\n identifiers.append(str(model_name))\n\n # Map all identifiers to this embedding object\n for identifier in identifiers:\n if identifier not in embedding_by_model:\n embedding_by_model[identifier] = emb_obj\n logger.info(f\"Mapped identifier '{identifier}' to embedding object {idx}\")\n else:\n # Conflict detected - track it\n if identifier not in identifier_conflicts:\n identifier_conflicts[identifier] = [embedding_by_model[identifier]]\n identifier_conflicts[identifier].append(emb_obj)\n logger.warning(\n f\"Identifier '{identifier}' has conflict - used by multiple embeddings\"\n )\n\n # For embeddings with model+deployment, create combined identifier\n # This helps when deployment is the same but model differs\n if deployment and model and deployment != model:\n combined_id = f\"{deployment}:{model}\"\n if combined_id not in embedding_by_model:\n embedding_by_model[combined_id] = emb_obj\n logger.info(\n f\"Created combined identifier '{combined_id}' for embedding object {idx}\"\n )\n\n # Log conflicts\n if identifier_conflicts:\n logger.warning(\n f\"Found {len(identifier_conflicts)} conflicting identifiers. \"\n f\"Consider using combined format 'deployment:model' or specifying unique model names.\"\n )\n for conflict_id, emb_list in identifier_conflicts.items():\n logger.warning(\n f\" Conflict on '{conflict_id}': {len(emb_list)} embeddings use this identifier\"\n )\n\n logger.info(f\"Generating embeddings for {len(available_models)} models in index\")\n logger.info(f\"Available embedding identifiers: {list(embedding_by_model.keys())}\")\n self.log(f\"[SEARCH] Models detected in index: {available_models}\")\n self.log(f\"[SEARCH] Available embedding identifiers: {list(embedding_by_model.keys())}\")\n\n # Track matching status for debugging\n matched_models = []\n unmatched_models = []\n\n for model_name in available_models:\n try:\n # Check if we have an embedding object for this model\n if model_name in embedding_by_model:\n # Use the matching embedding object directly\n emb_obj = embedding_by_model[model_name]\n emb_deployment = getattr(emb_obj, \"deployment\", None)\n emb_model = getattr(emb_obj, \"model\", None)\n emb_model_id = getattr(emb_obj, \"model_id\", None)\n emb_dimensions = getattr(emb_obj, \"dimensions\", None)\n emb_available_models = getattr(emb_obj, \"available_models\", None)\n\n logger.info(\n f\"Using embedding object for model '{model_name}': \"\n f\"deployment={emb_deployment}, model={emb_model}, model_id={emb_model_id}, \"\n f\"dimensions={emb_dimensions}\"\n )\n\n # Check if this is a dedicated instance from available_models dict\n if emb_available_models and isinstance(emb_available_models, dict):\n logger.info(\n f\"Model '{model_name}' using dedicated instance from available_models dict \"\n f\"(pre-configured with correct model and dimensions)\"\n )\n\n # Use the embedding instance directly - no model switching needed!\n vec = emb_obj.embed_query(q)\n query_embeddings[model_name] = vec\n matched_models.append(model_name)\n logger.info(\n f\"Generated embedding for model: {model_name} (actual dimensions: {len(vec)})\"\n )\n self.log(f\"[MATCH] Model '{model_name}' - generated {len(vec)}-dim embedding\")\n else:\n # No matching embedding found for this model\n unmatched_models.append(model_name)\n logger.warning(\n f\"No matching embedding found for model '{model_name}'. \"\n f\"This model will be skipped. Available identifiers: {list(embedding_by_model.keys())}\"\n )\n self.log(\n f\"[NO MATCH] Model '{model_name}' - available: {list(embedding_by_model.keys())}\"\n )\n except (\n RuntimeError,\n ValueError,\n ConnectionError,\n TimeoutError,\n AttributeError,\n KeyError,\n ) as e:\n logger.warning(f\"Failed to generate embedding for {model_name}: {e}\")\n self.log(f\"[ERROR] Embedding generation failed for '{model_name}': {e}\")\n\n # Log summary of model matching\n logger.info(\n f\"Model matching summary: {len(matched_models)} matched, {len(unmatched_models)} unmatched\"\n )\n self.log(\n f\"[SUMMARY] Model matching: {len(matched_models)} matched, {len(unmatched_models)} unmatched\"\n )\n if unmatched_models:\n self.log(f\"[WARN] Unmatched models in index: {unmatched_models}\")\n\n if not query_embeddings:\n msg = (\n f\"Failed to generate embeddings for any model. \"\n f\"Index has models: {available_models}, but no matching embedding objects found. \"\n f\"Available embedding identifiers: {list(embedding_by_model.keys())}\"\n )\n self.log(f\"[FAIL] Search failed: {msg}\")\n raise ValueError(msg)\n\n index_properties = self._get_index_properties(client)\n legacy_vector_field = getattr(self, \"vector_field\", \"chunk_embedding\")\n\n # Build KNN queries for each model\n embedding_fields: list[str] = []\n knn_queries_with_candidates = []\n knn_queries_without_candidates = []\n\n raw_num_candidates = getattr(self, \"num_candidates\", 1000)\n try:\n num_candidates = int(raw_num_candidates) if raw_num_candidates is not None else 0\n except (TypeError, ValueError):\n num_candidates = 0\n use_num_candidates = num_candidates > 0\n\n for model_name, embedding_vector in query_embeddings.items():\n field_name = get_embedding_field_name(model_name)\n selected_field = field_name\n vector_dim = len(embedding_vector)\n\n # Only use the expected dynamic field - no legacy fallback\n # This prevents dimension mismatches between models\n if not self._is_knn_vector_field(index_properties, selected_field):\n logger.warning(\n f\"Skipping model {model_name}: field '{field_name}' is not mapped as knn_vector. \"\n f\"Documents must be indexed with this embedding model before querying.\"\n )\n self.log(\n f\"[SKIP] Field '{selected_field}' not a knn_vector - skipping model '{model_name}'\"\n )\n continue\n\n # Validate vector dimensions match the field dimensions\n field_dim = self._get_field_dimension(index_properties, selected_field)\n if field_dim is not None and field_dim != vector_dim:\n logger.error(\n f\"Dimension mismatch for model '{model_name}': \"\n f\"Query vector has {vector_dim} dimensions but field '{selected_field}' expects {field_dim}. \"\n f\"Skipping this model to prevent search errors.\"\n )\n self.log(\n f\"[DIM MISMATCH] Model '{model_name}': query={vector_dim} vs field={field_dim} - skipping\"\n )\n continue\n\n logger.info(\n f\"Adding KNN query for model '{model_name}': field='{selected_field}', \"\n f\"query_dims={vector_dim}, field_dims={field_dim or 'unknown'}\"\n )\n embedding_fields.append(selected_field)\n\n base_query = {\n \"knn\": {\n selected_field: {\n \"vector\": embedding_vector,\n \"k\": 50,\n }\n }\n }\n\n if use_num_candidates:\n query_with_candidates = copy.deepcopy(base_query)\n query_with_candidates[\"knn\"][selected_field][\"num_candidates\"] = num_candidates\n else:\n query_with_candidates = base_query\n\n knn_queries_with_candidates.append(query_with_candidates)\n knn_queries_without_candidates.append(base_query)\n\n if not knn_queries_with_candidates:\n # No valid fields found - this can happen when:\n # 1. Index is empty (no documents yet)\n # 2. Embedding model has changed and field doesn't exist yet\n # Return empty results instead of failing\n logger.warning(\n \"No valid knn_vector fields found for embedding models. \"\n \"This may indicate an empty index or missing field mappings. \"\n \"Returning empty search results.\"\n )\n self.log(\n f\"[WARN] No valid KNN queries could be built. \"\n f\"Query embeddings generated: {list(query_embeddings.keys())}, \"\n f\"but no matching knn_vector fields found in index.\"\n )\n return []\n\n # Build exists filter - document must have at least one embedding field\n exists_any_embedding = {\n \"bool\": {\n \"should\": [{\"exists\": {\"field\": f}} for f in set(embedding_fields)],\n \"minimum_should_match\": 1,\n }\n }\n\n # Combine user filters with exists filter\n all_filters = [*filter_clauses, exists_any_embedding]\n\n # Get limit and score threshold\n limit = self._resolve_limit(filter_obj, default_limit=self.number_of_results)\n score_threshold = self._resolve_score_threshold(filter_obj)\n\n # Determine the best aggregation field for filename based on index mapping\n filename_agg_field = self._get_filename_agg_field(index_properties)\n\n # Build multi-model hybrid query\n body = {\n \"query\": {\n \"bool\": {\n \"should\": [\n {\n \"dis_max\": {\n \"tie_breaker\": 0.0, # Take only the best match, no blending\n \"boost\": 0.7, # 70% weight for semantic search\n \"queries\": knn_queries_with_candidates,\n }\n },\n {\n \"multi_match\": {\n \"query\": q,\n \"fields\": [\"text^2\", \"filename^1.5\"],\n \"type\": \"best_fields\",\n \"fuzziness\": \"AUTO\",\n \"boost\": 0.3, # 30% weight for keyword search\n }\n },\n ],\n \"minimum_should_match\": 1,\n \"filter\": all_filters,\n }\n },\n \"aggs\": {\n \"data_sources\": {\"terms\": {\"field\": filename_agg_field, \"size\": 20}},\n \"document_types\": {\"terms\": {\"field\": \"mimetype\", \"size\": 10}},\n \"owners\": {\"terms\": {\"field\": \"owner\", \"size\": 10}},\n \"embedding_models\": {\"terms\": {\"field\": \"embedding_model\", \"size\": 10}},\n },\n \"_source\": [\n \"filename\",\n \"mimetype\",\n \"page\",\n \"text\",\n \"source_url\",\n \"owner\",\n \"embedding_model\",\n \"parser\",\n \"chunk_size\",\n \"chunk_overlap\",\n \"allowed_users\",\n \"allowed_groups\",\n \"allowed_principals\",\n ],\n \"size\": limit,\n }\n\n if score_threshold is not None:\n body[\"min_score\"] = score_threshold\n\n logger.info(\n f\"Executing multi-model hybrid search with {len(knn_queries_with_candidates)} embedding models: \"\n f\"{list(query_embeddings.keys())}\"\n )\n self.log(\n f\"[EXEC] Executing search with {len(knn_queries_with_candidates)} KNN queries, limit={limit}\"\n )\n self.log(f\"[EXEC] Embedding models used: {list(query_embeddings.keys())}\")\n self.log(f\"[EXEC] KNN fields being queried: {embedding_fields}\")\n\n try:\n resp = client.search(index=self.index_name, body=body, params={\"terminate_after\": 0})\n except RequestError as e:\n error_message = str(e)\n lowered = error_message.lower()\n if use_num_candidates and \"num_candidates\" in lowered:\n logger.warning(\n \"Retrying search without num_candidates parameter due to cluster capabilities\",\n error=error_message,\n )\n fallback_body = copy.deepcopy(body)\n try:\n fallback_body[\"query\"][\"bool\"][\"should\"][0][\"dis_max\"][\"queries\"] = (\n knn_queries_without_candidates\n )\n except (KeyError, IndexError, TypeError) as inner_err:\n raise e from inner_err\n resp = client.search(\n index=self.index_name,\n body=fallback_body,\n params={\"terminate_after\": 0},\n )\n elif \"knn_vector\" in lowered or (\"field\" in lowered and \"knn\" in lowered):\n fallback_vector = next(iter(query_embeddings.values()), None)\n if fallback_vector is None:\n raise\n fallback_field = legacy_vector_field or \"chunk_embedding\"\n logger.warning(\n \"KNN search failed for dynamic fields; falling back to legacy field '%s'.\",\n fallback_field,\n )\n fallback_body = copy.deepcopy(body)\n fallback_body[\"query\"][\"bool\"][\"filter\"] = filter_clauses\n knn_fallback = {\n \"knn\": {\n fallback_field: {\n \"vector\": fallback_vector,\n \"k\": 50,\n }\n }\n }\n if use_num_candidates:\n knn_fallback[\"knn\"][fallback_field][\"num_candidates\"] = num_candidates\n fallback_body[\"query\"][\"bool\"][\"should\"][0][\"dis_max\"][\"queries\"] = [knn_fallback]\n resp = client.search(\n index=self.index_name,\n body=fallback_body,\n params={\"terminate_after\": 0},\n )\n else:\n raise\n hits = resp.get(\"hits\", {}).get(\"hits\", [])\n\n logger.info(f\"Found {len(hits)} results\")\n self.log(f\"[RESULT] Search complete: {len(hits)} results found\")\n\n if len(hits) == 0:\n self.log(\n f\"[EMPTY] Debug info: \"\n f\"models_in_index={available_models}, \"\n f\"matched_models={matched_models}, \"\n f\"knn_fields={embedding_fields}, \"\n f\"filters={len(filter_clauses)} clauses\"\n )\n\n return [\n {\n \"page_content\": fence_untrusted_text(hit[\"_source\"].get(\"text\", \"\")),\n \"metadata\": {\n **{k: v for k, v in hit[\"_source\"].items() if k != \"text\"},\n \"chunk_id\": hit.get(\"_id\"),\n \"id\": hit.get(\"_id\"),\n \"score\": hit.get(\"_score\"),\n },\n \"score\": hit.get(\"_score\"),\n }\n for hit in hits\n ]\n\n def search_documents(self) -> list[Data]:\n\n \"\"\"Search documents and return results as a list of Data objects.\n\n This is the main interface method that performs the multi-model search using the\n configured search_query and returns results in a format that downstream Parser\n components and tool wrappers can consume directly without DataFrame string truncation.\n\n Always builds the vector store (triggering ingestion if needed), then performs\n search only if a query is provided.\n\n Returns:\n List containing search results with text and metadata\n\n Raises:\n Exception: If search operation fails\n \"\"\"\n\n try:\n # Always build/cache the vector store to ensure ingestion happens\n logger.info(f\"Search query: {self.search_query}\")\n if self._cached_vector_store is None:\n self.build_vector_store()\n\n # Only perform search if query is provided\n search_query = (self.search_query or \"\").strip()\n if not search_query:\n self.log(\"No search query provided - ingestion completed, returning empty results\")\n\n return []\n\n # Perform search with the provided query\n raw = self.search(search_query)\n raw_list = [Data(text=hit[\"page_content\"], **hit[\"metadata\"]) for hit in raw]\n return raw_list\n\n except Exception as e:\n self.log(f\"search_documents error: {e}\")\n raise\n\n # -------- dynamic UI handling (auth switch) --------\n async def update_build_config(\n self, build_config: dict, field_value: str, field_name: str | None = None\n ) -> dict:\n \"\"\"Dynamically update component configuration based on field changes.\n\n This method handles real-time UI updates, particularly for authentication\n mode changes that show/hide relevant input fields.\n\n Args:\n build_config: Current component configuration\n field_value: New value for the changed field\n field_name: Name of the field that changed\n\n Returns:\n Updated build configuration with appropriate field visibility\n \"\"\"\n try:\n if field_name == \"auth_mode\":\n mode = (field_value or \"basic\").strip().lower()\n is_basic = mode == \"basic\"\n is_jwt = mode == \"jwt\"\n is_openrag = mode == \"openrag\"\n\n build_config[\"username\"][\"show\"] = is_basic\n build_config[\"password\"][\"show\"] = is_basic\n\n build_config[\"jwt_token\"][\"show\"] = is_jwt\n build_config[\"jwt_header\"][\"show\"] = is_jwt\n build_config[\"bearer_prefix\"][\"show\"] = is_jwt\n\n build_config[\"username\"][\"required\"] = is_basic\n build_config[\"password\"][\"required\"] = is_basic\n\n # build_config[\"jwt_token\"][\"required\"] = is_jwt\n build_config[\"jwt_header\"][\"required\"] = is_jwt\n build_config[\"bearer_prefix\"][\"required\"] = False\n\n # In 'openrag' mode, expose the OPENRAG_* fields up front\n # since they are the only credentials required.\n for openrag_field in (\n \"openrag_ingest_url\",\n \"openrag_ingest_token\",\n \"openrag_ingest_run_id\",\n \"openrag_ingest_batch_size\",\n ):\n if openrag_field in build_config:\n build_config[openrag_field][\"advanced\"] = not is_openrag\n build_config[openrag_field][\"required\"] = (\n is_openrag and openrag_field != \"openrag_ingest_batch_size\"\n )\n\n if is_basic or is_openrag:\n build_config[\"jwt_token\"][\"value\"] = \"\"\n\n return build_config\n\n except (KeyError, ValueError) as e:\n self.log(f\"update_build_config error: {e}\")\n\n return build_config\n"
+ },
+ "docs_metadata": {
+ "_input_type": "TableInput",
+ "advanced": false,
+ "api_editable": false,
+ "display_name": "Document Metadata",
+ "dynamic": false,
+ "info": "Additional metadata key-value pairs to be added to all ingested documents. Useful for tagging documents with source information, categories, or other custom attributes.",
+ "input_types": [
+ "Data",
+ "JSON"
+ ],
+ "is_list": true,
+ "list_add_label": "Add More",
+ "name": "docs_metadata",
+ "override_skip": false,
+ "placeholder": "",
+ "required": false,
+ "show": true,
+ "table_icon": "Table",
+ "table_schema": [
+ {
+ "description": "Key name",
+ "display_name": "Key",
+ "formatter": "text",
+ "name": "key",
+ "type": "str"
+ },
+ {
+ "description": "Value of the metadata",
+ "display_name": "Value",
+ "formatter": "text",
+ "name": "value",
+ "type": "str"
+ }
+ ],
+ "title_case": false,
+ "tool_mode": false,
+ "trace_as_metadata": true,
+ "track_in_telemetry": false,
+ "trigger_icon": "Table",
+ "trigger_text": "Open table",
+ "type": "table",
+ "value": []
+ },
+ "ef_construction": {
+ "_input_type": "IntInput",
+ "advanced": true,
+ "api_editable": false,
+ "display_name": "EF Construction",
+ "dynamic": false,
+ "info": "Size of the dynamic candidate list during index construction. Higher values improve recall but increase indexing time and memory usage.",
+ "list": false,
+ "list_add_label": "Add More",
+ "name": "ef_construction",
+ "override_skip": false,
+ "placeholder": "",
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "tool_mode": false,
+ "trace_as_metadata": true,
+ "track_in_telemetry": true,
+ "type": "int",
+ "value": 512
+ },
+ "embedding": {
+ "_input_type": "HandleInput",
+ "advanced": false,
+ "api_editable": false,
+ "display_name": "Embedding",
+ "dynamic": false,
+ "info": "",
+ "input_types": [
+ "Embeddings"
+ ],
+ "list": true,
+ "list_add_label": "Add More",
+ "name": "embedding",
+ "override_skip": false,
+ "placeholder": "",
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "trace_as_metadata": true,
+ "track_in_telemetry": false,
+ "type": "other",
+ "value": ""
},
- "_frontend_node_folder_id": {
- "value": "203c7c12-9e1d-4561-bb14-16102afec154"
+ "embedding_model_name": {
+ "_input_type": "StrInput",
+ "advanced": false,
+ "api_editable": false,
+ "display_name": "Embedding Model Name",
+ "dynamic": false,
+ "info": "Name of the embedding model to use for ingestion. This selects which embedding from the list will be used to embed documents. Matches on deployment, model, model_id, or model_name. For duplicate deployments, use combined format: 'deployment:model' (e.g., 'text-embedding-ada-002:text-embedding-3-large'). Leave empty to use the first embedding. Error message will show all available identifiers.",
+ "list": false,
+ "list_add_label": "Add More",
+ "load_from_db": true,
+ "name": "embedding_model_name",
+ "override_skip": false,
+ "placeholder": "",
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "tool_mode": false,
+ "trace_as_metadata": true,
+ "track_in_telemetry": false,
+ "type": "str",
+ "value": "SELECTED_EMBEDDING_MODEL"
},
- "_type": "Component",
- "auth_mode": {
+ "engine": {
"_input_type": "DropdownInput",
- "advanced": false,
+ "advanced": true,
"api_editable": false,
"combobox": false,
"dialog_inputs": {},
- "display_name": "Authentication Mode",
+ "display_name": "Vector Engine",
"dynamic": false,
"external_options": {},
- "info": "Authentication method: 'basic' for username/password authentication, 'jwt' for JSON Web Token (Bearer) authentication, or 'openrag' to delegate writes to the OpenRAG backend ingest callback (no direct OpenSearch credentials required — only OPENRAG_* fields).",
- "name": "auth_mode",
+ "info": "Vector search engine for similarity calculations. 'nmslib' works with standard OpenSearch. 'jvector' requires OpenSearch 2.9+. 'lucene' requires index.knn: true. Amazon OpenSearch Serverless only supports 'nmslib' or 'faiss'.",
+ "name": "engine",
"options": [
- "basic",
- "jwt",
- "openrag"
+ "nmslib",
+ "faiss",
+ "lucene",
+ "jvector"
],
"options_metadata": [],
"override_skip": false,
"placeholder": "",
- "real_time_refresh": true,
"required": false,
"show": true,
"title_case": false,
@@ -4088,102 +3133,202 @@
"trace_as_metadata": true,
"track_in_telemetry": true,
"type": "str",
- "value": "jwt"
+ "value": "jvector"
},
- "bearer_prefix": {
- "_input_type": "BoolInput",
- "advanced": true,
+ "filter_expression": {
+ "_input_type": "MultilineInput",
+ "advanced": false,
+ "ai_enabled": false,
"api_editable": false,
- "display_name": "Prefix 'Bearer '",
+ "copy_field": false,
+ "display_name": "Search Filters (JSON)",
"dynamic": false,
- "info": "",
+ "info": "Optional JSON configuration for search filtering, result limits, and score thresholds.\n\nFormat 1 - Explicit filters:\n{\"filter\": [{\"term\": {\"filename\":\"doc.pdf\"}}, {\"terms\":{\"owner\":[\"user1\",\"user2\"]}}], \"limit\": 10, \"score_threshold\": 1.6}\n\nFormat 2 - Context-style mapping:\n{\"data_sources\":[\"file.pdf\"], \"document_types\":[\"application/pdf\"], \"owners\":[\"user123\"]}\n\nUse __IMPOSSIBLE_VALUE__ as placeholder to ignore specific filters.",
+ "input_types": [
+ "Message"
+ ],
"list": false,
"list_add_label": "Add More",
- "name": "bearer_prefix",
+ "load_from_db": false,
+ "multiline": true,
+ "name": "filter_expression",
"override_skip": false,
+ "password": false,
"placeholder": "",
"required": false,
"show": true,
"title_case": false,
"tool_mode": false,
+ "trace_as_input": true,
"trace_as_metadata": true,
- "track_in_telemetry": true,
- "type": "bool",
- "value": false
+ "track_in_telemetry": false,
+ "type": "str",
+ "value": ""
},
- "code": {
+ "index_name": {
+ "_input_type": "StrInput",
+ "advanced": false,
+ "api_editable": false,
+ "display_name": "Index Name",
+ "dynamic": false,
+ "info": "The OpenSearch index name where documents will be stored and searched. Will be created automatically if it doesn't exist.",
+ "list": false,
+ "list_add_label": "Add More",
+ "load_from_db": true,
+ "name": "index_name",
+ "override_skip": false,
+ "placeholder": "",
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "tool_mode": false,
+ "trace_as_metadata": true,
+ "track_in_telemetry": false,
+ "type": "str",
+ "value": "OPENSEARCH_INDEX_NAME"
+ },
+ "ingest_data": {
+ "_input_type": "HandleInput",
+ "advanced": false,
+ "api_editable": false,
+ "display_name": "Ingest Data",
+ "dynamic": false,
+ "info": "",
+ "input_types": [
+ "Data",
+ "DataFrame",
+ "Table"
+ ],
+ "list": true,
+ "list_add_label": "Add More",
+ "name": "ingest_data",
+ "override_skip": false,
+ "placeholder": "",
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "trace_as_metadata": true,
+ "track_in_telemetry": false,
+ "type": "other",
+ "value": ""
+ },
+ "is_refresh": false,
+ "jwt_header": {
+ "_input_type": "StrInput",
"advanced": true,
"api_editable": false,
- "dynamic": true,
- "fileTypes": [],
- "file_path": "",
+ "display_name": "JWT Header Name",
+ "dynamic": false,
"info": "",
"list": false,
+ "list_add_label": "Add More",
"load_from_db": false,
- "multiline": true,
- "name": "code",
- "password": false,
+ "name": "jwt_header",
+ "override_skip": false,
"placeholder": "",
"required": true,
"show": true,
"title_case": false,
- "type": "code",
- "value": "from __future__ import annotations\n\nimport copy\nimport json\nimport uuid\nfrom concurrent.futures import ThreadPoolExecutor, as_completed\nfrom typing import Any\n\nimport httpx\nfrom lfx.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store\nfrom lfx.base.vectorstores.vector_store_connection_decorator import vector_store_connection\nfrom lfx.io import (\n BoolInput,\n DropdownInput,\n HandleInput,\n IntInput,\n MultilineInput,\n Output,\n SecretStrInput,\n StrInput,\n TableInput,\n)\nfrom lfx.log import logger\nfrom lfx.schema.data import Data\nfrom lfx.schema.dataframe import Table\nfrom opensearchpy import OpenSearch, helpers\nfrom opensearchpy.exceptions import OpenSearchException, RequestError\n\nREQUEST_TIMEOUT = 60\nMAX_RETRIES = 5\n\n# watsonx.ai surfaces rate-limit state via these (mostly non-standard) response\n# headers. The IBM SDK acts on the x-requests-limit-* family directly; we log\n# them on a failed embedding call to aid plan/region tuning.\n_WATSONX_RATE_LIMIT_HEADERS = (\n \"x-requests-limit-rate\",\n \"x-requests-limit-remaining\",\n \"x-requests-limit-reset\",\n \"Retry-After\",\n)\n\n\ndef _log_watsonx_rate_limit_headers(error: Exception) -> None:\n \"\"\"Best-effort diagnostic: log watsonx rate-limit headers from a failed call.\n\n The watsonx SDK raises ``ApiRequestFailure``, which carries the originating\n httpx/requests ``Response`` as ``.response``. On a 429 exhaustion we surface\n the documented rate-limit headers so operators can tune throughput.\n \"\"\"\n try:\n response = getattr(error, \"response\", None)\n headers = getattr(response, \"headers\", None)\n if not headers:\n return\n status = getattr(response, \"status_code\", \"unknown\")\n observed = {h: headers.get(h) for h in _WATSONX_RATE_LIMIT_HEADERS if headers.get(h) is not None}\n if str(status) == \"429\" or observed:\n logger.warning(f\"watsonx rate-limit response (status={status}): {observed}\")\n except Exception as log_error: # never let diagnostics mask the real error\n logger.debug(f\"Could not extract watsonx rate-limit headers: {log_error}\")\n\n\ndef normalize_model_name(model_name: str) -> str:\n \"\"\"Normalize embedding model name for use as field suffix.\n\n Converts model names to valid OpenSearch field names by replacing\n special characters and ensuring alphanumeric format.\n\n Args:\n model_name: Original embedding model name (e.g., \"text-embedding-3-small\")\n\n Returns:\n Normalized field suffix (e.g., \"text_embedding_3_small\")\n \"\"\"\n normalized = model_name.lower()\n # Replace common separators with underscores\n normalized = normalized.replace(\"-\", \"_\").replace(\":\", \"_\").replace(\"/\", \"_\").replace(\".\", \"_\")\n # Remove any non-alphanumeric characters except underscores\n normalized = \"\".join(c if c.isalnum() or c == \"_\" else \"_\" for c in normalized)\n # Remove duplicate underscores\n while \"__\" in normalized:\n normalized = normalized.replace(\"__\", \"_\")\n return normalized.strip(\"_\")\n\n\ndef get_embedding_field_name(model_name: str) -> str:\n \"\"\"Get the dynamic embedding field name for a model.\n\n Args:\n model_name: Embedding model name\n\n Returns:\n Field name in format: chunk_embedding_{normalized_model_name}\n \"\"\"\n logger.info(f\"chunk_embedding_{normalize_model_name(model_name)}\")\n return f\"chunk_embedding_{normalize_model_name(model_name)}\"\n\n\nUNTRUSTED_CHUNK_FENCE_START = \"<<<UNTRUSTED_DOC_CHUNK>>>\"\nUNTRUSTED_CHUNK_FENCE_END = \"<<<END_UNTRUSTED_DOC_CHUNK>>>\"\n\n\ndef fence_untrusted_text(text: str) -> str:\n \"\"\"Wrap retrieved document text in delimiters marking it as untrusted data.\n\n Retrieved chunk text can contain attacker-controlled natural-language\n instructions (indirect prompt injection, VULN-13906). Fencing it lets the\n system prompt tell the LLM to treat anything between these markers as\n data only, never as instructions or tool directives.\n\n Any literal fence markers already present in `text` are escaped first, so\n a poisoned chunk can't embed a fake end-of-fence marker to break out of\n the untrusted section and have its continuation misread as trusted.\n \"\"\"\n if not text:\n return text\n escaped = text.replace(\n UNTRUSTED_CHUNK_FENCE_START, \"\\\\\" + UNTRUSTED_CHUNK_FENCE_START\n ).replace(UNTRUSTED_CHUNK_FENCE_END, \"\\\\\" + UNTRUSTED_CHUNK_FENCE_END)\n return f\"{UNTRUSTED_CHUNK_FENCE_START}\\n{escaped}\\n{UNTRUSTED_CHUNK_FENCE_END}\"\n\n\n@vector_store_connection\nclass OpenSearchVectorStoreComponentMultimodalMultiEmbedding(LCVectorStoreComponent):\n \"\"\"OpenSearch Vector Store Component with Multi-Model Hybrid Search Capabilities.\n\n This component provides vector storage and retrieval using OpenSearch, combining semantic\n similarity search (KNN) with keyword-based search for optimal results. It supports:\n - Multiple embedding models per index with dynamic field names\n - Automatic detection and querying of all available embedding models\n - Parallel embedding generation for multi-model search\n - Document ingestion with model tracking\n - Advanced filtering and aggregations\n - Flexible authentication options\n\n Features:\n - Multi-model vector storage with dynamic fields (chunk_embedding_{model_name})\n - Hybrid search combining multiple KNN queries (dis_max) + keyword matching\n - Auto-detection of available models in the index\n - Parallel query embedding generation for all detected models\n - Vector storage with configurable engines (jvector, nmslib, faiss, lucene)\n - Flexible authentication (Basic auth, JWT tokens)\n\n Model Name Resolution:\n - Priority: deployment > model > model_name attributes\n - This ensures correct matching between embedding objects and index fields\n - When multiple embeddings are provided, specify embedding_model_name to select which one to use\n - During search, each detected model in the index is matched to its corresponding embedding object\n \"\"\"\n\n display_name: str = \"OpenSearch (Multi-Model Multi-Embedding)\"\n icon: str = \"OpenSearch\"\n description: str = (\n \"Store and search documents using OpenSearch with multi-model hybrid semantic and keyword search. \"\n \"To search use the tools search_documents and raw_search. \"\n \"Search documents takes a query for vector search, for example\\n\"\n ' {search_query: \"components in openrag\"}'\n )\n\n # Keys we consider baseline\n default_keys: list[str] = [\n \"opensearch_url\",\n \"index_name\",\n *[i.name for i in LCVectorStoreComponent.inputs], # search_query, add_documents, etc.\n \"embedding\",\n \"embedding_model_name\",\n \"vector_field\",\n \"number_of_results\",\n \"auth_mode\",\n \"username\",\n \"password\",\n \"jwt_token\",\n \"jwt_header\",\n \"bearer_prefix\",\n \"use_ssl\",\n \"verify_certs\",\n \"filter_expression\",\n \"engine\",\n \"space_type\",\n \"ef_construction\",\n \"m\",\n \"num_candidates\",\n \"docs_metadata\",\n \"request_timeout\",\n \"max_retries\",\n \"openrag_ingest_url\",\n \"openrag_ingest_token\",\n \"openrag_ingest_run_id\",\n \"openrag_ingest_batch_size\",\n ]\n _openrag_ingest_global_placeholders = {\n \"openrag_ingest_url\": \"OPENRAG_INGEST_URL\",\n \"openrag_ingest_token\": \"OPENRAG_INGEST_TOKEN\",\n \"openrag_ingest_run_id\": \"OPENRAG_INGEST_RUN_ID\",\n }\n\n inputs = [\n TableInput(\n name=\"docs_metadata\",\n display_name=\"Document Metadata\",\n info=(\n \"Additional metadata key-value pairs to be added to all ingested documents. \"\n \"Useful for tagging documents with source information, categories, or other custom attributes.\"\n ),\n table_schema=[\n {\n \"name\": \"key\",\n \"display_name\": \"Key\",\n \"type\": \"str\",\n \"description\": \"Key name\",\n },\n {\n \"name\": \"value\",\n \"display_name\": \"Value\",\n \"type\": \"str\",\n \"description\": \"Value of the metadata\",\n },\n ],\n value=[],\n input_types=[\"Data\", \"JSON\"],\n ),\n StrInput(\n name=\"opensearch_url\",\n display_name=\"OpenSearch URL\",\n value=\"http://localhost:9200\",\n info=(\n \"The connection URL for your OpenSearch cluster \"\n \"(e.g., http://localhost:9200 for local development or your cloud endpoint).\"\n ),\n ),\n StrInput(\n name=\"index_name\",\n display_name=\"Index Name\",\n value=\"langflow\",\n info=(\n \"The OpenSearch index name where documents will be stored and searched. \"\n \"Will be created automatically if it doesn't exist.\"\n ),\n ),\n DropdownInput(\n name=\"engine\",\n display_name=\"Vector Engine\",\n options=[\"nmslib\", \"faiss\", \"lucene\", \"jvector\"],\n value=\"jvector\",\n info=(\n \"Vector search engine for similarity calculations. 'nmslib' works with standard \"\n \"OpenSearch. 'jvector' requires OpenSearch 2.9+. 'lucene' requires index.knn: true. \"\n \"Amazon OpenSearch Serverless only supports 'nmslib' or 'faiss'.\"\n ),\n advanced=True,\n ),\n DropdownInput(\n name=\"space_type\",\n display_name=\"Distance Metric\",\n options=[\"l2\", \"l1\", \"cosinesimil\", \"linf\", \"innerproduct\"],\n value=\"l2\",\n info=(\n \"Distance metric for calculating vector similarity. 'l2' (Euclidean) is most common, \"\n \"'cosinesimil' for cosine similarity, 'innerproduct' for dot product.\"\n ),\n advanced=True,\n ),\n IntInput(\n name=\"ef_construction\",\n display_name=\"EF Construction\",\n value=512,\n info=(\n \"Size of the dynamic candidate list during index construction. \"\n \"Higher values improve recall but increase indexing time and memory usage.\"\n ),\n advanced=True,\n ),\n IntInput(\n name=\"m\",\n display_name=\"M Parameter\",\n value=16,\n info=(\n \"Number of bidirectional connections for each vector in the HNSW graph. \"\n \"Higher values improve search quality but increase memory usage and indexing time.\"\n ),\n advanced=True,\n ),\n IntInput(\n name=\"num_candidates\",\n display_name=\"Candidate Pool Size\",\n value=1000,\n info=(\n \"Number of approximate neighbors to consider for each KNN query. \"\n \"Some OpenSearch deployments do not support this parameter; set to 0 to disable.\"\n ),\n advanced=True,\n ),\n *LCVectorStoreComponent.inputs, # includes search_query, add_documents, etc.\n HandleInput(\n name=\"embedding\", display_name=\"Embedding\", input_types=[\"Embeddings\"], is_list=True\n ),\n StrInput(\n name=\"embedding_model_name\",\n display_name=\"Embedding Model Name\",\n value=\"\",\n info=(\n \"Name of the embedding model to use for ingestion. This selects which embedding from the list \"\n \"will be used to embed documents. Matches on deployment, model, model_id, or model_name. \"\n \"For duplicate deployments, use combined format: 'deployment:model' \"\n \"(e.g., 'text-embedding-ada-002:text-embedding-3-large'). \"\n \"Leave empty to use the first embedding. Error message will show all available identifiers.\"\n ),\n advanced=False,\n ),\n StrInput(\n name=\"vector_field\",\n display_name=\"Legacy Vector Field Name\",\n value=\"chunk_embedding\",\n advanced=True,\n info=(\n \"Legacy field name for backward compatibility. New documents use dynamic fields \"\n \"(chunk_embedding_{model_name}) based on the embedding_model_name.\"\n ),\n ),\n IntInput(\n name=\"number_of_results\",\n display_name=\"Default Result Limit\",\n value=10,\n advanced=True,\n info=(\n \"Default maximum number of search results to return when no limit is \"\n \"specified in the filter expression.\"\n ),\n ),\n MultilineInput(\n name=\"filter_expression\",\n display_name=\"Search Filters (JSON)\",\n value=\"\",\n info=(\n \"Optional JSON configuration for search filtering, result limits, and score thresholds.\\n\\n\"\n \"Format 1 - Explicit filters:\\n\"\n '{\"filter\": [{\"term\": {\"filename\":\"doc.pdf\"}}, '\n '{\"terms\":{\"owner\":[\"user1\",\"user2\"]}}], \"limit\": 10, \"score_threshold\": 1.6}\\n\\n'\n \"Format 2 - Context-style mapping:\\n\"\n '{\"data_sources\":[\"file.pdf\"], \"document_types\":[\"application/pdf\"], \"owners\":[\"user123\"]}\\n\\n'\n \"Use __IMPOSSIBLE_VALUE__ as placeholder to ignore specific filters.\"\n ),\n ),\n # ----- Auth controls (dynamic) -----\n DropdownInput(\n name=\"auth_mode\",\n display_name=\"Authentication Mode\",\n value=\"openrag\",\n options=[\"basic\", \"jwt\", \"openrag\"],\n info=(\n \"Authentication method: 'basic' for username/password authentication, \"\n \"'jwt' for JSON Web Token (Bearer) authentication, or 'openrag' to \"\n \"delegate writes to the OpenRAG backend ingest callback (no direct \"\n \"OpenSearch credentials required — only OPENRAG_* fields).\"\n ),\n real_time_refresh=True,\n advanced=False,\n ),\n StrInput(\n name=\"username\",\n display_name=\"Username\",\n value=\"admin\",\n show=True,\n ),\n SecretStrInput(\n name=\"password\",\n display_name=\"OpenSearch Password\",\n value=\"OPENSEARCH_PASSWORD\",\n load_from_db=True,\n show=True,\n ),\n SecretStrInput(\n name=\"jwt_token\",\n display_name=\"JWT Token\",\n value=\"JWT\",\n load_from_db=False,\n show=False,\n info=(\n \"Valid JSON Web Token for authentication. \"\n \"Will be sent in the Authorization header (with optional 'Bearer ' prefix).\"\n ),\n required=False\n ),\n StrInput(\n name=\"jwt_header\",\n display_name=\"JWT Header Name\",\n value=\"Authorization\",\n show=False,\n advanced=True,\n ),\n BoolInput(\n name=\"bearer_prefix\",\n display_name=\"Prefix 'Bearer '\",\n value=False,\n show=False,\n advanced=True,\n ),\n # ----- TLS -----\n BoolInput(\n name=\"use_ssl\",\n display_name=\"Use SSL/TLS\",\n value=True,\n advanced=True,\n info=\"Enable SSL/TLS encryption for secure connections to OpenSearch.\",\n ),\n BoolInput(\n name=\"verify_certs\",\n display_name=\"Verify SSL Certificates\",\n value=False,\n advanced=True,\n info=(\n \"Verify SSL certificates when connecting. \"\n \"Disable for self-signed certificates in development environments.\"\n ),\n ),\n # ----- Timeout / Retry -----\n StrInput(\n name=\"request_timeout\",\n display_name=\"Request Timeout (seconds)\",\n value=\"60\",\n advanced=True,\n info=(\n \"Time in seconds to wait for a response from OpenSearch. \"\n \"Increase for large bulk ingestion or complex hybrid queries.\"\n ),\n ),\n StrInput(\n name=\"max_retries\",\n display_name=\"Max Retries\",\n value=\"3\",\n advanced=True,\n info=\"Number of retries for failed connections before raising an error.\",\n ),\n StrInput(\n name=\"openrag_ingest_url\",\n display_name=\"OpenRAG Ingest URL\",\n value=\"OPENRAG_INGEST_URL\",\n load_from_db=True,\n input_types=[\"Text\", \"Message\"],\n advanced=True,\n info=\"Internal OpenRAG callback URL for backend-owned document indexing.\",\n ),\n SecretStrInput(\n name=\"openrag_ingest_token\",\n display_name=\"OpenRAG Ingest Token\",\n value=\"OPENRAG_INGEST_TOKEN\",\n load_from_db=True,\n input_types=[\"Text\", \"Message\"],\n advanced=True,\n info=\"Short-lived token used only for OpenRAG ingest callbacks.\",\n ),\n StrInput(\n name=\"openrag_ingest_run_id\",\n display_name=\"OpenRAG Ingest Run ID\",\n value=\"OPENRAG_INGEST_RUN_ID\",\n load_from_db=True,\n input_types=[\"Text\", \"Message\"],\n advanced=True,\n ),\n IntInput(\n name=\"openrag_ingest_batch_size\",\n display_name=\"OpenRAG Ingest Batch Size\",\n value=100,\n advanced=True,\n ),\n ]\n outputs = [\n Output(\n display_name=\"Search Results\",\n name=\"search_results\",\n method=\"search_documents\",\n ),\n Output(display_name=\"Raw Search\", name=\"raw_search\", method=\"raw_search\"),\n ]\n\n def raw_search(self, query: str | dict | None = None) -> Data:\n \"\"\"Execute a raw OpenSearch query against the target index.\n\n Args:\n query (dict[str, Any]): The OpenSearch query DSL dictionary.\n\n Returns:\n Data: Search results as a Data object.\n\n Raises:\n ValueError: If 'query' is not a valid OpenSearch query (must be a non-empty dict).\n \"\"\"\n raw_query = query if query is not None else self.search_query\n\n if raw_query is None or (isinstance(raw_query, str) and not raw_query.strip()):\n self.log(\"No query provided for raw search - returning empty results\")\n return Data(data={})\n\n if isinstance(raw_query, dict):\n query_body = copy.deepcopy(raw_query)\n elif isinstance(raw_query, str):\n s = raw_query.strip()\n\n # First, optimistically try to parse as JSON DSL\n try:\n query_body = json.loads(s)\n except json.JSONDecodeError:\n # Fallback: treat as a basic text query over common fields\n query_body = {\n \"query\": {\n \"multi_match\": {\n \"query\": s,\n \"fields\": [\"text^2\", \"filename^1.5\"],\n \"type\": \"best_fields\",\n \"fuzziness\": \"AUTO\",\n }\n }\n }\n else:\n msg = f\"Unsupported raw_search query type: {type(raw_query)!r}\"\n raise TypeError(msg)\n\n filter_obj = self._parse_filter_expression()\n filter_clauses = self._coerce_filter_clauses(filter_obj)\n\n if filter_clauses:\n if \"query\" in query_body:\n original_query = query_body[\"query\"]\n query_body[\"query\"] = {\n \"bool\": {\n \"must\": [original_query],\n \"filter\": filter_clauses,\n }\n }\n else:\n query_body[\"query\"] = {\n \"bool\": {\n \"must\": [{\"match_all\": {}}],\n \"filter\": filter_clauses,\n }\n }\n\n if filter_obj:\n # Apply limit if not already set in the raw query\n if \"size\" not in query_body:\n limit = self._resolve_limit(filter_obj, default_limit=None)\n if limit is not None:\n query_body[\"size\"] = limit\n\n # Apply score_threshold / scoreThreshold as min_score if not already set\n if \"min_score\" not in query_body:\n\n score_threshold = self._resolve_score_threshold(filter_obj)\n if score_threshold is not None:\n\n query_body[\"min_score\"] = score_threshold\n\n client = self.build_client()\n logger.info(f\"query: {query_body}\")\n resp = client.search(\n index=self.index_name,\n body=query_body,\n params={\"terminate_after\": 0},\n )\n # Remove any _source keys whose value is a list of floats (embedding vectors)\n # Minimum length threshold to identify embedding vectors\n min_vector_length = 100\n\n def is_vector(val):\n # Accepts if it's a list of numbers (float or int) and has reasonable vector length\n return (\n isinstance(val, list)\n and len(val) > min_vector_length\n and all(isinstance(x, (float, int)) for x in val)\n )\n\n if \"hits\" in resp and \"hits\" in resp[\"hits\"]:\n for hit in resp[\"hits\"][\"hits\"]:\n source = hit.get(\"_source\")\n if isinstance(source, dict):\n keys_to_remove = [k for k, v in source.items() if is_vector(v)]\n for k in keys_to_remove:\n source.pop(k)\n if \"text\" in source:\n source[\"text\"] = fence_untrusted_text(source[\"text\"])\n logger.info(f\"Raw search response (all embedding vectors removed): {resp}\")\n return Data(**resp)\n\n def _get_embedding_model_name(self, embedding_obj=None) -> str:\n \"\"\"Get the embedding model name from component config or embedding object.\n\n Priority: deployment > model > model_id > model_name\n This ensures we use the actual model being deployed, not just the configured model.\n Supports multiple embedding providers (OpenAI, Watsonx, Cohere, etc.)\n\n Args:\n embedding_obj: Specific embedding object to get name from (optional)\n\n Returns:\n Embedding model name\n\n Raises:\n ValueError: If embedding model name cannot be determined\n \"\"\"\n # First try explicit embedding_model_name input\n if hasattr(self, \"embedding_model_name\") and self.embedding_model_name:\n return self.embedding_model_name.strip()\n\n # Try to get from provided embedding object\n if embedding_obj:\n # Priority: deployment > model > model_id > model_name\n if hasattr(embedding_obj, \"deployment\") and embedding_obj.deployment:\n return str(embedding_obj.deployment)\n if hasattr(embedding_obj, \"model\") and embedding_obj.model:\n return str(embedding_obj.model)\n if hasattr(embedding_obj, \"model_id\") and embedding_obj.model_id:\n return str(embedding_obj.model_id)\n if hasattr(embedding_obj, \"model_name\") and embedding_obj.model_name:\n return str(embedding_obj.model_name)\n\n # Try to get from embedding component (legacy single embedding)\n if hasattr(self, \"embedding\") and self.embedding:\n # Handle list of embeddings\n if isinstance(self.embedding, list) and len(self.embedding) > 0:\n first_emb = self.embedding[0]\n if hasattr(first_emb, \"deployment\") and first_emb.deployment:\n return str(first_emb.deployment)\n if hasattr(first_emb, \"model\") and first_emb.model:\n return str(first_emb.model)\n if hasattr(first_emb, \"model_id\") and first_emb.model_id:\n return str(first_emb.model_id)\n if hasattr(first_emb, \"model_name\") and first_emb.model_name:\n return str(first_emb.model_name)\n # Handle single embedding\n elif not isinstance(self.embedding, list):\n if hasattr(self.embedding, \"deployment\") and self.embedding.deployment:\n return str(self.embedding.deployment)\n if hasattr(self.embedding, \"model\") and self.embedding.model:\n return str(self.embedding.model)\n if hasattr(self.embedding, \"model_id\") and self.embedding.model_id:\n return str(self.embedding.model_id)\n if hasattr(self.embedding, \"model_name\") and self.embedding.model_name:\n return str(self.embedding.model_name)\n\n msg = (\n \"Could not determine embedding model name. \"\n \"Please set the 'embedding_model_name' field or ensure the embedding component \"\n \"has a 'deployment', 'model', 'model_id', or 'model_name' attribute.\"\n )\n raise ValueError(msg)\n\n # ---------- helper functions for index management ----------\n def _default_text_mapping(\n self,\n dim: int,\n engine: str = \"jvector\",\n space_type: str = \"l2\",\n ef_search: int = 512,\n ef_construction: int = 100,\n m: int = 16,\n vector_field: str = \"vector_field\",\n ) -> dict[str, Any]:\n \"\"\"Create the default OpenSearch index mapping for vector search.\n\n This method generates the index configuration with k-NN settings optimized\n for approximate nearest neighbor search using the specified vector engine.\n Includes the embedding_model keyword field for tracking which model was used.\n\n Args:\n dim: Dimensionality of the vector embeddings\n engine: Vector search engine (jvector, nmslib, faiss, lucene)\n space_type: Distance metric for similarity calculation\n ef_search: Size of dynamic list used during search\n ef_construction: Size of dynamic list used during index construction\n m: Number of bidirectional links for each vector\n vector_field: Name of the field storing vector embeddings\n\n Returns:\n Dictionary containing OpenSearch index mapping configuration\n \"\"\"\n return {\n \"settings\": {\"index\": {\"knn\": True, \"knn.algo_param.ef_search\": ef_search}},\n \"mappings\": {\n \"properties\": {\n vector_field: {\n \"type\": \"knn_vector\",\n \"dimension\": dim,\n \"method\": {\n \"name\": \"disk_ann\",\n \"space_type\": space_type,\n \"engine\": engine,\n \"parameters\": {\"ef_construction\": ef_construction, \"m\": m},\n },\n },\n \"embedding_model\": {\"type\": \"keyword\"}, # Track which model was used\n \"embedding_dimensions\": {\"type\": \"integer\"},\n }\n },\n }\n\n def _ensure_embedding_field_mapping(\n self,\n client: OpenSearch,\n index_name: str,\n field_name: str,\n dim: int,\n engine: str,\n space_type: str,\n ef_construction: int,\n m: int,\n ) -> None:\n \"\"\"Lazily add a dynamic embedding field to the index if it doesn't exist.\n\n This allows adding new embedding models without recreating the entire index.\n Also ensures the embedding_model tracking field exists.\n\n Note: Some OpenSearch versions/configurations have issues with dynamically adding\n knn_vector mappings (NullPointerException). This method checks if the field\n already exists before attempting to add it, and gracefully skips if the field\n is already properly configured.\n\n Args:\n client: OpenSearch client instance\n index_name: Target index name\n field_name: Dynamic field name for this embedding model\n dim: Vector dimensionality\n engine: Vector search engine\n space_type: Distance metric\n ef_construction: Construction parameter\n m: HNSW parameter\n \"\"\"\n # First, check if the field already exists and is properly mapped\n properties = self._get_index_properties(client)\n if self._is_knn_vector_field(properties, field_name):\n # Field already exists as knn_vector - verify dimensions match\n existing_dim = self._get_field_dimension(properties, field_name)\n if existing_dim is not None and existing_dim != dim:\n logger.warning(\n f\"Field '{field_name}' exists with dimension {existing_dim}, \"\n f\"but current embedding has dimension {dim}. Using existing mapping.\"\n )\n else:\n logger.info(\n f\"[OpenSearchMultimodel] Field '{field_name}' already exists\"\n f\"as knn_vector with matching dimensions - skipping mapping update\"\n )\n return\n\n # Field doesn't exist, try to add the mapping\n try:\n mapping = {\n \"properties\": {\n field_name: {\n \"type\": \"knn_vector\",\n \"dimension\": dim,\n \"method\": {\n \"name\": \"disk_ann\",\n \"space_type\": space_type,\n \"engine\": engine,\n \"parameters\": {\"ef_construction\": ef_construction, \"m\": m},\n },\n },\n # Also ensure the embedding_model tracking field exists as keyword\n \"embedding_model\": {\"type\": \"keyword\"},\n \"embedding_dimensions\": {\"type\": \"integer\"},\n }\n }\n client.indices.put_mapping(index=index_name, body=mapping)\n logger.info(f\"Added/updated embedding field mapping: {field_name}\")\n except RequestError as e:\n error_str = str(e).lower()\n if \"invalid engine\" in error_str and \"jvector\" in error_str:\n msg = (\n \"The 'jvector' engine is not available in your OpenSearch installation. \"\n \"Use 'nmslib' or 'faiss' for standard OpenSearch, or upgrade to OpenSearch 2.9+.\"\n )\n raise ValueError(msg) from e\n if \"index.knn\" in error_str:\n msg = (\n \"The index has index.knn: false. Delete the existing index and let the \"\n \"component recreate it, or create a new index with a different name.\"\n )\n raise ValueError(msg) from e\n raise\n except Exception as e:\n # Check if this is the known OpenSearch k-NN NullPointerException issue\n error_str = str(e).lower()\n if \"null\" in error_str or \"nullpointerexception\" in error_str:\n logger.warning(\n f\"[OpenSearchMultimodel] Could not add embedding field mapping for {field_name}\"\n f\"due to OpenSearch k-NN plugin issue: {e}. \"\n f\"This is a known issue with some OpenSearch versions. \"\n f\"[OpenSearchMultimodel] Skipping mapping update. \"\n f\"Please ensure the index has the correct mapping for KNN search to work.\"\n )\n # Skip and continue - ingestion will proceed, but KNN search may fail if mapping doesn't exist\n return\n logger.warning(\n f\"[OpenSearchMultimodel] Could not add embedding field mapping for {field_name}: {e}\"\n )\n raise\n\n # Verify the field was added correctly\n properties = self._get_index_properties(client)\n if not self._is_knn_vector_field(properties, field_name):\n msg = f\"Field '{field_name}' is not mapped as knn_vector. Current mapping: {properties.get(field_name)}\"\n logger.error(msg)\n raise ValueError(msg)\n\n def _validate_aoss_with_engines(self, *, is_aoss: bool, engine: str) -> None:\n \"\"\"Validate engine compatibility with Amazon OpenSearch Serverless (AOSS).\n\n Amazon OpenSearch Serverless has restrictions on which vector engines\n can be used. This method ensures the selected engine is compatible.\n\n Args:\n is_aoss: Whether the connection is to Amazon OpenSearch Serverless\n engine: The selected vector search engine\n\n Raises:\n ValueError: If AOSS is used with an incompatible engine\n \"\"\"\n if is_aoss and engine not in {\"nmslib\", \"faiss\"}:\n msg = \"Amazon OpenSearch Service Serverless only supports `nmslib` or `faiss` engines\"\n raise ValueError(msg)\n\n def _is_aoss_enabled(self, http_auth: Any) -> bool:\n \"\"\"Determine if Amazon OpenSearch Serverless (AOSS) is being used.\n\n Args:\n http_auth: The HTTP authentication object\n\n Returns:\n True if AOSS is enabled, False otherwise\n \"\"\"\n return (\n http_auth is not None and hasattr(http_auth, \"service\") and http_auth.service == \"aoss\"\n )\n\n @staticmethod\n def _openrag_input_to_str(value: Any) -> str:\n if value is None:\n return \"\"\n if hasattr(value, \"get_secret_value\"):\n value = value.get_secret_value()\n if hasattr(value, \"text\"):\n value = value.text\n return str(value or \"\").strip()\n\n def _openrag_callback_value(self, attr_name: str) -> str:\n value = self._openrag_input_to_str(getattr(self, attr_name, \"\"))\n if value == self._openrag_ingest_global_placeholders.get(attr_name):\n return \"\"\n return value\n\n def _openrag_ingest_callback_config(self) -> tuple[str, str, str] | None:\n url = self._openrag_callback_value(\"openrag_ingest_url\")\n token = self._openrag_callback_value(\"openrag_ingest_token\")\n ingest_run_id = self._openrag_callback_value(\"openrag_ingest_run_id\")\n\n if not url and not token and not ingest_run_id:\n return None\n if not url or not token or not ingest_run_id:\n msg = \"OpenRAG ingest callback requires url, token, and ingest_run_id.\"\n raise ValueError(msg)\n\n logger.debug(\n \"[OpenRAG callback config] configured for ingest_run_id=%s (url_len=%d, token_len=%d)\",\n ingest_run_id,\n len(url),\n len(token),\n )\n return url, token, ingest_run_id\n\n def _post_openrag_ingest_batches(\n self,\n *,\n requests: list[dict],\n vector_field: str,\n text_field: str,\n ) -> None:\n callback_config = self._openrag_ingest_callback_config()\n if callback_config is None:\n return\n\n url, token, ingest_run_id = callback_config\n batch_size = max(self._parse_int_param(\"openrag_ingest_batch_size\", 100), 1)\n timeout = self._parse_int_param(\"request_timeout\", REQUEST_TIMEOUT)\n headers = {\"Authorization\": f\"Bearer {token}\"}\n\n logger.debug(\n f\"[OpenRAG ingest POST] total_chunks={len(requests)} batch_size={batch_size} timeout_s={timeout}\"\n )\n\n with httpx.Client(timeout=timeout) as client:\n total_batches = (len(requests) + batch_size - 1) // batch_size\n for batch_number, start in enumerate(range(0, len(requests), batch_size), start=1):\n batch = requests[start : start + batch_size]\n final = batch_number == total_batches\n payload = {\n \"ingest_run_id\": ingest_run_id,\n \"batch_id\": batch_number,\n \"final\": final,\n \"chunks\": [\n self._openrag_chunk_payload(\n request,\n vector_field=vector_field,\n text_field=text_field,\n )\n for request in batch\n ],\n }\n logger.debug(\n f\"[OpenRAG ingest POST] -> batch={batch_number}/{total_batches} \"\n f\"chunks={len(payload['chunks'])} final={final}\"\n )\n response = client.post(url, json=payload, headers=headers)\n logger.debug(f\"[OpenRAG ingest POST resp] batch={batch_number} status={response.status_code}\")\n if response.status_code >= 400:\n msg = (\n \"OpenRAG ingest callback failed \"\n f\"(batch={batch_number}, status={response.status_code})\"\n )\n logger.warning(msg)\n raise RuntimeError(msg)\n\n logger.debug(f\"Posted {len(requests)} chunks to OpenRAG backend ingest callback.\")\n\n @staticmethod\n def _openrag_chunk_payload(\n request: dict,\n *,\n vector_field: str,\n text_field: str,\n ) -> dict:\n metadata = {\n key: value\n for key, value in request.items()\n if key not in {\"_op_type\", \"_index\", \"_id\", \"id\", vector_field, text_field}\n }\n page = metadata.get(\"page\")\n if isinstance(page, str) and page.isdigit():\n page = int(page)\n return {\n \"id\": request.get(\"_id\") or request.get(\"id\"),\n \"text\": request.get(text_field, \"\"),\n \"vector\": request[vector_field],\n \"page\": page if isinstance(page, int) else None,\n \"metadata\": metadata,\n }\n\n def _bulk_ingest_embeddings(\n self,\n client: OpenSearch,\n index_name: str,\n embeddings: list[list[float]],\n texts: list[str],\n metadatas: list[dict] | None = None,\n ids: list[str] | None = None,\n vector_field: str = \"vector_field\",\n text_field: str = \"text\",\n embedding_model: str = \"unknown\",\n mapping: dict | None = None,\n max_chunk_bytes: int | None = 1 * 1024 * 1024,\n *,\n is_aoss: bool = False,\n ) -> list[str]:\n \"\"\"Efficiently ingest multiple documents with embeddings into OpenSearch.\n\n This method uses bulk operations to insert documents with their vector\n embeddings and metadata into the specified OpenSearch index. Each document\n is tagged with the embedding_model name for tracking.\n\n Args:\n client: OpenSearch client instance\n index_name: Target index for document storage\n embeddings: List of vector embeddings for each document\n texts: List of document texts\n metadatas: Optional metadata dictionaries for each document\n ids: Optional document IDs (UUIDs generated if not provided)\n vector_field: Field name for storing vector embeddings\n text_field: Field name for storing document text\n embedding_model: Name of the embedding model used\n mapping: Optional index mapping configuration\n max_chunk_bytes: Maximum size per bulk request chunk\n is_aoss: Whether using Amazon OpenSearch Serverless\n\n Returns:\n List of document IDs that were successfully ingested\n \"\"\"\n logger.debug(f\"[OpenSearchMultimodel] Bulk ingesting embeddings for {index_name}\")\n if not mapping:\n mapping = {}\n\n requests = []\n return_ids = []\n vector_dimensions = len(embeddings[0]) if embeddings else None\n\n for i, text in enumerate(texts):\n metadata = metadatas[i] if metadatas else {}\n if vector_dimensions is not None and \"embedding_dimensions\" not in metadata:\n metadata = {**metadata, \"embedding_dimensions\": vector_dimensions}\n\n # Normalize ACL fields that may arrive as JSON strings from flows\n for key in (\"allowed_users\", \"allowed_groups\", \"allowed_principals\"):\n value = metadata.get(key)\n if isinstance(value, str):\n try:\n parsed = json.loads(value)\n if isinstance(parsed, list):\n metadata[key] = parsed\n except (json.JSONDecodeError, TypeError):\n # Leave value as-is if it isn't valid JSON\n pass\n\n metadata_document_id = str(metadata.get(\"document_id\") or \"\").strip()\n if metadata_document_id and metadata_document_id.lower() != \"none\":\n generated_id = f\"{metadata_document_id}_{i}\"\n else:\n generated_id = str(uuid.uuid4())\n _id = ids[i] if ids else generated_id\n request = {\n \"_op_type\": \"index\",\n \"_index\": index_name,\n vector_field: embeddings[i],\n text_field: text,\n \"embedding_model\": embedding_model, # Track which model was used\n **metadata,\n }\n if is_aoss:\n request[\"id\"] = _id\n else:\n request[\"_id\"] = _id\n requests.append(request)\n return_ids.append(_id)\n if metadatas:\n self.log(f\"Sample metadata: {metadatas[0] if metadatas else {}}\")\n if self._openrag_ingest_callback_config() is not None:\n self._post_openrag_ingest_batches(\n requests=requests,\n vector_field=vector_field,\n text_field=text_field,\n )\n return return_ids\n try:\n helpers.bulk(client, requests, max_chunk_bytes=max_chunk_bytes)\n except Exception as bulk_error:\n if \"Unsupported request type for filter level DLS\" not in str(bulk_error):\n raise\n logger.warning(\n \"[OpenSearchMultimodel] Bulk ingest is blocked by filter-level DLS; \"\n \"falling back to per-document index requests.\"\n )\n self._index_embeddings_individually(client, requests)\n return return_ids\n\n def _index_embeddings_individually(\n self,\n client: OpenSearch,\n requests: list[dict],\n ) -> None:\n \"\"\"Index documents one at a time when OpenSearch DLS rejects bulk writes.\"\"\"\n for request in requests:\n document_id = request.get(\"_id\") or request.get(\"id\")\n body = {\n key: value\n for key, value in request.items()\n if key not in {\"_op_type\", \"_index\", \"_id\", \"id\"}\n }\n client.index(index=request[\"_index\"], id=document_id, body=body)\n\n def _log_index_admin_skip(self, operation: str, error: Exception) -> None:\n \"\"\"Log index-admin operations that may be blocked under filter-level DLS.\"\"\"\n logger.warning(\n f\"[OpenSearchMultimodel] Could not run index-admin operation '{operation}': {error}. \"\n \"Assuming the backend pre-created the required index/mapping and continuing.\"\n )\n\n # ---------- param helpers ----------\n def _parse_int_param(self, attr_name: str, default: int) -> int:\n \"\"\"Parse a string attribute to int, returning *default* on failure.\"\"\"\n raw = getattr(self, attr_name, None)\n if raw is None or str(raw).strip() == \"\":\n return default\n try:\n value = int(str(raw).strip())\n except ValueError:\n logger.warning(\n f\"Invalid integer value '{raw}' for {attr_name}, using default {default}\"\n )\n return default\n\n if value < 0:\n logger.warning(f\"Negative value '{raw}' for {attr_name}, using default {default}\")\n return default\n\n return value\n\n # ---------- auth / client ----------\n def _build_auth_kwargs(self) -> dict[str, Any]:\n \"\"\"Build authentication configuration for OpenSearch client.\n\n Constructs the appropriate authentication parameters based on the\n selected auth mode (basic username/password or JWT token).\n\n Returns:\n Dictionary containing authentication configuration\n\n Raises:\n ValueError: If required authentication parameters are missing\n \"\"\"\n mode = (self.auth_mode or \"basic\").strip().lower()\n if mode == \"jwt\":\n token = (self.jwt_token or \"\").strip()\n if not token:\n msg = \"Auth Mode is 'jwt' but no jwt_token was provided.\"\n raise ValueError(msg)\n header_name = (self.jwt_header or \"Authorization\").strip()\n header_value = f\"Bearer {token}\" if self.bearer_prefix else token\n return {\"headers\": {header_name: header_value}}\n if mode == \"openrag\":\n # Writes are delegated to the OpenRAG backend ingest callback,\n # so no direct OpenSearch credentials are needed. Only the\n # OPENRAG_* fields are required for ingestion to function.\n url = self._openrag_callback_value(\"openrag_ingest_url\")\n token = self._openrag_callback_value(\"openrag_ingest_token\")\n ingest_run_id = self._openrag_callback_value(\"openrag_ingest_run_id\")\n missing = [\n name\n for name, value in (\n (\"openrag_ingest_url\", url),\n (\"openrag_ingest_token\", token),\n (\"openrag_ingest_run_id\", ingest_run_id),\n )\n if not (value or \"\").strip()\n ]\n if missing:\n msg = (\n \"Auth Mode is 'openrag' but required OPENRAG_* fields are \"\n f\"missing: {', '.join(missing)}.\"\n )\n raise ValueError(msg)\n return {}\n user = (self.username or \"\").strip()\n pwd = (self._openrag_input_to_str(self.password) or \"\").strip()\n if pwd == \"OPENSEARCH_PASSWORD\" or not pwd:\n from config.settings import get_opensearch_password\n pwd = get_opensearch_password() or \"\"\n if not user or not pwd:\n msg = \"Auth Mode is 'basic' but username/password are missing.\"\n raise ValueError(msg)\n return {\"http_auth\": (user, pwd)}\n\n def build_client(self) -> OpenSearch:\n \"\"\"Create and configure an OpenSearch client instance.\n\n Returns:\n Configured OpenSearch client ready for operations\n \"\"\"\n logger.debug(\"[OpenSearchMultimodel] Building OpenSearch client\")\n auth_kwargs = self._build_auth_kwargs()\n return OpenSearch(\n hosts=[self.opensearch_url],\n use_ssl=self.use_ssl,\n verify_certs=self.verify_certs,\n ssl_assert_hostname=False,\n ssl_show_warn=False,\n timeout=self._parse_int_param(\"request_timeout\", REQUEST_TIMEOUT),\n max_retries=self._parse_int_param(\"max_retries\", MAX_RETRIES),\n retry_on_timeout=True,\n **auth_kwargs,\n )\n\n @check_cached_vector_store\n def build_vector_store(self) -> OpenSearch:\n # Return raw OpenSearch client as our \"vector store.\"\n client = self.build_client()\n\n # Check if we're in ingestion-only mode (no search query)\n has_search_query = bool((self.search_query or \"\").strip())\n if not has_search_query:\n logger.debug(\n \"[OpenSearchMultimodel] Ingestion-only mode activated: search operations will be skipped\"\n )\n logger.debug(\"[OpenSearchMultimodel] Starting ingestion mode...\")\n\n logger.debug(f\"[OpenSearchMultimodel] Embedding: {self.embedding}\")\n self._add_documents_to_vector_store(client=client)\n return client\n\n # ---------- ingest ----------\n def _add_documents_to_vector_store(self, client: OpenSearch) -> None:\n \"\"\"Process and ingest documents into the OpenSearch vector store.\n\n This method handles the complete document ingestion pipeline:\n - Prepares document data and metadata\n - Generates vector embeddings using the selected model\n - Creates appropriate index mappings with dynamic field names\n - Bulk inserts documents with vectors and model tracking\n\n Args:\n client: OpenSearch client for performing operations\n \"\"\"\n logger.debug(\"[OpenSearchMultimodel][INGESTION] _add_documents_to_vector_store called\")\n # Convert DataFrame to Data if needed using parent's method\n self.ingest_data = self._prepare_ingest_data()\n\n logger.debug(\n f\"[OpenSearchMultimodel][INGESTION] ingest_data type: \"\n f\"{type(self.ingest_data)}, length: {len(self.ingest_data) if self.ingest_data else 0}\"\n )\n logger.debug(\n f\"[OpenSearchMultimodel][INGESTION] ingest_data content: \"\n f\"{self.ingest_data[:2] if self.ingest_data and len(self.ingest_data) > 0 else 'empty'}\"\n )\n\n docs = self.ingest_data or []\n if not docs:\n logger.debug(\"Ingestion complete: No documents provided\")\n return\n\n if not self.embedding:\n msg = \"Embedding handle is required to embed documents.\"\n raise ValueError(msg)\n\n # Normalize embedding to list first\n embeddings_list = self.embedding if isinstance(self.embedding, list) else [self.embedding]\n\n # Filter out None values (fail-safe mode) - do this BEFORE checking if empty\n embeddings_list = [e for e in embeddings_list if e is not None]\n\n # NOW check if we have any valid embeddings left after filtering\n if not embeddings_list:\n logger.warning(\n \"All embeddings returned None (fail-safe mode enabled). Skipping document ingestion.\"\n )\n self.log(\n \"Embedding returned None (fail-safe mode enabled). Skipping document ingestion.\"\n )\n return\n\n logger.debug(\n f\"[OpenSearchMultimodel][INGESTION] Valid embeddings after filtering: {len(embeddings_list)}\"\n )\n self.log(\n f\"[OpenSearchMultimodel][INGESTION] Available embedding models: {len(embeddings_list)}\"\n )\n\n # Select the embedding to use for ingestion\n selected_embedding = None\n embedding_model = None\n\n # If embedding_model_name is specified, find matching embedding\n if (\n hasattr(self, \"embedding_model_name\")\n and self.embedding_model_name\n and self.embedding_model_name.strip()\n ):\n target_model_name = self.embedding_model_name.strip()\n self.log(f\"Looking for embedding model: {target_model_name}\")\n\n for emb_obj in embeddings_list:\n # Check all possible model identifiers (deployment, model, model_id, model_name)\n # Also check available_models list from EmbeddingsWithModels\n possible_names = []\n deployment = getattr(emb_obj, \"deployment\", None)\n model = getattr(emb_obj, \"model\", None)\n model_id = getattr(emb_obj, \"model_id\", None)\n model_name = getattr(emb_obj, \"model_name\", None)\n available_models_attr = getattr(emb_obj, \"available_models\", None)\n\n if deployment:\n possible_names.append(str(deployment))\n if model:\n possible_names.append(str(model))\n if model_id:\n possible_names.append(str(model_id))\n if model_name:\n possible_names.append(str(model_name))\n\n # Also add combined identifier\n if deployment and model and deployment != model:\n possible_names.append(f\"{deployment}:{model}\")\n\n # Add all models from available_models dict\n if available_models_attr and isinstance(available_models_attr, dict):\n possible_names.extend(\n str(model_key).strip()\n for model_key in available_models_attr\n if model_key and str(model_key).strip()\n )\n\n # Match if target matches any of the possible names\n if target_model_name in possible_names:\n # Check if target is in available_models dict - use dedicated instance\n if (\n available_models_attr\n and isinstance(available_models_attr, dict)\n and target_model_name in available_models_attr\n ):\n # Use the dedicated embedding instance from the dict\n selected_embedding = available_models_attr[target_model_name]\n embedding_model = target_model_name\n self.log(\n f\"Found dedicated embedding instance for '{embedding_model}' in available_models dict\"\n )\n else:\n # Traditional identifier match\n selected_embedding = emb_obj\n embedding_model = self._get_embedding_model_name(emb_obj)\n self.log(\n f\"Found matching embedding model: {embedding_model} (matched on: {target_model_name})\"\n )\n break\n\n if not selected_embedding:\n # Build detailed list of available embeddings with all their identifiers\n available_info = []\n for idx, emb in enumerate(embeddings_list):\n emb_type = type(emb).__name__\n identifiers = []\n deployment = getattr(emb, \"deployment\", None)\n model = getattr(emb, \"model\", None)\n model_id = getattr(emb, \"model_id\", None)\n model_name = getattr(emb, \"model_name\", None)\n available_models_attr = getattr(emb, \"available_models\", None)\n\n if deployment:\n identifiers.append(f\"deployment='{deployment}'\")\n if model:\n identifiers.append(f\"model='{model}'\")\n if model_id:\n identifiers.append(f\"model_id='{model_id}'\")\n if model_name:\n identifiers.append(f\"model_name='{model_name}'\")\n\n # Add combined identifier as an option\n if deployment and model and deployment != model:\n identifiers.append(f\"combined='{deployment}:{model}'\")\n\n # Add available_models dict if present\n if available_models_attr and isinstance(available_models_attr, dict):\n identifiers.append(f\"available_models={list(available_models_attr.keys())}\")\n\n available_info.append(\n f\" [{idx}] {emb_type}: {', '.join(identifiers) if identifiers else 'No identifiers'}\"\n )\n\n msg = (\n f\"Embedding model '{target_model_name}' not found in available embeddings.\\n\\n\"\n f\"Available embeddings:\\n\" + \"\\n\".join(available_info) + \"\\n\\n\"\n \"Please set 'embedding_model_name' to one of the identifier values shown above \"\n \"(use the value after the '=' sign, without quotes).\\n\"\n \"For duplicate deployments, use the 'combined' format.\\n\"\n \"Or leave it empty to use the first embedding.\"\n )\n raise ValueError(msg)\n else:\n # Use first embedding if no model name specified\n selected_embedding = embeddings_list[0]\n embedding_model = self._get_embedding_model_name(selected_embedding)\n self.log(f\"No embedding_model_name specified, using first embedding: {embedding_model}\")\n\n dynamic_field_name = get_embedding_field_name(embedding_model)\n\n logger.info(f\"Selected embedding model for ingestion: '{embedding_model}'\")\n self.log(f\"Using embedding model for ingestion: {embedding_model}\")\n self.log(f\"Dynamic vector field: {dynamic_field_name}\")\n\n # Log embedding details for debugging\n if hasattr(selected_embedding, \"deployment\"):\n logger.info(f\"Embedding deployment: {selected_embedding.deployment}\")\n if hasattr(selected_embedding, \"model\"):\n logger.info(f\"Embedding model: {selected_embedding.model}\")\n if hasattr(selected_embedding, \"model_id\"):\n logger.info(f\"Embedding model_id: {selected_embedding.model_id}\")\n if hasattr(selected_embedding, \"dimensions\"):\n logger.info(f\"Embedding dimensions: {selected_embedding.dimensions}\")\n if hasattr(selected_embedding, \"available_models\"):\n logger.info(f\"Embedding available_models: {selected_embedding.available_models}\")\n\n # No model switching needed - each model in available_models has its own dedicated instance\n # The selected_embedding is already configured correctly for the target model\n logger.info(\n f\"Using embedding instance for '{embedding_model}' - pre-configured and ready to use\"\n )\n\n # Extract texts and metadata from documents\n texts = []\n metadatas = []\n # Process docs_metadata table input into a dict\n additional_metadata = {}\n logger.debug(f\"[LF] Docs metadata {self.docs_metadata}\")\n if hasattr(self, \"docs_metadata\") and self.docs_metadata:\n logger.info(f\"[LF] Docs metadata {self.docs_metadata}\")\n if isinstance(self.docs_metadata[-1], Data):\n logger.info(f\"[LF] Docs metadata is a Data object {self.docs_metadata}\")\n self.docs_metadata = self.docs_metadata[-1].data\n logger.info(f\"[LF] Docs metadata is a Data object {self.docs_metadata}\")\n additional_metadata.update(self.docs_metadata)\n else:\n for item in self.docs_metadata:\n if isinstance(item, dict) and \"key\" in item and \"value\" in item:\n additional_metadata[item[\"key\"]] = item[\"value\"]\n # Replace string \"None\" values with actual None\n for key, value in additional_metadata.items():\n if value == \"None\":\n additional_metadata[key] = None\n logger.info(f\"[LF] Additional metadata {additional_metadata}\")\n for doc_obj in docs:\n data_copy = json.loads(doc_obj.model_dump_json())\n text = data_copy.pop(doc_obj.text_key, doc_obj.default_value)\n texts.append(text)\n\n # Merge additional metadata from table input\n data_copy.update(additional_metadata)\n\n metadatas.append(data_copy)\n self.log(metadatas)\n\n # Determine whether the selected embedding is watsonx/IBM. The watsonx\n # SDK ships its own rate-limit machinery (input batching, proactive\n # x-requests-limit-* TokenBucket throttling, and jittered exponential\n # backoff on 429), so we lean on it instead of retrying on top of it.\n # The type-name check also covers watsonx-hosted, non-\"ibm/\" models\n # (e.g. intfloat/multilingual-e5-large).\n is_ibm = (embedding_model and \"ibm\" in str(embedding_model).lower()) or (\n selected_embedding and \"watsonx\" in type(selected_embedding).__name__.lower()\n )\n logger.debug(f\"Is IBM/watsonx embedding: {is_ibm}\")\n\n if is_ibm:\n\n # Hand the full batch to the SDK and let it batch/throttle/retry.\n # Retry attempts and base backoff are tunable via the SDK's own\n # WATSONX_MAX_RETRIES / WATSONX_DELAY_TIME environment variables.\n logger.info(\n f\"Embedding {len(texts)} chunks via watsonx SDK batch (SDK-managed throttle + 429 retry)\"\n )\n try:\n vectors: list[list[float]] = selected_embedding.embed_documents(texts)\n logger.info(f\"Successfully embedded {len(vectors)} chunks via watsonx SDK\")\n except Exception as embed_error:\n _log_watsonx_rate_limit_headers(embed_error)\n logger.error(\n f\"Failed to embed {len(texts)} chunks via watsonx SDK. Error: {embed_error}\",\n )\n raise\n\n else:\n # Non-watsonx providers (OpenAI, Ollama) lack the watsonx SDK's\n # built-in rate-limit handling, so embed per chunk in parallel with\n # a generic rate-limit-aware tenacity retry.\n vectors: list[list[float]] = [None] * len(texts)\n from tenacity import (\n retry,\n retry_if_exception,\n stop_after_attempt,\n wait_exponential,\n )\n\n def is_rate_limit_error(exception: Exception) -> bool:\n \"\"\"Check if exception is a rate limit error (429).\"\"\"\n error_str = str(exception).lower()\n return \"429\" in error_str or \"rate_limit\" in error_str or \"rate limit\" in error_str\n\n def is_other_retryable_error(exception: Exception) -> bool:\n \"\"\"Check if exception is a transient network error worth retrying.\"\"\"\n if is_rate_limit_error(exception):\n return False\n return isinstance(exception, (ConnectionError, TimeoutError, OSError))\n\n # Retry decorator for rate limit errors (longer backoff)\n retry_on_rate_limit = retry(\n retry=retry_if_exception(is_rate_limit_error),\n stop=stop_after_attempt(5),\n wait=wait_exponential(multiplier=2, min=2, max=30),\n reraise=True,\n before_sleep=lambda retry_state: logger.warning(\n f\"Rate limit hit for chunk (attempt {retry_state.attempt_number}/5), \"\n f\"backing off for {retry_state.next_action.sleep:.1f}s\"\n ),\n )\n\n # Retry decorator for other errors (shorter backoff)\n retry_on_other_errors = retry(\n retry=retry_if_exception(is_other_retryable_error),\n stop=stop_after_attempt(3),\n wait=wait_exponential(multiplier=1, min=1, max=8),\n reraise=True,\n before_sleep=lambda retry_state: logger.warning(\n f\"Error embedding chunk (attempt {retry_state.attempt_number}/3), \"\n f\"retrying in {retry_state.next_action.sleep:.1f}s: {retry_state.outcome.exception()}\"\n ),\n )\n\n def embed_chunk_with_retry(chunk_text: str, chunk_idx: int) -> list[float]:\n \"\"\"Embed a single chunk with rate-limit-aware retry logic.\"\"\"\n\n @retry_on_rate_limit\n @retry_on_other_errors\n def _embed(text: str) -> list[float]:\n return selected_embedding.embed_documents([text])[0]\n\n try:\n return _embed(chunk_text)\n except Exception as e:\n logger.error(\n f\"Failed to embed chunk {chunk_idx} after all retries: {e}\",\n error=str(e),\n )\n raise\n\n max_workers = min(max(len(texts), 1), 8)\n logger.debug(f\"Using parallel processing with {max_workers} workers\")\n\n with ThreadPoolExecutor(max_workers=max_workers) as executor:\n futures = {\n executor.submit(embed_chunk_with_retry, chunk, idx): idx\n for idx, chunk in enumerate(texts)\n }\n for future in as_completed(futures):\n idx = futures[future]\n vectors[idx] = future.result()\n\n if not vectors:\n self.log(f\"No vectors generated from documents for model {embedding_model}.\")\n return\n\n # Get vector dimension for mapping\n dim = len(vectors[0]) if vectors else 768 # default fallback\n use_openrag_ingest_callback = self._openrag_ingest_callback_config() is not None\n\n is_aoss = False\n mapping: dict | None = None\n\n engine = getattr(self, \"engine\", \"jvector\")\n\n if use_openrag_ingest_callback:\n self.log(\"Using OpenRAG backend ingest callback; skipping direct OpenSearch writes.\")\n else:\n # Check for AOSS\n auth_kwargs = self._build_auth_kwargs()\n is_aoss = self._is_aoss_enabled(auth_kwargs.get(\"http_auth\"))\n\n # Validate engine with AOSS\n self._validate_aoss_with_engines(is_aoss=is_aoss, engine=engine)\n\n # Create mapping with proper KNN settings\n space_type = getattr(self, \"space_type\", \"l2\")\n ef_construction = getattr(self, \"ef_construction\", 512)\n m = getattr(self, \"m\", 16)\n\n mapping = self._default_text_mapping(\n dim=dim,\n engine=engine,\n space_type=space_type,\n ef_construction=ef_construction,\n m=m,\n vector_field=dynamic_field_name, # Use dynamic field name\n )\n\n # Ensure index exists with baseline mapping (index.knn: true is required for vector search)\n index_exists = True\n try:\n index_exists = bool(client.indices.exists(index=self.index_name))\n except OpenSearchException as exists_error:\n self._log_index_admin_skip(\"indices.exists\", exists_error)\n\n try:\n if not index_exists:\n self.log(f\"Creating index '{self.index_name}' with base mapping\")\n client.indices.create(index=self.index_name, body=mapping)\n except RequestError as creation_error:\n if creation_error.error == \"resource_already_exists_exception\":\n pass # Index was created concurrently\n else:\n error_msg = str(creation_error).lower()\n if \"invalid engine\" in error_msg or \"illegal_argument\" in error_msg:\n if \"jvector\" in error_msg:\n msg = (\n \"The 'jvector' engine is not available in your OpenSearch installation. \"\n \"Use 'nmslib' or 'faiss' for standard OpenSearch, or upgrade to 2.9+.\"\n )\n raise ValueError(msg) from creation_error\n if \"index.knn\" in error_msg:\n msg = (\n \"The index has index.knn: false. Delete the existing index and let the \"\n \"component recreate it, or create a new index with a different name.\"\n )\n raise ValueError(msg) from creation_error\n logger.warning(f\"Failed to create index '{self.index_name}': {creation_error}\")\n raise\n\n # Ensure the dynamic field exists in the index\n self._ensure_embedding_field_mapping(\n client=client,\n index_name=self.index_name,\n field_name=dynamic_field_name,\n dim=dim,\n engine=engine,\n space_type=space_type,\n ef_construction=ef_construction,\n m=m,\n )\n\n self.log(\n f\"Indexing {len(texts)} documents into '{self.index_name}' with model '{embedding_model}'...\"\n )\n logger.info(f\"Will store embeddings in field: {dynamic_field_name}\")\n logger.info(f\"Will tag documents with embedding_model: {embedding_model}\")\n\n # Use the bulk ingestion with model tracking\n return_ids = self._bulk_ingest_embeddings(\n client=client,\n index_name=self.index_name,\n embeddings=vectors,\n texts=texts,\n metadatas=metadatas,\n vector_field=dynamic_field_name, # Use dynamic field name\n text_field=\"text\",\n embedding_model=embedding_model, # Track the model\n mapping=mapping,\n is_aoss=is_aoss,\n )\n self.log(metadatas)\n\n logger.info(\n f\"Ingestion complete: Successfully indexed {len(return_ids)} documents with model '{embedding_model}'\"\n )\n self.log(f\"Successfully indexed {len(return_ids)} documents with model {embedding_model}.\")\n\n # ---------- helpers for filters ----------\n def _is_placeholder_term(self, term_obj: dict) -> bool:\n # term_obj like {\"filename\": \"__IMPOSSIBLE_VALUE__\"}\n return any(v == \"__IMPOSSIBLE_VALUE__\" for v in term_obj.values())\n\n def _coerce_filter_clauses(self, filter_obj: dict | None) -> list[dict]:\n \"\"\"Convert filter expressions into OpenSearch-compatible filter clauses.\n\n This method accepts two filter formats and converts them to standardized\n OpenSearch query clauses:\n\n Format A - Explicit filters:\n {\"filter\": [{\"term\": {\"field\": \"value\"}}, {\"terms\": {\"field\": [\"val1\", \"val2\"]}}],\n \"limit\": 10, \"score_threshold\": 1.5}\n\n Format B - Context-style mapping:\n {\"data_sources\": [\"file1.pdf\"], \"document_types\": [\"pdf\"], \"owners\": [\"user1\"]}\n\n Args:\n filter_obj: Filter configuration dictionary or None\n\n Returns:\n List of OpenSearch filter clauses (term/terms objects)\n Placeholder values with \"__IMPOSSIBLE_VALUE__\" are ignored\n \"\"\"\n if not filter_obj:\n return []\n\n # If it is a string, try to parse it once\n if isinstance(filter_obj, str):\n try:\n filter_obj = json.loads(filter_obj)\n except json.JSONDecodeError:\n # Not valid JSON - treat as no filters\n return []\n\n # Case A: already an explicit list/dict under \"filter\"\n if \"filter\" in filter_obj:\n raw = filter_obj[\"filter\"]\n if isinstance(raw, dict):\n raw = [raw]\n explicit_clauses: list[dict] = []\n for f in raw or []:\n if (\n \"term\" in f\n and isinstance(f[\"term\"], dict)\n and not self._is_placeholder_term(f[\"term\"])\n ):\n explicit_clauses.append(f)\n elif \"terms\" in f and isinstance(f[\"terms\"], dict):\n field, vals = next(iter(f[\"terms\"].items()))\n if isinstance(vals, list) and len(vals) > 0:\n explicit_clauses.append(f)\n return explicit_clauses\n\n # Case B: convert context-style maps into clauses\n field_mapping = {\n \"data_sources\": \"filename\",\n \"document_types\": \"mimetype\",\n \"owners\": \"owner\",\n }\n context_clauses: list[dict] = []\n for k, values in filter_obj.items():\n if not isinstance(values, list):\n continue\n field = field_mapping.get(k, k)\n if len(values) == 0:\n # Match-nothing placeholder (kept to mirror your tool semantics)\n context_clauses.append({\"term\": {field: \"__IMPOSSIBLE_VALUE__\"}})\n elif len(values) == 1:\n if values[0] != \"__IMPOSSIBLE_VALUE__\":\n context_clauses.append({\"term\": {field: values[0]}})\n else:\n context_clauses.append({\"terms\": {field: values}})\n return context_clauses\n\n\n def _parse_filter_expression(self) -> dict | None:\n \"\"\"Parse and validate optional filter_expression JSON.\n\n Returns:\n Parsed JSON object as a dict, or None when unset/blank.\n\n Raises:\n ValueError: If JSON is invalid or does not decode to an object.\n \"\"\"\n filter_expression = getattr(self, \"filter_expression\", \"\")\n if not isinstance(filter_expression, str) or not filter_expression.strip():\n return None\n try:\n filter_obj = json.loads(filter_expression)\n except json.JSONDecodeError as e:\n msg = f\"Invalid filter_expression JSON: {e}\"\n raise ValueError(msg) from e\n\n if not isinstance(filter_obj, dict):\n msg = \"Invalid filter_expression JSON type: expected a JSON object.\"\n raise TypeError(msg)\n return filter_obj\n\n def _resolve_limit(self, filter_obj: dict | None, default_limit: int | None) -> int | None:\n \"\"\"Resolve an integer result limit from filter settings.\"\"\"\n if not filter_obj:\n return default_limit\n raw_limit = filter_obj.get(\"limit\", default_limit)\n if raw_limit is None:\n return None\n if isinstance(raw_limit, bool):\n msg = \"Invalid filter_expression.limit: expected a positive integer.\"\n raise TypeError(msg)\n try:\n limit = int(raw_limit)\n except (TypeError, ValueError) as e:\n msg = \"Invalid filter_expression.limit: expected a positive integer.\"\n raise ValueError(msg) from e\n if limit <= 0:\n msg = \"Invalid filter_expression.limit: expected a positive integer.\"\n raise ValueError(msg)\n return limit\n\n def _resolve_score_threshold(self, filter_obj: dict | None) -> float | None:\n \"\"\"Resolve optional positive min score from filter settings.\"\"\"\n if not filter_obj:\n return None\n score_threshold = filter_obj.get(\"score_threshold\")\n if score_threshold is None:\n score_threshold = filter_obj.get(\"scoreThreshold\")\n if not isinstance(score_threshold, (int, float)) or score_threshold <= 0:\n return None\n return float(score_threshold)\n\n def _detect_available_models(self, client: OpenSearch, filter_clauses: list[dict] | None = None) -> list[str]:\n\n \"\"\"Detect which embedding models have documents in the index.\n\n Uses aggregation to find all unique embedding_model values, optionally\n filtered to only documents matching the user's filter criteria.\n\n Args:\n client: OpenSearch client instance\n filter_clauses: Optional filter clauses to scope model detection\n\n Returns:\n List of embedding model names found in the index\n \"\"\"\n try:\n agg_query = {\n \"size\": 0,\n \"aggs\": {\"embedding_models\": {\"terms\": {\"field\": \"embedding_model\", \"size\": 10}}},\n }\n\n # Apply filters to model detection if any exist\n if filter_clauses:\n agg_query[\"query\"] = {\"bool\": {\"filter\": filter_clauses}}\n\n logger.debug(f\"Model detection query: {agg_query}\")\n result = client.search(\n index=self.index_name,\n body=agg_query,\n params={\"terminate_after\": 0},\n )\n buckets = result.get(\"aggregations\", {}).get(\"embedding_models\", {}).get(\"buckets\", [])\n models = [b[\"key\"] for b in buckets if b[\"key\"]]\n\n # Log detailed bucket info for debugging\n logger.info(\n f\"Detected embedding models in corpus: {models}\"\n + (f\" (with {len(filter_clauses)} filters)\" if filter_clauses else \"\")\n )\n if not models:\n total_hits = result.get(\"hits\", {}).get(\"total\", {})\n total_count = (\n total_hits.get(\"value\", 0) if isinstance(total_hits, dict) else total_hits\n )\n logger.warning(\n f\"No embedding_model values found in index '{self.index_name}'. \"\n f\"Total docs in index: {total_count}. \"\n f\"This may indicate documents were indexed without the embedding_model field.\"\n )\n except (OpenSearchException, KeyError, ValueError) as e:\n logger.warning(f\"Failed to detect embedding models: {e}\")\n # Fallback to current model\n fallback_model = self._get_embedding_model_name()\n logger.info(f\"Using fallback model: {fallback_model}\")\n return [fallback_model]\n else:\n return models\n\n def _get_index_properties(self, client: OpenSearch) -> dict[str, Any] | None:\n \"\"\"Retrieve flattened mapping properties for the current index.\"\"\"\n try:\n mapping = client.indices.get_mapping(index=self.index_name)\n except OpenSearchException as e:\n logger.warning(\n f\"Failed to fetch mapping for index '{self.index_name}': {e}. Proceeding without mapping metadata.\"\n )\n return None\n\n properties: dict[str, Any] = {}\n for index_data in mapping.values():\n props = index_data.get(\"mappings\", {}).get(\"properties\", {})\n if isinstance(props, dict):\n properties.update(props)\n return properties\n\n def _is_knn_vector_field(self, properties: dict[str, Any] | None, field_name: str) -> bool:\n \"\"\"Check whether the field is mapped as a knn_vector.\"\"\"\n if not field_name:\n return False\n if properties is None:\n logger.warning(\n f\"Mapping metadata unavailable; assuming field '{field_name}' is usable.\"\n )\n return True\n field_def = properties.get(field_name)\n if not isinstance(field_def, dict):\n return False\n if field_def.get(\"type\") == \"knn_vector\":\n return True\n\n nested_props = field_def.get(\"properties\")\n return bool(isinstance(nested_props, dict) and nested_props.get(\"type\") == \"knn_vector\")\n\n def _get_field_dimension(\n self, properties: dict[str, Any] | None, field_name: str\n ) -> int | None:\n \"\"\"Get the dimension of a knn_vector field from the index mapping.\n\n Args:\n properties: Index properties from mapping\n field_name: Name of the vector field\n\n Returns:\n Dimension of the field, or None if not found\n \"\"\"\n if not field_name or properties is None:\n return None\n\n field_def = properties.get(field_name)\n if not isinstance(field_def, dict):\n return None\n\n # Check direct knn_vector field\n if field_def.get(\"type\") == \"knn_vector\":\n return field_def.get(\"dimension\")\n\n # Check nested properties\n nested_props = field_def.get(\"properties\")\n if isinstance(nested_props, dict) and nested_props.get(\"type\") == \"knn_vector\":\n return nested_props.get(\"dimension\")\n\n return None\n\n def _get_filename_agg_field(self, index_properties: dict[str, Any] | None) -> str:\n \"\"\"Choose the appropriate field for filename aggregations.\"\"\"\n if not index_properties:\n return \"filename.keyword\"\n\n filename_def = index_properties.get(\"filename\")\n if not isinstance(filename_def, dict):\n return \"filename.keyword\"\n\n field_type = filename_def.get(\"type\")\n fields_def = filename_def.get(\"fields\", {})\n\n # Top-level keyword with no subfields\n if field_type == \"keyword\" and not isinstance(fields_def, dict):\n return \"filename\"\n\n # Text field with keyword subfield\n if isinstance(fields_def, dict) and \"keyword\" in fields_def:\n return \"filename.keyword\"\n\n # Fallback: aggregate on filename directly\n return \"filename\"\n\n # ---------- search (multi-model hybrid) ----------\n def search(self, query: str | None = None) -> list[dict[str, Any]]:\n \"\"\"Perform multi-model hybrid search combining multiple vector similarities and keyword matching.\n\n This method executes a sophisticated search that:\n 1. Auto-detects all embedding models present in the index\n 2. Generates query embeddings for ALL detected models in parallel\n 3. Combines multiple KNN queries using dis_max (picks best match)\n 4. Adds keyword search with fuzzy matching (30% weight)\n 5. Applies optional filtering and score thresholds\n 6. Returns aggregations for faceted search\n\n Search weights:\n - Semantic search (dis_max across all models): 70%\n - Keyword search: 30%\n\n Args:\n query: Search query string (used for both vector embedding and keyword search)\n\n Returns:\n List of search results with page_content, metadata, and relevance scores\n\n Raises:\n ValueError: If embedding component is not provided or filter JSON is invalid\n \"\"\"\n logger.info(self.ingest_data)\n client = self.build_client()\n q = (query or \"\").strip()\n\n # Parse optional filter expression\n filter_obj = self._parse_filter_expression()\n\n if not self.embedding:\n msg = \"Embedding is required to run hybrid search (KNN + keyword).\"\n raise ValueError(msg)\n\n # Check if embedding is None (fail-safe mode)\n if self.embedding is None or (\n isinstance(self.embedding, list) and all(e is None for e in self.embedding)\n ):\n logger.error(\"Embedding returned None (fail-safe mode enabled). Cannot perform search.\")\n return []\n\n # Build filter clauses first so we can use them in model detection\n filter_clauses = self._coerce_filter_clauses(filter_obj)\n\n # Detect available embedding models in the index (scoped by filters)\n available_models = self._detect_available_models(client, filter_clauses)\n\n if not available_models:\n logger.warning(\"No embedding models found in index, using current model\")\n available_models = [self._get_embedding_model_name()]\n\n # Generate embeddings for ALL detected models\n query_embeddings = {}\n\n # Normalize embedding to list\n embeddings_list = self.embedding if isinstance(self.embedding, list) else [self.embedding]\n # Filter out None values (fail-safe mode)\n embeddings_list = [e for e in embeddings_list if e is not None]\n\n if not embeddings_list:\n logger.error(\n \"No valid embeddings available after filtering None values (fail-safe mode). Cannot perform search.\"\n )\n return []\n\n # Create a comprehensive map of model names to embedding objects\n # Check all possible identifiers (deployment, model, model_id, model_name)\n # Also leverage available_models list from EmbeddingsWithModels\n # Handle duplicate identifiers by creating combined keys\n embedding_by_model = {}\n identifier_conflicts = {} # Track which identifiers have conflicts\n\n for idx, emb_obj in enumerate(embeddings_list):\n # Get all possible identifiers for this embedding\n identifiers = []\n deployment = getattr(emb_obj, \"deployment\", None)\n model = getattr(emb_obj, \"model\", None)\n model_id = getattr(emb_obj, \"model_id\", None)\n model_name = getattr(emb_obj, \"model_name\", None)\n dimensions = getattr(emb_obj, \"dimensions\", None)\n available_models_attr = getattr(emb_obj, \"available_models\", None)\n\n logger.info(\n f\"Embedding object {idx}: deployment={deployment}, model={model}, \"\n f\"model_id={model_id}, model_name={model_name}, dimensions={dimensions}, \"\n f\"available_models={available_models_attr}\"\n )\n\n # If this embedding has available_models dict, map all models to their dedicated instances\n if available_models_attr and isinstance(available_models_attr, dict):\n logger.info(\n f\"Embedding object {idx} provides {len(available_models_attr)} models via available_models dict\"\n )\n for model_name_key, dedicated_embedding in available_models_attr.items():\n if model_name_key and str(model_name_key).strip():\n model_str = str(model_name_key).strip()\n if model_str not in embedding_by_model:\n # Use the dedicated embedding instance from the dict\n embedding_by_model[model_str] = dedicated_embedding\n logger.info(\n f\"Mapped available model '{model_str}' to dedicated embedding instance\"\n )\n else:\n # Conflict detected - track it\n if model_str not in identifier_conflicts:\n identifier_conflicts[model_str] = [embedding_by_model[model_str]]\n identifier_conflicts[model_str].append(dedicated_embedding)\n logger.warning(\n f\"Available model '{model_str}' has conflict - used by multiple embeddings\"\n )\n\n # Also map traditional identifiers (for backward compatibility)\n if deployment:\n identifiers.append(str(deployment))\n if model:\n identifiers.append(str(model))\n if model_id:\n identifiers.append(str(model_id))\n if model_name:\n identifiers.append(str(model_name))\n\n # Map all identifiers to this embedding object\n for identifier in identifiers:\n if identifier not in embedding_by_model:\n embedding_by_model[identifier] = emb_obj\n logger.info(f\"Mapped identifier '{identifier}' to embedding object {idx}\")\n else:\n # Conflict detected - track it\n if identifier not in identifier_conflicts:\n identifier_conflicts[identifier] = [embedding_by_model[identifier]]\n identifier_conflicts[identifier].append(emb_obj)\n logger.warning(\n f\"Identifier '{identifier}' has conflict - used by multiple embeddings\"\n )\n\n # For embeddings with model+deployment, create combined identifier\n # This helps when deployment is the same but model differs\n if deployment and model and deployment != model:\n combined_id = f\"{deployment}:{model}\"\n if combined_id not in embedding_by_model:\n embedding_by_model[combined_id] = emb_obj\n logger.info(\n f\"Created combined identifier '{combined_id}' for embedding object {idx}\"\n )\n\n # Log conflicts\n if identifier_conflicts:\n logger.warning(\n f\"Found {len(identifier_conflicts)} conflicting identifiers. \"\n f\"Consider using combined format 'deployment:model' or specifying unique model names.\"\n )\n for conflict_id, emb_list in identifier_conflicts.items():\n logger.warning(\n f\" Conflict on '{conflict_id}': {len(emb_list)} embeddings use this identifier\"\n )\n\n logger.info(f\"Generating embeddings for {len(available_models)} models in index\")\n logger.info(f\"Available embedding identifiers: {list(embedding_by_model.keys())}\")\n self.log(f\"[SEARCH] Models detected in index: {available_models}\")\n self.log(f\"[SEARCH] Available embedding identifiers: {list(embedding_by_model.keys())}\")\n\n # Track matching status for debugging\n matched_models = []\n unmatched_models = []\n\n for model_name in available_models:\n try:\n # Check if we have an embedding object for this model\n if model_name in embedding_by_model:\n # Use the matching embedding object directly\n emb_obj = embedding_by_model[model_name]\n emb_deployment = getattr(emb_obj, \"deployment\", None)\n emb_model = getattr(emb_obj, \"model\", None)\n emb_model_id = getattr(emb_obj, \"model_id\", None)\n emb_dimensions = getattr(emb_obj, \"dimensions\", None)\n emb_available_models = getattr(emb_obj, \"available_models\", None)\n\n logger.info(\n f\"Using embedding object for model '{model_name}': \"\n f\"deployment={emb_deployment}, model={emb_model}, model_id={emb_model_id}, \"\n f\"dimensions={emb_dimensions}\"\n )\n\n # Check if this is a dedicated instance from available_models dict\n if emb_available_models and isinstance(emb_available_models, dict):\n logger.info(\n f\"Model '{model_name}' using dedicated instance from available_models dict \"\n f\"(pre-configured with correct model and dimensions)\"\n )\n\n # Use the embedding instance directly - no model switching needed!\n vec = emb_obj.embed_query(q)\n query_embeddings[model_name] = vec\n matched_models.append(model_name)\n logger.info(\n f\"Generated embedding for model: {model_name} (actual dimensions: {len(vec)})\"\n )\n self.log(f\"[MATCH] Model '{model_name}' - generated {len(vec)}-dim embedding\")\n else:\n # No matching embedding found for this model\n unmatched_models.append(model_name)\n logger.warning(\n f\"No matching embedding found for model '{model_name}'. \"\n f\"This model will be skipped. Available identifiers: {list(embedding_by_model.keys())}\"\n )\n self.log(\n f\"[NO MATCH] Model '{model_name}' - available: {list(embedding_by_model.keys())}\"\n )\n except (\n RuntimeError,\n ValueError,\n ConnectionError,\n TimeoutError,\n AttributeError,\n KeyError,\n ) as e:\n logger.warning(f\"Failed to generate embedding for {model_name}: {e}\")\n self.log(f\"[ERROR] Embedding generation failed for '{model_name}': {e}\")\n\n # Log summary of model matching\n logger.info(\n f\"Model matching summary: {len(matched_models)} matched, {len(unmatched_models)} unmatched\"\n )\n self.log(\n f\"[SUMMARY] Model matching: {len(matched_models)} matched, {len(unmatched_models)} unmatched\"\n )\n if unmatched_models:\n self.log(f\"[WARN] Unmatched models in index: {unmatched_models}\")\n\n if not query_embeddings:\n msg = (\n f\"Failed to generate embeddings for any model. \"\n f\"Index has models: {available_models}, but no matching embedding objects found. \"\n f\"Available embedding identifiers: {list(embedding_by_model.keys())}\"\n )\n self.log(f\"[FAIL] Search failed: {msg}\")\n raise ValueError(msg)\n\n index_properties = self._get_index_properties(client)\n legacy_vector_field = getattr(self, \"vector_field\", \"chunk_embedding\")\n\n # Build KNN queries for each model\n embedding_fields: list[str] = []\n knn_queries_with_candidates = []\n knn_queries_without_candidates = []\n\n raw_num_candidates = getattr(self, \"num_candidates\", 1000)\n try:\n num_candidates = int(raw_num_candidates) if raw_num_candidates is not None else 0\n except (TypeError, ValueError):\n num_candidates = 0\n use_num_candidates = num_candidates > 0\n\n for model_name, embedding_vector in query_embeddings.items():\n field_name = get_embedding_field_name(model_name)\n selected_field = field_name\n vector_dim = len(embedding_vector)\n\n # Only use the expected dynamic field - no legacy fallback\n # This prevents dimension mismatches between models\n if not self._is_knn_vector_field(index_properties, selected_field):\n logger.warning(\n f\"Skipping model {model_name}: field '{field_name}' is not mapped as knn_vector. \"\n f\"Documents must be indexed with this embedding model before querying.\"\n )\n self.log(\n f\"[SKIP] Field '{selected_field}' not a knn_vector - skipping model '{model_name}'\"\n )\n continue\n\n # Validate vector dimensions match the field dimensions\n field_dim = self._get_field_dimension(index_properties, selected_field)\n if field_dim is not None and field_dim != vector_dim:\n logger.error(\n f\"Dimension mismatch for model '{model_name}': \"\n f\"Query vector has {vector_dim} dimensions but field '{selected_field}' expects {field_dim}. \"\n f\"Skipping this model to prevent search errors.\"\n )\n self.log(\n f\"[DIM MISMATCH] Model '{model_name}': query={vector_dim} vs field={field_dim} - skipping\"\n )\n continue\n\n logger.info(\n f\"Adding KNN query for model '{model_name}': field='{selected_field}', \"\n f\"query_dims={vector_dim}, field_dims={field_dim or 'unknown'}\"\n )\n embedding_fields.append(selected_field)\n\n base_query = {\n \"knn\": {\n selected_field: {\n \"vector\": embedding_vector,\n \"k\": 50,\n }\n }\n }\n\n if use_num_candidates:\n query_with_candidates = copy.deepcopy(base_query)\n query_with_candidates[\"knn\"][selected_field][\"num_candidates\"] = num_candidates\n else:\n query_with_candidates = base_query\n\n knn_queries_with_candidates.append(query_with_candidates)\n knn_queries_without_candidates.append(base_query)\n\n if not knn_queries_with_candidates:\n # No valid fields found - this can happen when:\n # 1. Index is empty (no documents yet)\n # 2. Embedding model has changed and field doesn't exist yet\n # Return empty results instead of failing\n logger.warning(\n \"No valid knn_vector fields found for embedding models. \"\n \"This may indicate an empty index or missing field mappings. \"\n \"Returning empty search results.\"\n )\n self.log(\n f\"[WARN] No valid KNN queries could be built. \"\n f\"Query embeddings generated: {list(query_embeddings.keys())}, \"\n f\"but no matching knn_vector fields found in index.\"\n )\n return []\n\n # Build exists filter - document must have at least one embedding field\n exists_any_embedding = {\n \"bool\": {\n \"should\": [{\"exists\": {\"field\": f}} for f in set(embedding_fields)],\n \"minimum_should_match\": 1,\n }\n }\n\n # Combine user filters with exists filter\n all_filters = [*filter_clauses, exists_any_embedding]\n\n # Get limit and score threshold\n limit = self._resolve_limit(filter_obj, default_limit=self.number_of_results)\n score_threshold = self._resolve_score_threshold(filter_obj)\n\n # Determine the best aggregation field for filename based on index mapping\n filename_agg_field = self._get_filename_agg_field(index_properties)\n\n # Build multi-model hybrid query\n body = {\n \"query\": {\n \"bool\": {\n \"should\": [\n {\n \"dis_max\": {\n \"tie_breaker\": 0.0, # Take only the best match, no blending\n \"boost\": 0.7, # 70% weight for semantic search\n \"queries\": knn_queries_with_candidates,\n }\n },\n {\n \"multi_match\": {\n \"query\": q,\n \"fields\": [\"text^2\", \"filename^1.5\"],\n \"type\": \"best_fields\",\n \"fuzziness\": \"AUTO\",\n \"boost\": 0.3, # 30% weight for keyword search\n }\n },\n ],\n \"minimum_should_match\": 1,\n \"filter\": all_filters,\n }\n },\n \"aggs\": {\n \"data_sources\": {\"terms\": {\"field\": filename_agg_field, \"size\": 20}},\n \"document_types\": {\"terms\": {\"field\": \"mimetype\", \"size\": 10}},\n \"owners\": {\"terms\": {\"field\": \"owner\", \"size\": 10}},\n \"embedding_models\": {\"terms\": {\"field\": \"embedding_model\", \"size\": 10}},\n },\n \"_source\": [\n \"filename\",\n \"mimetype\",\n \"page\",\n \"text\",\n \"source_url\",\n \"owner\",\n \"embedding_model\",\n \"parser\",\n \"chunk_size\",\n \"chunk_overlap\",\n \"allowed_users\",\n \"allowed_groups\",\n \"allowed_principals\",\n ],\n \"size\": limit,\n }\n\n if score_threshold is not None:\n body[\"min_score\"] = score_threshold\n\n logger.info(\n f\"Executing multi-model hybrid search with {len(knn_queries_with_candidates)} embedding models: \"\n f\"{list(query_embeddings.keys())}\"\n )\n self.log(\n f\"[EXEC] Executing search with {len(knn_queries_with_candidates)} KNN queries, limit={limit}\"\n )\n self.log(f\"[EXEC] Embedding models used: {list(query_embeddings.keys())}\")\n self.log(f\"[EXEC] KNN fields being queried: {embedding_fields}\")\n\n try:\n resp = client.search(index=self.index_name, body=body, params={\"terminate_after\": 0})\n except RequestError as e:\n error_message = str(e)\n lowered = error_message.lower()\n if use_num_candidates and \"num_candidates\" in lowered:\n logger.warning(\n \"Retrying search without num_candidates parameter due to cluster capabilities\",\n error=error_message,\n )\n fallback_body = copy.deepcopy(body)\n try:\n fallback_body[\"query\"][\"bool\"][\"should\"][0][\"dis_max\"][\"queries\"] = (\n knn_queries_without_candidates\n )\n except (KeyError, IndexError, TypeError) as inner_err:\n raise e from inner_err\n resp = client.search(\n index=self.index_name,\n body=fallback_body,\n params={\"terminate_after\": 0},\n )\n elif \"knn_vector\" in lowered or (\"field\" in lowered and \"knn\" in lowered):\n fallback_vector = next(iter(query_embeddings.values()), None)\n if fallback_vector is None:\n raise\n fallback_field = legacy_vector_field or \"chunk_embedding\"\n logger.warning(\n \"KNN search failed for dynamic fields; falling back to legacy field '%s'.\",\n fallback_field,\n )\n fallback_body = copy.deepcopy(body)\n fallback_body[\"query\"][\"bool\"][\"filter\"] = filter_clauses\n knn_fallback = {\n \"knn\": {\n fallback_field: {\n \"vector\": fallback_vector,\n \"k\": 50,\n }\n }\n }\n if use_num_candidates:\n knn_fallback[\"knn\"][fallback_field][\"num_candidates\"] = num_candidates\n fallback_body[\"query\"][\"bool\"][\"should\"][0][\"dis_max\"][\"queries\"] = [knn_fallback]\n resp = client.search(\n index=self.index_name,\n body=fallback_body,\n params={\"terminate_after\": 0},\n )\n else:\n raise\n hits = resp.get(\"hits\", {}).get(\"hits\", [])\n\n logger.info(f\"Found {len(hits)} results\")\n self.log(f\"[RESULT] Search complete: {len(hits)} results found\")\n\n if len(hits) == 0:\n self.log(\n f\"[EMPTY] Debug info: \"\n f\"models_in_index={available_models}, \"\n f\"matched_models={matched_models}, \"\n f\"knn_fields={embedding_fields}, \"\n f\"filters={len(filter_clauses)} clauses\"\n )\n\n return [\n {\n \"page_content\": fence_untrusted_text(hit[\"_source\"].get(\"text\", \"\")),\n \"metadata\": {\n **{k: v for k, v in hit[\"_source\"].items() if k != \"text\"},\n \"chunk_id\": hit.get(\"_id\"),\n \"id\": hit.get(\"_id\"),\n \"score\": hit.get(\"_score\"),\n },\n \"score\": hit.get(\"_score\"),\n }\n for hit in hits\n ]\n\n def search_documents(self) -> list[Data]:\n\n \"\"\"Search documents and return results as a list of Data objects.\n\n This is the main interface method that performs the multi-model search using the\n configured search_query and returns results in a format that downstream Parser\n components and tool wrappers can consume directly without DataFrame string truncation.\n\n Always builds the vector store (triggering ingestion if needed), then performs\n search only if a query is provided.\n\n Returns:\n List containing search results with text and metadata\n\n Raises:\n Exception: If search operation fails\n \"\"\"\n\n try:\n # Always build/cache the vector store to ensure ingestion happens\n logger.info(f\"Search query: {self.search_query}\")\n if self._cached_vector_store is None:\n self.build_vector_store()\n\n # Only perform search if query is provided\n search_query = (self.search_query or \"\").strip()\n if not search_query:\n self.log(\"No search query provided - ingestion completed, returning empty results\")\n\n return []\n\n # Perform search with the provided query\n raw = self.search(search_query)\n raw_list = [Data(text=hit[\"page_content\"], **hit[\"metadata\"]) for hit in raw]\n return raw_list\n\n except Exception as e:\n self.log(f\"search_documents error: {e}\")\n raise\n\n # -------- dynamic UI handling (auth switch) --------\n async def update_build_config(\n self, build_config: dict, field_value: str, field_name: str | None = None\n ) -> dict:\n \"\"\"Dynamically update component configuration based on field changes.\n\n This method handles real-time UI updates, particularly for authentication\n mode changes that show/hide relevant input fields.\n\n Args:\n build_config: Current component configuration\n field_value: New value for the changed field\n field_name: Name of the field that changed\n\n Returns:\n Updated build configuration with appropriate field visibility\n \"\"\"\n try:\n if field_name == \"auth_mode\":\n mode = (field_value or \"basic\").strip().lower()\n is_basic = mode == \"basic\"\n is_jwt = mode == \"jwt\"\n is_openrag = mode == \"openrag\"\n\n build_config[\"username\"][\"show\"] = is_basic\n build_config[\"password\"][\"show\"] = is_basic\n\n build_config[\"jwt_token\"][\"show\"] = is_jwt\n build_config[\"jwt_header\"][\"show\"] = is_jwt\n build_config[\"bearer_prefix\"][\"show\"] = is_jwt\n\n build_config[\"username\"][\"required\"] = is_basic\n build_config[\"password\"][\"required\"] = is_basic\n\n # build_config[\"jwt_token\"][\"required\"] = is_jwt\n build_config[\"jwt_header\"][\"required\"] = is_jwt\n build_config[\"bearer_prefix\"][\"required\"] = False\n\n # In 'openrag' mode, expose the OPENRAG_* fields up front\n # since they are the only credentials required.\n for openrag_field in (\n \"openrag_ingest_url\",\n \"openrag_ingest_token\",\n \"openrag_ingest_run_id\",\n \"openrag_ingest_batch_size\",\n ):\n if openrag_field in build_config:\n build_config[openrag_field][\"advanced\"] = not is_openrag\n build_config[openrag_field][\"required\"] = (\n is_openrag and openrag_field != \"openrag_ingest_batch_size\"\n )\n\n if is_basic or is_openrag:\n build_config[\"jwt_token\"][\"value\"] = \"\"\n\n return build_config\n\n except (KeyError, ValueError) as e:\n self.log(f\"update_build_config error: {e}\")\n\n return build_config\n"
+ "tool_mode": false,
+ "trace_as_metadata": true,
+ "track_in_telemetry": false,
+ "type": "str",
+ "value": "Authorization"
},
- "docs_metadata": {
- "_input_type": "TableInput",
+ "jwt_token": {
+ "_input_type": "SecretStrInput",
"advanced": false,
"api_editable": false,
- "display_name": "Document Metadata",
+ "display_name": "JWT Token",
"dynamic": false,
- "info": "Additional metadata key-value pairs to be added to all ingested documents. Useful for tagging documents with source information, categories, or other custom attributes.",
- "input_types": [
- "Data",
- "JSON"
- ],
- "is_list": true,
+ "info": "Valid JSON Web Token for authentication. Will be sent in the Authorization header (with optional 'Bearer ' prefix).",
+ "input_types": [],
+ "load_from_db": true,
+ "name": "jwt_token",
+ "override_skip": false,
+ "password": true,
+ "placeholder": "",
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "track_in_telemetry": false,
+ "type": "str",
+ "value": "JWT"
+ },
+ "m": {
+ "_input_type": "IntInput",
+ "advanced": true,
+ "api_editable": false,
+ "display_name": "M Parameter",
+ "dynamic": false,
+ "info": "Number of bidirectional connections for each vector in the HNSW graph. Higher values improve search quality but increase memory usage and indexing time.",
+ "list": false,
"list_add_label": "Add More",
- "name": "docs_metadata",
+ "name": "m",
+ "override_skip": false,
+ "placeholder": "",
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "tool_mode": false,
+ "trace_as_metadata": true,
+ "track_in_telemetry": true,
+ "type": "int",
+ "value": 16
+ },
+ "max_retries": {
+ "_input_type": "StrInput",
+ "advanced": true,
+ "api_editable": false,
+ "display_name": "Max Retries",
+ "dynamic": false,
+ "info": "Number of retries for failed connections before raising an error.",
+ "list": false,
+ "list_add_label": "Add More",
+ "load_from_db": false,
+ "name": "max_retries",
+ "override_skip": false,
+ "placeholder": "",
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "tool_mode": false,
+ "trace_as_metadata": true,
+ "track_in_telemetry": false,
+ "type": "str",
+ "value": "3"
+ },
+ "num_candidates": {
+ "_input_type": "IntInput",
+ "advanced": true,
+ "api_editable": false,
+ "display_name": "Candidate Pool Size",
+ "dynamic": false,
+ "info": "Number of approximate neighbors to consider for each KNN query. Some OpenSearch deployments do not support this parameter; set to 0 to disable.",
+ "list": false,
+ "list_add_label": "Add More",
+ "name": "num_candidates",
"override_skip": false,
"placeholder": "",
"required": false,
"show": true,
- "table_icon": "Table",
- "table_schema": [
- {
- "description": "Key name",
- "display_name": "Key",
- "formatter": "text",
- "name": "key",
- "type": "str"
- },
- {
- "description": "Value of the metadata",
- "display_name": "Value",
- "formatter": "text",
- "name": "value",
- "type": "str"
- }
- ],
"title_case": false,
"tool_mode": false,
"trace_as_metadata": true,
- "track_in_telemetry": false,
- "trigger_icon": "Table",
- "trigger_text": "Open table",
- "type": "table",
- "value": []
+ "track_in_telemetry": true,
+ "type": "int",
+ "value": 1000
},
- "ef_construction": {
+ "number_of_results": {
"_input_type": "IntInput",
"advanced": true,
"api_editable": false,
- "display_name": "EF Construction",
+ "display_name": "Default Result Limit",
"dynamic": false,
- "info": "Size of the dynamic candidate list during index construction. Higher values improve recall but increase indexing time and memory usage.",
+ "info": "Default maximum number of search results to return when no limit is specified in the filter expression.",
"list": false,
"list_add_label": "Add More",
- "name": "ef_construction",
+ "name": "number_of_results",
"override_skip": false,
"placeholder": "",
"required": false,
@@ -4193,42 +3338,44 @@
"trace_as_metadata": true,
"track_in_telemetry": true,
"type": "int",
- "value": 512
+ "value": 10
},
- "embedding": {
- "_input_type": "HandleInput",
- "advanced": false,
+ "openrag_ingest_batch_size": {
+ "_input_type": "IntInput",
+ "advanced": true,
"api_editable": false,
- "display_name": "Embedding",
+ "display_name": "OpenRAG Ingest Batch Size",
"dynamic": false,
"info": "",
- "input_types": [
- "Embeddings"
- ],
- "list": true,
+ "list": false,
"list_add_label": "Add More",
- "name": "embedding",
+ "name": "openrag_ingest_batch_size",
"override_skip": false,
"placeholder": "",
"required": false,
"show": true,
"title_case": false,
+ "tool_mode": false,
"trace_as_metadata": true,
- "track_in_telemetry": false,
- "type": "other",
- "value": ""
+ "track_in_telemetry": true,
+ "type": "int",
+ "value": 100
},
- "embedding_model_name": {
+ "openrag_ingest_run_id": {
"_input_type": "StrInput",
- "advanced": false,
+ "advanced": true,
"api_editable": false,
- "display_name": "Embedding Model Name",
+ "display_name": "OpenRAG Ingest Run ID",
"dynamic": false,
- "info": "Name of the embedding model to use for ingestion. This selects which embedding from the list will be used to embed documents. Matches on deployment, model, model_id, or model_name. For duplicate deployments, use combined format: 'deployment:model' (e.g., 'text-embedding-ada-002:text-embedding-3-large'). Leave empty to use the first embedding. Error message will show all available identifiers.",
+ "info": "",
+ "input_types": [
+ "Text",
+ "Message"
+ ],
"list": false,
"list_add_label": "Add More",
"load_from_db": true,
- "name": "embedding_model_name",
+ "name": "openrag_ingest_run_id",
"override_skip": false,
"placeholder": "",
"required": false,
@@ -4238,79 +3385,68 @@
"trace_as_metadata": true,
"track_in_telemetry": false,
"type": "str",
- "value": "SELECTED_EMBEDDING_MODEL"
+ "value": "OPENRAG_INGEST_RUN_ID"
},
- "engine": {
- "_input_type": "DropdownInput",
+ "openrag_ingest_token": {
+ "_input_type": "SecretStrInput",
"advanced": true,
"api_editable": false,
- "combobox": false,
- "dialog_inputs": {},
- "display_name": "Vector Engine",
+ "display_name": "OpenRAG Ingest Token",
"dynamic": false,
- "external_options": {},
- "info": "Vector search engine for similarity calculations. 'nmslib' works with standard OpenSearch. 'jvector' requires OpenSearch 2.9+. 'lucene' requires index.knn: true. Amazon OpenSearch Serverless only supports 'nmslib' or 'faiss'.",
- "name": "engine",
- "options": [
- "nmslib",
- "faiss",
- "lucene",
- "jvector"
+ "info": "Short-lived token used only for OpenRAG ingest callbacks.",
+ "input_types": [
+ "Text",
+ "Message"
],
- "options_metadata": [],
+ "load_from_db": true,
+ "name": "openrag_ingest_token",
"override_skip": false,
+ "password": true,
"placeholder": "",
"required": false,
"show": true,
"title_case": false,
- "toggle": false,
- "tool_mode": false,
- "trace_as_metadata": true,
- "track_in_telemetry": true,
+ "track_in_telemetry": false,
"type": "str",
- "value": "jvector"
+ "value": "OPENRAG_INGEST_TOKEN"
},
- "filter_expression": {
- "_input_type": "MultilineInput",
- "advanced": false,
- "ai_enabled": false,
+ "openrag_ingest_url": {
+ "_input_type": "StrInput",
+ "advanced": true,
"api_editable": false,
- "copy_field": false,
- "display_name": "Search Filters (JSON)",
+ "display_name": "OpenRAG Ingest URL",
"dynamic": false,
- "info": "Optional JSON configuration for search filtering, result limits, and score thresholds.\n\nFormat 1 - Explicit filters:\n{\"filter\": [{\"term\": {\"filename\":\"doc.pdf\"}}, {\"terms\":{\"owner\":[\"user1\",\"user2\"]}}], \"limit\": 10, \"score_threshold\": 1.6}\n\nFormat 2 - Context-style mapping:\n{\"data_sources\":[\"file.pdf\"], \"document_types\":[\"application/pdf\"], \"owners\":[\"user123\"]}\n\nUse __IMPOSSIBLE_VALUE__ as placeholder to ignore specific filters.",
+ "info": "Internal OpenRAG callback URL for backend-owned document indexing.",
"input_types": [
+ "Text",
"Message"
],
"list": false,
"list_add_label": "Add More",
- "load_from_db": false,
- "multiline": true,
- "name": "filter_expression",
+ "load_from_db": true,
+ "name": "openrag_ingest_url",
"override_skip": false,
- "password": false,
"placeholder": "",
"required": false,
"show": true,
"title_case": false,
"tool_mode": false,
- "trace_as_input": true,
"trace_as_metadata": true,
"track_in_telemetry": false,
"type": "str",
- "value": ""
+ "value": "OPENRAG_INGEST_URL"
},
- "index_name": {
+ "opensearch_url": {
"_input_type": "StrInput",
"advanced": false,
"api_editable": false,
- "display_name": "Index Name",
+ "display_name": "OpenSearch URL",
"dynamic": false,
- "info": "The OpenSearch index name where documents will be stored and searched. Will be created automatically if it doesn't exist.",
+ "info": "The connection URL for your OpenSearch cluster (e.g., http://localhost:9200 for local development or your cloud endpoint).",
"list": false,
"list_add_label": "Add More",
"load_from_db": true,
- "name": "index_name",
+ "name": "opensearch_url",
"override_skip": false,
"placeholder": "",
"required": false,
@@ -4320,108 +3456,86 @@
"trace_as_metadata": true,
"track_in_telemetry": false,
"type": "str",
- "value": "OPENSEARCH_INDEX_NAME"
+ "value": "OPENSEARCH_URL"
},
- "ingest_data": {
- "_input_type": "HandleInput",
+ "password": {
+ "_input_type": "SecretStrInput",
"advanced": false,
"api_editable": false,
- "display_name": "Ingest Data",
+ "display_name": "OpenSearch Password",
"dynamic": false,
"info": "",
- "input_types": [
- "Data",
- "DataFrame",
- "Table"
- ],
- "list": true,
- "list_add_label": "Add More",
- "name": "ingest_data",
+ "input_types": [],
+ "load_from_db": true,
+ "name": "password",
"override_skip": false,
+ "password": true,
"placeholder": "",
"required": false,
- "show": true,
+ "show": false,
"title_case": false,
- "trace_as_metadata": true,
"track_in_telemetry": false,
- "type": "other",
- "value": ""
+ "type": "str",
+ "value": "OPENSEARCH_PASSWORD"
},
- "is_refresh": false,
- "jwt_header": {
+ "request_timeout": {
"_input_type": "StrInput",
"advanced": true,
"api_editable": false,
- "display_name": "JWT Header Name",
+ "display_name": "Request Timeout (seconds)",
"dynamic": false,
- "info": "",
+ "info": "Time in seconds to wait for a response from OpenSearch. Increase for large bulk ingestion or complex hybrid queries.",
"list": false,
"list_add_label": "Add More",
"load_from_db": false,
- "name": "jwt_header",
+ "name": "request_timeout",
"override_skip": false,
"placeholder": "",
- "required": true,
+ "required": false,
"show": true,
"title_case": false,
"tool_mode": false,
"trace_as_metadata": true,
"track_in_telemetry": false,
"type": "str",
- "value": "Authorization"
+ "value": "60"
},
- "jwt_token": {
- "_input_type": "SecretStrInput",
+ "search_query": {
+ "_input_type": "QueryInput",
"advanced": false,
"api_editable": false,
- "display_name": "JWT Token",
- "dynamic": false,
- "info": "Valid JSON Web Token for authentication. Will be sent in the Authorization header (with optional 'Bearer ' prefix).",
- "input_types": [],
- "load_from_db": true,
- "name": "jwt_token",
- "override_skip": false,
- "password": true,
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "track_in_telemetry": false,
- "type": "str",
- "value": "JWT"
- },
- "m": {
- "_input_type": "IntInput",
- "advanced": true,
- "api_editable": false,
- "display_name": "M Parameter",
+ "display_name": "Search Query",
"dynamic": false,
- "info": "Number of bidirectional connections for each vector in the HNSW graph. Higher values improve search quality but increase memory usage and indexing time.",
+ "info": "Enter a query to run a similarity search.",
+ "input_types": [
+ "Message"
+ ],
"list": false,
"list_add_label": "Add More",
- "name": "m",
+ "load_from_db": false,
+ "name": "search_query",
"override_skip": false,
- "placeholder": "",
+ "placeholder": "Enter a query...",
"required": false,
"show": true,
"title_case": false,
- "tool_mode": false,
+ "tool_mode": true,
+ "trace_as_input": true,
"trace_as_metadata": true,
- "track_in_telemetry": true,
- "type": "int",
- "value": 16
+ "track_in_telemetry": false,
+ "type": "query",
+ "value": ""
},
- "max_retries": {
- "_input_type": "StrInput",
+ "should_cache_vector_store": {
+ "_input_type": "BoolInput",
"advanced": true,
"api_editable": false,
- "display_name": "Max Retries",
+ "display_name": "Cache Vector Store",
"dynamic": false,
- "info": "Number of retries for failed connections before raising an error.",
+ "info": "If True, the vector store will be cached for the current build of the component. This is useful for components that have multiple output methods and want to share the same vector store.",
"list": false,
"list_add_label": "Add More",
- "load_from_db": false,
- "name": "max_retries",
+ "name": "should_cache_vector_store",
"override_skip": false,
"placeholder": "",
"required": false,
@@ -4429,62 +3543,134 @@
"title_case": false,
"tool_mode": false,
"trace_as_metadata": true,
- "track_in_telemetry": false,
- "type": "str",
- "value": "3"
+ "track_in_telemetry": true,
+ "type": "bool",
+ "value": true
},
- "num_candidates": {
- "_input_type": "IntInput",
+ "space_type": {
+ "_input_type": "DropdownInput",
"advanced": true,
"api_editable": false,
- "display_name": "Candidate Pool Size",
+ "combobox": false,
+ "dialog_inputs": {},
+ "display_name": "Distance Metric",
"dynamic": false,
- "info": "Number of approximate neighbors to consider for each KNN query. Some OpenSearch deployments do not support this parameter; set to 0 to disable.",
- "list": false,
- "list_add_label": "Add More",
- "name": "num_candidates",
+ "external_options": {},
+ "info": "Distance metric for calculating vector similarity. 'l2' (Euclidean) is most common, 'cosinesimil' for cosine similarity, 'innerproduct' for dot product.",
+ "name": "space_type",
+ "options": [
+ "l2",
+ "l1",
+ "cosinesimil",
+ "linf",
+ "innerproduct"
+ ],
+ "options_metadata": [],
"override_skip": false,
"placeholder": "",
"required": false,
"show": true,
"title_case": false,
+ "toggle": false,
"tool_mode": false,
"trace_as_metadata": true,
"track_in_telemetry": true,
- "type": "int",
- "value": 1000
+ "type": "str",
+ "value": "l2"
},
- "number_of_results": {
- "_input_type": "IntInput",
- "advanced": true,
+ "tools_metadata": {
+ "_input_type": "ToolsInput",
+ "advanced": false,
"api_editable": false,
- "display_name": "Default Result Limit",
+ "display_name": "Actions",
"dynamic": false,
- "info": "Default maximum number of search results to return when no limit is specified in the filter expression.",
- "list": false,
+ "info": "Modify tool names and descriptions to help agents understand when to use each tool.",
+ "is_list": true,
"list_add_label": "Add More",
- "name": "number_of_results",
+ "name": "tools_metadata",
"override_skip": false,
"placeholder": "",
+ "real_time_refresh": true,
"required": false,
"show": true,
"title_case": false,
"tool_mode": false,
"trace_as_metadata": true,
- "track_in_telemetry": true,
- "type": "int",
- "value": 10
+ "track_in_telemetry": false,
+ "type": "tools",
+ "value": [
+ {
+ "approval_actions": [],
+ "args": {
+ "search_query": {
+ "default": "",
+ "description": "Enter a query to run a similarity search.",
+ "title": "Search Query",
+ "type": "string"
+ }
+ },
+ "description": "Store and search documents using OpenSearch with multi-model hybrid semantic and keyword search. To search use the tools search_documents and raw_search. Search documents takes a query for vector search, for example\n {search_query: \"components in openrag\"}",
+ "display_description": "Store and search documents using OpenSearch with multi-model hybrid semantic and keyword search. To search use the tools search_documents and raw_search. Search documents takes a query for vector search, for example\n {search_query: \"components in openrag\"}",
+ "display_name": "search_documents",
+ "name": "search_documents",
+ "readonly": false,
+ "status": true,
+ "tags": [
+ "search_documents"
+ ]
+ },
+ {
+ "approval_actions": [],
+ "args": {
+ "search_query": {
+ "default": "",
+ "description": "Enter a query to run a similarity search.",
+ "title": "Search Query",
+ "type": "string"
+ }
+ },
+ "description": "Store and search documents using OpenSearch with multi-model hybrid semantic and keyword search. To search use the tools search_documents and raw_search. Search documents takes a query for vector search, for example\n {search_query: \"components in openrag\"}",
+ "display_description": "Store and search documents using OpenSearch with multi-model hybrid semantic and keyword search. To search use the tools search_documents and raw_search. Search documents takes a query for vector search, for example\n {search_query: \"components in openrag\"}",
+ "display_name": "raw_search",
+ "name": "raw_search",
+ "readonly": false,
+ "status": true,
+ "tags": [
+ "raw_search"
+ ]
+ },
+ {
+ "approval_actions": [],
+ "args": {
+ "search_query": {
+ "default": "",
+ "description": "Enter a query to run a similarity search.",
+ "title": "Search Query",
+ "type": "string"
+ }
+ },
+ "description": "Store and search documents using OpenSearch with multi-model hybrid semantic and keyword search. To search use the tools search_documents and raw_search. Search documents takes a query for vector search, for example\n {search_query: \"components in openrag\"}",
+ "display_description": "Store and search documents using OpenSearch with multi-model hybrid semantic and keyword search. To search use the tools search_documents and raw_search. Search documents takes a query for vector search, for example\n {search_query: \"components in openrag\"}",
+ "display_name": "as_vector_store",
+ "name": "as_vector_store",
+ "readonly": false,
+ "status": true,
+ "tags": [
+ "as_vector_store"
+ ]
+ }
+ ]
},
- "openrag_ingest_batch_size": {
- "_input_type": "IntInput",
+ "use_ssl": {
+ "_input_type": "BoolInput",
"advanced": true,
"api_editable": false,
- "display_name": "OpenRAG Ingest Batch Size",
+ "display_name": "Use SSL/TLS",
"dynamic": false,
- "info": "",
+ "info": "Enable SSL/TLS encryption for secure connections to OpenSearch.",
"list": false,
"list_add_label": "Add More",
- "name": "openrag_ingest_batch_size",
+ "name": "use_ssl",
"override_skip": false,
"placeholder": "",
"required": false,
@@ -4493,73 +3679,63 @@
"tool_mode": false,
"trace_as_metadata": true,
"track_in_telemetry": true,
- "type": "int",
- "value": 100
+ "type": "bool",
+ "value": true
},
- "openrag_ingest_run_id": {
+ "username": {
"_input_type": "StrInput",
- "advanced": true,
+ "advanced": false,
"api_editable": false,
- "display_name": "OpenRAG Ingest Run ID",
+ "display_name": "Username",
"dynamic": false,
"info": "",
- "input_types": [
- "Text",
- "Message"
- ],
"list": false,
"list_add_label": "Add More",
- "load_from_db": true,
- "name": "openrag_ingest_run_id",
+ "load_from_db": false,
+ "name": "username",
"override_skip": false,
"placeholder": "",
"required": false,
- "show": true,
+ "show": false,
"title_case": false,
"tool_mode": false,
"trace_as_metadata": true,
"track_in_telemetry": false,
"type": "str",
- "value": "OPENRAG_INGEST_RUN_ID"
+ "value": "admin"
},
- "openrag_ingest_token": {
- "_input_type": "SecretStrInput",
+ "vector_field": {
+ "_input_type": "StrInput",
"advanced": true,
"api_editable": false,
- "display_name": "OpenRAG Ingest Token",
+ "display_name": "Legacy Vector Field Name",
"dynamic": false,
- "info": "Short-lived token used only for OpenRAG ingest callbacks.",
- "input_types": [
- "Text",
- "Message"
- ],
- "load_from_db": true,
- "name": "openrag_ingest_token",
+ "info": "Legacy field name for backward compatibility. New documents use dynamic fields (chunk_embedding_{model_name}) based on the embedding_model_name.",
+ "list": false,
+ "list_add_label": "Add More",
+ "load_from_db": false,
+ "name": "vector_field",
"override_skip": false,
- "password": true,
"placeholder": "",
"required": false,
"show": true,
"title_case": false,
+ "tool_mode": false,
+ "trace_as_metadata": true,
"track_in_telemetry": false,
"type": "str",
- "value": "OPENRAG_INGEST_TOKEN"
+ "value": "chunk_embedding"
},
- "openrag_ingest_url": {
- "_input_type": "StrInput",
+ "verify_certs": {
+ "_input_type": "BoolInput",
"advanced": true,
"api_editable": false,
- "display_name": "OpenRAG Ingest URL",
+ "display_name": "Verify SSL Certificates",
"dynamic": false,
- "info": "Internal OpenRAG callback URL for backend-owned document indexing.",
- "input_types": [
- "Text",
- "Message"
- ],
+ "info": "Verify SSL certificates when connecting. Disable for self-signed certificates in development environments.",
"list": false,
"list_add_label": "Add More",
- "load_from_db": true,
- "name": "openrag_ingest_url",
+ "name": "verify_certs",
"override_skip": false,
"placeholder": "",
"required": false,
@@ -4567,21 +3743,127 @@
"title_case": false,
"tool_mode": false,
"trace_as_metadata": true,
- "track_in_telemetry": false,
- "type": "str",
- "value": "OPENRAG_INGEST_URL"
+ "track_in_telemetry": true,
+ "type": "bool",
+ "value": false
+ }
+ },
+ "tool_mode": true
+ },
+ "selected_output": "search_results",
+ "showNode": true,
+ "type": "ext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra"
+ },
+ "dragging": false,
+ "id": "OpenSearchVectorStoreComponentMultimodalMultiEmbedding-3x7Ll",
+ "measured": {
+ "height": 999,
+ "width": 320
+ },
+ "position": {
+ "x": 1325.2370822527334,
+ "y": 1777.486986803783
+ },
+ "selected": false,
+ "type": "genericNode"
+ },
+ {
+ "data": {
+ "id": "OpenAICompatibleLLM-u2sHy",
+ "node": {
+ "base_classes": [
+ "LanguageModel",
+ "Message"
+ ],
+ "beta": false,
+ "conditional_paths": [],
+ "custom_fields": {},
+ "description": "Chat model via OpenRAG's OpenAI-compatible /v1 proxy. Base URL and hop token come from global variables at runtime.",
+ "display_name": "OpenRAG LLM",
+ "documentation": "",
+ "edited": false,
+ "field_order": [
+ "input_value",
+ "system_message",
+ "stream",
+ "model_name",
+ "api_key",
+ "api_base",
+ "temperature",
+ "max_tokens",
+ "seed"
+ ],
+ "frozen": false,
+ "icon": "OpenRAG",
+ "legacy": false,
+ "metadata": {
+ "code_hash": "c71fbff77a9e",
+ "dependencies": {
+ "dependencies": [
+ {
+ "name": "langchain_openai",
+ "version": "1.5.2"
+ },
+ {
+ "name": "lfx",
+ "version": "1.11.2"
+ }
+ ],
+ "total_dependencies": 2
},
- "opensearch_url": {
+ "keywords": [
+ "model",
+ "llm",
+ "language model",
+ "large language model"
+ ],
+ "module": "custom_components.openrag_llm"
+ },
+ "minimized": false,
+ "output_types": [],
+ "outputs": [
+ {
+ "allows_loop": false,
+ "cache": true,
+ "display_name": "Model Response",
+ "group_outputs": false,
+ "method": "text_response",
+ "name": "text_output",
+ "tool_mode": true,
+ "types": [
+ "Message"
+ ],
+ "value": "__UNDEFINED__"
+ },
+ {
+ "allows_loop": false,
+ "cache": true,
+ "display_name": "Language Model",
+ "group_outputs": false,
+ "method": "build_model",
+ "name": "model_output",
+ "selected": "LanguageModel",
+ "tool_mode": true,
+ "types": [
+ "LanguageModel"
+ ],
+ "value": "__UNDEFINED__"
+ }
+ ],
+ "pinned": false,
+ "template": {
+ "_type": "Component",
+ "api_base": {
"_input_type": "StrInput",
"advanced": false,
"api_editable": false,
- "display_name": "OpenSearch URL",
+ "display_name": "OpenAI API Base",
"dynamic": false,
- "info": "The connection URL for your OpenSearch cluster (e.g., http://localhost:9200 for local development or your cloud endpoint).",
+ "info": "Must end with /v1 (for example http://openrag-backend:8000/v1). Bound to OPENRAG_LLM_BASE_URL at runtime. Same URL as embeddings.",
"list": false,
"list_add_label": "Add More",
"load_from_db": true,
- "name": "opensearch_url",
+ "name": "api_base",
"override_skip": false,
"placeholder": "",
"required": false,
@@ -4591,86 +3873,83 @@
"trace_as_metadata": true,
"track_in_telemetry": false,
"type": "str",
- "value": "OPENSEARCH_URL"
+ "value": "OPENRAG_LLM_BASE_URL"
},
- "password": {
+ "api_key": {
"_input_type": "SecretStrInput",
"advanced": false,
"api_editable": false,
- "display_name": "OpenSearch Password",
+ "display_name": "OpenRAG LLM Token",
"dynamic": false,
- "info": "",
+ "info": "Hop token from OPENRAG_LLM_TOKEN. OpenRAG injects this per Langflow run.",
"input_types": [],
"load_from_db": true,
- "name": "password",
+ "name": "api_key",
"override_skip": false,
"password": true,
"placeholder": "",
"required": false,
- "show": false,
+ "show": true,
"title_case": false,
"track_in_telemetry": false,
"type": "str",
- "value": "OPENSEARCH_PASSWORD"
+ "value": "OPENRAG_LLM_TOKEN"
},
- "request_timeout": {
- "_input_type": "StrInput",
+ "code": {
"advanced": true,
"api_editable": false,
- "display_name": "Request Timeout (seconds)",
- "dynamic": false,
- "info": "Time in seconds to wait for a response from OpenSearch. Increase for large bulk ingestion or complex hybrid queries.",
+ "dynamic": true,
+ "fileTypes": [],
+ "file_path": "",
+ "info": "",
"list": false,
- "list_add_label": "Add More",
"load_from_db": false,
- "name": "request_timeout",
- "override_skip": false,
+ "multiline": true,
+ "name": "code",
+ "password": false,
"placeholder": "",
- "required": false,
+ "required": true,
"show": true,
"title_case": false,
- "tool_mode": false,
- "trace_as_metadata": true,
- "track_in_telemetry": false,
- "type": "str",
- "value": "60"
+ "type": "code",
+ "value": "\"\"\"OpenAI-compatible chat model that talks to the OpenRAG `/v1` proxy.\n\nLangflow never holds upstream vendor keys. At runtime OpenRAG injects:\n\n- ``OPENRAG_LLM_TOKEN`` — short-lived hop token (Authorization Bearer)\n- ``OPENRAG_LLM_BASE_URL`` — ``http://<backend>/v1``\n- ``SELECTED_LANGUAGE_MODEL`` — configured chat model id\n\n``ChatOpenAI`` posts to ``{base_url}/chat/completions``. The backend gateway\nthen calls the real vendor (OpenAI, Anthropic, Watsonx, Ollama, or any other\nLiteLLM provider). Embeddings use the same base URL and hop token; see\n``openai_compatible_embedding.py``.\n\"\"\"\n\nfrom __future__ import annotations\n\nfrom typing import Any\n\nfrom langchain_openai import ChatOpenAI\nfrom lfx.base.models.model import LCModelComponent\nfrom lfx.field_typing.constants import LanguageModel\nfrom lfx.field_typing.range_spec import RangeSpec\nfrom lfx.inputs.inputs import BoolInput, StrInput\nfrom lfx.io import IntInput, MessageInput, MultilineInput, SecretStrInput, SliderInput\n\n# Names must match src/api/settings/langflow_sync.py + src/utils/langflow_headers.py\nOPENRAG_LLM_BASE_URL_VAR = \"OPENRAG_LLM_BASE_URL\"\nOPENRAG_LLM_TOKEN_VAR = \"OPENRAG_LLM_TOKEN\"\nSELECTED_LANGUAGE_MODEL_VAR = \"SELECTED_LANGUAGE_MODEL\"\n\n\ndef _as_str(value: object) -> str | None:\n if value is None:\n return None\n getter = getattr(value, \"get_secret_value\", None)\n if callable(getter):\n value = getter()\n text = str(value).strip()\n return text or None\n\n\nclass OpenAICompatibleLLMComponent(LCModelComponent):\n display_name = \"OpenRAG LLM\"\n description = (\n \"Chat model via OpenRAG's OpenAI-compatible /v1 proxy. \"\n \"Base URL and hop token come from global variables at runtime.\"\n )\n icon = \"OpenRAG\"\n name = \"OpenAICompatibleLLM\"\n\n inputs = [\n MessageInput(\n name=\"input_value\",\n display_name=\"Input\",\n info=\"The input text to send to the model\",\n ),\n MultilineInput(\n name=\"system_message\",\n display_name=\"System Message\",\n info=\"A system message that helps set the behavior of the assistant\",\n advanced=False,\n ),\n BoolInput(\n name=\"stream\",\n display_name=\"Stream\",\n info=\"Whether to stream the response\",\n value=False,\n advanced=True,\n ),\n StrInput(\n name=\"model_name\",\n display_name=\"Model Name\",\n info=\"Chat model id. Bound to SELECTED_LANGUAGE_MODEL at runtime.\",\n value=SELECTED_LANGUAGE_MODEL_VAR,\n load_from_db=True,\n ),\n SecretStrInput(\n name=\"api_key\",\n display_name=\"OpenRAG LLM Token\",\n info=\"Hop token from OPENRAG_LLM_TOKEN. OpenRAG injects this per Langflow run.\",\n value=OPENRAG_LLM_TOKEN_VAR,\n required=False,\n load_from_db=True,\n ),\n StrInput(\n name=\"api_base\",\n display_name=\"OpenAI API Base\",\n info=(\n \"Must end with /v1 (for example http://openrag-backend:8000/v1). \"\n \"Bound to OPENRAG_LLM_BASE_URL at runtime. Same URL as embeddings.\"\n ),\n value=OPENRAG_LLM_BASE_URL_VAR,\n load_from_db=True,\n ),\n SliderInput(\n name=\"temperature\",\n display_name=\"Temperature\",\n value=0.1,\n info=\"Controls randomness in responses\",\n range_spec=RangeSpec(min=0, max=1, step=0.01),\n advanced=True,\n ),\n IntInput(\n name=\"max_tokens\",\n display_name=\"Max Tokens\",\n info=\"Maximum number of tokens to generate. Leave empty for the model default.\",\n advanced=True,\n ),\n IntInput(\n name=\"seed\",\n display_name=\"Seed\",\n info=\"The seed controls the reproducibility of the job.\",\n advanced=True,\n value=1,\n ),\n ]\n\n def build_model(self) -> LanguageModel:\n api_key = _as_str(self.api_key)\n api_base = _as_str(self.api_base)\n if api_base:\n api_base = api_base.rstrip(\"/\")\n\n kwargs: dict[str, Any] = {\n \"model\": self.model_name,\n \"api_key\": api_key,\n \"base_url\": api_base or None,\n \"streaming\": bool(getattr(self, \"stream\", False)),\n }\n max_tokens = getattr(self, \"max_tokens\", None)\n if max_tokens:\n kwargs[\"max_tokens\"] = max_tokens\n temperature = getattr(self, \"temperature\", None)\n if temperature is not None:\n kwargs[\"temperature\"] = temperature\n seed = getattr(self, \"seed\", None)\n if seed is not None:\n kwargs[\"seed\"] = seed\n return ChatOpenAI(**kwargs)\n"
},
- "search_query": {
- "_input_type": "QueryInput",
+ "input_value": {
+ "_input_type": "MessageInput",
"advanced": false,
"api_editable": false,
- "display_name": "Search Query",
+ "display_name": "Input",
"dynamic": false,
- "info": "Enter a query to run a similarity search.",
+ "info": "The input text to send to the model",
"input_types": [
"Message"
],
"list": false,
"list_add_label": "Add More",
"load_from_db": false,
- "name": "search_query",
+ "name": "input_value",
"override_skip": false,
- "placeholder": "Enter a query...",
+ "placeholder": "",
"required": false,
"show": true,
"title_case": false,
- "tool_mode": true,
+ "tool_mode": false,
"trace_as_input": true,
"trace_as_metadata": true,
"track_in_telemetry": false,
- "type": "query",
+ "type": "str",
"value": ""
},
- "should_cache_vector_store": {
- "_input_type": "BoolInput",
+ "max_tokens": {
+ "_input_type": "IntInput",
"advanced": true,
"api_editable": false,
- "display_name": "Cache Vector Store",
+ "display_name": "Max Tokens",
"dynamic": false,
- "info": "If True, the vector store will be cached for the current build of the component. This is useful for components that have multiple output methods and want to share the same vector store.",
+ "info": "Maximum number of tokens to generate. Leave empty for the model default.",
"list": false,
"list_add_label": "Add More",
- "name": "should_cache_vector_store",
+ "name": "max_tokens",
"override_skip": false,
"placeholder": "",
"required": false,
@@ -4679,133 +3958,62 @@
"tool_mode": false,
"trace_as_metadata": true,
"track_in_telemetry": true,
- "type": "bool",
- "value": true
+ "type": "int",
+ "value": 0
},
- "space_type": {
- "_input_type": "DropdownInput",
- "advanced": true,
+ "model_name": {
+ "_input_type": "StrInput",
+ "advanced": false,
"api_editable": false,
- "combobox": false,
- "dialog_inputs": {},
- "display_name": "Distance Metric",
+ "display_name": "Model Name",
"dynamic": false,
- "external_options": {},
- "info": "Distance metric for calculating vector similarity. 'l2' (Euclidean) is most common, 'cosinesimil' for cosine similarity, 'innerproduct' for dot product.",
- "name": "space_type",
- "options": [
- "l2",
- "l1",
- "cosinesimil",
- "linf",
- "innerproduct"
- ],
- "options_metadata": [],
+ "info": "Chat model id. Bound to SELECTED_LANGUAGE_MODEL at runtime.",
+ "list": false,
+ "list_add_label": "Add More",
+ "load_from_db": true,
+ "name": "model_name",
"override_skip": false,
"placeholder": "",
"required": false,
"show": true,
"title_case": false,
- "toggle": false,
"tool_mode": false,
"trace_as_metadata": true,
- "track_in_telemetry": true,
+ "track_in_telemetry": false,
"type": "str",
- "value": "l2"
+ "value": "SELECTED_LANGUAGE_MODEL"
},
- "tools_metadata": {
- "_input_type": "ToolsInput",
- "advanced": false,
+ "seed": {
+ "_input_type": "IntInput",
+ "advanced": true,
"api_editable": false,
- "display_name": "Actions",
+ "display_name": "Seed",
"dynamic": false,
- "info": "Modify tool names and descriptions to help agents understand when to use each tool.",
- "is_list": true,
+ "info": "The seed controls the reproducibility of the job.",
+ "list": false,
"list_add_label": "Add More",
- "name": "tools_metadata",
+ "name": "seed",
"override_skip": false,
"placeholder": "",
- "real_time_refresh": true,
"required": false,
"show": true,
"title_case": false,
"tool_mode": false,
"trace_as_metadata": true,
- "track_in_telemetry": false,
- "type": "tools",
- "value": [
- {
- "approval_actions": [],
- "args": {
- "search_query": {
- "default": "",
- "description": "Enter a query to run a similarity search.",
- "title": "Search Query",
- "type": "string"
- }
- },
- "description": "Store and search documents using OpenSearch with multi-model hybrid semantic and keyword search. To search use the tools search_documents and raw_search. Search documents takes a query for vector search, for example\n {search_query: \"components in openrag\"}",
- "display_description": "Store and search documents using OpenSearch with multi-model hybrid semantic and keyword search. To search use the tools search_documents and raw_search. Search documents takes a query for vector search, for example\n {search_query: \"components in openrag\"}",
- "display_name": "search_documents",
- "name": "search_documents",
- "readonly": false,
- "status": true,
- "tags": [
- "search_documents"
- ]
- },
- {
- "approval_actions": [],
- "args": {
- "search_query": {
- "default": "",
- "description": "Enter a query to run a similarity search.",
- "title": "Search Query",
- "type": "string"
- }
- },
- "description": "Store and search documents using OpenSearch with multi-model hybrid semantic and keyword search. To search use the tools search_documents and raw_search. Search documents takes a query for vector search, for example\n {search_query: \"components in openrag\"}",
- "display_description": "Store and search documents using OpenSearch with multi-model hybrid semantic and keyword search. To search use the tools search_documents and raw_search. Search documents takes a query for vector search, for example\n {search_query: \"components in openrag\"}",
- "display_name": "raw_search",
- "name": "raw_search",
- "readonly": false,
- "status": true,
- "tags": [
- "raw_search"
- ]
- },
- {
- "approval_actions": [],
- "args": {
- "search_query": {
- "default": "",
- "description": "Enter a query to run a similarity search.",
- "title": "Search Query",
- "type": "string"
- }
- },
- "description": "Store and search documents using OpenSearch with multi-model hybrid semantic and keyword search. To search use the tools search_documents and raw_search. Search documents takes a query for vector search, for example\n {search_query: \"components in openrag\"}",
- "display_description": "Store and search documents using OpenSearch with multi-model hybrid semantic and keyword search. To search use the tools search_documents and raw_search. Search documents takes a query for vector search, for example\n {search_query: \"components in openrag\"}",
- "display_name": "as_vector_store",
- "name": "as_vector_store",
- "readonly": false,
- "status": false,
- "tags": [
- "as_vector_store"
- ]
- }
- ]
+ "track_in_telemetry": true,
+ "type": "int",
+ "value": 1
},
- "use_ssl": {
+ "stream": {
"_input_type": "BoolInput",
"advanced": true,
"api_editable": false,
- "display_name": "Use SSL/TLS",
+ "display_name": "Stream",
"dynamic": false,
- "info": "Enable SSL/TLS encryption for secure connections to OpenSearch.",
+ "info": "Whether to stream the response",
"list": false,
"list_add_label": "Add More",
- "name": "use_ssl",
+ "name": "stream",
"override_skip": false,
"placeholder": "",
"required": false,
@@ -4815,94 +4023,94 @@
"trace_as_metadata": true,
"track_in_telemetry": true,
"type": "bool",
- "value": true
+ "value": false
},
- "username": {
- "_input_type": "StrInput",
+ "system_message": {
+ "_input_type": "MultilineInput",
"advanced": false,
+ "ai_enabled": false,
"api_editable": false,
- "display_name": "Username",
- "dynamic": false,
- "info": "",
- "list": false,
- "list_add_label": "Add More",
- "load_from_db": false,
- "name": "username",
- "override_skip": false,
- "placeholder": "",
- "required": false,
- "show": false,
- "title_case": false,
- "tool_mode": false,
- "trace_as_metadata": true,
- "track_in_telemetry": false,
- "type": "str",
- "value": "admin"
- },
- "vector_field": {
- "_input_type": "StrInput",
- "advanced": true,
- "api_editable": false,
- "display_name": "Legacy Vector Field Name",
+ "copy_field": false,
+ "display_name": "System Message",
"dynamic": false,
- "info": "Legacy field name for backward compatibility. New documents use dynamic fields (chunk_embedding_{model_name}) based on the embedding_model_name.",
+ "info": "A system message that helps set the behavior of the assistant",
+ "input_types": [
+ "Message"
+ ],
"list": false,
"list_add_label": "Add More",
"load_from_db": false,
- "name": "vector_field",
+ "multiline": true,
+ "name": "system_message",
"override_skip": false,
+ "password": false,
"placeholder": "",
"required": false,
"show": true,
"title_case": false,
"tool_mode": false,
+ "trace_as_input": true,
"trace_as_metadata": true,
"track_in_telemetry": false,
"type": "str",
- "value": "chunk_embedding"
+ "value": ""
},
- "verify_certs": {
- "_input_type": "BoolInput",
+ "temperature": {
+ "_input_type": "SliderInput",
"advanced": true,
"api_editable": false,
- "display_name": "Verify SSL Certificates",
+ "display_name": "Temperature",
"dynamic": false,
- "info": "Verify SSL certificates when connecting. Disable for self-signed certificates in development environments.",
- "list": false,
- "list_add_label": "Add More",
- "name": "verify_certs",
+ "info": "Controls randomness in responses",
+ "max_label": "",
+ "max_label_icon": "",
+ "min_label": "",
+ "min_label_icon": "",
+ "name": "temperature",
"override_skip": false,
"placeholder": "",
+ "range_spec": {
+ "max": 1,
+ "min": 0,
+ "step": 0.01,
+ "step_type": "float"
+ },
"required": false,
"show": true,
+ "slider_buttons": false,
+ "slider_buttons_options": [],
+ "slider_input": false,
"title_case": false,
"tool_mode": false,
- "trace_as_metadata": true,
- "track_in_telemetry": true,
- "type": "bool",
- "value": false
+ "track_in_telemetry": false,
+ "type": "slider",
+ "value": 0.1
}
},
- "tool_mode": true
+ "tool_mode": false
},
- "selected_output": "search_results",
- "showNode": true,
- "type": "ext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra"
+ "selected_output": "model_output",
+ "showNode": false,
+ "type": "OpenAICompatibleLLM"
},
"dragging": false,
- "id": "ext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-Ji9kZ",
+ "id": "OpenAICompatibleLLM-u2sHy",
+ "measured": {
+ "height": 80,
+ "width": 192
+ },
"position": {
- "x": 1018.3951511071341,
- "y": 1400.1504172377802
+ "x": 1353.9033717672569,
+ "y": 1464.2864703820715
},
"selected": false,
"type": "genericNode"
}
],
"viewport": {
- "x": -225.80752375709142,
- "y": -753.6093215920815,
- "zoom": 0.6231364613222056
+ "x": -215.08916846415786,
+ "y": -488.01500238347467,
+ "zoom": 0.5214244492327448
}
},
"description": "OpenRAG OpenSearch Agent",
diff --git a/flows/openrag_nudges.json b/flows/openrag_nudges.json
index a6a1bb466..7226d5f11 100644
--- a/flows/openrag_nudges.json
+++ b/flows/openrag_nudges.json
@@ -34,96 +34,94 @@
"className": "",
"data": {
"sourceHandle": {
- "dataType": "Prompt Template",
- "id": "Prompt Template-Wo6kR",
- "name": "prompt",
+ "dataType": "ParserComponent",
+ "id": "ParserComponent-x6BS7",
+ "name": "parsed_text",
"output_types": [
"Message"
]
},
"targetHandle": {
- "fieldName": "input_value",
- "id": "LanguageModelComponent-KdXf9",
+ "fieldName": "docs",
+ "id": "Prompt Template-Wo6kR",
"inputTypes": [
"Message"
],
"type": "str"
}
},
- "id": "xy-edge__Prompt Template-Wo6kR{œdataTypeœ:œPrompt Templateœ,œidœ:œPrompt Template-Wo6kRœ,œnameœ:œpromptœ,œoutput_typesœ:[œMessageœ]}-LanguageModelComponent-KdXf9{œfieldNameœ:œinput_valueœ,œidœ:œLanguageModelComponent-KdXf9œ,œinputTypesœ:[œMessageœ],œtypeœ:œstrœ}",
+ "id": "xy-edge__ParserComponent-x6BS7{œdataTypeœ:œParserComponentœ,œidœ:œParserComponent-x6BS7œ,œnameœ:œparsed_textœ,œoutput_typesœ:[œMessageœ]}-Prompt Template-Wo6kR{œfieldNameœ:œdocsœ,œidœ:œPrompt Template-Wo6kRœ,œinputTypesœ:[œMessageœ],œtypeœ:œstrœ}",
"selected": false,
- "source": "Prompt Template-Wo6kR",
- "sourceHandle": "{œdataTypeœ:œPrompt Templateœ,œidœ:œPrompt Template-Wo6kRœ,œnameœ:œpromptœ,œoutput_typesœ:[œMessageœ]}",
- "target": "LanguageModelComponent-KdXf9",
- "targetHandle": "{œfieldNameœ:œinput_valueœ,œidœ:œLanguageModelComponent-KdXf9œ,œinputTypesœ:[œMessageœ],œtypeœ:œstrœ}"
+ "source": "ParserComponent-x6BS7",
+ "sourceHandle": "{œdataTypeœ:œParserComponentœ,œidœ:œParserComponent-x6BS7œ,œnameœ:œparsed_textœ,œoutput_typesœ:[œMessageœ]}",
+ "target": "Prompt Template-Wo6kR",
+ "targetHandle": "{œfieldNameœ:œdocsœ,œidœ:œPrompt Template-Wo6kRœ,œinputTypesœ:[œMessageœ],œtypeœ:œstrœ}"
},
{
"animated": false,
"className": "",
"data": {
"sourceHandle": {
- "dataType": "ParserComponent",
- "id": "ParserComponent-x6BS7",
- "name": "parsed_text",
+ "dataType": "TextInput",
+ "id": "TextInput-BG2U3",
+ "name": "text",
"output_types": [
"Message"
]
},
"targetHandle": {
- "fieldName": "docs",
- "id": "Prompt Template-Wo6kR",
+ "fieldName": "filter_expression",
+ "id": "ext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-yrQui",
"inputTypes": [
"Message"
],
"type": "str"
}
},
- "id": "xy-edge__ParserComponent-x6BS7{œdataTypeœ:œParserComponentœ,œidœ:œParserComponent-x6BS7œ,œnameœ:œparsed_textœ,œoutput_typesœ:[œMessageœ]}-Prompt Template-Wo6kR{œfieldNameœ:œdocsœ,œidœ:œPrompt Template-Wo6kRœ,œinputTypesœ:[œMessageœ],œtypeœ:œstrœ}",
+ "id": "xy-edge__TextInput-BG2U3{œdataTypeœ:œTextInputœ,œidœ:œTextInput-BG2U3œ,œnameœ:œtextœ,œoutput_typesœ:[œMessageœ]}-ext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-yrQui{œfieldNameœ:œfilter_expressionœ,œidœ:œext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-yrQuiœ,œinputTypesœ:[œMessageœ],œtypeœ:œstrœ}",
"selected": false,
- "source": "ParserComponent-x6BS7",
- "sourceHandle": "{œdataTypeœ:œParserComponentœ,œidœ:œParserComponent-x6BS7œ,œnameœ:œparsed_textœ,œoutput_typesœ:[œMessageœ]}",
- "target": "Prompt Template-Wo6kR",
- "targetHandle": "{œfieldNameœ:œdocsœ,œidœ:œPrompt Template-Wo6kRœ,œinputTypesœ:[œMessageœ],œtypeœ:œstrœ}"
+ "source": "TextInput-BG2U3",
+ "sourceHandle": "{œdataTypeœ:œTextInputœ,œidœ:œTextInput-BG2U3œ,œnameœ:œtextœ,œoutput_typesœ:[œMessageœ]}",
+ "target": "ext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-yrQui",
+ "targetHandle": "{œfieldNameœ:œfilter_expressionœ,œidœ:œext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-yrQuiœ,œinputTypesœ:[œMessageœ],œtypeœ:œstrœ}"
},
{
"animated": false,
"className": "",
"data": {
"sourceHandle": {
- "dataType": "LanguageModelComponent",
- "id": "LanguageModelComponent-KdXf9",
- "name": "text_output",
+ "dataType": "ext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra",
+ "id": "ext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-yrQui",
+ "name": "search_results",
"output_types": [
- "Message"
+ "JSON"
]
},
"targetHandle": {
- "fieldName": "input_value",
- "id": "ChatOutput-axewE",
+ "fieldName": "input_data",
+ "id": "ParserComponent-x6BS7",
"inputTypes": [
- "Data",
- "JSON",
"DataFrame",
"Table",
- "Message"
+ "Data",
+ "JSON"
],
"type": "other"
}
},
- "id": "xy-edge__LanguageModelComponent-KdXf9{œdataTypeœ:œLanguageModelComponentœ,œidœ:œLanguageModelComponent-KdXf9œ,œnameœ:œtext_outputœ,œoutput_typesœ:[œMessageœ]}-ChatOutput-axewE{œfieldNameœ:œinput_valueœ,œidœ:œChatOutput-axewEœ,œinputTypesœ:[œDataœ,œJSONœ,œDataFrameœ,œTableœ,œMessageœ],œtypeœ:œotherœ}",
+ "id": "xy-edge__ext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-yrQui{œdataTypeœ:œext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extraœ,œidœ:œext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-yrQuiœ,œnameœ:œsearch_resultsœ,œoutput_typesœ:[œJSONœ]}-ParserComponent-x6BS7{œfieldNameœ:œinput_dataœ,œidœ:œParserComponent-x6BS7œ,œinputTypesœ:[œDataFrameœ,œTableœ,œDataœ,œJSONœ],œtypeœ:œotherœ}",
"selected": false,
- "source": "LanguageModelComponent-KdXf9",
- "sourceHandle": "{œdataTypeœ:œLanguageModelComponentœ,œidœ:œLanguageModelComponent-KdXf9œ,œnameœ:œtext_outputœ,œoutput_typesœ:[œMessageœ]}",
- "target": "ChatOutput-axewE",
- "targetHandle": "{œfieldNameœ:œinput_valueœ,œidœ:œChatOutput-axewEœ,œinputTypesœ:[œDataœ,œJSONœ,œDataFrameœ,œTableœ,œMessageœ],œtypeœ:œotherœ}"
+ "source": "ext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-yrQui",
+ "sourceHandle": "{œdataTypeœ:œext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extraœ,œidœ:œext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-yrQuiœ,œnameœ:œsearch_resultsœ,œoutput_typesœ:[œJSONœ]}",
+ "target": "ParserComponent-x6BS7",
+ "targetHandle": "{œfieldNameœ:œinput_dataœ,œidœ:œParserComponent-x6BS7œ,œinputTypesœ:[œDataFrameœ,œTableœ,œDataœ,œJSONœ],œtypeœ:œotherœ}"
},
{
"animated": false,
- "className": "",
"data": {
"sourceHandle": {
- "dataType": "EmbeddingModel",
- "id": "EmbeddingModel-cONxU",
+ "dataType": "OpenAICompatibleEmbedding",
+ "id": "OpenAICompatibleEmbedding-CdOpv",
"name": "embeddings",
"output_types": [
"Embeddings"
@@ -138,69 +136,70 @@
"type": "other"
}
},
- "id": "xy-edge__EmbeddingModel-cONxU{œdataTypeœ:œEmbeddingModelœ,œidœ:œEmbeddingModel-cONxUœ,œnameœ:œembeddingsœ,œoutput_typesœ:[œEmbeddingsœ]}-ext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-yrQui{œfieldNameœ:œembeddingœ,œidœ:œext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-yrQuiœ,œinputTypesœ:[œEmbeddingsœ],œtypeœ:œotherœ}",
+ "id": "xy-edge__OpenAICompatibleEmbedding-CdOpv{œdataTypeœ:œOpenAICompatibleEmbeddingœ,œidœ:œOpenAICompatibleEmbedding-CdOpvœ,œnameœ:œembeddingsœ,œoutput_typesœ:[œEmbeddingsœ]}-ext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-yrQui{œfieldNameœ:œembeddingœ,œidœ:œext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-yrQuiœ,œinputTypesœ:[œEmbeddingsœ],œtypeœ:œotherœ}",
"selected": false,
- "source": "EmbeddingModel-cONxU",
- "sourceHandle": "{œdataTypeœ:œEmbeddingModelœ,œidœ:œEmbeddingModel-cONxUœ,œnameœ:œembeddingsœ,œoutput_typesœ:[œEmbeddingsœ]}",
+ "source": "OpenAICompatibleEmbedding-CdOpv",
+ "sourceHandle": "{œdataTypeœ:œOpenAICompatibleEmbeddingœ,œidœ:œOpenAICompatibleEmbedding-CdOpvœ,œnameœ:œembeddingsœ,œoutput_typesœ:[œEmbeddingsœ]}",
"target": "ext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-yrQui",
"targetHandle": "{œfieldNameœ:œembeddingœ,œidœ:œext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-yrQuiœ,œinputTypesœ:[œEmbeddingsœ],œtypeœ:œotherœ}"
},
{
"animated": false,
- "className": "",
"data": {
"sourceHandle": {
- "dataType": "TextInput",
- "id": "TextInput-BG2U3",
- "name": "text",
+ "dataType": "Prompt Template",
+ "id": "Prompt Template-Wo6kR",
+ "name": "prompt",
"output_types": [
"Message"
]
},
"targetHandle": {
- "fieldName": "filter_expression",
- "id": "ext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-yrQui",
+ "fieldName": "input_value",
+ "id": "OpenAICompatibleLLM-0PA0e",
"inputTypes": [
"Message"
],
"type": "str"
}
},
- "id": "xy-edge__TextInput-BG2U3{œdataTypeœ:œTextInputœ,œidœ:œTextInput-BG2U3œ,œnameœ:œtextœ,œoutput_typesœ:[œMessageœ]}-ext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-yrQui{œfieldNameœ:œfilter_expressionœ,œidœ:œext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-yrQuiœ,œinputTypesœ:[œMessageœ],œtypeœ:œstrœ}",
+ "id": "xy-edge__Prompt Template-Wo6kR{œdataTypeœ:œPrompt Templateœ,œidœ:œPrompt Template-Wo6kRœ,œnameœ:œpromptœ,œoutput_typesœ:[œMessageœ]}-OpenAICompatibleLLM-0PA0e{œfieldNameœ:œinput_valueœ,œidœ:œOpenAICompatibleLLM-0PA0eœ,œinputTypesœ:[œMessageœ],œtypeœ:œstrœ}",
"selected": false,
- "source": "TextInput-BG2U3",
- "sourceHandle": "{œdataTypeœ:œTextInputœ,œidœ:œTextInput-BG2U3œ,œnameœ:œtextœ,œoutput_typesœ:[œMessageœ]}",
- "target": "ext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-yrQui",
- "targetHandle": "{œfieldNameœ:œfilter_expressionœ,œidœ:œext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-yrQuiœ,œinputTypesœ:[œMessageœ],œtypeœ:œstrœ}"
+ "source": "Prompt Template-Wo6kR",
+ "sourceHandle": "{œdataTypeœ:œPrompt Templateœ,œidœ:œPrompt Template-Wo6kRœ,œnameœ:œpromptœ,œoutput_typesœ:[œMessageœ]}",
+ "target": "OpenAICompatibleLLM-0PA0e",
+ "targetHandle": "{œfieldNameœ:œinput_valueœ,œidœ:œOpenAICompatibleLLM-0PA0eœ,œinputTypesœ:[œMessageœ],œtypeœ:œstrœ}"
},
{
- "className": "",
+ "animated": false,
"data": {
"sourceHandle": {
- "dataType": "ext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra",
- "id": "ext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-yrQui",
- "name": "search_results",
+ "dataType": "OpenAICompatibleLLM",
+ "id": "OpenAICompatibleLLM-0PA0e",
+ "name": "text_output",
"output_types": [
- "JSON"
+ "Message"
]
},
"targetHandle": {
- "fieldName": "input_data",
- "id": "ParserComponent-x6BS7",
+ "fieldName": "input_value",
+ "id": "ChatOutput-axewE",
"inputTypes": [
+ "Data",
+ "JSON",
"DataFrame",
"Table",
- "Data",
- "JSON"
+ "Message"
],
"type": "other"
}
},
- "id": "xy-edge__ext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-yrQui{œdataTypeœ:œext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extraœ,œidœ:œext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-yrQuiœ,œnameœ:œsearch_resultsœ,œoutput_typesœ:[œJSONœ]}-ParserComponent-x6BS7{œfieldNameœ:œinput_dataœ,œidœ:œParserComponent-x6BS7œ,œinputTypesœ:[œDataFrameœ,œTableœ,œDataœ,œJSONœ],œtypeœ:œotherœ}",
- "source": "ext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-yrQui",
- "sourceHandle": "{œdataTypeœ:œext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extraœ,œidœ:œext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-yrQuiœ,œnameœ:œsearch_resultsœ,œoutput_typesœ:[œJSONœ]}",
- "target": "ParserComponent-x6BS7",
- "targetHandle": "{œfieldNameœ:œinput_dataœ,œidœ:œParserComponent-x6BS7œ,œinputTypesœ:[œDataFrameœ,œTableœ,œDataœ,œJSONœ],œtypeœ:œotherœ}"
+ "id": "xy-edge__OpenAICompatibleLLM-0PA0e{œdataTypeœ:œOpenAICompatibleLLMœ,œidœ:œOpenAICompatibleLLM-0PA0eœ,œnameœ:œtext_outputœ,œoutput_typesœ:[œMessageœ]}-ChatOutput-axewE{œfieldNameœ:œinput_valueœ,œidœ:œChatOutput-axewEœ,œinputTypesœ:[œDataœ,œJSONœ,œDataFrameœ,œTableœ,œMessageœ],œtypeœ:œotherœ}",
+ "selected": false,
+ "source": "OpenAICompatibleLLM-0PA0e",
+ "sourceHandle": "{œdataTypeœ:œOpenAICompatibleLLMœ,œidœ:œOpenAICompatibleLLM-0PA0eœ,œnameœ:œtext_outputœ,œoutput_typesœ:[œMessageœ]}",
+ "target": "ChatOutput-axewE",
+ "targetHandle": "{œfieldNameœ:œinput_valueœ,œidœ:œChatOutput-axewEœ,œinputTypesœ:[œDataœ,œJSONœ,œDataFrameœ,œTableœ,œMessageœ],œtypeœ:œotherœ}"
}
],
"nodes": [
@@ -411,14 +410,18 @@
},
"tool_mode": false
},
- "showNode": true,
+ "showNode": false,
"type": "Prompt Template"
},
"dragging": false,
"id": "Prompt Template-Wo6kR",
+ "measured": {
+ "height": 80,
+ "width": 192
+ },
"position": {
- "x": 1258.723154248008,
- "y": 1242.0705456678813
+ "x": 1153.5888851298432,
+ "y": 1486.860784211668
},
"selected": false,
"type": "genericNode"
@@ -705,11 +708,15 @@
},
"tool_mode": false
},
- "showNode": true,
+ "showNode": false,
"type": "ChatInput"
},
"dragging": false,
"id": "ChatInput-7W1BE",
+ "measured": {
+ "height": 52,
+ "width": 192
+ },
"position": {
"x": 847.7008874324687,
"y": 1560.6273308605132
@@ -1010,66 +1017,53 @@
},
"dragging": false,
"id": "ChatOutput-axewE",
+ "measured": {
+ "height": 52,
+ "width": 192
+ },
"position": {
- "x": 2049.2872443904885,
- "y": 1648.484385108906
+ "x": 1746.4377826023422,
+ "y": 1516.674256662252
},
"selected": false,
"type": "genericNode"
},
{
"data": {
- "description": "Runs a language model given a specified provider.",
- "display_name": "Language Model",
- "id": "LanguageModelComponent-KdXf9",
+ "description": "Get user text inputs.",
+ "display_name": "Text Input",
+ "id": "TextInput-BG2U3",
"node": {
"base_classes": [
- "LanguageModel",
"Message"
],
"beta": false,
"conditional_paths": [],
"custom_fields": {},
- "description": "Runs a language model given a specified provider.",
- "display_name": "Language Model",
- "documentation": "https://docs.langflow.org/components-models",
+ "description": "Get user text inputs.",
+ "display_name": "Text Input",
+ "documentation": "https://docs.langflow.org/text-input-and-output",
"edited": false,
"field_order": [
- "model",
- "model_name",
- "provider",
- "api_key",
- "base_url_ibm_watsonx",
- "project_id",
- "ollama_base_url",
"input_value",
- "system_message",
- "stream",
- "temperature",
- "max_tokens"
+ "use_global_variable"
],
"frozen": false,
- "icon": "brain-circuit",
- "last_updated": "2026-07-29T14:28:06.176Z",
- "legacy": false,
+ "icon": "type",
+ "last_updated": "2026-07-17T19:15:11.463Z",
+ "legacy": true,
"metadata": {
- "code_hash": "c1f16fbd02f1",
+ "code_hash": "2811c0e0496f",
"dependencies": {
"dependencies": [
{
"name": "lfx",
- "version": "1.11.1rc0"
+ "version": null
}
],
"total_dependencies": 1
},
- "keywords": [
- "model",
- "llm",
- "language model",
- "large language model"
- ],
- "module": "custom_components.language_model"
+ "module": "custom_components.text_input"
},
"minimized": false,
"output_types": [],
@@ -1077,12 +1071,11 @@
{
"allows_loop": false,
"cache": true,
- "display_name": "Model Response",
+ "display_name": "Output Text",
"group_outputs": false,
- "hidden": null,
"loop_types": null,
"method": "text_response",
- "name": "text_output",
+ "name": "text",
"options": null,
"required_inputs": null,
"selected": "Message",
@@ -1091,90 +1084,20 @@
"Message"
],
"value": "__UNDEFINED__"
- },
- {
- "allows_loop": false,
- "cache": true,
- "display_name": "Language Model",
- "group_outputs": false,
- "hidden": null,
- "loop_types": null,
- "method": "build_model",
- "name": "model_output",
- "options": null,
- "required_inputs": null,
- "selected": "LanguageModel",
- "tool_mode": true,
- "types": [
- "LanguageModel"
- ],
- "value": "__UNDEFINED__"
}
],
"pinned": false,
+ "replacement": [
+ "input_output.ChatInput"
+ ],
"template": {
"_frontend_node_flow_id": {
"value": "ebc01d31-1976-46ce-a385-b0240327226c"
},
"_frontend_node_folder_id": {
- "value": "203c7c12-9e1d-4561-bb14-16102afec154"
+ "value": "f1efb4f8-3ca5-4e89-8685-0e8b2ba1187f"
},
"_type": "Component",
- "api_key": {
- "_input_type": "SecretStrInput",
- "advanced": true,
- "api_editable": false,
- "display_name": "API Key",
- "dynamic": false,
- "info": "Overrides global provider settings. Leave blank to use your pre-configured API Key.",
- "input_types": [],
- "load_from_db": false,
- "name": "api_key",
- "override_skip": false,
- "password": true,
- "placeholder": "",
- "real_time_refresh": true,
- "required": false,
- "show": true,
- "title_case": false,
- "track_in_telemetry": false,
- "type": "str",
- "value": ""
- },
- "base_url_ibm_watsonx": {
- "_input_type": "DropdownInput",
- "advanced": false,
- "api_editable": false,
- "combobox": true,
- "dialog_inputs": {},
- "display_name": "watsonx API Endpoint",
- "dynamic": false,
- "external_options": {},
- "info": "The base URL of the API (IBM watsonx.ai only)",
- "load_from_db": false,
- "name": "base_url_ibm_watsonx",
- "options": [
- "https://us-south.ml.cloud.ibm.com",
- "https://eu-de.ml.cloud.ibm.com",
- "https://eu-gb.ml.cloud.ibm.com",
- "https://au-syd.ml.cloud.ibm.com",
- "https://jp-tok.ml.cloud.ibm.com",
- "https://ca-tor.ml.cloud.ibm.com"
- ],
- "options_metadata": [],
- "override_skip": false,
- "placeholder": "",
- "real_time_refresh": true,
- "required": false,
- "show": false,
- "title_case": false,
- "toggle": false,
- "tool_mode": false,
- "trace_as_metadata": true,
- "track_in_telemetry": true,
- "type": "str",
- "value": ""
- },
"code": {
"advanced": true,
"api_editable": false,
@@ -1192,23 +1115,27 @@
"show": true,
"title_case": false,
"type": "code",
- "value": "from lfx.base.models.model import LCModelComponent\nfrom lfx.base.models.unified_models import (\n get_language_model_options,\n get_llm,\n handle_model_input_update,\n)\nfrom lfx.base.models.watsonx_constants import IBM_WATSONX_URLS\nfrom lfx.components.models_and_agents.model_selection import apply_model_overrides\nfrom lfx.field_typing.constants import LanguageModel\nfrom lfx.field_typing.range_spec import RangeSpec\nfrom lfx.inputs.inputs import BoolInput, DropdownInput, StrInput\nfrom lfx.io import IntInput, MessageInput, ModelInput, MultilineInput, SecretStrInput, SliderInput\n\n\nclass LanguageModelComponent(LCModelComponent):\n display_name = \"Language Model\"\n description = \"Runs a language model given a specified provider.\"\n documentation: str = \"https://docs.langflow.org/components-models\"\n icon = \"brain-circuit\"\n category = \"models\"\n\n inputs = [\n ModelInput(\n name=\"model\",\n display_name=\"Language Model\",\n info=\"Select your model provider\",\n real_time_refresh=True,\n required=True,\n ),\n StrInput(\n name=\"model_name\",\n display_name=\"Model Name Override\",\n info=(\n \"Optional model name to use instead of the selected model. \"\n \"Can be set from a global variable for runtime model selection.\"\n ),\n advanced=True,\n load_from_db=False,\n ),\n StrInput(\n name=\"provider\",\n display_name=\"Provider Override\",\n info=(\n \"Optional provider to use with Model Name Override. Leave blank to use the selected model's provider.\"\n ),\n advanced=True,\n load_from_db=False,\n ),\n SecretStrInput(\n name=\"api_key\",\n display_name=\"API Key\",\n info=\"Overrides global provider settings. Leave blank to use your pre-configured API Key.\",\n required=False,\n show=True,\n real_time_refresh=True,\n advanced=True,\n ),\n DropdownInput(\n name=\"base_url_ibm_watsonx\",\n display_name=\"watsonx API Endpoint\",\n info=\"The base URL of the API (IBM watsonx.ai only)\",\n options=IBM_WATSONX_URLS,\n value=IBM_WATSONX_URLS[0],\n combobox=True,\n show=False,\n real_time_refresh=True,\n ),\n StrInput(\n name=\"project_id\",\n display_name=\"watsonx Project ID\",\n info=\"The project ID associated with the foundation model (IBM watsonx.ai only)\",\n show=False,\n required=False,\n ),\n StrInput(\n name=\"ollama_base_url\",\n display_name=\"Ollama API URL\",\n info=\"Endpoint of the Ollama API (Ollama only)\",\n show=False,\n real_time_refresh=True,\n ),\n MessageInput(\n name=\"input_value\",\n display_name=\"Input\",\n info=\"The input text to send to the model\",\n ),\n MultilineInput(\n name=\"system_message\",\n display_name=\"System Message\",\n info=\"A system message that helps set the behavior of the assistant\",\n advanced=False,\n ),\n BoolInput(\n name=\"stream\",\n display_name=\"Stream\",\n info=\"Whether to stream the response\",\n value=False,\n advanced=True,\n ),\n SliderInput(\n name=\"temperature\",\n display_name=\"Temperature\",\n value=0.1,\n info=\"Controls randomness in responses\",\n range_spec=RangeSpec(min=0, max=1, step=0.01),\n advanced=True,\n ),\n IntInput(\n name=\"max_tokens\",\n display_name=\"Max Tokens\",\n info=\"Maximum number of tokens to generate. Field name varies by provider.\",\n advanced=True,\n range_spec=RangeSpec(min=1, max=128000, step=1, step_type=\"int\"),\n ),\n ]\n\n def build_model(self) -> LanguageModel:\n model = apply_model_overrides(\n self.model,\n model_name=getattr(self, \"model_name\", None),\n provider=getattr(self, \"provider\", None),\n user_id=self.user_id,\n get_options=get_language_model_options,\n )\n return get_llm(\n model=model,\n user_id=self.user_id,\n api_key=self.api_key,\n temperature=self.temperature,\n stream=self.stream,\n max_tokens=getattr(self, \"max_tokens\", None),\n watsonx_url=getattr(self, \"base_url_ibm_watsonx\", None),\n watsonx_project_id=getattr(self, \"project_id\", None),\n ollama_base_url=getattr(self, \"ollama_base_url\", None),\n )\n\n def update_build_config(self, build_config: dict, field_value: str, field_name: str | None = None):\n \"\"\"Dynamically update build config with user-filtered model options.\"\"\"\n return handle_model_input_update(self, build_config, field_value, field_name)\n"
+ "value": "from typing import Any\n\nfrom lfx.base.io.text import TextComponent\nfrom lfx.io import BoolInput, MultilineInput, Output\nfrom lfx.schema.message import Message\n\n\nclass TextInputComponent(TextComponent):\n display_name = \"Text Input\"\n description = \"Get user text inputs.\"\n documentation: str = \"https://docs.langflow.org/text-input-and-output\"\n icon = \"type\"\n name = \"TextInput\"\n legacy = True\n replacement = [\"input_output.ChatInput\"]\n\n inputs = [\n MultilineInput(\n name=\"input_value\",\n display_name=\"Text\",\n info=\"Text to be passed as input.\",\n ),\n BoolInput(\n name=\"use_global_variable\",\n display_name=\"Use Global Variable\",\n info=\"Enable to select from global variables (shows globe icon). Disables multiline editing.\",\n value=False,\n advanced=True,\n real_time_refresh=True,\n ),\n ]\n outputs = [\n Output(display_name=\"Output Text\", name=\"text\", method=\"text_response\"),\n ]\n\n def update_build_config(self, build_config: dict, field_value: Any, field_name: str | None = None) -> dict:\n if field_name == \"use_global_variable\":\n if field_value:\n # Enable global variable mode: single-line with password masking and globe dropdown\n build_config[\"input_value\"][\"multiline\"] = False\n build_config[\"input_value\"][\"password\"] = True\n else:\n # Default mode: multiline text editing\n build_config[\"input_value\"][\"multiline\"] = True\n build_config[\"input_value\"][\"password\"] = False\n return build_config\n\n def text_response(self) -> Message:\n return Message(\n text=self.input_value,\n )\n"
},
"input_value": {
- "_input_type": "MessageInput",
+ "_input_type": "MultilineInput",
"advanced": false,
+ "ai_enabled": false,
"api_editable": false,
- "display_name": "Input",
+ "copy_field": false,
+ "display_name": "Text",
"dynamic": false,
- "info": "The input text to send to the model",
+ "info": "Text to be passed as input.",
"input_types": [
"Message"
],
"list": false,
"list_add_label": "Add More",
- "load_from_db": false,
+ "load_from_db": true,
+ "multiline": false,
"name": "input_value",
"override_skip": false,
+ "password": true,
"placeholder": "",
"required": false,
"show": true,
@@ -1218,477 +1145,191 @@
"trace_as_metadata": true,
"track_in_telemetry": false,
"type": "str",
- "value": ""
+ "value": "OPENRAG-QUERY-FILTER"
},
- "is_refresh": true,
- "max_tokens": {
- "_input_type": "IntInput",
+ "is_refresh": false,
+ "use_global_variable": {
+ "_input_type": "BoolInput",
"advanced": true,
"api_editable": false,
- "display_name": "Max Tokens",
+ "display_name": "Use Global Variable",
"dynamic": false,
- "info": "Maximum number of tokens to generate. Field name varies by provider.",
+ "info": "Enable to select from global variables (shows globe icon). Disables multiline editing.",
"list": false,
"list_add_label": "Add More",
- "name": "max_tokens",
+ "load_from_db": false,
+ "name": "use_global_variable",
"override_skip": false,
"placeholder": "",
- "range_spec": {
- "max": 128000,
- "min": 1,
- "step": 1,
- "step_type": "int"
- },
+ "real_time_refresh": true,
"required": false,
"show": true,
"title_case": false,
"tool_mode": false,
"trace_as_metadata": true,
"track_in_telemetry": true,
- "type": "int",
- "value": 0
- },
- "model": {
- "_input_type": "ModelInput",
- "advanced": true,
- "api_editable": false,
- "display_name": "Language Model",
- "dynamic": false,
- "external_options": {
- "fields": {
- "data": {
- "node": {
- "display_name": "Connect other models",
- "icon": "CornerDownLeft",
- "name": "connect_other_models"
- }
- }
- }
- },
- "info": "Select your model provider",
- "input_types": [
- "LanguageModel"
- ],
- "list": false,
- "list_add_label": "Add More",
- "load_from_db": false,
- "model_type": "language",
- "name": "model",
- "options": [
- {
- "category": "Anthropic",
- "icon": "Anthropic",
- "metadata": {
- "api_key_param": "api_key",
- "context_length": 128000,
- "max_tokens_field_name": "max_tokens",
- "model_class": "ChatAnthropic",
- "model_name_param": "model",
- "reasoning": true,
- "reasoning_models": [
- "claude-opus-5"
- ]
- },
- "name": "claude-opus-5",
- "provider": "Anthropic"
- },
- {
- "category": "Anthropic",
- "icon": "Anthropic",
- "metadata": {
- "api_key_param": "api_key",
- "context_length": 128000,
- "max_tokens_field_name": "max_tokens",
- "model_class": "ChatAnthropic",
- "model_name_param": "model",
- "reasoning": true,
- "reasoning_models": [
- "claude-sonnet-5"
- ]
- },
- "name": "claude-sonnet-5",
- "provider": "Anthropic"
- },
- {
- "category": "Anthropic",
- "icon": "Anthropic",
- "metadata": {
- "api_key_param": "api_key",
- "context_length": 128000,
- "max_tokens_field_name": "max_tokens",
- "model_class": "ChatAnthropic",
- "model_name_param": "model",
- "reasoning": true,
- "reasoning_models": [
- "claude-fable-5"
- ]
- },
- "name": "claude-fable-5",
- "provider": "Anthropic"
- },
- {
- "category": "Anthropic",
- "icon": "Anthropic",
- "metadata": {
- "api_key_param": "api_key",
- "context_length": 128000,
- "max_tokens_field_name": "max_tokens",
- "model_class": "ChatAnthropic",
- "model_name_param": "model",
- "reasoning": true,
- "reasoning_models": [
- "claude-opus-4-8"
- ]
- },
- "name": "claude-opus-4-8",
- "provider": "Anthropic"
- },
- {
- "category": "Anthropic",
- "icon": "Anthropic",
- "metadata": {
- "api_key_param": "api_key",
- "context_length": 128000,
- "max_tokens_field_name": "max_tokens",
- "model_class": "ChatAnthropic",
- "model_name_param": "model",
- "reasoning": true,
- "reasoning_models": [
- "claude-opus-4-7"
- ]
- },
- "name": "claude-opus-4-7",
- "provider": "Anthropic"
- },
- {
- "category": "OpenAI",
- "icon": "OpenAI",
- "metadata": {
- "api_key_param": "api_key",
- "context_length": 128000,
- "max_tokens_field_name": "max_tokens",
- "model_class": "ChatOpenAI",
- "model_name_param": "model",
- "reasoning": true,
- "reasoning_models": [
- "gpt-5.6-sol"
- ]
- },
- "name": "gpt-5.6-sol",
- "provider": "OpenAI"
- },
- {
- "category": "OpenAI",
- "icon": "OpenAI",
- "metadata": {
- "api_key_param": "api_key",
- "context_length": 128000,
- "max_tokens_field_name": "max_tokens",
- "model_class": "ChatOpenAI",
- "model_name_param": "model",
- "reasoning": true,
- "reasoning_models": [
- "gpt-5.6-luna"
- ]
- },
- "name": "gpt-5.6-luna",
- "provider": "OpenAI"
- },
- {
- "category": "OpenAI",
- "icon": "OpenAI",
- "metadata": {
- "api_key_param": "api_key",
- "context_length": 128000,
- "max_tokens_field_name": "max_tokens",
- "model_class": "ChatOpenAI",
- "model_name_param": "model",
- "reasoning": true,
- "reasoning_models": [
- "gpt-5.6"
- ]
- },
- "name": "gpt-5.6",
- "provider": "OpenAI"
- },
- {
- "category": "OpenAI",
- "icon": "OpenAI",
- "metadata": {
- "api_key_param": "api_key",
- "context_length": 128000,
- "max_tokens_field_name": "max_tokens",
- "model_class": "ChatOpenAI",
- "model_name_param": "model",
- "reasoning": true,
- "reasoning_models": [
- "gpt-5.6-terra"
- ]
- },
- "name": "gpt-5.6-terra",
- "provider": "OpenAI"
- },
- {
- "category": "OpenAI",
- "icon": "OpenAI",
- "metadata": {
- "api_key_param": "api_key",
- "context_length": 128000,
- "max_tokens_field_name": "max_tokens",
- "model_class": "ChatOpenAI",
- "model_name_param": "model",
- "reasoning": true,
- "reasoning_models": [
- "gpt-realtime-2.1"
- ]
- },
- "name": "gpt-realtime-2.1",
- "provider": "OpenAI"
- },
- {
- "category": "IBM WatsonX",
- "icon": "WatsonxAI",
- "metadata": {
- "api_key_param": "apikey",
- "context_length": 128000,
- "max_tokens_field_name": "max_tokens",
- "model_class": "ChatWatsonx",
- "model_name_param": "model_id",
- "project_id_param": "project_id",
- "url_param": "url"
- },
- "name": "ibm/granite-4-h-small",
- "provider": "IBM WatsonX"
- },
- {
- "category": "IBM WatsonX",
- "icon": "WatsonxAI",
- "metadata": {
- "api_key_param": "apikey",
- "context_length": 128000,
- "max_tokens_field_name": "max_tokens",
- "model_class": "ChatWatsonx",
- "model_name_param": "model_id",
- "project_id_param": "project_id",
- "url_param": "url"
- },
- "name": "ibm/granite-8b-code-instruct",
- "provider": "IBM WatsonX"
- },
- {
- "category": "IBM WatsonX",
- "icon": "WatsonxAI",
- "metadata": {
- "api_key_param": "apikey",
- "context_length": 128000,
- "max_tokens_field_name": "max_tokens",
- "model_class": "ChatWatsonx",
- "model_name_param": "model_id",
- "project_id_param": "project_id",
- "url_param": "url"
- },
- "name": "ibm/granite-guardian-3-8b",
- "provider": "IBM WatsonX"
- },
- {
- "category": "IBM WatsonX",
- "icon": "WatsonxAI",
- "metadata": {
- "api_key_param": "apikey",
- "context_length": 128000,
- "max_tokens_field_name": "max_tokens",
- "model_class": "ChatWatsonx",
- "model_name_param": "model_id",
- "project_id_param": "project_id",
- "url_param": "url"
- },
- "name": "meta-llama/llama-3-3-70b-instruct",
- "provider": "IBM WatsonX"
- },
- {
- "category": "IBM WatsonX",
- "icon": "WatsonxAI",
- "metadata": {
- "api_key_param": "apikey",
- "context_length": 128000,
- "max_tokens_field_name": "max_tokens",
- "model_class": "ChatWatsonx",
- "model_name_param": "model_id",
- "project_id_param": "project_id",
- "url_param": "url"
- },
- "name": "meta-llama/llama-4-maverick-17b-128e-instruct-fp8",
- "provider": "IBM WatsonX"
- },
+ "type": "bool",
+ "value": true
+ }
+ },
+ "tool_mode": false
+ },
+ "showNode": false,
+ "type": "TextInput"
+ },
+ "dragging": false,
+ "id": "TextInput-BG2U3",
+ "measured": {
+ "height": 129,
+ "width": 192
+ },
+ "position": {
+ "x": -64.9892298542755,
+ "y": 1521.7195088276985
+ },
+ "selected": false,
+ "type": "genericNode"
+ },
+ {
+ "data": {
+ "description": "Extracts text using a template.",
+ "display_name": "Parser",
+ "id": "ParserComponent-x6BS7",
+ "node": {
+ "base_classes": [
+ "Message"
+ ],
+ "beta": false,
+ "conditional_paths": [],
+ "custom_fields": {},
+ "description": "Extracts text using a template.",
+ "display_name": "Parser",
+ "documentation": "https://docs.langflow.org/parser",
+ "edited": false,
+ "field_order": [
+ "input_data",
+ "mode",
+ "pattern",
+ "sep"
+ ],
+ "frozen": false,
+ "icon": "braces",
+ "legacy": false,
+ "metadata": {
+ "code_hash": "7ab5fd0e0a10",
+ "dependencies": {
+ "dependencies": [
{
- "category": "OpenAI",
- "icon": "OpenAI",
- "metadata": {
- "api_key_param": "api_key",
- "context_length": 128000,
- "max_tokens_field_name": "max_tokens",
- "model_class": "ChatOpenAI",
- "model_name_param": "model",
- "not_enabled_locally": true,
- "reasoning": true,
- "reasoning_models": [
- "gpt-5.4-mini"
- ]
- },
- "name": "gpt-5.4-mini",
- "provider": "OpenAI"
+ "name": "lfx",
+ "version": null
}
],
- "override_skip": false,
- "placeholder": "Setup Provider",
- "real_time_refresh": true,
- "refresh_button": true,
- "required": true,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_input": true,
- "track_in_telemetry": false,
- "type": "model",
- "value": [
- {
- "category": "OpenAI",
- "icon": "OpenAI",
- "metadata": {
- "api_key_param": "api_key",
- "context_length": 128000,
- "max_tokens_field_name": "max_tokens",
- "model_class": "ChatOpenAI",
- "model_name_param": "model",
- "reasoning": true,
- "reasoning_models": [
- "gpt-5.4-mini"
- ]
- },
- "name": "gpt-5.4-mini",
- "provider": "OpenAI"
- }
- ]
- },
- "model_name": {
- "_input_type": "StrInput",
- "advanced": false,
- "api_editable": false,
- "display_name": "Model Name Override",
- "dynamic": false,
- "info": "Optional model name to use instead of the selected model. Can be set from a global variable for runtime model selection.",
- "list": false,
- "list_add_label": "Add More",
- "load_from_db": true,
- "name": "model_name",
- "override_skip": false,
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_metadata": true,
- "track_in_telemetry": false,
- "type": "str",
- "value": "SELECTED_LANGUAGE_MODEL"
+ "total_dependencies": 1
},
- "ollama_base_url": {
- "_input_type": "StrInput",
- "advanced": false,
+ "module": "custom_components.parser"
+ },
+ "minimized": false,
+ "output_types": [],
+ "outputs": [
+ {
+ "allows_loop": false,
+ "cache": true,
+ "display_name": "Parsed Text",
+ "group_outputs": false,
+ "loop_types": null,
+ "method": "parse_combined_text",
+ "name": "parsed_text",
+ "options": null,
+ "required_inputs": null,
+ "selected": "Message",
+ "tool_mode": true,
+ "types": [
+ "Message"
+ ],
+ "value": "__UNDEFINED__"
+ }
+ ],
+ "pinned": false,
+ "template": {
+ "_type": "Component",
+ "code": {
+ "advanced": true,
"api_editable": false,
- "display_name": "Ollama API URL",
- "dynamic": false,
- "info": "Endpoint of the Ollama API (Ollama only)",
+ "dynamic": true,
+ "fileTypes": [],
+ "file_path": "",
+ "info": "",
"list": false,
- "list_add_label": "Add More",
"load_from_db": false,
- "name": "ollama_base_url",
- "override_skip": false,
+ "multiline": true,
+ "name": "code",
+ "password": false,
"placeholder": "",
- "real_time_refresh": true,
- "required": false,
- "show": false,
+ "required": true,
+ "show": true,
"title_case": false,
- "tool_mode": false,
- "trace_as_metadata": true,
- "track_in_telemetry": false,
- "type": "str",
- "value": ""
+ "type": "code",
+ "value": "from lfx.custom.custom_component.component import Component\nfrom lfx.helpers.data import safe_convert\nfrom lfx.inputs.inputs import BoolInput, HandleInput, MessageTextInput, MultilineInput, TabInput\nfrom lfx.schema.data import Data\nfrom lfx.schema.dataframe import DataFrame\nfrom lfx.schema.message import Message\nfrom lfx.template.field.base import Output\n\n\nclass _DefaultDict(dict):\n def __init__(self, data_item: Data):\n super().__init__(data_item.data)\n self.default_value = data_item.default_value\n\n def __missing__(self, key):\n return self.default_value if self.default_value is not None else \"\"\n\n\nclass ParserComponent(Component):\n display_name = \"Parser\"\n description = \"Extracts text using a template.\"\n documentation: str = \"https://docs.langflow.org/parser\"\n icon = \"braces\"\n\n inputs = [\n HandleInput(\n name=\"input_data\",\n display_name=\"JSON or Table\",\n input_types=[\"DataFrame\", \"Table\", \"Data\", \"JSON\"],\n info=\"Accepts a DataFrame, a Data object, or a list of Data objects.\",\n required=True,\n ),\n TabInput(\n name=\"mode\",\n display_name=\"Mode\",\n options=[\"Parser\", \"Stringify\"],\n value=\"Parser\",\n info=\"Convert into raw string instead of using a template.\",\n real_time_refresh=True,\n ),\n MultilineInput(\n name=\"pattern\",\n display_name=\"Template\",\n info=(\n \"Use variables within curly brackets to extract column values for DataFrames \"\n \"or key values for Data.\"\n \"For example: `Name: {Name}, Age: {Age}, Country: {Country}`\"\n ),\n value=\"Text: {text}\", # Example default\n dynamic=True,\n show=True,\n required=True,\n ),\n MessageTextInput(\n name=\"sep\",\n display_name=\"Separator\",\n advanced=True,\n value=\"\\n\",\n info=\"String used to separate rows/items.\",\n ),\n ]\n\n outputs = [\n Output(\n display_name=\"Parsed Text\",\n name=\"parsed_text\",\n info=\"Formatted text output.\",\n method=\"parse_combined_text\",\n ),\n ]\n\n def update_build_config(self, build_config, field_value, field_name=None):\n \"\"\"Dynamically hide/show `template` and enforce requirement based on `stringify`.\"\"\"\n if field_name == \"mode\":\n build_config[\"pattern\"][\"show\"] = self.mode == \"Parser\"\n build_config[\"pattern\"][\"required\"] = self.mode == \"Parser\"\n if field_value:\n clean_data = BoolInput(\n name=\"clean_data\",\n display_name=\"Clean Data\",\n info=(\n \"Enable to clean the data by removing empty rows and lines \"\n \"in each cell of the DataFrame/ Data object.\"\n ),\n value=True,\n advanced=True,\n required=False,\n )\n build_config[\"clean_data\"] = clean_data.to_dict()\n else:\n build_config.pop(\"clean_data\", None)\n\n return build_config\n\n def _clean_args(self) -> tuple[DataFrame | None, Data | list[Data] | None]:\n \"\"\"Prepare arguments based on input type.\"\"\"\n input_data = self.input_data\n\n match input_data:\n case list() if all(isinstance(item, Data) for item in input_data):\n return None, input_data\n case DataFrame():\n return input_data, None\n case Data():\n return None, input_data\n case dict() if \"data\" in input_data:\n try:\n if \"columns\" in input_data: # Likely a DataFrame\n return DataFrame.from_dict(input_data), None\n # Likely a Data object\n return None, Data(**input_data)\n except (TypeError, ValueError, KeyError) as e:\n msg = f\"Invalid structured input provided: {e!s}\"\n raise ValueError(msg) from e\n case _:\n msg = f\"Unsupported input type: {type(input_data)}. Expected DataFrame, Data, or list[Data].\"\n raise ValueError(msg)\n\n def parse_combined_text(self) -> Message:\n \"\"\"Parse all rows/items into a single text or convert input to string if `stringify` is enabled.\"\"\"\n # Early return for stringify option\n if self.mode == \"Stringify\":\n return self.convert_to_string()\n\n df, data = self._clean_args()\n\n lines = []\n if df is not None:\n for _, row in df.iterrows():\n formatted_text = self.pattern.format(**row.to_dict())\n lines.append(formatted_text)\n elif data is not None:\n data_items = data if isinstance(data, list) else [data]\n for data_item in data_items:\n formatted_text = self.pattern.format_map(_DefaultDict(data_item))\n lines.append(formatted_text)\n\n combined_text = self.sep.join(lines)\n self.status = combined_text\n return Message(text=combined_text)\n\n def convert_to_string(self) -> Message:\n \"\"\"Convert input data to string with proper error handling.\"\"\"\n clean_data = getattr(self, \"clean_data\", False)\n if isinstance(self.input_data, list):\n result = \"\\n\".join(safe_convert(item, clean_data=clean_data) for item in self.input_data)\n else:\n result = safe_convert(self.input_data, clean_data=clean_data)\n self.log(f\"Converted to string with length: {len(result)}\")\n\n message = Message(text=result)\n self.status = message\n return message\n"
},
- "project_id": {
- "_input_type": "StrInput",
+ "input_data": {
+ "_input_type": "HandleInput",
"advanced": false,
"api_editable": false,
- "display_name": "watsonx Project ID",
+ "display_name": "JSON or Table",
"dynamic": false,
- "info": "The project ID associated with the foundation model (IBM watsonx.ai only)",
+ "info": "Accepts a DataFrame, a Data object, or a list of Data objects.",
+ "input_types": [
+ "DataFrame",
+ "Table",
+ "Data",
+ "JSON"
+ ],
"list": false,
"list_add_label": "Add More",
- "load_from_db": false,
- "name": "project_id",
+ "name": "input_data",
"override_skip": false,
"placeholder": "",
- "required": false,
- "show": false,
+ "required": true,
+ "show": true,
"title_case": false,
- "tool_mode": false,
"trace_as_metadata": true,
"track_in_telemetry": false,
- "type": "str",
+ "type": "other",
"value": ""
},
- "provider": {
- "_input_type": "StrInput",
+ "mode": {
+ "_input_type": "TabInput",
"advanced": false,
"api_editable": false,
- "display_name": "Provider Override",
- "dynamic": false,
- "info": "Optional provider to use with Model Name Override. Leave blank to use the selected model's provider.",
- "list": false,
- "list_add_label": "Add More",
- "load_from_db": true,
- "name": "provider",
- "override_skip": false,
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_metadata": true,
- "track_in_telemetry": false,
- "type": "str",
- "value": "SELECTED_LANGUAGE_MODEL_PROVIDER"
- },
- "stream": {
- "_input_type": "BoolInput",
- "advanced": true,
- "api_editable": false,
- "display_name": "Stream",
+ "display_name": "Mode",
"dynamic": false,
- "info": "Whether to stream the response",
- "list": false,
- "list_add_label": "Add More",
- "name": "stream",
+ "info": "Convert into raw string instead of using a template.",
+ "name": "mode",
+ "options": [
+ "Parser",
+ "Stringify"
+ ],
"override_skip": false,
"placeholder": "",
+ "real_time_refresh": true,
"required": false,
"show": true,
"title_case": false,
"tool_mode": false,
"trace_as_metadata": true,
"track_in_telemetry": true,
- "type": "bool",
- "value": false
+ "type": "tab",
+ "value": "Parser"
},
- "system_message": {
+ "pattern": {
"_input_type": "MultilineInput",
"advanced": false,
"ai_enabled": false,
"api_editable": false,
"copy_field": false,
- "display_name": "System Message",
- "dynamic": false,
- "info": "A system message that helps set the behavior of the assistant",
+ "display_name": "Template",
+ "dynamic": true,
+ "info": "Use variables within curly brackets to extract column values for DataFrames or key values for Data.For example: `Name: {Name}, Age: {Age}, Country: {Country}`",
"input_types": [
"Message"
],
@@ -1696,11 +1337,11 @@
"list_add_label": "Add More",
"load_from_db": false,
"multiline": true,
- "name": "system_message",
+ "name": "pattern",
"override_skip": false,
"password": false,
"placeholder": "",
- "required": false,
+ "required": true,
"show": true,
"title_case": false,
"tool_mode": false,
@@ -1708,125 +1349,190 @@
"trace_as_metadata": true,
"track_in_telemetry": false,
"type": "str",
- "value": ""
+ "value": "{text}"
},
- "temperature": {
- "_input_type": "SliderInput",
+ "sep": {
+ "_input_type": "MessageTextInput",
"advanced": true,
"api_editable": false,
- "display_name": "Temperature",
+ "display_name": "Separator",
"dynamic": false,
- "info": "Controls randomness in responses",
- "max_label": "",
- "max_label_icon": "",
- "min_label": "",
- "min_label_icon": "",
- "name": "temperature",
+ "info": "String used to separate rows/items.",
+ "input_types": [
+ "Message"
+ ],
+ "list": false,
+ "list_add_label": "Add More",
+ "load_from_db": false,
+ "name": "sep",
"override_skip": false,
"placeholder": "",
- "range_spec": {
- "max": 1,
- "min": 0,
- "step": 0.01,
- "step_type": "float"
- },
"required": false,
"show": true,
- "slider_buttons": false,
- "slider_buttons_options": [],
- "slider_input": false,
"title_case": false,
"tool_mode": false,
+ "trace_as_input": true,
+ "trace_as_metadata": true,
"track_in_telemetry": false,
- "type": "slider",
- "value": 0.1
+ "type": "str",
+ "value": "\n"
}
},
"tool_mode": false
},
- "selected_output": "text_output",
- "showNode": true,
- "type": "LanguageModelComponent"
+ "showNode": false,
+ "type": "ParserComponent"
},
"dragging": false,
- "id": "LanguageModelComponent-KdXf9",
+ "id": "ParserComponent-x6BS7",
+ "measured": {
+ "height": 80,
+ "width": 192
+ },
"position": {
- "x": 1667.085299897802,
- "y": 1326.2080401399078
+ "x": 851.661470235947,
+ "y": 1429.639922711361
},
"selected": false,
"type": "genericNode"
},
{
"data": {
- "_connectionMode": false,
- "description": "Generate embeddings using a specified provider.",
- "display_name": "Embedding Model",
- "id": "EmbeddingModel-cONxU",
+ "id": "ext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-yrQui",
"node": {
"base_classes": [
- "Embeddings"
+ "JSON",
+ "VectorStore"
],
"beta": false,
+ "bundle": "openrag",
"conditional_paths": [],
"custom_fields": {},
- "description": "Generate embeddings using a specified provider.",
- "display_name": "Embedding Model",
- "documentation": "https://docs.langflow.org/components-embedding-models",
+ "description": "Store and search documents using OpenSearch with multi-model hybrid semantic and keyword search. To search use the tools search_documents and raw_search. Search documents takes a query for vector search, for example\n {search_query: \"components in openrag\"}",
+ "display_name": "OpenSearch (Multi-Model Multi-Embedding)",
+ "documentation": "",
"edited": false,
+ "extension": "openrag",
+ "extension_version": "0.0.0",
"field_order": [
- "model",
- "model_name",
- "provider",
- "api_key",
- "api_base",
- "base_url_ibm_watsonx",
- "project_id",
- "ollama_base_url",
- "dimensions",
- "chunk_size",
+ "docs_metadata",
+ "opensearch_url",
+ "index_name",
+ "engine",
+ "space_type",
+ "ef_construction",
+ "m",
+ "num_candidates",
+ "ingest_data",
+ "search_query",
+ "should_cache_vector_store",
+ "embedding",
+ "embedding_model_name",
+ "vector_field",
+ "number_of_results",
+ "filter_expression",
+ "auth_mode",
+ "username",
+ "password",
+ "jwt_token",
+ "jwt_header",
+ "bearer_prefix",
+ "use_ssl",
+ "verify_certs",
"request_timeout",
"max_retries",
- "show_progress_bar",
- "model_kwargs",
- "truncate_input_tokens",
- "input_text"
+ "openrag_ingest_url",
+ "openrag_ingest_token",
+ "openrag_ingest_run_id",
+ "openrag_ingest_batch_size"
],
"frozen": false,
- "icon": "binary",
- "last_updated": "2026-07-29T14:28:19.770Z",
+ "icon": "OpenSearch",
+ "last_updated": "2026-08-05T16:19:12.028Z",
"legacy": false,
"metadata": {
- "code_hash": "0780e9bbc5fa",
+ "code_hash": "6c375fdaa9e7",
"dependencies": {
"dependencies": [
+ {
+ "name": "httpx",
+ "version": "0.28.1"
+ },
{
"name": "lfx",
- "version": "1.11.1rc0"
+ "version": "1.11.2"
+ },
+ {
+ "name": "opensearchpy",
+ "version": "3.2.0"
+ },
+ {
+ "name": "config",
+ "version": null
+ },
+ {
+ "name": "tenacity",
+ "version": "8.5.0"
}
],
- "total_dependencies": 1
+ "total_dependencies": 5
},
- "module": "custom_components.embedding_model"
+ "module": "_lfx_ext.extra.openrag.opensearch_multimodal"
},
"minimized": false,
+ "name": "OpenSearchVectorStoreComponentMultimodalMultiEmbedding",
+ "namespaced_id": "ext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra",
"output_types": [],
"outputs": [
{
"allows_loop": false,
"cache": true,
- "display_name": "Embedding Model",
+ "display_name": "Search Results",
"group_outputs": false,
- "hidden": null,
"loop_types": null,
- "method": "build_embeddings",
- "name": "embeddings",
+ "method": "search_documents",
+ "name": "search_results",
"options": null,
"required_inputs": null,
- "selected": "Embeddings",
+ "selected": "JSON",
"tool_mode": true,
"types": [
- "Embeddings"
+ "JSON"
+ ],
+ "value": "__UNDEFINED__"
+ },
+ {
+ "allows_loop": false,
+ "cache": true,
+ "display_name": "Raw Search",
+ "group_outputs": false,
+ "loop_types": null,
+ "method": "raw_search",
+ "name": "raw_search",
+ "options": null,
+ "required_inputs": null,
+ "selected": "JSON",
+ "tool_mode": true,
+ "types": [
+ "JSON"
+ ],
+ "value": "__UNDEFINED__"
+ },
+ {
+ "allows_loop": false,
+ "cache": true,
+ "display_name": "Vector Store Connection",
+ "group_outputs": false,
+ "hidden": false,
+ "loop_types": null,
+ "method": "as_vector_store",
+ "name": "vectorstoreconnection",
+ "options": null,
+ "required_inputs": null,
+ "selected": "VectorStore",
+ "tool_mode": true,
+ "types": [
+ "VectorStore"
],
"value": "__UNDEFINED__"
}
@@ -1840,97 +1546,46 @@
"value": "203c7c12-9e1d-4561-bb14-16102afec154"
},
"_type": "Component",
- "api_base": {
- "_input_type": "MessageTextInput",
- "advanced": true,
- "api_editable": false,
- "display_name": "API Base URL",
- "dynamic": false,
- "info": "Base URL for the API. Leave empty for default.",
- "input_types": [
- "Message"
- ],
- "list": false,
- "list_add_label": "Add More",
- "load_from_db": false,
- "name": "api_base",
- "override_skip": false,
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_input": true,
- "trace_as_metadata": true,
- "track_in_telemetry": false,
- "type": "str",
- "value": ""
- },
- "api_key": {
- "_input_type": "SecretStrInput",
- "advanced": true,
- "api_editable": false,
- "display_name": "API Key",
- "dynamic": false,
- "info": "Overrides global provider settings. Leave blank to use your pre-configured API Key.",
- "input_types": [],
- "load_from_db": false,
- "name": "api_key",
- "override_skip": false,
- "password": true,
- "placeholder": "",
- "real_time_refresh": true,
- "required": false,
- "show": true,
- "title_case": false,
- "track_in_telemetry": false,
- "type": "str",
- "value": ""
- },
- "base_url_ibm_watsonx": {
+ "auth_mode": {
"_input_type": "DropdownInput",
"advanced": false,
"api_editable": false,
- "combobox": true,
+ "combobox": false,
"dialog_inputs": {},
- "display_name": "watsonx API Endpoint",
+ "display_name": "Authentication Mode",
"dynamic": false,
"external_options": {},
- "info": "The base URL of the API (IBM watsonx.ai only)",
- "load_from_db": false,
- "name": "base_url_ibm_watsonx",
+ "info": "Authentication method: 'basic' for username/password authentication, 'jwt' for JSON Web Token (Bearer) authentication, or 'openrag' to delegate writes to the OpenRAG backend ingest callback (no direct OpenSearch credentials required — only OPENRAG_* fields).",
+ "name": "auth_mode",
"options": [
- "https://us-south.ml.cloud.ibm.com",
- "https://eu-de.ml.cloud.ibm.com",
- "https://eu-gb.ml.cloud.ibm.com",
- "https://au-syd.ml.cloud.ibm.com",
- "https://jp-tok.ml.cloud.ibm.com",
- "https://ca-tor.ml.cloud.ibm.com"
+ "basic",
+ "jwt",
+ "openrag"
],
"options_metadata": [],
"override_skip": false,
"placeholder": "",
"real_time_refresh": true,
"required": false,
- "show": false,
+ "show": true,
"title_case": false,
"toggle": false,
"tool_mode": false,
"trace_as_metadata": true,
"track_in_telemetry": true,
"type": "str",
- "value": ""
+ "value": "jwt"
},
- "chunk_size": {
- "_input_type": "IntInput",
+ "bearer_prefix": {
+ "_input_type": "BoolInput",
"advanced": true,
"api_editable": false,
- "display_name": "Chunk Size",
+ "display_name": "Prefix 'Bearer '",
"dynamic": false,
"info": "",
"list": false,
"list_add_label": "Add More",
- "name": "chunk_size",
+ "name": "bearer_prefix",
"override_skip": false,
"placeholder": "",
"required": false,
@@ -1939,8 +1594,8 @@
"tool_mode": false,
"trace_as_metadata": true,
"track_in_telemetry": true,
- "type": "int",
- "value": 1000
+ "type": "bool",
+ "value": false
},
"code": {
"advanced": true,
@@ -1959,303 +1614,189 @@
"show": true,
"title_case": false,
"type": "code",
- "value": "from lfx.base.embeddings.model import LCEmbeddingsModel\nfrom lfx.base.models.unified_models import (\n get_embedding_model_options,\n get_embeddings,\n handle_model_input_update,\n)\nfrom lfx.base.models.watsonx_constants import IBM_WATSONX_URLS\nfrom lfx.components.models_and_agents.model_selection import apply_model_overrides\nfrom lfx.field_typing import Embeddings\nfrom lfx.io import (\n BoolInput,\n DictInput,\n DropdownInput,\n FloatInput,\n IntInput,\n MessageTextInput,\n ModelInput,\n SecretStrInput,\n StrInput,\n)\n\n\nclass EmbeddingModelComponent(LCEmbeddingsModel):\n display_name = \"Embedding Model\"\n description = \"Generate embeddings using a specified provider.\"\n documentation: str = \"https://docs.langflow.org/components-embedding-models\"\n icon = \"binary\"\n name = \"EmbeddingModel\"\n category = \"models\"\n\n def update_build_config(self, build_config: dict, field_value: str, field_name: str | None = None):\n \"\"\"Dynamically update build config with user-filtered model options.\"\"\"\n return handle_model_input_update(\n self,\n dict(build_config),\n field_value,\n field_name,\n cache_key_prefix=\"embedding_model_options\",\n get_options_func=get_embedding_model_options,\n )\n\n inputs = [\n ModelInput(\n name=\"model\",\n display_name=\"Embedding Model\",\n info=\"Select your model provider\",\n real_time_refresh=True,\n required=True,\n model_type=\"embedding\",\n input_types=[\"Embeddings\"], # Override default to accept Embeddings instead of LanguageModel\n ),\n StrInput(\n name=\"model_name\",\n display_name=\"Model Name Override\",\n info=(\n \"Optional embedding model name to use instead of the selected model. \"\n \"Can be set from a global variable for runtime model selection.\"\n ),\n advanced=True,\n load_from_db=False,\n ),\n StrInput(\n name=\"provider\",\n display_name=\"Provider Override\",\n info=(\n \"Optional provider to use with Model Name Override. Leave blank to use the selected model's provider.\"\n ),\n advanced=True,\n load_from_db=False,\n ),\n SecretStrInput(\n name=\"api_key\",\n display_name=\"API Key\",\n info=\"Overrides global provider settings. Leave blank to use your pre-configured API Key.\",\n real_time_refresh=True,\n advanced=True,\n ),\n MessageTextInput(\n name=\"api_base\",\n display_name=\"API Base URL\",\n info=\"Base URL for the API. Leave empty for default.\",\n advanced=True,\n ),\n # Watson-specific inputs\n DropdownInput(\n name=\"base_url_ibm_watsonx\",\n display_name=\"watsonx API Endpoint\",\n info=\"The base URL of the API (IBM watsonx.ai only)\",\n options=IBM_WATSONX_URLS,\n value=IBM_WATSONX_URLS[0],\n combobox=True,\n show=False,\n real_time_refresh=True,\n ),\n MessageTextInput(\n name=\"project_id\",\n display_name=\"Project ID\",\n info=\"IBM watsonx.ai Project ID (required for IBM watsonx.ai)\",\n show=False,\n ),\n # Ollama-specific input\n StrInput(\n name=\"ollama_base_url\",\n display_name=\"Ollama API URL\",\n info=\"Endpoint of the Ollama API (Ollama only)\",\n show=False,\n real_time_refresh=True,\n ),\n IntInput(\n name=\"dimensions\",\n display_name=\"Dimensions\",\n info=\"The number of dimensions the resulting output embeddings should have. \"\n \"Only supported by certain models.\",\n advanced=True,\n ),\n IntInput(\n name=\"chunk_size\",\n display_name=\"Chunk Size\",\n advanced=True,\n value=1000,\n ),\n FloatInput(\n name=\"request_timeout\",\n display_name=\"Request Timeout\",\n advanced=True,\n ),\n IntInput(\n name=\"max_retries\",\n display_name=\"Max Retries\",\n advanced=True,\n value=3,\n ),\n BoolInput(\n name=\"show_progress_bar\",\n display_name=\"Show Progress Bar\",\n advanced=True,\n ),\n DictInput(\n name=\"model_kwargs\",\n display_name=\"Model Kwargs\",\n advanced=True,\n info=(\n \"Additional keyword arguments to pass to the model. Only used by providers that support this parameter \"\n \"(e.g. OpenAI, Google Generative AI). \"\n \"Ignored for providers that do not include it in their parameter mapping.\"\n ),\n ),\n IntInput(\n name=\"truncate_input_tokens\",\n display_name=\"Truncate Input Tokens\",\n advanced=True,\n value=200,\n show=False,\n ),\n BoolInput(\n name=\"input_text\",\n display_name=\"Include the original text in the output\",\n value=True,\n advanced=True,\n show=False,\n ),\n ]\n\n def build_embeddings(self) -> Embeddings:\n \"\"\"Build and return an embeddings instance based on the selected model.\"\"\"\n model = apply_model_overrides(\n self.model,\n model_name=getattr(self, \"model_name\", None),\n provider=getattr(self, \"provider\", None),\n user_id=self.user_id,\n get_options=get_embedding_model_options,\n )\n return get_embeddings(\n model=model,\n user_id=self.user_id,\n api_key=self.api_key,\n api_base=self.api_base,\n dimensions=self.dimensions,\n chunk_size=self.chunk_size,\n request_timeout=self.request_timeout,\n max_retries=self.max_retries,\n show_progress_bar=self.show_progress_bar,\n model_kwargs=self.model_kwargs,\n watsonx_url=getattr(self, \"base_url_ibm_watsonx\", None),\n watsonx_project_id=getattr(self, \"project_id\", None),\n watsonx_truncate_input_tokens=getattr(self, \"truncate_input_tokens\", None),\n watsonx_input_text=getattr(self, \"input_text\", None),\n ollama_base_url=getattr(self, \"ollama_base_url\", None),\n )\n"
+ "value": "from __future__ import annotations\n\nimport copy\nimport json\nimport uuid\nfrom concurrent.futures import ThreadPoolExecutor, as_completed\nfrom typing import Any\n\nimport httpx\nfrom lfx.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store\nfrom lfx.base.vectorstores.vector_store_connection_decorator import vector_store_connection\nfrom lfx.io import (\n BoolInput,\n DropdownInput,\n HandleInput,\n IntInput,\n MultilineInput,\n Output,\n SecretStrInput,\n StrInput,\n TableInput,\n)\nfrom lfx.log import logger\nfrom lfx.schema.data import Data\nfrom lfx.schema.dataframe import Table\nfrom opensearchpy import OpenSearch, helpers\nfrom opensearchpy.exceptions import OpenSearchException, RequestError\n\nREQUEST_TIMEOUT = 60\nMAX_RETRIES = 5\n\n# watsonx.ai surfaces rate-limit state via these (mostly non-standard) response\n# headers. The IBM SDK acts on the x-requests-limit-* family directly; we log\n# them on a failed embedding call to aid plan/region tuning.\n_WATSONX_RATE_LIMIT_HEADERS = (\n \"x-requests-limit-rate\",\n \"x-requests-limit-remaining\",\n \"x-requests-limit-reset\",\n \"Retry-After\",\n)\n\n\ndef _log_watsonx_rate_limit_headers(error: Exception) -> None:\n \"\"\"Best-effort diagnostic: log watsonx rate-limit headers from a failed call.\n\n The watsonx SDK raises ``ApiRequestFailure``, which carries the originating\n httpx/requests ``Response`` as ``.response``. On a 429 exhaustion we surface\n the documented rate-limit headers so operators can tune throughput.\n \"\"\"\n try:\n response = getattr(error, \"response\", None)\n headers = getattr(response, \"headers\", None)\n if not headers:\n return\n status = getattr(response, \"status_code\", \"unknown\")\n observed = {h: headers.get(h) for h in _WATSONX_RATE_LIMIT_HEADERS if headers.get(h) is not None}\n if str(status) == \"429\" or observed:\n logger.warning(f\"watsonx rate-limit response (status={status}): {observed}\")\n except Exception as log_error: # never let diagnostics mask the real error\n logger.debug(f\"Could not extract watsonx rate-limit headers: {log_error}\")\n\n\ndef normalize_model_name(model_name: str) -> str:\n \"\"\"Normalize embedding model name for use as field suffix.\n\n Converts model names to valid OpenSearch field names by replacing\n special characters and ensuring alphanumeric format.\n\n Args:\n model_name: Original embedding model name (e.g., \"text-embedding-3-small\")\n\n Returns:\n Normalized field suffix (e.g., \"text_embedding_3_small\")\n \"\"\"\n normalized = model_name.lower()\n # Replace common separators with underscores\n normalized = normalized.replace(\"-\", \"_\").replace(\":\", \"_\").replace(\"/\", \"_\").replace(\".\", \"_\")\n # Remove any non-alphanumeric characters except underscores\n normalized = \"\".join(c if c.isalnum() or c == \"_\" else \"_\" for c in normalized)\n # Remove duplicate underscores\n while \"__\" in normalized:\n normalized = normalized.replace(\"__\", \"_\")\n return normalized.strip(\"_\")\n\n\ndef get_embedding_field_name(model_name: str) -> str:\n \"\"\"Get the dynamic embedding field name for a model.\n\n Args:\n model_name: Embedding model name\n\n Returns:\n Field name in format: chunk_embedding_{normalized_model_name}\n \"\"\"\n logger.info(f\"chunk_embedding_{normalize_model_name(model_name)}\")\n return f\"chunk_embedding_{normalize_model_name(model_name)}\"\n\n\nUNTRUSTED_CHUNK_FENCE_START = \"<<<UNTRUSTED_DOC_CHUNK>>>\"\nUNTRUSTED_CHUNK_FENCE_END = \"<<<END_UNTRUSTED_DOC_CHUNK>>>\"\n\n\ndef fence_untrusted_text(text: str) -> str:\n \"\"\"Wrap retrieved document text in delimiters marking it as untrusted data.\n\n Retrieved chunk text can contain attacker-controlled natural-language\n instructions (indirect prompt injection, VULN-13906). Fencing it lets the\n system prompt tell the LLM to treat anything between these markers as\n data only, never as instructions or tool directives.\n\n Any literal fence markers already present in `text` are escaped first, so\n a poisoned chunk can't embed a fake end-of-fence marker to break out of\n the untrusted section and have its continuation misread as trusted.\n \"\"\"\n if not text:\n return text\n escaped = text.replace(\n UNTRUSTED_CHUNK_FENCE_START, \"\\\\\" + UNTRUSTED_CHUNK_FENCE_START\n ).replace(UNTRUSTED_CHUNK_FENCE_END, \"\\\\\" + UNTRUSTED_CHUNK_FENCE_END)\n return f\"{UNTRUSTED_CHUNK_FENCE_START}\\n{escaped}\\n{UNTRUSTED_CHUNK_FENCE_END}\"\n\n\n@vector_store_connection\nclass OpenSearchVectorStoreComponentMultimodalMultiEmbedding(LCVectorStoreComponent):\n \"\"\"OpenSearch Vector Store Component with Multi-Model Hybrid Search Capabilities.\n\n This component provides vector storage and retrieval using OpenSearch, combining semantic\n similarity search (KNN) with keyword-based search for optimal results. It supports:\n - Multiple embedding models per index with dynamic field names\n - Automatic detection and querying of all available embedding models\n - Parallel embedding generation for multi-model search\n - Document ingestion with model tracking\n - Advanced filtering and aggregations\n - Flexible authentication options\n\n Features:\n - Multi-model vector storage with dynamic fields (chunk_embedding_{model_name})\n - Hybrid search combining multiple KNN queries (dis_max) + keyword matching\n - Auto-detection of available models in the index\n - Parallel query embedding generation for all detected models\n - Vector storage with configurable engines (jvector, nmslib, faiss, lucene)\n - Flexible authentication (Basic auth, JWT tokens)\n\n Model Name Resolution:\n - Priority: deployment > model > model_name attributes\n - This ensures correct matching between embedding objects and index fields\n - When multiple embeddings are provided, specify embedding_model_name to select which one to use\n - During search, each detected model in the index is matched to its corresponding embedding object\n \"\"\"\n\n display_name: str = \"OpenSearch (Multi-Model Multi-Embedding)\"\n icon: str = \"OpenSearch\"\n description: str = (\n \"Store and search documents using OpenSearch with multi-model hybrid semantic and keyword search. \"\n \"To search use the tools search_documents and raw_search. \"\n \"Search documents takes a query for vector search, for example\\n\"\n ' {search_query: \"components in openrag\"}'\n )\n\n # Keys we consider baseline\n default_keys: list[str] = [\n \"opensearch_url\",\n \"index_name\",\n *[i.name for i in LCVectorStoreComponent.inputs], # search_query, add_documents, etc.\n \"embedding\",\n \"embedding_model_name\",\n \"vector_field\",\n \"number_of_results\",\n \"auth_mode\",\n \"username\",\n \"password\",\n \"jwt_token\",\n \"jwt_header\",\n \"bearer_prefix\",\n \"use_ssl\",\n \"verify_certs\",\n \"filter_expression\",\n \"engine\",\n \"space_type\",\n \"ef_construction\",\n \"m\",\n \"num_candidates\",\n \"docs_metadata\",\n \"request_timeout\",\n \"max_retries\",\n \"openrag_ingest_url\",\n \"openrag_ingest_token\",\n \"openrag_ingest_run_id\",\n \"openrag_ingest_batch_size\",\n ]\n _openrag_ingest_global_placeholders = {\n \"openrag_ingest_url\": \"OPENRAG_INGEST_URL\",\n \"openrag_ingest_token\": \"OPENRAG_INGEST_TOKEN\",\n \"openrag_ingest_run_id\": \"OPENRAG_INGEST_RUN_ID\",\n }\n\n inputs = [\n TableInput(\n name=\"docs_metadata\",\n display_name=\"Document Metadata\",\n info=(\n \"Additional metadata key-value pairs to be added to all ingested documents. \"\n \"Useful for tagging documents with source information, categories, or other custom attributes.\"\n ),\n table_schema=[\n {\n \"name\": \"key\",\n \"display_name\": \"Key\",\n \"type\": \"str\",\n \"description\": \"Key name\",\n },\n {\n \"name\": \"value\",\n \"display_name\": \"Value\",\n \"type\": \"str\",\n \"description\": \"Value of the metadata\",\n },\n ],\n value=[],\n input_types=[\"Data\", \"JSON\"],\n ),\n StrInput(\n name=\"opensearch_url\",\n display_name=\"OpenSearch URL\",\n value=\"http://localhost:9200\",\n info=(\n \"The connection URL for your OpenSearch cluster \"\n \"(e.g., http://localhost:9200 for local development or your cloud endpoint).\"\n ),\n ),\n StrInput(\n name=\"index_name\",\n display_name=\"Index Name\",\n value=\"langflow\",\n info=(\n \"The OpenSearch index name where documents will be stored and searched. \"\n \"Will be created automatically if it doesn't exist.\"\n ),\n ),\n DropdownInput(\n name=\"engine\",\n display_name=\"Vector Engine\",\n options=[\"nmslib\", \"faiss\", \"lucene\", \"jvector\"],\n value=\"jvector\",\n info=(\n \"Vector search engine for similarity calculations. 'nmslib' works with standard \"\n \"OpenSearch. 'jvector' requires OpenSearch 2.9+. 'lucene' requires index.knn: true. \"\n \"Amazon OpenSearch Serverless only supports 'nmslib' or 'faiss'.\"\n ),\n advanced=True,\n ),\n DropdownInput(\n name=\"space_type\",\n display_name=\"Distance Metric\",\n options=[\"l2\", \"l1\", \"cosinesimil\", \"linf\", \"innerproduct\"],\n value=\"l2\",\n info=(\n \"Distance metric for calculating vector similarity. 'l2' (Euclidean) is most common, \"\n \"'cosinesimil' for cosine similarity, 'innerproduct' for dot product.\"\n ),\n advanced=True,\n ),\n IntInput(\n name=\"ef_construction\",\n display_name=\"EF Construction\",\n value=512,\n info=(\n \"Size of the dynamic candidate list during index construction. \"\n \"Higher values improve recall but increase indexing time and memory usage.\"\n ),\n advanced=True,\n ),\n IntInput(\n name=\"m\",\n display_name=\"M Parameter\",\n value=16,\n info=(\n \"Number of bidirectional connections for each vector in the HNSW graph. \"\n \"Higher values improve search quality but increase memory usage and indexing time.\"\n ),\n advanced=True,\n ),\n IntInput(\n name=\"num_candidates\",\n display_name=\"Candidate Pool Size\",\n value=1000,\n info=(\n \"Number of approximate neighbors to consider for each KNN query. \"\n \"Some OpenSearch deployments do not support this parameter; set to 0 to disable.\"\n ),\n advanced=True,\n ),\n *LCVectorStoreComponent.inputs, # includes search_query, add_documents, etc.\n HandleInput(\n name=\"embedding\", display_name=\"Embedding\", input_types=[\"Embeddings\"], is_list=True\n ),\n StrInput(\n name=\"embedding_model_name\",\n display_name=\"Embedding Model Name\",\n value=\"\",\n info=(\n \"Name of the embedding model to use for ingestion. This selects which embedding from the list \"\n \"will be used to embed documents. Matches on deployment, model, model_id, or model_name. \"\n \"For duplicate deployments, use combined format: 'deployment:model' \"\n \"(e.g., 'text-embedding-ada-002:text-embedding-3-large'). \"\n \"Leave empty to use the first embedding. Error message will show all available identifiers.\"\n ),\n advanced=False,\n ),\n StrInput(\n name=\"vector_field\",\n display_name=\"Legacy Vector Field Name\",\n value=\"chunk_embedding\",\n advanced=True,\n info=(\n \"Legacy field name for backward compatibility. New documents use dynamic fields \"\n \"(chunk_embedding_{model_name}) based on the embedding_model_name.\"\n ),\n ),\n IntInput(\n name=\"number_of_results\",\n display_name=\"Default Result Limit\",\n value=10,\n advanced=True,\n info=(\n \"Default maximum number of search results to return when no limit is \"\n \"specified in the filter expression.\"\n ),\n ),\n MultilineInput(\n name=\"filter_expression\",\n display_name=\"Search Filters (JSON)\",\n value=\"\",\n info=(\n \"Optional JSON configuration for search filtering, result limits, and score thresholds.\\n\\n\"\n \"Format 1 - Explicit filters:\\n\"\n '{\"filter\": [{\"term\": {\"filename\":\"doc.pdf\"}}, '\n '{\"terms\":{\"owner\":[\"user1\",\"user2\"]}}], \"limit\": 10, \"score_threshold\": 1.6}\\n\\n'\n \"Format 2 - Context-style mapping:\\n\"\n '{\"data_sources\":[\"file.pdf\"], \"document_types\":[\"application/pdf\"], \"owners\":[\"user123\"]}\\n\\n'\n \"Use __IMPOSSIBLE_VALUE__ as placeholder to ignore specific filters.\"\n ),\n ),\n # ----- Auth controls (dynamic) -----\n DropdownInput(\n name=\"auth_mode\",\n display_name=\"Authentication Mode\",\n value=\"openrag\",\n options=[\"basic\", \"jwt\", \"openrag\"],\n info=(\n \"Authentication method: 'basic' for username/password authentication, \"\n \"'jwt' for JSON Web Token (Bearer) authentication, or 'openrag' to \"\n \"delegate writes to the OpenRAG backend ingest callback (no direct \"\n \"OpenSearch credentials required — only OPENRAG_* fields).\"\n ),\n real_time_refresh=True,\n advanced=False,\n ),\n StrInput(\n name=\"username\",\n display_name=\"Username\",\n value=\"admin\",\n show=True,\n ),\n SecretStrInput(\n name=\"password\",\n display_name=\"OpenSearch Password\",\n value=\"OPENSEARCH_PASSWORD\",\n load_from_db=True,\n show=True,\n ),\n SecretStrInput(\n name=\"jwt_token\",\n display_name=\"JWT Token\",\n value=\"JWT\",\n load_from_db=False,\n show=False,\n info=(\n \"Valid JSON Web Token for authentication. \"\n \"Will be sent in the Authorization header (with optional 'Bearer ' prefix).\"\n ),\n required=False\n ),\n StrInput(\n name=\"jwt_header\",\n display_name=\"JWT Header Name\",\n value=\"Authorization\",\n show=False,\n advanced=True,\n ),\n BoolInput(\n name=\"bearer_prefix\",\n display_name=\"Prefix 'Bearer '\",\n value=False,\n show=False,\n advanced=True,\n ),\n # ----- TLS -----\n BoolInput(\n name=\"use_ssl\",\n display_name=\"Use SSL/TLS\",\n value=True,\n advanced=True,\n info=\"Enable SSL/TLS encryption for secure connections to OpenSearch.\",\n ),\n BoolInput(\n name=\"verify_certs\",\n display_name=\"Verify SSL Certificates\",\n value=False,\n advanced=True,\n info=(\n \"Verify SSL certificates when connecting. \"\n \"Disable for self-signed certificates in development environments.\"\n ),\n ),\n # ----- Timeout / Retry -----\n StrInput(\n name=\"request_timeout\",\n display_name=\"Request Timeout (seconds)\",\n value=\"60\",\n advanced=True,\n info=(\n \"Time in seconds to wait for a response from OpenSearch. \"\n \"Increase for large bulk ingestion or complex hybrid queries.\"\n ),\n ),\n StrInput(\n name=\"max_retries\",\n display_name=\"Max Retries\",\n value=\"3\",\n advanced=True,\n info=\"Number of retries for failed connections before raising an error.\",\n ),\n StrInput(\n name=\"openrag_ingest_url\",\n display_name=\"OpenRAG Ingest URL\",\n value=\"OPENRAG_INGEST_URL\",\n load_from_db=True,\n input_types=[\"Text\", \"Message\"],\n advanced=True,\n info=\"Internal OpenRAG callback URL for backend-owned document indexing.\",\n ),\n SecretStrInput(\n name=\"openrag_ingest_token\",\n display_name=\"OpenRAG Ingest Token\",\n value=\"OPENRAG_INGEST_TOKEN\",\n load_from_db=True,\n input_types=[\"Text\", \"Message\"],\n advanced=True,\n info=\"Short-lived token used only for OpenRAG ingest callbacks.\",\n ),\n StrInput(\n name=\"openrag_ingest_run_id\",\n display_name=\"OpenRAG Ingest Run ID\",\n value=\"OPENRAG_INGEST_RUN_ID\",\n load_from_db=True,\n input_types=[\"Text\", \"Message\"],\n advanced=True,\n ),\n IntInput(\n name=\"openrag_ingest_batch_size\",\n display_name=\"OpenRAG Ingest Batch Size\",\n value=100,\n advanced=True,\n ),\n ]\n outputs = [\n Output(\n display_name=\"Search Results\",\n name=\"search_results\",\n method=\"search_documents\",\n ),\n Output(display_name=\"Raw Search\", name=\"raw_search\", method=\"raw_search\"),\n ]\n\n def raw_search(self, query: str | dict | None = None) -> Data:\n \"\"\"Execute a raw OpenSearch query against the target index.\n\n Args:\n query (dict[str, Any]): The OpenSearch query DSL dictionary.\n\n Returns:\n Data: Search results as a Data object.\n\n Raises:\n ValueError: If 'query' is not a valid OpenSearch query (must be a non-empty dict).\n \"\"\"\n raw_query = query if query is not None else self.search_query\n\n if raw_query is None or (isinstance(raw_query, str) and not raw_query.strip()):\n self.log(\"No query provided for raw search - returning empty results\")\n return Data(data={})\n\n if isinstance(raw_query, dict):\n query_body = copy.deepcopy(raw_query)\n elif isinstance(raw_query, str):\n s = raw_query.strip()\n\n # First, optimistically try to parse as JSON DSL\n try:\n query_body = json.loads(s)\n except json.JSONDecodeError:\n # Fallback: treat as a basic text query over common fields\n query_body = {\n \"query\": {\n \"multi_match\": {\n \"query\": s,\n \"fields\": [\"text^2\", \"filename^1.5\"],\n \"type\": \"best_fields\",\n \"fuzziness\": \"AUTO\",\n }\n }\n }\n else:\n msg = f\"Unsupported raw_search query type: {type(raw_query)!r}\"\n raise TypeError(msg)\n\n filter_obj = self._parse_filter_expression()\n filter_clauses = self._coerce_filter_clauses(filter_obj)\n\n if filter_clauses:\n if \"query\" in query_body:\n original_query = query_body[\"query\"]\n query_body[\"query\"] = {\n \"bool\": {\n \"must\": [original_query],\n \"filter\": filter_clauses,\n }\n }\n else:\n query_body[\"query\"] = {\n \"bool\": {\n \"must\": [{\"match_all\": {}}],\n \"filter\": filter_clauses,\n }\n }\n\n if filter_obj:\n # Apply limit if not already set in the raw query\n if \"size\" not in query_body:\n limit = self._resolve_limit(filter_obj, default_limit=None)\n if limit is not None:\n query_body[\"size\"] = limit\n\n # Apply score_threshold / scoreThreshold as min_score if not already set\n if \"min_score\" not in query_body:\n\n score_threshold = self._resolve_score_threshold(filter_obj)\n if score_threshold is not None:\n\n query_body[\"min_score\"] = score_threshold\n\n client = self.build_client()\n logger.info(f\"query: {query_body}\")\n resp = client.search(\n index=self.index_name,\n body=query_body,\n params={\"terminate_after\": 0},\n )\n # Remove any _source keys whose value is a list of floats (embedding vectors)\n # Minimum length threshold to identify embedding vectors\n min_vector_length = 100\n\n def is_vector(val):\n # Accepts if it's a list of numbers (float or int) and has reasonable vector length\n return (\n isinstance(val, list)\n and len(val) > min_vector_length\n and all(isinstance(x, (float, int)) for x in val)\n )\n\n if \"hits\" in resp and \"hits\" in resp[\"hits\"]:\n for hit in resp[\"hits\"][\"hits\"]:\n source = hit.get(\"_source\")\n if isinstance(source, dict):\n keys_to_remove = [k for k, v in source.items() if is_vector(v)]\n for k in keys_to_remove:\n source.pop(k)\n if \"text\" in source:\n source[\"text\"] = fence_untrusted_text(source[\"text\"])\n logger.info(f\"Raw search response (all embedding vectors removed): {resp}\")\n return Data(**resp)\n\n def _get_embedding_model_name(self, embedding_obj=None) -> str:\n \"\"\"Get the embedding model name from component config or embedding object.\n\n Priority: deployment > model > model_id > model_name\n This ensures we use the actual model being deployed, not just the configured model.\n Supports multiple embedding providers (OpenAI, Watsonx, Cohere, etc.)\n\n Args:\n embedding_obj: Specific embedding object to get name from (optional)\n\n Returns:\n Embedding model name\n\n Raises:\n ValueError: If embedding model name cannot be determined\n \"\"\"\n # First try explicit embedding_model_name input\n if hasattr(self, \"embedding_model_name\") and self.embedding_model_name:\n return self.embedding_model_name.strip()\n\n # Try to get from provided embedding object\n if embedding_obj:\n # Priority: deployment > model > model_id > model_name\n if hasattr(embedding_obj, \"deployment\") and embedding_obj.deployment:\n return str(embedding_obj.deployment)\n if hasattr(embedding_obj, \"model\") and embedding_obj.model:\n return str(embedding_obj.model)\n if hasattr(embedding_obj, \"model_id\") and embedding_obj.model_id:\n return str(embedding_obj.model_id)\n if hasattr(embedding_obj, \"model_name\") and embedding_obj.model_name:\n return str(embedding_obj.model_name)\n\n # Try to get from embedding component (legacy single embedding)\n if hasattr(self, \"embedding\") and self.embedding:\n # Handle list of embeddings\n if isinstance(self.embedding, list) and len(self.embedding) > 0:\n first_emb = self.embedding[0]\n if hasattr(first_emb, \"deployment\") and first_emb.deployment:\n return str(first_emb.deployment)\n if hasattr(first_emb, \"model\") and first_emb.model:\n return str(first_emb.model)\n if hasattr(first_emb, \"model_id\") and first_emb.model_id:\n return str(first_emb.model_id)\n if hasattr(first_emb, \"model_name\") and first_emb.model_name:\n return str(first_emb.model_name)\n # Handle single embedding\n elif not isinstance(self.embedding, list):\n if hasattr(self.embedding, \"deployment\") and self.embedding.deployment:\n return str(self.embedding.deployment)\n if hasattr(self.embedding, \"model\") and self.embedding.model:\n return str(self.embedding.model)\n if hasattr(self.embedding, \"model_id\") and self.embedding.model_id:\n return str(self.embedding.model_id)\n if hasattr(self.embedding, \"model_name\") and self.embedding.model_name:\n return str(self.embedding.model_name)\n\n msg = (\n \"Could not determine embedding model name. \"\n \"Please set the 'embedding_model_name' field or ensure the embedding component \"\n \"has a 'deployment', 'model', 'model_id', or 'model_name' attribute.\"\n )\n raise ValueError(msg)\n\n # ---------- helper functions for index management ----------\n def _default_text_mapping(\n self,\n dim: int,\n engine: str = \"jvector\",\n space_type: str = \"l2\",\n ef_search: int = 512,\n ef_construction: int = 100,\n m: int = 16,\n vector_field: str = \"vector_field\",\n ) -> dict[str, Any]:\n \"\"\"Create the default OpenSearch index mapping for vector search.\n\n This method generates the index configuration with k-NN settings optimized\n for approximate nearest neighbor search using the specified vector engine.\n Includes the embedding_model keyword field for tracking which model was used.\n\n Args:\n dim: Dimensionality of the vector embeddings\n engine: Vector search engine (jvector, nmslib, faiss, lucene)\n space_type: Distance metric for similarity calculation\n ef_search: Size of dynamic list used during search\n ef_construction: Size of dynamic list used during index construction\n m: Number of bidirectional links for each vector\n vector_field: Name of the field storing vector embeddings\n\n Returns:\n Dictionary containing OpenSearch index mapping configuration\n \"\"\"\n return {\n \"settings\": {\"index\": {\"knn\": True, \"knn.algo_param.ef_search\": ef_search}},\n \"mappings\": {\n \"properties\": {\n vector_field: {\n \"type\": \"knn_vector\",\n \"dimension\": dim,\n \"method\": {\n \"name\": \"disk_ann\",\n \"space_type\": space_type,\n \"engine\": engine,\n \"parameters\": {\"ef_construction\": ef_construction, \"m\": m},\n },\n },\n \"embedding_model\": {\"type\": \"keyword\"}, # Track which model was used\n \"embedding_dimensions\": {\"type\": \"integer\"},\n }\n },\n }\n\n def _ensure_embedding_field_mapping(\n self,\n client: OpenSearch,\n index_name: str,\n field_name: str,\n dim: int,\n engine: str,\n space_type: str,\n ef_construction: int,\n m: int,\n ) -> None:\n \"\"\"Lazily add a dynamic embedding field to the index if it doesn't exist.\n\n This allows adding new embedding models without recreating the entire index.\n Also ensures the embedding_model tracking field exists.\n\n Note: Some OpenSearch versions/configurations have issues with dynamically adding\n knn_vector mappings (NullPointerException). This method checks if the field\n already exists before attempting to add it, and gracefully skips if the field\n is already properly configured.\n\n Args:\n client: OpenSearch client instance\n index_name: Target index name\n field_name: Dynamic field name for this embedding model\n dim: Vector dimensionality\n engine: Vector search engine\n space_type: Distance metric\n ef_construction: Construction parameter\n m: HNSW parameter\n \"\"\"\n # First, check if the field already exists and is properly mapped\n properties = self._get_index_properties(client)\n if self._is_knn_vector_field(properties, field_name):\n # Field already exists as knn_vector - verify dimensions match\n existing_dim = self._get_field_dimension(properties, field_name)\n if existing_dim is not None and existing_dim != dim:\n logger.warning(\n f\"Field '{field_name}' exists with dimension {existing_dim}, \"\n f\"but current embedding has dimension {dim}. Using existing mapping.\"\n )\n else:\n logger.info(\n f\"[OpenSearchMultimodel] Field '{field_name}' already exists\"\n f\"as knn_vector with matching dimensions - skipping mapping update\"\n )\n return\n\n # Field doesn't exist, try to add the mapping\n try:\n mapping = {\n \"properties\": {\n field_name: {\n \"type\": \"knn_vector\",\n \"dimension\": dim,\n \"method\": {\n \"name\": \"disk_ann\",\n \"space_type\": space_type,\n \"engine\": engine,\n \"parameters\": {\"ef_construction\": ef_construction, \"m\": m},\n },\n },\n # Also ensure the embedding_model tracking field exists as keyword\n \"embedding_model\": {\"type\": \"keyword\"},\n \"embedding_dimensions\": {\"type\": \"integer\"},\n }\n }\n client.indices.put_mapping(index=index_name, body=mapping)\n logger.info(f\"Added/updated embedding field mapping: {field_name}\")\n except RequestError as e:\n error_str = str(e).lower()\n if \"invalid engine\" in error_str and \"jvector\" in error_str:\n msg = (\n \"The 'jvector' engine is not available in your OpenSearch installation. \"\n \"Use 'nmslib' or 'faiss' for standard OpenSearch, or upgrade to OpenSearch 2.9+.\"\n )\n raise ValueError(msg) from e\n if \"index.knn\" in error_str:\n msg = (\n \"The index has index.knn: false. Delete the existing index and let the \"\n \"component recreate it, or create a new index with a different name.\"\n )\n raise ValueError(msg) from e\n raise\n except Exception as e:\n # Check if this is the known OpenSearch k-NN NullPointerException issue\n error_str = str(e).lower()\n if \"null\" in error_str or \"nullpointerexception\" in error_str:\n logger.warning(\n f\"[OpenSearchMultimodel] Could not add embedding field mapping for {field_name}\"\n f\"due to OpenSearch k-NN plugin issue: {e}. \"\n f\"This is a known issue with some OpenSearch versions. \"\n f\"[OpenSearchMultimodel] Skipping mapping update. \"\n f\"Please ensure the index has the correct mapping for KNN search to work.\"\n )\n # Skip and continue - ingestion will proceed, but KNN search may fail if mapping doesn't exist\n return\n logger.warning(\n f\"[OpenSearchMultimodel] Could not add embedding field mapping for {field_name}: {e}\"\n )\n raise\n\n # Verify the field was added correctly\n properties = self._get_index_properties(client)\n if not self._is_knn_vector_field(properties, field_name):\n msg = f\"Field '{field_name}' is not mapped as knn_vector. Current mapping: {properties.get(field_name)}\"\n logger.error(msg)\n raise ValueError(msg)\n\n def _validate_aoss_with_engines(self, *, is_aoss: bool, engine: str) -> None:\n \"\"\"Validate engine compatibility with Amazon OpenSearch Serverless (AOSS).\n\n Amazon OpenSearch Serverless has restrictions on which vector engines\n can be used. This method ensures the selected engine is compatible.\n\n Args:\n is_aoss: Whether the connection is to Amazon OpenSearch Serverless\n engine: The selected vector search engine\n\n Raises:\n ValueError: If AOSS is used with an incompatible engine\n \"\"\"\n if is_aoss and engine not in {\"nmslib\", \"faiss\"}:\n msg = \"Amazon OpenSearch Service Serverless only supports `nmslib` or `faiss` engines\"\n raise ValueError(msg)\n\n def _is_aoss_enabled(self, http_auth: Any) -> bool:\n \"\"\"Determine if Amazon OpenSearch Serverless (AOSS) is being used.\n\n Args:\n http_auth: The HTTP authentication object\n\n Returns:\n True if AOSS is enabled, False otherwise\n \"\"\"\n return (\n http_auth is not None and hasattr(http_auth, \"service\") and http_auth.service == \"aoss\"\n )\n\n @staticmethod\n def _openrag_input_to_str(value: Any) -> str:\n if value is None:\n return \"\"\n if hasattr(value, \"get_secret_value\"):\n value = value.get_secret_value()\n if hasattr(value, \"text\"):\n value = value.text\n return str(value or \"\").strip()\n\n def _openrag_callback_value(self, attr_name: str) -> str:\n value = self._openrag_input_to_str(getattr(self, attr_name, \"\"))\n if value == self._openrag_ingest_global_placeholders.get(attr_name):\n return \"\"\n return value\n\n def _openrag_ingest_callback_config(self) -> tuple[str, str, str] | None:\n url = self._openrag_callback_value(\"openrag_ingest_url\")\n token = self._openrag_callback_value(\"openrag_ingest_token\")\n ingest_run_id = self._openrag_callback_value(\"openrag_ingest_run_id\")\n\n if not url and not token and not ingest_run_id:\n return None\n if not url or not token or not ingest_run_id:\n msg = \"OpenRAG ingest callback requires url, token, and ingest_run_id.\"\n raise ValueError(msg)\n\n logger.debug(\n \"[OpenRAG callback config] configured for ingest_run_id=%s (url_len=%d, token_len=%d)\",\n ingest_run_id,\n len(url),\n len(token),\n )\n return url, token, ingest_run_id\n\n def _post_openrag_ingest_batches(\n self,\n *,\n requests: list[dict],\n vector_field: str,\n text_field: str,\n ) -> None:\n callback_config = self._openrag_ingest_callback_config()\n if callback_config is None:\n return\n\n url, token, ingest_run_id = callback_config\n batch_size = max(self._parse_int_param(\"openrag_ingest_batch_size\", 100), 1)\n timeout = self._parse_int_param(\"request_timeout\", REQUEST_TIMEOUT)\n headers = {\"Authorization\": f\"Bearer {token}\"}\n\n logger.debug(\n f\"[OpenRAG ingest POST] total_chunks={len(requests)} batch_size={batch_size} timeout_s={timeout}\"\n )\n\n with httpx.Client(timeout=timeout) as client:\n total_batches = (len(requests) + batch_size - 1) // batch_size\n for batch_number, start in enumerate(range(0, len(requests), batch_size), start=1):\n batch = requests[start : start + batch_size]\n final = batch_number == total_batches\n payload = {\n \"ingest_run_id\": ingest_run_id,\n \"batch_id\": batch_number,\n \"final\": final,\n \"chunks\": [\n self._openrag_chunk_payload(\n request,\n vector_field=vector_field,\n text_field=text_field,\n )\n for request in batch\n ],\n }\n logger.debug(\n f\"[OpenRAG ingest POST] -> batch={batch_number}/{total_batches} \"\n f\"chunks={len(payload['chunks'])} final={final}\"\n )\n response = client.post(url, json=payload, headers=headers)\n logger.debug(f\"[OpenRAG ingest POST resp] batch={batch_number} status={response.status_code}\")\n if response.status_code >= 400:\n msg = (\n \"OpenRAG ingest callback failed \"\n f\"(batch={batch_number}, status={response.status_code})\"\n )\n logger.warning(msg)\n raise RuntimeError(msg)\n\n logger.debug(f\"Posted {len(requests)} chunks to OpenRAG backend ingest callback.\")\n\n @staticmethod\n def _openrag_chunk_payload(\n request: dict,\n *,\n vector_field: str,\n text_field: str,\n ) -> dict:\n metadata = {\n key: value\n for key, value in request.items()\n if key not in {\"_op_type\", \"_index\", \"_id\", \"id\", vector_field, text_field}\n }\n page = metadata.get(\"page\")\n if isinstance(page, str) and page.isdigit():\n page = int(page)\n return {\n \"id\": request.get(\"_id\") or request.get(\"id\"),\n \"text\": request.get(text_field, \"\"),\n \"vector\": request[vector_field],\n \"page\": page if isinstance(page, int) else None,\n \"metadata\": metadata,\n }\n\n def _bulk_ingest_embeddings(\n self,\n client: OpenSearch,\n index_name: str,\n embeddings: list[list[float]],\n texts: list[str],\n metadatas: list[dict] | None = None,\n ids: list[str] | None = None,\n vector_field: str = \"vector_field\",\n text_field: str = \"text\",\n embedding_model: str = \"unknown\",\n mapping: dict | None = None,\n max_chunk_bytes: int | None = 1 * 1024 * 1024,\n *,\n is_aoss: bool = False,\n ) -> list[str]:\n \"\"\"Efficiently ingest multiple documents with embeddings into OpenSearch.\n\n This method uses bulk operations to insert documents with their vector\n embeddings and metadata into the specified OpenSearch index. Each document\n is tagged with the embedding_model name for tracking.\n\n Args:\n client: OpenSearch client instance\n index_name: Target index for document storage\n embeddings: List of vector embeddings for each document\n texts: List of document texts\n metadatas: Optional metadata dictionaries for each document\n ids: Optional document IDs (UUIDs generated if not provided)\n vector_field: Field name for storing vector embeddings\n text_field: Field name for storing document text\n embedding_model: Name of the embedding model used\n mapping: Optional index mapping configuration\n max_chunk_bytes: Maximum size per bulk request chunk\n is_aoss: Whether using Amazon OpenSearch Serverless\n\n Returns:\n List of document IDs that were successfully ingested\n \"\"\"\n logger.debug(f\"[OpenSearchMultimodel] Bulk ingesting embeddings for {index_name}\")\n if not mapping:\n mapping = {}\n\n requests = []\n return_ids = []\n vector_dimensions = len(embeddings[0]) if embeddings else None\n\n for i, text in enumerate(texts):\n metadata = metadatas[i] if metadatas else {}\n if vector_dimensions is not None and \"embedding_dimensions\" not in metadata:\n metadata = {**metadata, \"embedding_dimensions\": vector_dimensions}\n\n # Normalize ACL fields that may arrive as JSON strings from flows\n for key in (\"allowed_users\", \"allowed_groups\", \"allowed_principals\"):\n value = metadata.get(key)\n if isinstance(value, str):\n try:\n parsed = json.loads(value)\n if isinstance(parsed, list):\n metadata[key] = parsed\n except (json.JSONDecodeError, TypeError):\n # Leave value as-is if it isn't valid JSON\n pass\n\n metadata_document_id = str(metadata.get(\"document_id\") or \"\").strip()\n if metadata_document_id and metadata_document_id.lower() != \"none\":\n generated_id = f\"{metadata_document_id}_{i}\"\n else:\n generated_id = str(uuid.uuid4())\n _id = ids[i] if ids else generated_id\n request = {\n \"_op_type\": \"index\",\n \"_index\": index_name,\n vector_field: embeddings[i],\n text_field: text,\n \"embedding_model\": embedding_model, # Track which model was used\n **metadata,\n }\n if is_aoss:\n request[\"id\"] = _id\n else:\n request[\"_id\"] = _id\n requests.append(request)\n return_ids.append(_id)\n if metadatas:\n self.log(f\"Sample metadata: {metadatas[0] if metadatas else {}}\")\n if self._openrag_ingest_callback_config() is not None:\n self._post_openrag_ingest_batches(\n requests=requests,\n vector_field=vector_field,\n text_field=text_field,\n )\n return return_ids\n try:\n helpers.bulk(client, requests, max_chunk_bytes=max_chunk_bytes)\n except Exception as bulk_error:\n if \"Unsupported request type for filter level DLS\" not in str(bulk_error):\n raise\n logger.warning(\n \"[OpenSearchMultimodel] Bulk ingest is blocked by filter-level DLS; \"\n \"falling back to per-document index requests.\"\n )\n self._index_embeddings_individually(client, requests)\n return return_ids\n\n def _index_embeddings_individually(\n self,\n client: OpenSearch,\n requests: list[dict],\n ) -> None:\n \"\"\"Index documents one at a time when OpenSearch DLS rejects bulk writes.\"\"\"\n for request in requests:\n document_id = request.get(\"_id\") or request.get(\"id\")\n body = {\n key: value\n for key, value in request.items()\n if key not in {\"_op_type\", \"_index\", \"_id\", \"id\"}\n }\n client.index(index=request[\"_index\"], id=document_id, body=body)\n\n def _log_index_admin_skip(self, operation: str, error: Exception) -> None:\n \"\"\"Log index-admin operations that may be blocked under filter-level DLS.\"\"\"\n logger.warning(\n f\"[OpenSearchMultimodel] Could not run index-admin operation '{operation}': {error}. \"\n \"Assuming the backend pre-created the required index/mapping and continuing.\"\n )\n\n # ---------- param helpers ----------\n def _parse_int_param(self, attr_name: str, default: int) -> int:\n \"\"\"Parse a string attribute to int, returning *default* on failure.\"\"\"\n raw = getattr(self, attr_name, None)\n if raw is None or str(raw).strip() == \"\":\n return default\n try:\n value = int(str(raw).strip())\n except ValueError:\n logger.warning(\n f\"Invalid integer value '{raw}' for {attr_name}, using default {default}\"\n )\n return default\n\n if value < 0:\n logger.warning(f\"Negative value '{raw}' for {attr_name}, using default {default}\")\n return default\n\n return value\n\n # ---------- auth / client ----------\n def _build_auth_kwargs(self) -> dict[str, Any]:\n \"\"\"Build authentication configuration for OpenSearch client.\n\n Constructs the appropriate authentication parameters based on the\n selected auth mode (basic username/password or JWT token).\n\n Returns:\n Dictionary containing authentication configuration\n\n Raises:\n ValueError: If required authentication parameters are missing\n \"\"\"\n mode = (self.auth_mode or \"basic\").strip().lower()\n if mode == \"jwt\":\n token = (self.jwt_token or \"\").strip()\n if not token:\n msg = \"Auth Mode is 'jwt' but no jwt_token was provided.\"\n raise ValueError(msg)\n header_name = (self.jwt_header or \"Authorization\").strip()\n header_value = f\"Bearer {token}\" if self.bearer_prefix else token\n return {\"headers\": {header_name: header_value}}\n if mode == \"openrag\":\n # Writes are delegated to the OpenRAG backend ingest callback,\n # so no direct OpenSearch credentials are needed. Only the\n # OPENRAG_* fields are required for ingestion to function.\n url = self._openrag_callback_value(\"openrag_ingest_url\")\n token = self._openrag_callback_value(\"openrag_ingest_token\")\n ingest_run_id = self._openrag_callback_value(\"openrag_ingest_run_id\")\n missing = [\n name\n for name, value in (\n (\"openrag_ingest_url\", url),\n (\"openrag_ingest_token\", token),\n (\"openrag_ingest_run_id\", ingest_run_id),\n )\n if not (value or \"\").strip()\n ]\n if missing:\n msg = (\n \"Auth Mode is 'openrag' but required OPENRAG_* fields are \"\n f\"missing: {', '.join(missing)}.\"\n )\n raise ValueError(msg)\n return {}\n user = (self.username or \"\").strip()\n pwd = (self._openrag_input_to_str(self.password) or \"\").strip()\n if pwd == \"OPENSEARCH_PASSWORD\" or not pwd:\n from config.settings import get_opensearch_password\n pwd = get_opensearch_password() or \"\"\n if not user or not pwd:\n msg = \"Auth Mode is 'basic' but username/password are missing.\"\n raise ValueError(msg)\n return {\"http_auth\": (user, pwd)}\n\n def build_client(self) -> OpenSearch:\n \"\"\"Create and configure an OpenSearch client instance.\n\n Returns:\n Configured OpenSearch client ready for operations\n \"\"\"\n logger.debug(\"[OpenSearchMultimodel] Building OpenSearch client\")\n auth_kwargs = self._build_auth_kwargs()\n return OpenSearch(\n hosts=[self.opensearch_url],\n use_ssl=self.use_ssl,\n verify_certs=self.verify_certs,\n ssl_assert_hostname=False,\n ssl_show_warn=False,\n timeout=self._parse_int_param(\"request_timeout\", REQUEST_TIMEOUT),\n max_retries=self._parse_int_param(\"max_retries\", MAX_RETRIES),\n retry_on_timeout=True,\n **auth_kwargs,\n )\n\n @check_cached_vector_store\n def build_vector_store(self) -> OpenSearch:\n # Return raw OpenSearch client as our \"vector store.\"\n client = self.build_client()\n\n # Check if we're in ingestion-only mode (no search query)\n has_search_query = bool((self.search_query or \"\").strip())\n if not has_search_query:\n logger.debug(\n \"[OpenSearchMultimodel] Ingestion-only mode activated: search operations will be skipped\"\n )\n logger.debug(\"[OpenSearchMultimodel] Starting ingestion mode...\")\n\n logger.debug(f\"[OpenSearchMultimodel] Embedding: {self.embedding}\")\n self._add_documents_to_vector_store(client=client)\n return client\n\n # ---------- ingest ----------\n def _add_documents_to_vector_store(self, client: OpenSearch) -> None:\n \"\"\"Process and ingest documents into the OpenSearch vector store.\n\n This method handles the complete document ingestion pipeline:\n - Prepares document data and metadata\n - Generates vector embeddings using the selected model\n - Creates appropriate index mappings with dynamic field names\n - Bulk inserts documents with vectors and model tracking\n\n Args:\n client: OpenSearch client for performing operations\n \"\"\"\n logger.debug(\"[OpenSearchMultimodel][INGESTION] _add_documents_to_vector_store called\")\n # Convert DataFrame to Data if needed using parent's method\n self.ingest_data = self._prepare_ingest_data()\n\n logger.debug(\n f\"[OpenSearchMultimodel][INGESTION] ingest_data type: \"\n f\"{type(self.ingest_data)}, length: {len(self.ingest_data) if self.ingest_data else 0}\"\n )\n logger.debug(\n f\"[OpenSearchMultimodel][INGESTION] ingest_data content: \"\n f\"{self.ingest_data[:2] if self.ingest_data and len(self.ingest_data) > 0 else 'empty'}\"\n )\n\n docs = self.ingest_data or []\n if not docs:\n logger.debug(\"Ingestion complete: No documents provided\")\n return\n\n if not self.embedding:\n msg = \"Embedding handle is required to embed documents.\"\n raise ValueError(msg)\n\n # Normalize embedding to list first\n embeddings_list = self.embedding if isinstance(self.embedding, list) else [self.embedding]\n\n # Filter out None values (fail-safe mode) - do this BEFORE checking if empty\n embeddings_list = [e for e in embeddings_list if e is not None]\n\n # NOW check if we have any valid embeddings left after filtering\n if not embeddings_list:\n logger.warning(\n \"All embeddings returned None (fail-safe mode enabled). Skipping document ingestion.\"\n )\n self.log(\n \"Embedding returned None (fail-safe mode enabled). Skipping document ingestion.\"\n )\n return\n\n logger.debug(\n f\"[OpenSearchMultimodel][INGESTION] Valid embeddings after filtering: {len(embeddings_list)}\"\n )\n self.log(\n f\"[OpenSearchMultimodel][INGESTION] Available embedding models: {len(embeddings_list)}\"\n )\n\n # Select the embedding to use for ingestion\n selected_embedding = None\n embedding_model = None\n\n # If embedding_model_name is specified, find matching embedding\n if (\n hasattr(self, \"embedding_model_name\")\n and self.embedding_model_name\n and self.embedding_model_name.strip()\n ):\n target_model_name = self.embedding_model_name.strip()\n self.log(f\"Looking for embedding model: {target_model_name}\")\n\n for emb_obj in embeddings_list:\n # Check all possible model identifiers (deployment, model, model_id, model_name)\n # Also check available_models list from EmbeddingsWithModels\n possible_names = []\n deployment = getattr(emb_obj, \"deployment\", None)\n model = getattr(emb_obj, \"model\", None)\n model_id = getattr(emb_obj, \"model_id\", None)\n model_name = getattr(emb_obj, \"model_name\", None)\n available_models_attr = getattr(emb_obj, \"available_models\", None)\n\n if deployment:\n possible_names.append(str(deployment))\n if model:\n possible_names.append(str(model))\n if model_id:\n possible_names.append(str(model_id))\n if model_name:\n possible_names.append(str(model_name))\n\n # Also add combined identifier\n if deployment and model and deployment != model:\n possible_names.append(f\"{deployment}:{model}\")\n\n # Add all models from available_models dict\n if available_models_attr and isinstance(available_models_attr, dict):\n possible_names.extend(\n str(model_key).strip()\n for model_key in available_models_attr\n if model_key and str(model_key).strip()\n )\n\n # Match if target matches any of the possible names\n if target_model_name in possible_names:\n # Check if target is in available_models dict - use dedicated instance\n if (\n available_models_attr\n and isinstance(available_models_attr, dict)\n and target_model_name in available_models_attr\n ):\n # Use the dedicated embedding instance from the dict\n selected_embedding = available_models_attr[target_model_name]\n embedding_model = target_model_name\n self.log(\n f\"Found dedicated embedding instance for '{embedding_model}' in available_models dict\"\n )\n else:\n # Traditional identifier match\n selected_embedding = emb_obj\n embedding_model = self._get_embedding_model_name(emb_obj)\n self.log(\n f\"Found matching embedding model: {embedding_model} (matched on: {target_model_name})\"\n )\n break\n\n if not selected_embedding:\n # Build detailed list of available embeddings with all their identifiers\n available_info = []\n for idx, emb in enumerate(embeddings_list):\n emb_type = type(emb).__name__\n identifiers = []\n deployment = getattr(emb, \"deployment\", None)\n model = getattr(emb, \"model\", None)\n model_id = getattr(emb, \"model_id\", None)\n model_name = getattr(emb, \"model_name\", None)\n available_models_attr = getattr(emb, \"available_models\", None)\n\n if deployment:\n identifiers.append(f\"deployment='{deployment}'\")\n if model:\n identifiers.append(f\"model='{model}'\")\n if model_id:\n identifiers.append(f\"model_id='{model_id}'\")\n if model_name:\n identifiers.append(f\"model_name='{model_name}'\")\n\n # Add combined identifier as an option\n if deployment and model and deployment != model:\n identifiers.append(f\"combined='{deployment}:{model}'\")\n\n # Add available_models dict if present\n if available_models_attr and isinstance(available_models_attr, dict):\n identifiers.append(f\"available_models={list(available_models_attr.keys())}\")\n\n available_info.append(\n f\" [{idx}] {emb_type}: {', '.join(identifiers) if identifiers else 'No identifiers'}\"\n )\n\n msg = (\n f\"Embedding model '{target_model_name}' not found in available embeddings.\\n\\n\"\n f\"Available embeddings:\\n\" + \"\\n\".join(available_info) + \"\\n\\n\"\n \"Please set 'embedding_model_name' to one of the identifier values shown above \"\n \"(use the value after the '=' sign, without quotes).\\n\"\n \"For duplicate deployments, use the 'combined' format.\\n\"\n \"Or leave it empty to use the first embedding.\"\n )\n raise ValueError(msg)\n else:\n # Use first embedding if no model name specified\n selected_embedding = embeddings_list[0]\n embedding_model = self._get_embedding_model_name(selected_embedding)\n self.log(f\"No embedding_model_name specified, using first embedding: {embedding_model}\")\n\n dynamic_field_name = get_embedding_field_name(embedding_model)\n\n logger.info(f\"Selected embedding model for ingestion: '{embedding_model}'\")\n self.log(f\"Using embedding model for ingestion: {embedding_model}\")\n self.log(f\"Dynamic vector field: {dynamic_field_name}\")\n\n # Log embedding details for debugging\n if hasattr(selected_embedding, \"deployment\"):\n logger.info(f\"Embedding deployment: {selected_embedding.deployment}\")\n if hasattr(selected_embedding, \"model\"):\n logger.info(f\"Embedding model: {selected_embedding.model}\")\n if hasattr(selected_embedding, \"model_id\"):\n logger.info(f\"Embedding model_id: {selected_embedding.model_id}\")\n if hasattr(selected_embedding, \"dimensions\"):\n logger.info(f\"Embedding dimensions: {selected_embedding.dimensions}\")\n if hasattr(selected_embedding, \"available_models\"):\n logger.info(f\"Embedding available_models: {selected_embedding.available_models}\")\n\n # No model switching needed - each model in available_models has its own dedicated instance\n # The selected_embedding is already configured correctly for the target model\n logger.info(\n f\"Using embedding instance for '{embedding_model}' - pre-configured and ready to use\"\n )\n\n # Extract texts and metadata from documents\n texts = []\n metadatas = []\n # Process docs_metadata table input into a dict\n additional_metadata = {}\n logger.debug(f\"[LF] Docs metadata {self.docs_metadata}\")\n if hasattr(self, \"docs_metadata\") and self.docs_metadata:\n logger.info(f\"[LF] Docs metadata {self.docs_metadata}\")\n if isinstance(self.docs_metadata[-1], Data):\n logger.info(f\"[LF] Docs metadata is a Data object {self.docs_metadata}\")\n self.docs_metadata = self.docs_metadata[-1].data\n logger.info(f\"[LF] Docs metadata is a Data object {self.docs_metadata}\")\n additional_metadata.update(self.docs_metadata)\n else:\n for item in self.docs_metadata:\n if isinstance(item, dict) and \"key\" in item and \"value\" in item:\n additional_metadata[item[\"key\"]] = item[\"value\"]\n # Replace string \"None\" values with actual None\n for key, value in additional_metadata.items():\n if value == \"None\":\n additional_metadata[key] = None\n logger.info(f\"[LF] Additional metadata {additional_metadata}\")\n for doc_obj in docs:\n data_copy = json.loads(doc_obj.model_dump_json())\n text = data_copy.pop(doc_obj.text_key, doc_obj.default_value)\n texts.append(text)\n\n # Merge additional metadata from table input\n data_copy.update(additional_metadata)\n\n metadatas.append(data_copy)\n self.log(metadatas)\n\n # Determine whether the selected embedding is watsonx/IBM. The watsonx\n # SDK ships its own rate-limit machinery (input batching, proactive\n # x-requests-limit-* TokenBucket throttling, and jittered exponential\n # backoff on 429), so we lean on it instead of retrying on top of it.\n # The type-name check also covers watsonx-hosted, non-\"ibm/\" models\n # (e.g. intfloat/multilingual-e5-large).\n is_ibm = (embedding_model and \"ibm\" in str(embedding_model).lower()) or (\n selected_embedding and \"watsonx\" in type(selected_embedding).__name__.lower()\n )\n logger.debug(f\"Is IBM/watsonx embedding: {is_ibm}\")\n\n if is_ibm:\n\n # Hand the full batch to the SDK and let it batch/throttle/retry.\n # Retry attempts and base backoff are tunable via the SDK's own\n # WATSONX_MAX_RETRIES / WATSONX_DELAY_TIME environment variables.\n logger.info(\n f\"Embedding {len(texts)} chunks via watsonx SDK batch (SDK-managed throttle + 429 retry)\"\n )\n try:\n vectors: list[list[float]] = selected_embedding.embed_documents(texts)\n logger.info(f\"Successfully embedded {len(vectors)} chunks via watsonx SDK\")\n except Exception as embed_error:\n _log_watsonx_rate_limit_headers(embed_error)\n logger.error(\n f\"Failed to embed {len(texts)} chunks via watsonx SDK. Error: {embed_error}\",\n )\n raise\n\n else:\n # Non-watsonx providers (OpenAI, Ollama) lack the watsonx SDK's\n # built-in rate-limit handling, so embed per chunk in parallel with\n # a generic rate-limit-aware tenacity retry.\n vectors: list[list[float]] = [None] * len(texts)\n from tenacity import (\n retry,\n retry_if_exception,\n stop_after_attempt,\n wait_exponential,\n )\n\n def is_rate_limit_error(exception: Exception) -> bool:\n \"\"\"Check if exception is a rate limit error (429).\"\"\"\n error_str = str(exception).lower()\n return \"429\" in error_str or \"rate_limit\" in error_str or \"rate limit\" in error_str\n\n def is_other_retryable_error(exception: Exception) -> bool:\n \"\"\"Check if exception is a transient network error worth retrying.\"\"\"\n if is_rate_limit_error(exception):\n return False\n return isinstance(exception, (ConnectionError, TimeoutError, OSError))\n\n # Retry decorator for rate limit errors (longer backoff)\n retry_on_rate_limit = retry(\n retry=retry_if_exception(is_rate_limit_error),\n stop=stop_after_attempt(5),\n wait=wait_exponential(multiplier=2, min=2, max=30),\n reraise=True,\n before_sleep=lambda retry_state: logger.warning(\n f\"Rate limit hit for chunk (attempt {retry_state.attempt_number}/5), \"\n f\"backing off for {retry_state.next_action.sleep:.1f}s\"\n ),\n )\n\n # Retry decorator for other errors (shorter backoff)\n retry_on_other_errors = retry(\n retry=retry_if_exception(is_other_retryable_error),\n stop=stop_after_attempt(3),\n wait=wait_exponential(multiplier=1, min=1, max=8),\n reraise=True,\n before_sleep=lambda retry_state: logger.warning(\n f\"Error embedding chunk (attempt {retry_state.attempt_number}/3), \"\n f\"retrying in {retry_state.next_action.sleep:.1f}s: {retry_state.outcome.exception()}\"\n ),\n )\n\n def embed_chunk_with_retry(chunk_text: str, chunk_idx: int) -> list[float]:\n \"\"\"Embed a single chunk with rate-limit-aware retry logic.\"\"\"\n\n @retry_on_rate_limit\n @retry_on_other_errors\n def _embed(text: str) -> list[float]:\n return selected_embedding.embed_documents([text])[0]\n\n try:\n return _embed(chunk_text)\n except Exception as e:\n logger.error(\n f\"Failed to embed chunk {chunk_idx} after all retries: {e}\",\n error=str(e),\n )\n raise\n\n max_workers = min(max(len(texts), 1), 8)\n logger.debug(f\"Using parallel processing with {max_workers} workers\")\n\n with ThreadPoolExecutor(max_workers=max_workers) as executor:\n futures = {\n executor.submit(embed_chunk_with_retry, chunk, idx): idx\n for idx, chunk in enumerate(texts)\n }\n for future in as_completed(futures):\n idx = futures[future]\n vectors[idx] = future.result()\n\n if not vectors:\n self.log(f\"No vectors generated from documents for model {embedding_model}.\")\n return\n\n # Get vector dimension for mapping\n dim = len(vectors[0]) if vectors else 768 # default fallback\n use_openrag_ingest_callback = self._openrag_ingest_callback_config() is not None\n\n is_aoss = False\n mapping: dict | None = None\n\n engine = getattr(self, \"engine\", \"jvector\")\n\n if use_openrag_ingest_callback:\n self.log(\"Using OpenRAG backend ingest callback; skipping direct OpenSearch writes.\")\n else:\n # Check for AOSS\n auth_kwargs = self._build_auth_kwargs()\n is_aoss = self._is_aoss_enabled(auth_kwargs.get(\"http_auth\"))\n\n # Validate engine with AOSS\n self._validate_aoss_with_engines(is_aoss=is_aoss, engine=engine)\n\n # Create mapping with proper KNN settings\n space_type = getattr(self, \"space_type\", \"l2\")\n ef_construction = getattr(self, \"ef_construction\", 512)\n m = getattr(self, \"m\", 16)\n\n mapping = self._default_text_mapping(\n dim=dim,\n engine=engine,\n space_type=space_type,\n ef_construction=ef_construction,\n m=m,\n vector_field=dynamic_field_name, # Use dynamic field name\n )\n\n # Ensure index exists with baseline mapping (index.knn: true is required for vector search)\n index_exists = True\n try:\n index_exists = bool(client.indices.exists(index=self.index_name))\n except OpenSearchException as exists_error:\n self._log_index_admin_skip(\"indices.exists\", exists_error)\n\n try:\n if not index_exists:\n self.log(f\"Creating index '{self.index_name}' with base mapping\")\n client.indices.create(index=self.index_name, body=mapping)\n except RequestError as creation_error:\n if creation_error.error == \"resource_already_exists_exception\":\n pass # Index was created concurrently\n else:\n error_msg = str(creation_error).lower()\n if \"invalid engine\" in error_msg or \"illegal_argument\" in error_msg:\n if \"jvector\" in error_msg:\n msg = (\n \"The 'jvector' engine is not available in your OpenSearch installation. \"\n \"Use 'nmslib' or 'faiss' for standard OpenSearch, or upgrade to 2.9+.\"\n )\n raise ValueError(msg) from creation_error\n if \"index.knn\" in error_msg:\n msg = (\n \"The index has index.knn: false. Delete the existing index and let the \"\n \"component recreate it, or create a new index with a different name.\"\n )\n raise ValueError(msg) from creation_error\n logger.warning(f\"Failed to create index '{self.index_name}': {creation_error}\")\n raise\n\n # Ensure the dynamic field exists in the index\n self._ensure_embedding_field_mapping(\n client=client,\n index_name=self.index_name,\n field_name=dynamic_field_name,\n dim=dim,\n engine=engine,\n space_type=space_type,\n ef_construction=ef_construction,\n m=m,\n )\n\n self.log(\n f\"Indexing {len(texts)} documents into '{self.index_name}' with model '{embedding_model}'...\"\n )\n logger.info(f\"Will store embeddings in field: {dynamic_field_name}\")\n logger.info(f\"Will tag documents with embedding_model: {embedding_model}\")\n\n # Use the bulk ingestion with model tracking\n return_ids = self._bulk_ingest_embeddings(\n client=client,\n index_name=self.index_name,\n embeddings=vectors,\n texts=texts,\n metadatas=metadatas,\n vector_field=dynamic_field_name, # Use dynamic field name\n text_field=\"text\",\n embedding_model=embedding_model, # Track the model\n mapping=mapping,\n is_aoss=is_aoss,\n )\n self.log(metadatas)\n\n logger.info(\n f\"Ingestion complete: Successfully indexed {len(return_ids)} documents with model '{embedding_model}'\"\n )\n self.log(f\"Successfully indexed {len(return_ids)} documents with model {embedding_model}.\")\n\n # ---------- helpers for filters ----------\n def _is_placeholder_term(self, term_obj: dict) -> bool:\n # term_obj like {\"filename\": \"__IMPOSSIBLE_VALUE__\"}\n return any(v == \"__IMPOSSIBLE_VALUE__\" for v in term_obj.values())\n\n def _coerce_filter_clauses(self, filter_obj: dict | None) -> list[dict]:\n \"\"\"Convert filter expressions into OpenSearch-compatible filter clauses.\n\n This method accepts two filter formats and converts them to standardized\n OpenSearch query clauses:\n\n Format A - Explicit filters:\n {\"filter\": [{\"term\": {\"field\": \"value\"}}, {\"terms\": {\"field\": [\"val1\", \"val2\"]}}],\n \"limit\": 10, \"score_threshold\": 1.5}\n\n Format B - Context-style mapping:\n {\"data_sources\": [\"file1.pdf\"], \"document_types\": [\"pdf\"], \"owners\": [\"user1\"]}\n\n Args:\n filter_obj: Filter configuration dictionary or None\n\n Returns:\n List of OpenSearch filter clauses (term/terms objects)\n Placeholder values with \"__IMPOSSIBLE_VALUE__\" are ignored\n \"\"\"\n if not filter_obj:\n return []\n\n # If it is a string, try to parse it once\n if isinstance(filter_obj, str):\n try:\n filter_obj = json.loads(filter_obj)\n except json.JSONDecodeError:\n # Not valid JSON - treat as no filters\n return []\n\n # Case A: already an explicit list/dict under \"filter\"\n if \"filter\" in filter_obj:\n raw = filter_obj[\"filter\"]\n if isinstance(raw, dict):\n raw = [raw]\n explicit_clauses: list[dict] = []\n for f in raw or []:\n if (\n \"term\" in f\n and isinstance(f[\"term\"], dict)\n and not self._is_placeholder_term(f[\"term\"])\n ):\n explicit_clauses.append(f)\n elif \"terms\" in f and isinstance(f[\"terms\"], dict):\n field, vals = next(iter(f[\"terms\"].items()))\n if isinstance(vals, list) and len(vals) > 0:\n explicit_clauses.append(f)\n return explicit_clauses\n\n # Case B: convert context-style maps into clauses\n field_mapping = {\n \"data_sources\": \"filename\",\n \"document_types\": \"mimetype\",\n \"owners\": \"owner\",\n }\n context_clauses: list[dict] = []\n for k, values in filter_obj.items():\n if not isinstance(values, list):\n continue\n field = field_mapping.get(k, k)\n if len(values) == 0:\n # Match-nothing placeholder (kept to mirror your tool semantics)\n context_clauses.append({\"term\": {field: \"__IMPOSSIBLE_VALUE__\"}})\n elif len(values) == 1:\n if values[0] != \"__IMPOSSIBLE_VALUE__\":\n context_clauses.append({\"term\": {field: values[0]}})\n else:\n context_clauses.append({\"terms\": {field: values}})\n return context_clauses\n\n\n def _parse_filter_expression(self) -> dict | None:\n \"\"\"Parse and validate optional filter_expression JSON.\n\n Returns:\n Parsed JSON object as a dict, or None when unset/blank.\n\n Raises:\n ValueError: If JSON is invalid or does not decode to an object.\n \"\"\"\n filter_expression = getattr(self, \"filter_expression\", \"\")\n if not isinstance(filter_expression, str) or not filter_expression.strip():\n return None\n try:\n filter_obj = json.loads(filter_expression)\n except json.JSONDecodeError as e:\n msg = f\"Invalid filter_expression JSON: {e}\"\n raise ValueError(msg) from e\n\n if not isinstance(filter_obj, dict):\n msg = \"Invalid filter_expression JSON type: expected a JSON object.\"\n raise TypeError(msg)\n return filter_obj\n\n def _resolve_limit(self, filter_obj: dict | None, default_limit: int | None) -> int | None:\n \"\"\"Resolve an integer result limit from filter settings.\"\"\"\n if not filter_obj:\n return default_limit\n raw_limit = filter_obj.get(\"limit\", default_limit)\n if raw_limit is None:\n return None\n if isinstance(raw_limit, bool):\n msg = \"Invalid filter_expression.limit: expected a positive integer.\"\n raise TypeError(msg)\n try:\n limit = int(raw_limit)\n except (TypeError, ValueError) as e:\n msg = \"Invalid filter_expression.limit: expected a positive integer.\"\n raise ValueError(msg) from e\n if limit <= 0:\n msg = \"Invalid filter_expression.limit: expected a positive integer.\"\n raise ValueError(msg)\n return limit\n\n def _resolve_score_threshold(self, filter_obj: dict | None) -> float | None:\n \"\"\"Resolve optional positive min score from filter settings.\"\"\"\n if not filter_obj:\n return None\n score_threshold = filter_obj.get(\"score_threshold\")\n if score_threshold is None:\n score_threshold = filter_obj.get(\"scoreThreshold\")\n if not isinstance(score_threshold, (int, float)) or score_threshold <= 0:\n return None\n return float(score_threshold)\n\n def _detect_available_models(self, client: OpenSearch, filter_clauses: list[dict] | None = None) -> list[str]:\n\n \"\"\"Detect which embedding models have documents in the index.\n\n Uses aggregation to find all unique embedding_model values, optionally\n filtered to only documents matching the user's filter criteria.\n\n Args:\n client: OpenSearch client instance\n filter_clauses: Optional filter clauses to scope model detection\n\n Returns:\n List of embedding model names found in the index\n \"\"\"\n try:\n agg_query = {\n \"size\": 0,\n \"aggs\": {\"embedding_models\": {\"terms\": {\"field\": \"embedding_model\", \"size\": 10}}},\n }\n\n # Apply filters to model detection if any exist\n if filter_clauses:\n agg_query[\"query\"] = {\"bool\": {\"filter\": filter_clauses}}\n\n logger.debug(f\"Model detection query: {agg_query}\")\n result = client.search(\n index=self.index_name,\n body=agg_query,\n params={\"terminate_after\": 0},\n )\n buckets = result.get(\"aggregations\", {}).get(\"embedding_models\", {}).get(\"buckets\", [])\n models = [b[\"key\"] for b in buckets if b[\"key\"]]\n\n # Log detailed bucket info for debugging\n logger.info(\n f\"Detected embedding models in corpus: {models}\"\n + (f\" (with {len(filter_clauses)} filters)\" if filter_clauses else \"\")\n )\n if not models:\n total_hits = result.get(\"hits\", {}).get(\"total\", {})\n total_count = (\n total_hits.get(\"value\", 0) if isinstance(total_hits, dict) else total_hits\n )\n logger.warning(\n f\"No embedding_model values found in index '{self.index_name}'. \"\n f\"Total docs in index: {total_count}. \"\n f\"This may indicate documents were indexed without the embedding_model field.\"\n )\n except (OpenSearchException, KeyError, ValueError) as e:\n logger.warning(f\"Failed to detect embedding models: {e}\")\n # Fallback to current model\n fallback_model = self._get_embedding_model_name()\n logger.info(f\"Using fallback model: {fallback_model}\")\n return [fallback_model]\n else:\n return models\n\n def _get_index_properties(self, client: OpenSearch) -> dict[str, Any] | None:\n \"\"\"Retrieve flattened mapping properties for the current index.\"\"\"\n try:\n mapping = client.indices.get_mapping(index=self.index_name)\n except OpenSearchException as e:\n logger.warning(\n f\"Failed to fetch mapping for index '{self.index_name}': {e}. Proceeding without mapping metadata.\"\n )\n return None\n\n properties: dict[str, Any] = {}\n for index_data in mapping.values():\n props = index_data.get(\"mappings\", {}).get(\"properties\", {})\n if isinstance(props, dict):\n properties.update(props)\n return properties\n\n def _is_knn_vector_field(self, properties: dict[str, Any] | None, field_name: str) -> bool:\n \"\"\"Check whether the field is mapped as a knn_vector.\"\"\"\n if not field_name:\n return False\n if properties is None:\n logger.warning(\n f\"Mapping metadata unavailable; assuming field '{field_name}' is usable.\"\n )\n return True\n field_def = properties.get(field_name)\n if not isinstance(field_def, dict):\n return False\n if field_def.get(\"type\") == \"knn_vector\":\n return True\n\n nested_props = field_def.get(\"properties\")\n return bool(isinstance(nested_props, dict) and nested_props.get(\"type\") == \"knn_vector\")\n\n def _get_field_dimension(\n self, properties: dict[str, Any] | None, field_name: str\n ) -> int | None:\n \"\"\"Get the dimension of a knn_vector field from the index mapping.\n\n Args:\n properties: Index properties from mapping\n field_name: Name of the vector field\n\n Returns:\n Dimension of the field, or None if not found\n \"\"\"\n if not field_name or properties is None:\n return None\n\n field_def = properties.get(field_name)\n if not isinstance(field_def, dict):\n return None\n\n # Check direct knn_vector field\n if field_def.get(\"type\") == \"knn_vector\":\n return field_def.get(\"dimension\")\n\n # Check nested properties\n nested_props = field_def.get(\"properties\")\n if isinstance(nested_props, dict) and nested_props.get(\"type\") == \"knn_vector\":\n return nested_props.get(\"dimension\")\n\n return None\n\n def _get_filename_agg_field(self, index_properties: dict[str, Any] | None) -> str:\n \"\"\"Choose the appropriate field for filename aggregations.\"\"\"\n if not index_properties:\n return \"filename.keyword\"\n\n filename_def = index_properties.get(\"filename\")\n if not isinstance(filename_def, dict):\n return \"filename.keyword\"\n\n field_type = filename_def.get(\"type\")\n fields_def = filename_def.get(\"fields\", {})\n\n # Top-level keyword with no subfields\n if field_type == \"keyword\" and not isinstance(fields_def, dict):\n return \"filename\"\n\n # Text field with keyword subfield\n if isinstance(fields_def, dict) and \"keyword\" in fields_def:\n return \"filename.keyword\"\n\n # Fallback: aggregate on filename directly\n return \"filename\"\n\n # ---------- search (multi-model hybrid) ----------\n def search(self, query: str | None = None) -> list[dict[str, Any]]:\n \"\"\"Perform multi-model hybrid search combining multiple vector similarities and keyword matching.\n\n This method executes a sophisticated search that:\n 1. Auto-detects all embedding models present in the index\n 2. Generates query embeddings for ALL detected models in parallel\n 3. Combines multiple KNN queries using dis_max (picks best match)\n 4. Adds keyword search with fuzzy matching (30% weight)\n 5. Applies optional filtering and score thresholds\n 6. Returns aggregations for faceted search\n\n Search weights:\n - Semantic search (dis_max across all models): 70%\n - Keyword search: 30%\n\n Args:\n query: Search query string (used for both vector embedding and keyword search)\n\n Returns:\n List of search results with page_content, metadata, and relevance scores\n\n Raises:\n ValueError: If embedding component is not provided or filter JSON is invalid\n \"\"\"\n logger.info(self.ingest_data)\n client = self.build_client()\n q = (query or \"\").strip()\n\n # Parse optional filter expression\n filter_obj = self._parse_filter_expression()\n\n if not self.embedding:\n msg = \"Embedding is required to run hybrid search (KNN + keyword).\"\n raise ValueError(msg)\n\n # Check if embedding is None (fail-safe mode)\n if self.embedding is None or (\n isinstance(self.embedding, list) and all(e is None for e in self.embedding)\n ):\n logger.error(\"Embedding returned None (fail-safe mode enabled). Cannot perform search.\")\n return []\n\n # Build filter clauses first so we can use them in model detection\n filter_clauses = self._coerce_filter_clauses(filter_obj)\n\n # Detect available embedding models in the index (scoped by filters)\n available_models = self._detect_available_models(client, filter_clauses)\n\n if not available_models:\n logger.warning(\"No embedding models found in index, using current model\")\n available_models = [self._get_embedding_model_name()]\n\n # Generate embeddings for ALL detected models\n query_embeddings = {}\n\n # Normalize embedding to list\n embeddings_list = self.embedding if isinstance(self.embedding, list) else [self.embedding]\n # Filter out None values (fail-safe mode)\n embeddings_list = [e for e in embeddings_list if e is not None]\n\n if not embeddings_list:\n logger.error(\n \"No valid embeddings available after filtering None values (fail-safe mode). Cannot perform search.\"\n )\n return []\n\n # Create a comprehensive map of model names to embedding objects\n # Check all possible identifiers (deployment, model, model_id, model_name)\n # Also leverage available_models list from EmbeddingsWithModels\n # Handle duplicate identifiers by creating combined keys\n embedding_by_model = {}\n identifier_conflicts = {} # Track which identifiers have conflicts\n\n for idx, emb_obj in enumerate(embeddings_list):\n # Get all possible identifiers for this embedding\n identifiers = []\n deployment = getattr(emb_obj, \"deployment\", None)\n model = getattr(emb_obj, \"model\", None)\n model_id = getattr(emb_obj, \"model_id\", None)\n model_name = getattr(emb_obj, \"model_name\", None)\n dimensions = getattr(emb_obj, \"dimensions\", None)\n available_models_attr = getattr(emb_obj, \"available_models\", None)\n\n logger.info(\n f\"Embedding object {idx}: deployment={deployment}, model={model}, \"\n f\"model_id={model_id}, model_name={model_name}, dimensions={dimensions}, \"\n f\"available_models={available_models_attr}\"\n )\n\n # If this embedding has available_models dict, map all models to their dedicated instances\n if available_models_attr and isinstance(available_models_attr, dict):\n logger.info(\n f\"Embedding object {idx} provides {len(available_models_attr)} models via available_models dict\"\n )\n for model_name_key, dedicated_embedding in available_models_attr.items():\n if model_name_key and str(model_name_key).strip():\n model_str = str(model_name_key).strip()\n if model_str not in embedding_by_model:\n # Use the dedicated embedding instance from the dict\n embedding_by_model[model_str] = dedicated_embedding\n logger.info(\n f\"Mapped available model '{model_str}' to dedicated embedding instance\"\n )\n else:\n # Conflict detected - track it\n if model_str not in identifier_conflicts:\n identifier_conflicts[model_str] = [embedding_by_model[model_str]]\n identifier_conflicts[model_str].append(dedicated_embedding)\n logger.warning(\n f\"Available model '{model_str}' has conflict - used by multiple embeddings\"\n )\n\n # Also map traditional identifiers (for backward compatibility)\n if deployment:\n identifiers.append(str(deployment))\n if model:\n identifiers.append(str(model))\n if model_id:\n identifiers.append(str(model_id))\n if model_name:\n identifiers.append(str(model_name))\n\n # Map all identifiers to this embedding object\n for identifier in identifiers:\n if identifier not in embedding_by_model:\n embedding_by_model[identifier] = emb_obj\n logger.info(f\"Mapped identifier '{identifier}' to embedding object {idx}\")\n else:\n # Conflict detected - track it\n if identifier not in identifier_conflicts:\n identifier_conflicts[identifier] = [embedding_by_model[identifier]]\n identifier_conflicts[identifier].append(emb_obj)\n logger.warning(\n f\"Identifier '{identifier}' has conflict - used by multiple embeddings\"\n )\n\n # For embeddings with model+deployment, create combined identifier\n # This helps when deployment is the same but model differs\n if deployment and model and deployment != model:\n combined_id = f\"{deployment}:{model}\"\n if combined_id not in embedding_by_model:\n embedding_by_model[combined_id] = emb_obj\n logger.info(\n f\"Created combined identifier '{combined_id}' for embedding object {idx}\"\n )\n\n # Log conflicts\n if identifier_conflicts:\n logger.warning(\n f\"Found {len(identifier_conflicts)} conflicting identifiers. \"\n f\"Consider using combined format 'deployment:model' or specifying unique model names.\"\n )\n for conflict_id, emb_list in identifier_conflicts.items():\n logger.warning(\n f\" Conflict on '{conflict_id}': {len(emb_list)} embeddings use this identifier\"\n )\n\n logger.info(f\"Generating embeddings for {len(available_models)} models in index\")\n logger.info(f\"Available embedding identifiers: {list(embedding_by_model.keys())}\")\n self.log(f\"[SEARCH] Models detected in index: {available_models}\")\n self.log(f\"[SEARCH] Available embedding identifiers: {list(embedding_by_model.keys())}\")\n\n # Track matching status for debugging\n matched_models = []\n unmatched_models = []\n\n for model_name in available_models:\n try:\n # Check if we have an embedding object for this model\n if model_name in embedding_by_model:\n # Use the matching embedding object directly\n emb_obj = embedding_by_model[model_name]\n emb_deployment = getattr(emb_obj, \"deployment\", None)\n emb_model = getattr(emb_obj, \"model\", None)\n emb_model_id = getattr(emb_obj, \"model_id\", None)\n emb_dimensions = getattr(emb_obj, \"dimensions\", None)\n emb_available_models = getattr(emb_obj, \"available_models\", None)\n\n logger.info(\n f\"Using embedding object for model '{model_name}': \"\n f\"deployment={emb_deployment}, model={emb_model}, model_id={emb_model_id}, \"\n f\"dimensions={emb_dimensions}\"\n )\n\n # Check if this is a dedicated instance from available_models dict\n if emb_available_models and isinstance(emb_available_models, dict):\n logger.info(\n f\"Model '{model_name}' using dedicated instance from available_models dict \"\n f\"(pre-configured with correct model and dimensions)\"\n )\n\n # Use the embedding instance directly - no model switching needed!\n vec = emb_obj.embed_query(q)\n query_embeddings[model_name] = vec\n matched_models.append(model_name)\n logger.info(\n f\"Generated embedding for model: {model_name} (actual dimensions: {len(vec)})\"\n )\n self.log(f\"[MATCH] Model '{model_name}' - generated {len(vec)}-dim embedding\")\n else:\n # No matching embedding found for this model\n unmatched_models.append(model_name)\n logger.warning(\n f\"No matching embedding found for model '{model_name}'. \"\n f\"This model will be skipped. Available identifiers: {list(embedding_by_model.keys())}\"\n )\n self.log(\n f\"[NO MATCH] Model '{model_name}' - available: {list(embedding_by_model.keys())}\"\n )\n except (\n RuntimeError,\n ValueError,\n ConnectionError,\n TimeoutError,\n AttributeError,\n KeyError,\n ) as e:\n logger.warning(f\"Failed to generate embedding for {model_name}: {e}\")\n self.log(f\"[ERROR] Embedding generation failed for '{model_name}': {e}\")\n\n # Log summary of model matching\n logger.info(\n f\"Model matching summary: {len(matched_models)} matched, {len(unmatched_models)} unmatched\"\n )\n self.log(\n f\"[SUMMARY] Model matching: {len(matched_models)} matched, {len(unmatched_models)} unmatched\"\n )\n if unmatched_models:\n self.log(f\"[WARN] Unmatched models in index: {unmatched_models}\")\n\n if not query_embeddings:\n msg = (\n f\"Failed to generate embeddings for any model. \"\n f\"Index has models: {available_models}, but no matching embedding objects found. \"\n f\"Available embedding identifiers: {list(embedding_by_model.keys())}\"\n )\n self.log(f\"[FAIL] Search failed: {msg}\")\n raise ValueError(msg)\n\n index_properties = self._get_index_properties(client)\n legacy_vector_field = getattr(self, \"vector_field\", \"chunk_embedding\")\n\n # Build KNN queries for each model\n embedding_fields: list[str] = []\n knn_queries_with_candidates = []\n knn_queries_without_candidates = []\n\n raw_num_candidates = getattr(self, \"num_candidates\", 1000)\n try:\n num_candidates = int(raw_num_candidates) if raw_num_candidates is not None else 0\n except (TypeError, ValueError):\n num_candidates = 0\n use_num_candidates = num_candidates > 0\n\n for model_name, embedding_vector in query_embeddings.items():\n field_name = get_embedding_field_name(model_name)\n selected_field = field_name\n vector_dim = len(embedding_vector)\n\n # Only use the expected dynamic field - no legacy fallback\n # This prevents dimension mismatches between models\n if not self._is_knn_vector_field(index_properties, selected_field):\n logger.warning(\n f\"Skipping model {model_name}: field '{field_name}' is not mapped as knn_vector. \"\n f\"Documents must be indexed with this embedding model before querying.\"\n )\n self.log(\n f\"[SKIP] Field '{selected_field}' not a knn_vector - skipping model '{model_name}'\"\n )\n continue\n\n # Validate vector dimensions match the field dimensions\n field_dim = self._get_field_dimension(index_properties, selected_field)\n if field_dim is not None and field_dim != vector_dim:\n logger.error(\n f\"Dimension mismatch for model '{model_name}': \"\n f\"Query vector has {vector_dim} dimensions but field '{selected_field}' expects {field_dim}. \"\n f\"Skipping this model to prevent search errors.\"\n )\n self.log(\n f\"[DIM MISMATCH] Model '{model_name}': query={vector_dim} vs field={field_dim} - skipping\"\n )\n continue\n\n logger.info(\n f\"Adding KNN query for model '{model_name}': field='{selected_field}', \"\n f\"query_dims={vector_dim}, field_dims={field_dim or 'unknown'}\"\n )\n embedding_fields.append(selected_field)\n\n base_query = {\n \"knn\": {\n selected_field: {\n \"vector\": embedding_vector,\n \"k\": 50,\n }\n }\n }\n\n if use_num_candidates:\n query_with_candidates = copy.deepcopy(base_query)\n query_with_candidates[\"knn\"][selected_field][\"num_candidates\"] = num_candidates\n else:\n query_with_candidates = base_query\n\n knn_queries_with_candidates.append(query_with_candidates)\n knn_queries_without_candidates.append(base_query)\n\n if not knn_queries_with_candidates:\n # No valid fields found - this can happen when:\n # 1. Index is empty (no documents yet)\n # 2. Embedding model has changed and field doesn't exist yet\n # Return empty results instead of failing\n logger.warning(\n \"No valid knn_vector fields found for embedding models. \"\n \"This may indicate an empty index or missing field mappings. \"\n \"Returning empty search results.\"\n )\n self.log(\n f\"[WARN] No valid KNN queries could be built. \"\n f\"Query embeddings generated: {list(query_embeddings.keys())}, \"\n f\"but no matching knn_vector fields found in index.\"\n )\n return []\n\n # Build exists filter - document must have at least one embedding field\n exists_any_embedding = {\n \"bool\": {\n \"should\": [{\"exists\": {\"field\": f}} for f in set(embedding_fields)],\n \"minimum_should_match\": 1,\n }\n }\n\n # Combine user filters with exists filter\n all_filters = [*filter_clauses, exists_any_embedding]\n\n # Get limit and score threshold\n limit = self._resolve_limit(filter_obj, default_limit=self.number_of_results)\n score_threshold = self._resolve_score_threshold(filter_obj)\n\n # Determine the best aggregation field for filename based on index mapping\n filename_agg_field = self._get_filename_agg_field(index_properties)\n\n # Build multi-model hybrid query\n body = {\n \"query\": {\n \"bool\": {\n \"should\": [\n {\n \"dis_max\": {\n \"tie_breaker\": 0.0, # Take only the best match, no blending\n \"boost\": 0.7, # 70% weight for semantic search\n \"queries\": knn_queries_with_candidates,\n }\n },\n {\n \"multi_match\": {\n \"query\": q,\n \"fields\": [\"text^2\", \"filename^1.5\"],\n \"type\": \"best_fields\",\n \"fuzziness\": \"AUTO\",\n \"boost\": 0.3, # 30% weight for keyword search\n }\n },\n ],\n \"minimum_should_match\": 1,\n \"filter\": all_filters,\n }\n },\n \"aggs\": {\n \"data_sources\": {\"terms\": {\"field\": filename_agg_field, \"size\": 20}},\n \"document_types\": {\"terms\": {\"field\": \"mimetype\", \"size\": 10}},\n \"owners\": {\"terms\": {\"field\": \"owner\", \"size\": 10}},\n \"embedding_models\": {\"terms\": {\"field\": \"embedding_model\", \"size\": 10}},\n },\n \"_source\": [\n \"filename\",\n \"mimetype\",\n \"page\",\n \"text\",\n \"source_url\",\n \"owner\",\n \"embedding_model\",\n \"parser\",\n \"chunk_size\",\n \"chunk_overlap\",\n \"allowed_users\",\n \"allowed_groups\",\n \"allowed_principals\",\n ],\n \"size\": limit,\n }\n\n if score_threshold is not None:\n body[\"min_score\"] = score_threshold\n\n logger.info(\n f\"Executing multi-model hybrid search with {len(knn_queries_with_candidates)} embedding models: \"\n f\"{list(query_embeddings.keys())}\"\n )\n self.log(\n f\"[EXEC] Executing search with {len(knn_queries_with_candidates)} KNN queries, limit={limit}\"\n )\n self.log(f\"[EXEC] Embedding models used: {list(query_embeddings.keys())}\")\n self.log(f\"[EXEC] KNN fields being queried: {embedding_fields}\")\n\n try:\n resp = client.search(index=self.index_name, body=body, params={\"terminate_after\": 0})\n except RequestError as e:\n error_message = str(e)\n lowered = error_message.lower()\n if use_num_candidates and \"num_candidates\" in lowered:\n logger.warning(\n \"Retrying search without num_candidates parameter due to cluster capabilities\",\n error=error_message,\n )\n fallback_body = copy.deepcopy(body)\n try:\n fallback_body[\"query\"][\"bool\"][\"should\"][0][\"dis_max\"][\"queries\"] = (\n knn_queries_without_candidates\n )\n except (KeyError, IndexError, TypeError) as inner_err:\n raise e from inner_err\n resp = client.search(\n index=self.index_name,\n body=fallback_body,\n params={\"terminate_after\": 0},\n )\n elif \"knn_vector\" in lowered or (\"field\" in lowered and \"knn\" in lowered):\n fallback_vector = next(iter(query_embeddings.values()), None)\n if fallback_vector is None:\n raise\n fallback_field = legacy_vector_field or \"chunk_embedding\"\n logger.warning(\n \"KNN search failed for dynamic fields; falling back to legacy field '%s'.\",\n fallback_field,\n )\n fallback_body = copy.deepcopy(body)\n fallback_body[\"query\"][\"bool\"][\"filter\"] = filter_clauses\n knn_fallback = {\n \"knn\": {\n fallback_field: {\n \"vector\": fallback_vector,\n \"k\": 50,\n }\n }\n }\n if use_num_candidates:\n knn_fallback[\"knn\"][fallback_field][\"num_candidates\"] = num_candidates\n fallback_body[\"query\"][\"bool\"][\"should\"][0][\"dis_max\"][\"queries\"] = [knn_fallback]\n resp = client.search(\n index=self.index_name,\n body=fallback_body,\n params={\"terminate_after\": 0},\n )\n else:\n raise\n hits = resp.get(\"hits\", {}).get(\"hits\", [])\n\n logger.info(f\"Found {len(hits)} results\")\n self.log(f\"[RESULT] Search complete: {len(hits)} results found\")\n\n if len(hits) == 0:\n self.log(\n f\"[EMPTY] Debug info: \"\n f\"models_in_index={available_models}, \"\n f\"matched_models={matched_models}, \"\n f\"knn_fields={embedding_fields}, \"\n f\"filters={len(filter_clauses)} clauses\"\n )\n\n return [\n {\n \"page_content\": fence_untrusted_text(hit[\"_source\"].get(\"text\", \"\")),\n \"metadata\": {\n **{k: v for k, v in hit[\"_source\"].items() if k != \"text\"},\n \"chunk_id\": hit.get(\"_id\"),\n \"id\": hit.get(\"_id\"),\n \"score\": hit.get(\"_score\"),\n },\n \"score\": hit.get(\"_score\"),\n }\n for hit in hits\n ]\n\n def search_documents(self) -> list[Data]:\n\n \"\"\"Search documents and return results as a list of Data objects.\n\n This is the main interface method that performs the multi-model search using the\n configured search_query and returns results in a format that downstream Parser\n components and tool wrappers can consume directly without DataFrame string truncation.\n\n Always builds the vector store (triggering ingestion if needed), then performs\n search only if a query is provided.\n\n Returns:\n List containing search results with text and metadata\n\n Raises:\n Exception: If search operation fails\n \"\"\"\n\n try:\n # Always build/cache the vector store to ensure ingestion happens\n logger.info(f\"Search query: {self.search_query}\")\n if self._cached_vector_store is None:\n self.build_vector_store()\n\n # Only perform search if query is provided\n search_query = (self.search_query or \"\").strip()\n if not search_query:\n self.log(\"No search query provided - ingestion completed, returning empty results\")\n\n return []\n\n # Perform search with the provided query\n raw = self.search(search_query)\n raw_list = [Data(text=hit[\"page_content\"], **hit[\"metadata\"]) for hit in raw]\n return raw_list\n\n except Exception as e:\n self.log(f\"search_documents error: {e}\")\n raise\n\n # -------- dynamic UI handling (auth switch) --------\n async def update_build_config(\n self, build_config: dict, field_value: str, field_name: str | None = None\n ) -> dict:\n \"\"\"Dynamically update component configuration based on field changes.\n\n This method handles real-time UI updates, particularly for authentication\n mode changes that show/hide relevant input fields.\n\n Args:\n build_config: Current component configuration\n field_value: New value for the changed field\n field_name: Name of the field that changed\n\n Returns:\n Updated build configuration with appropriate field visibility\n \"\"\"\n try:\n if field_name == \"auth_mode\":\n mode = (field_value or \"basic\").strip().lower()\n is_basic = mode == \"basic\"\n is_jwt = mode == \"jwt\"\n is_openrag = mode == \"openrag\"\n\n build_config[\"username\"][\"show\"] = is_basic\n build_config[\"password\"][\"show\"] = is_basic\n\n build_config[\"jwt_token\"][\"show\"] = is_jwt\n build_config[\"jwt_header\"][\"show\"] = is_jwt\n build_config[\"bearer_prefix\"][\"show\"] = is_jwt\n\n build_config[\"username\"][\"required\"] = is_basic\n build_config[\"password\"][\"required\"] = is_basic\n\n # build_config[\"jwt_token\"][\"required\"] = is_jwt\n build_config[\"jwt_header\"][\"required\"] = is_jwt\n build_config[\"bearer_prefix\"][\"required\"] = False\n\n # In 'openrag' mode, expose the OPENRAG_* fields up front\n # since they are the only credentials required.\n for openrag_field in (\n \"openrag_ingest_url\",\n \"openrag_ingest_token\",\n \"openrag_ingest_run_id\",\n \"openrag_ingest_batch_size\",\n ):\n if openrag_field in build_config:\n build_config[openrag_field][\"advanced\"] = not is_openrag\n build_config[openrag_field][\"required\"] = (\n is_openrag and openrag_field != \"openrag_ingest_batch_size\"\n )\n\n if is_basic or is_openrag:\n build_config[\"jwt_token\"][\"value\"] = \"\"\n\n return build_config\n\n except (KeyError, ValueError) as e:\n self.log(f\"update_build_config error: {e}\")\n\n return build_config\n"
},
- "dimensions": {
- "_input_type": "IntInput",
- "advanced": true,
+ "docs_metadata": {
+ "_input_type": "TableInput",
+ "advanced": false,
"api_editable": false,
- "display_name": "Dimensions",
+ "display_name": "Document Metadata",
"dynamic": false,
- "info": "The number of dimensions the resulting output embeddings should have. Only supported by certain models.",
- "list": false,
+ "info": "Additional metadata key-value pairs to be added to all ingested documents. Useful for tagging documents with source information, categories, or other custom attributes.",
+ "input_types": [
+ "Data",
+ "JSON"
+ ],
+ "is_list": true,
"list_add_label": "Add More",
- "load_from_db": false,
- "name": "dimensions",
+ "name": "docs_metadata",
"override_skip": false,
"placeholder": "",
"required": false,
"show": true,
+ "table_icon": "Table",
+ "table_schema": [
+ {
+ "description": "Key name",
+ "display_name": "Key",
+ "formatter": "text",
+ "name": "key",
+ "type": "str"
+ },
+ {
+ "description": "Value of the metadata",
+ "display_name": "Value",
+ "formatter": "text",
+ "name": "value",
+ "type": "str"
+ }
+ ],
"title_case": false,
"tool_mode": false,
"trace_as_metadata": true,
- "track_in_telemetry": true,
- "type": "int",
- "value": ""
+ "track_in_telemetry": false,
+ "trigger_icon": "Table",
+ "trigger_text": "Open table",
+ "type": "table",
+ "value": []
},
- "input_text": {
- "_input_type": "BoolInput",
+ "ef_construction": {
+ "_input_type": "IntInput",
"advanced": true,
"api_editable": false,
- "display_name": "Include the original text in the output",
+ "display_name": "EF Construction",
"dynamic": false,
- "info": "",
+ "info": "Size of the dynamic candidate list during index construction. Higher values improve recall but increase indexing time and memory usage.",
"list": false,
"list_add_label": "Add More",
- "name": "input_text",
+ "name": "ef_construction",
"override_skip": false,
"placeholder": "",
"required": false,
- "show": false,
+ "show": true,
"title_case": false,
"tool_mode": false,
"trace_as_metadata": true,
"track_in_telemetry": true,
- "type": "bool",
- "value": true
+ "type": "int",
+ "value": 512
},
- "is_refresh": true,
- "max_retries": {
- "_input_type": "IntInput",
- "advanced": true,
+ "embedding": {
+ "_input_type": "HandleInput",
+ "advanced": false,
"api_editable": false,
- "display_name": "Max Retries",
+ "display_name": "Embedding",
"dynamic": false,
"info": "",
- "list": false,
- "list_add_label": "Add More",
- "name": "max_retries",
+ "input_types": [
+ "Embeddings"
+ ],
+ "list": true,
+ "list_add_label": "Add More",
+ "name": "embedding",
"override_skip": false,
"placeholder": "",
"required": false,
"show": true,
"title_case": false,
- "tool_mode": false,
"trace_as_metadata": true,
- "track_in_telemetry": true,
- "type": "int",
- "value": 3
+ "track_in_telemetry": false,
+ "type": "other",
+ "value": ""
},
- "model": {
- "_input_type": "ModelInput",
- "advanced": true,
+ "embedding_model_name": {
+ "_input_type": "StrInput",
+ "advanced": false,
"api_editable": false,
- "display_name": "Embedding Model",
+ "display_name": "Embedding Model Name",
"dynamic": false,
- "external_options": {
- "fields": {
- "data": {
- "node": {
- "display_name": "Connect other models",
- "icon": "CornerDownLeft",
- "name": "connect_other_models"
- }
- }
- }
- },
- "info": "Select your model provider",
- "input_types": [
- "Embeddings"
- ],
+ "info": "Name of the embedding model to use for ingestion. This selects which embedding from the list will be used to embed documents. Matches on deployment, model, model_id, or model_name. For duplicate deployments, use combined format: 'deployment:model' (e.g., 'text-embedding-ada-002:text-embedding-3-large'). Leave empty to use the first embedding. Error message will show all available identifiers.",
"list": false,
"list_add_label": "Add More",
- "load_from_db": false,
- "model_type": "embedding",
- "name": "model",
- "options": [
- {
- "category": "OpenAI",
- "icon": "OpenAI",
- "metadata": {
- "embedding_class": "OpenAIEmbeddings",
- "model_type": "embeddings",
- "param_mapping": {
- "api_base": "base_url",
- "api_key": "api_key",
- "chunk_size": "chunk_size",
- "dimensions": "dimensions",
- "max_retries": "max_retries",
- "model": "model",
- "model_kwargs": "model_kwargs",
- "request_timeout": "timeout",
- "show_progress_bar": "show_progress_bar"
- }
- },
- "name": "text-embedding-3-large",
- "provider": "OpenAI"
- },
- {
- "category": "OpenAI",
- "icon": "OpenAI",
- "metadata": {
- "embedding_class": "OpenAIEmbeddings",
- "model_type": "embeddings",
- "param_mapping": {
- "api_base": "base_url",
- "api_key": "api_key",
- "chunk_size": "chunk_size",
- "dimensions": "dimensions",
- "max_retries": "max_retries",
- "model": "model",
- "model_kwargs": "model_kwargs",
- "request_timeout": "timeout",
- "show_progress_bar": "show_progress_bar"
- }
- },
- "name": "text-embedding-3-small",
- "provider": "OpenAI"
- },
- {
- "category": "OpenAI",
- "icon": "OpenAI",
- "metadata": {
- "embedding_class": "OpenAIEmbeddings",
- "model_type": "embeddings",
- "param_mapping": {
- "api_base": "base_url",
- "api_key": "api_key",
- "chunk_size": "chunk_size",
- "dimensions": "dimensions",
- "max_retries": "max_retries",
- "model": "model",
- "model_kwargs": "model_kwargs",
- "request_timeout": "timeout",
- "show_progress_bar": "show_progress_bar"
- }
- },
- "name": "text-embedding-ada-002",
- "provider": "OpenAI"
- },
- {
- "category": "IBM WatsonX",
- "icon": "WatsonxAI",
- "metadata": {
- "embedding_class": "WatsonxEmbeddings",
- "model_type": "embeddings",
- "param_mapping": {
- "api_key": "apikey",
- "model_id": "model_id",
- "project_id": "project_id",
- "request_timeout": "request_timeout",
- "space_id": "space_id",
- "url": "url"
- }
- },
- "name": "ibm/granite-embedding-278m-multilingual",
- "provider": "IBM WatsonX"
- },
- {
- "category": "IBM WatsonX",
- "icon": "WatsonxAI",
- "metadata": {
- "embedding_class": "WatsonxEmbeddings",
- "model_type": "embeddings",
- "param_mapping": {
- "api_key": "apikey",
- "model_id": "model_id",
- "project_id": "project_id",
- "request_timeout": "request_timeout",
- "space_id": "space_id",
- "url": "url"
- }
- },
- "name": "ibm/slate-125m-english-rtrvr-v2",
- "provider": "IBM WatsonX"
- },
- {
- "category": "IBM WatsonX",
- "icon": "WatsonxAI",
- "metadata": {
- "embedding_class": "WatsonxEmbeddings",
- "model_type": "embeddings",
- "param_mapping": {
- "api_key": "apikey",
- "model_id": "model_id",
- "project_id": "project_id",
- "request_timeout": "request_timeout",
- "space_id": "space_id",
- "url": "url"
- }
- },
- "name": "ibm/slate-30m-english-rtrvr-v2",
- "provider": "IBM WatsonX"
- },
- {
- "category": "IBM WatsonX",
- "icon": "WatsonxAI",
- "metadata": {
- "embedding_class": "WatsonxEmbeddings",
- "model_type": "embeddings",
- "param_mapping": {
- "api_key": "apikey",
- "model_id": "model_id",
- "project_id": "project_id",
- "request_timeout": "request_timeout",
- "space_id": "space_id",
- "url": "url"
- }
- },
- "name": "intfloat/multilingual-e5-large",
- "provider": "IBM WatsonX"
- }
- ],
+ "load_from_db": true,
+ "name": "embedding_model_name",
"override_skip": false,
- "placeholder": "Setup Provider",
- "real_time_refresh": true,
- "refresh_button": true,
- "required": true,
+ "placeholder": "",
+ "required": false,
"show": true,
"title_case": false,
"tool_mode": false,
- "trace_as_input": true,
+ "trace_as_metadata": true,
"track_in_telemetry": false,
- "type": "model",
- "value": [
- {
- "category": "OpenAI",
- "icon": "OpenAI",
- "metadata": {
- "embedding_class": "OpenAIEmbeddings",
- "model_type": "embeddings",
- "param_mapping": {
- "api_base": "base_url",
- "api_key": "api_key",
- "chunk_size": "chunk_size",
- "dimensions": "dimensions",
- "max_retries": "max_retries",
- "model": "model",
- "model_kwargs": "model_kwargs",
- "request_timeout": "timeout",
- "show_progress_bar": "show_progress_bar"
- }
- },
- "name": "text-embedding-3-small",
- "provider": "OpenAI"
- }
- ]
+ "type": "str",
+ "value": "SELECTED_EMBEDDING_MODEL"
},
- "model_kwargs": {
- "_input_type": "DictInput",
+ "engine": {
+ "_input_type": "DropdownInput",
"advanced": true,
"api_editable": false,
- "display_name": "Model Kwargs",
+ "combobox": false,
+ "dialog_inputs": {},
+ "display_name": "Vector Engine",
+ "dynamic": false,
+ "external_options": {},
+ "info": "Vector search engine for similarity calculations. 'nmslib' works with standard OpenSearch. 'jvector' requires OpenSearch 2.9+. 'lucene' requires index.knn: true. Amazon OpenSearch Serverless only supports 'nmslib' or 'faiss'.",
+ "name": "engine",
+ "options": [
+ "nmslib",
+ "faiss",
+ "lucene",
+ "jvector"
+ ],
+ "options_metadata": [],
+ "override_skip": false,
+ "placeholder": "",
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "toggle": false,
+ "tool_mode": false,
+ "trace_as_metadata": true,
+ "track_in_telemetry": true,
+ "type": "str",
+ "value": "jvector"
+ },
+ "filter_expression": {
+ "_input_type": "MultilineInput",
+ "advanced": false,
+ "ai_enabled": false,
+ "api_editable": false,
+ "copy_field": false,
+ "display_name": "Search Filters (JSON)",
"dynamic": false,
- "info": "Additional keyword arguments to pass to the model. Only used by providers that support this parameter (e.g. OpenAI, Google Generative AI). Ignored for providers that do not include it in their parameter mapping.",
+ "info": "Optional JSON configuration for search filtering, result limits, and score thresholds.\n\nFormat 1 - Explicit filters:\n{\"filter\": [{\"term\": {\"filename\":\"doc.pdf\"}}, {\"terms\":{\"owner\":[\"user1\",\"user2\"]}}], \"limit\": 10, \"score_threshold\": 1.6}\n\nFormat 2 - Context-style mapping:\n{\"data_sources\":[\"file.pdf\"], \"document_types\":[\"application/pdf\"], \"owners\":[\"user123\"]}\n\nUse __IMPOSSIBLE_VALUE__ as placeholder to ignore specific filters.",
+ "input_types": [
+ "Message"
+ ],
"list": false,
"list_add_label": "Add More",
- "name": "model_kwargs",
+ "load_from_db": false,
+ "multiline": true,
+ "name": "filter_expression",
"override_skip": false,
+ "password": false,
"placeholder": "",
"required": false,
"show": true,
"title_case": false,
"tool_mode": false,
"trace_as_input": true,
+ "trace_as_metadata": true,
"track_in_telemetry": false,
- "type": "dict",
- "value": {}
+ "type": "str",
+ "value": ""
},
- "model_name": {
+ "index_name": {
"_input_type": "StrInput",
"advanced": false,
"api_editable": false,
- "display_name": "Model Name Override",
+ "display_name": "Index Name",
"dynamic": false,
- "info": "Optional embedding model name to use instead of the selected model. Can be set from a global variable for runtime model selection.",
+ "info": "The OpenSearch index name where documents will be stored and searched. Will be created automatically if it doesn't exist.",
"list": false,
"list_add_label": "Add More",
"load_from_db": true,
- "name": "model_name",
+ "name": "index_name",
"override_skip": false,
"placeholder": "",
"required": false,
@@ -2265,68 +1806,108 @@
"trace_as_metadata": true,
"track_in_telemetry": false,
"type": "str",
- "value": "SELECTED_EMBEDDING_MODEL"
+ "value": "OPENSEARCH_INDEX_NAME"
},
- "ollama_base_url": {
- "_input_type": "StrInput",
+ "ingest_data": {
+ "_input_type": "HandleInput",
"advanced": false,
"api_editable": false,
- "display_name": "Ollama API URL",
+ "display_name": "Ingest Data",
+ "dynamic": false,
+ "info": "",
+ "input_types": [
+ "Data",
+ "DataFrame",
+ "Table"
+ ],
+ "list": true,
+ "list_add_label": "Add More",
+ "name": "ingest_data",
+ "override_skip": false,
+ "placeholder": "",
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "trace_as_metadata": true,
+ "track_in_telemetry": false,
+ "type": "other",
+ "value": ""
+ },
+ "is_refresh": false,
+ "jwt_header": {
+ "_input_type": "StrInput",
+ "advanced": true,
+ "api_editable": false,
+ "display_name": "JWT Header Name",
"dynamic": false,
- "info": "Endpoint of the Ollama API (Ollama only)",
+ "info": "",
"list": false,
"list_add_label": "Add More",
"load_from_db": false,
- "name": "ollama_base_url",
+ "name": "jwt_header",
"override_skip": false,
"placeholder": "",
- "real_time_refresh": true,
- "required": false,
- "show": false,
+ "required": true,
+ "show": true,
"title_case": false,
"tool_mode": false,
"trace_as_metadata": true,
"track_in_telemetry": false,
"type": "str",
- "value": ""
+ "value": "Authorization"
},
- "project_id": {
- "_input_type": "MessageTextInput",
+ "jwt_token": {
+ "_input_type": "SecretStrInput",
"advanced": false,
"api_editable": false,
- "display_name": "Project ID",
+ "display_name": "JWT Token",
"dynamic": false,
- "info": "IBM watsonx.ai Project ID (required for IBM watsonx.ai)",
- "input_types": [
- "Message"
- ],
+ "info": "Valid JSON Web Token for authentication. Will be sent in the Authorization header (with optional 'Bearer ' prefix).",
+ "input_types": [],
+ "load_from_db": true,
+ "name": "jwt_token",
+ "override_skip": false,
+ "password": true,
+ "placeholder": "",
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "track_in_telemetry": false,
+ "type": "str",
+ "value": "JWT"
+ },
+ "m": {
+ "_input_type": "IntInput",
+ "advanced": true,
+ "api_editable": false,
+ "display_name": "M Parameter",
+ "dynamic": false,
+ "info": "Number of bidirectional connections for each vector in the HNSW graph. Higher values improve search quality but increase memory usage and indexing time.",
"list": false,
"list_add_label": "Add More",
- "load_from_db": false,
- "name": "project_id",
+ "name": "m",
"override_skip": false,
"placeholder": "",
"required": false,
- "show": false,
+ "show": true,
"title_case": false,
"tool_mode": false,
- "trace_as_input": true,
"trace_as_metadata": true,
- "track_in_telemetry": false,
- "type": "str",
- "value": ""
+ "track_in_telemetry": true,
+ "type": "int",
+ "value": 16
},
- "provider": {
+ "max_retries": {
"_input_type": "StrInput",
- "advanced": false,
+ "advanced": true,
"api_editable": false,
- "display_name": "Provider Override",
+ "display_name": "Max Retries",
"dynamic": false,
- "info": "Optional provider to use with Model Name Override. Leave blank to use the selected model's provider.",
+ "info": "Number of retries for failed connections before raising an error.",
"list": false,
"list_add_label": "Add More",
- "load_from_db": true,
- "name": "provider",
+ "load_from_db": false,
+ "name": "max_retries",
"override_skip": false,
"placeholder": "",
"required": false,
@@ -2336,18 +1917,18 @@
"trace_as_metadata": true,
"track_in_telemetry": false,
"type": "str",
- "value": "SELECTED_EMBEDDING_MODEL_PROVIDER"
+ "value": "3"
},
- "request_timeout": {
- "_input_type": "FloatInput",
+ "num_candidates": {
+ "_input_type": "IntInput",
"advanced": true,
"api_editable": false,
- "display_name": "Request Timeout",
+ "display_name": "Candidate Pool Size",
"dynamic": false,
- "info": "",
+ "info": "Number of approximate neighbors to consider for each KNN query. Some OpenSearch deployments do not support this parameter; set to 0 to disable.",
"list": false,
"list_add_label": "Add More",
- "name": "request_timeout",
+ "name": "num_candidates",
"override_skip": false,
"placeholder": "",
"required": false,
@@ -2356,19 +1937,19 @@
"tool_mode": false,
"trace_as_metadata": true,
"track_in_telemetry": true,
- "type": "float",
- "value": ""
+ "type": "int",
+ "value": 1000
},
- "show_progress_bar": {
- "_input_type": "BoolInput",
+ "number_of_results": {
+ "_input_type": "IntInput",
"advanced": true,
"api_editable": false,
- "display_name": "Show Progress Bar",
+ "display_name": "Default Result Limit",
"dynamic": false,
- "info": "",
+ "info": "Default maximum number of search results to return when no limit is specified in the filter expression.",
"list": false,
"list_add_label": "Add More",
- "name": "show_progress_bar",
+ "name": "number_of_results",
"override_skip": false,
"placeholder": "",
"required": false,
@@ -2377,724 +1958,116 @@
"tool_mode": false,
"trace_as_metadata": true,
"track_in_telemetry": true,
- "type": "bool",
- "value": false
+ "type": "int",
+ "value": 10
},
- "truncate_input_tokens": {
+ "openrag_ingest_batch_size": {
"_input_type": "IntInput",
"advanced": true,
"api_editable": false,
- "display_name": "Truncate Input Tokens",
+ "display_name": "OpenRAG Ingest Batch Size",
"dynamic": false,
"info": "",
"list": false,
"list_add_label": "Add More",
- "name": "truncate_input_tokens",
+ "name": "openrag_ingest_batch_size",
"override_skip": false,
"placeholder": "",
"required": false,
- "show": false,
+ "show": true,
"title_case": false,
"tool_mode": false,
"trace_as_metadata": true,
"track_in_telemetry": true,
"type": "int",
- "value": 200
- }
- },
- "tool_mode": false
- },
- "showNode": false,
- "type": "EmbeddingModel"
- },
- "dragging": false,
- "id": "EmbeddingModel-cONxU",
- "position": {
- "x": -22.139984432593124,
- "y": 1292.0572058205992
- },
- "selected": false,
- "type": "genericNode"
- },
- {
- "data": {
- "description": "Get user text inputs.",
- "display_name": "Text Input",
- "id": "TextInput-BG2U3",
- "node": {
- "base_classes": [
- "Message"
- ],
- "beta": false,
- "conditional_paths": [],
- "custom_fields": {},
- "description": "Get user text inputs.",
- "display_name": "Text Input",
- "documentation": "https://docs.langflow.org/text-input-and-output",
- "edited": false,
- "field_order": [
- "input_value",
- "use_global_variable"
- ],
- "frozen": false,
- "icon": "type",
- "last_updated": "2026-07-17T19:15:11.463Z",
- "legacy": true,
- "metadata": {
- "code_hash": "2811c0e0496f",
- "dependencies": {
- "dependencies": [
- {
- "name": "lfx",
- "version": null
- }
- ],
- "total_dependencies": 1
- },
- "module": "custom_components.text_input"
- },
- "minimized": false,
- "output_types": [],
- "outputs": [
- {
- "allows_loop": false,
- "cache": true,
- "display_name": "Output Text",
- "group_outputs": false,
- "loop_types": null,
- "method": "text_response",
- "name": "text",
- "options": null,
- "required_inputs": null,
- "selected": "Message",
- "tool_mode": true,
- "types": [
- "Message"
- ],
- "value": "__UNDEFINED__"
- }
- ],
- "pinned": false,
- "replacement": [
- "input_output.ChatInput"
- ],
- "template": {
- "_frontend_node_flow_id": {
- "value": "ebc01d31-1976-46ce-a385-b0240327226c"
- },
- "_frontend_node_folder_id": {
- "value": "f1efb4f8-3ca5-4e89-8685-0e8b2ba1187f"
- },
- "_type": "Component",
- "code": {
- "advanced": true,
- "api_editable": false,
- "dynamic": true,
- "fileTypes": [],
- "file_path": "",
- "info": "",
- "list": false,
- "load_from_db": false,
- "multiline": true,
- "name": "code",
- "password": false,
- "placeholder": "",
- "required": true,
- "show": true,
- "title_case": false,
- "type": "code",
- "value": "from typing import Any\n\nfrom lfx.base.io.text import TextComponent\nfrom lfx.io import BoolInput, MultilineInput, Output\nfrom lfx.schema.message import Message\n\n\nclass TextInputComponent(TextComponent):\n display_name = \"Text Input\"\n description = \"Get user text inputs.\"\n documentation: str = \"https://docs.langflow.org/text-input-and-output\"\n icon = \"type\"\n name = \"TextInput\"\n legacy = True\n replacement = [\"input_output.ChatInput\"]\n\n inputs = [\n MultilineInput(\n name=\"input_value\",\n display_name=\"Text\",\n info=\"Text to be passed as input.\",\n ),\n BoolInput(\n name=\"use_global_variable\",\n display_name=\"Use Global Variable\",\n info=\"Enable to select from global variables (shows globe icon). Disables multiline editing.\",\n value=False,\n advanced=True,\n real_time_refresh=True,\n ),\n ]\n outputs = [\n Output(display_name=\"Output Text\", name=\"text\", method=\"text_response\"),\n ]\n\n def update_build_config(self, build_config: dict, field_value: Any, field_name: str | None = None) -> dict:\n if field_name == \"use_global_variable\":\n if field_value:\n # Enable global variable mode: single-line with password masking and globe dropdown\n build_config[\"input_value\"][\"multiline\"] = False\n build_config[\"input_value\"][\"password\"] = True\n else:\n # Default mode: multiline text editing\n build_config[\"input_value\"][\"multiline\"] = True\n build_config[\"input_value\"][\"password\"] = False\n return build_config\n\n def text_response(self) -> Message:\n return Message(\n text=self.input_value,\n )\n"
- },
- "input_value": {
- "_input_type": "MultilineInput",
- "advanced": false,
- "ai_enabled": false,
- "api_editable": false,
- "copy_field": false,
- "display_name": "Text",
- "dynamic": false,
- "info": "Text to be passed as input.",
- "input_types": [
- "Message"
- ],
- "list": false,
- "list_add_label": "Add More",
- "load_from_db": true,
- "multiline": false,
- "name": "input_value",
- "override_skip": false,
- "password": true,
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_input": true,
- "trace_as_metadata": true,
- "track_in_telemetry": false,
- "type": "str",
- "value": "OPENRAG-QUERY-FILTER"
- },
- "is_refresh": false,
- "use_global_variable": {
- "_input_type": "BoolInput",
- "advanced": true,
- "api_editable": false,
- "display_name": "Use Global Variable",
- "dynamic": false,
- "info": "Enable to select from global variables (shows globe icon). Disables multiline editing.",
- "list": false,
- "list_add_label": "Add More",
- "load_from_db": false,
- "name": "use_global_variable",
- "override_skip": false,
- "placeholder": "",
- "real_time_refresh": true,
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_metadata": true,
- "track_in_telemetry": true,
- "type": "bool",
- "value": true
- }
- },
- "tool_mode": false
- },
- "showNode": true,
- "type": "TextInput"
- },
- "dragging": false,
- "id": "TextInput-BG2U3",
- "position": {
- "x": -129.32512588180916,
- "y": 1389.9093803810442
- },
- "selected": false,
- "type": "genericNode"
- },
- {
- "data": {
- "description": "Extracts text using a template.",
- "display_name": "Parser",
- "id": "ParserComponent-x6BS7",
- "node": {
- "base_classes": [
- "Message"
- ],
- "beta": false,
- "conditional_paths": [],
- "custom_fields": {},
- "description": "Extracts text using a template.",
- "display_name": "Parser",
- "documentation": "https://docs.langflow.org/parser",
- "edited": false,
- "field_order": [
- "input_data",
- "mode",
- "pattern",
- "sep"
- ],
- "frozen": false,
- "icon": "braces",
- "legacy": false,
- "metadata": {
- "code_hash": "7ab5fd0e0a10",
- "dependencies": {
- "dependencies": [
- {
- "name": "lfx",
- "version": null
- }
- ],
- "total_dependencies": 1
- },
- "module": "custom_components.parser"
- },
- "minimized": false,
- "output_types": [],
- "outputs": [
- {
- "allows_loop": false,
- "cache": true,
- "display_name": "Parsed Text",
- "group_outputs": false,
- "loop_types": null,
- "method": "parse_combined_text",
- "name": "parsed_text",
- "options": null,
- "required_inputs": null,
- "selected": "Message",
- "tool_mode": true,
- "types": [
- "Message"
- ],
- "value": "__UNDEFINED__"
- }
- ],
- "pinned": false,
- "template": {
- "_type": "Component",
- "code": {
- "advanced": true,
- "api_editable": false,
- "dynamic": true,
- "fileTypes": [],
- "file_path": "",
- "info": "",
- "list": false,
- "load_from_db": false,
- "multiline": true,
- "name": "code",
- "password": false,
- "placeholder": "",
- "required": true,
- "show": true,
- "title_case": false,
- "type": "code",
- "value": "from lfx.custom.custom_component.component import Component\nfrom lfx.helpers.data import safe_convert\nfrom lfx.inputs.inputs import BoolInput, HandleInput, MessageTextInput, MultilineInput, TabInput\nfrom lfx.schema.data import Data\nfrom lfx.schema.dataframe import DataFrame\nfrom lfx.schema.message import Message\nfrom lfx.template.field.base import Output\n\n\nclass _DefaultDict(dict):\n def __init__(self, data_item: Data):\n super().__init__(data_item.data)\n self.default_value = data_item.default_value\n\n def __missing__(self, key):\n return self.default_value if self.default_value is not None else \"\"\n\n\nclass ParserComponent(Component):\n display_name = \"Parser\"\n description = \"Extracts text using a template.\"\n documentation: str = \"https://docs.langflow.org/parser\"\n icon = \"braces\"\n\n inputs = [\n HandleInput(\n name=\"input_data\",\n display_name=\"JSON or Table\",\n input_types=[\"DataFrame\", \"Table\", \"Data\", \"JSON\"],\n info=\"Accepts a DataFrame, a Data object, or a list of Data objects.\",\n required=True,\n ),\n TabInput(\n name=\"mode\",\n display_name=\"Mode\",\n options=[\"Parser\", \"Stringify\"],\n value=\"Parser\",\n info=\"Convert into raw string instead of using a template.\",\n real_time_refresh=True,\n ),\n MultilineInput(\n name=\"pattern\",\n display_name=\"Template\",\n info=(\n \"Use variables within curly brackets to extract column values for DataFrames \"\n \"or key values for Data.\"\n \"For example: `Name: {Name}, Age: {Age}, Country: {Country}`\"\n ),\n value=\"Text: {text}\", # Example default\n dynamic=True,\n show=True,\n required=True,\n ),\n MessageTextInput(\n name=\"sep\",\n display_name=\"Separator\",\n advanced=True,\n value=\"\\n\",\n info=\"String used to separate rows/items.\",\n ),\n ]\n\n outputs = [\n Output(\n display_name=\"Parsed Text\",\n name=\"parsed_text\",\n info=\"Formatted text output.\",\n method=\"parse_combined_text\",\n ),\n ]\n\n def update_build_config(self, build_config, field_value, field_name=None):\n \"\"\"Dynamically hide/show `template` and enforce requirement based on `stringify`.\"\"\"\n if field_name == \"mode\":\n build_config[\"pattern\"][\"show\"] = self.mode == \"Parser\"\n build_config[\"pattern\"][\"required\"] = self.mode == \"Parser\"\n if field_value:\n clean_data = BoolInput(\n name=\"clean_data\",\n display_name=\"Clean Data\",\n info=(\n \"Enable to clean the data by removing empty rows and lines \"\n \"in each cell of the DataFrame/ Data object.\"\n ),\n value=True,\n advanced=True,\n required=False,\n )\n build_config[\"clean_data\"] = clean_data.to_dict()\n else:\n build_config.pop(\"clean_data\", None)\n\n return build_config\n\n def _clean_args(self) -> tuple[DataFrame | None, Data | list[Data] | None]:\n \"\"\"Prepare arguments based on input type.\"\"\"\n input_data = self.input_data\n\n match input_data:\n case list() if all(isinstance(item, Data) for item in input_data):\n return None, input_data\n case DataFrame():\n return input_data, None\n case Data():\n return None, input_data\n case dict() if \"data\" in input_data:\n try:\n if \"columns\" in input_data: # Likely a DataFrame\n return DataFrame.from_dict(input_data), None\n # Likely a Data object\n return None, Data(**input_data)\n except (TypeError, ValueError, KeyError) as e:\n msg = f\"Invalid structured input provided: {e!s}\"\n raise ValueError(msg) from e\n case _:\n msg = f\"Unsupported input type: {type(input_data)}. Expected DataFrame, Data, or list[Data].\"\n raise ValueError(msg)\n\n def parse_combined_text(self) -> Message:\n \"\"\"Parse all rows/items into a single text or convert input to string if `stringify` is enabled.\"\"\"\n # Early return for stringify option\n if self.mode == \"Stringify\":\n return self.convert_to_string()\n\n df, data = self._clean_args()\n\n lines = []\n if df is not None:\n for _, row in df.iterrows():\n formatted_text = self.pattern.format(**row.to_dict())\n lines.append(formatted_text)\n elif data is not None:\n data_items = data if isinstance(data, list) else [data]\n for data_item in data_items:\n formatted_text = self.pattern.format_map(_DefaultDict(data_item))\n lines.append(formatted_text)\n\n combined_text = self.sep.join(lines)\n self.status = combined_text\n return Message(text=combined_text)\n\n def convert_to_string(self) -> Message:\n \"\"\"Convert input data to string with proper error handling.\"\"\"\n clean_data = getattr(self, \"clean_data\", False)\n if isinstance(self.input_data, list):\n result = \"\\n\".join(safe_convert(item, clean_data=clean_data) for item in self.input_data)\n else:\n result = safe_convert(self.input_data, clean_data=clean_data)\n self.log(f\"Converted to string with length: {len(result)}\")\n\n message = Message(text=result)\n self.status = message\n return message\n"
- },
- "input_data": {
- "_input_type": "HandleInput",
- "advanced": false,
- "api_editable": false,
- "display_name": "JSON or Table",
- "dynamic": false,
- "info": "Accepts a DataFrame, a Data object, or a list of Data objects.",
- "input_types": [
- "DataFrame",
- "Table",
- "Data",
- "JSON"
- ],
- "list": false,
- "list_add_label": "Add More",
- "name": "input_data",
- "override_skip": false,
- "placeholder": "",
- "required": true,
- "show": true,
- "title_case": false,
- "trace_as_metadata": true,
- "track_in_telemetry": false,
- "type": "other",
- "value": ""
- },
- "mode": {
- "_input_type": "TabInput",
- "advanced": false,
- "api_editable": false,
- "display_name": "Mode",
- "dynamic": false,
- "info": "Convert into raw string instead of using a template.",
- "name": "mode",
- "options": [
- "Parser",
- "Stringify"
- ],
- "override_skip": false,
- "placeholder": "",
- "real_time_refresh": true,
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_metadata": true,
- "track_in_telemetry": true,
- "type": "tab",
- "value": "Parser"
- },
- "pattern": {
- "_input_type": "MultilineInput",
- "advanced": false,
- "ai_enabled": false,
- "api_editable": false,
- "copy_field": false,
- "display_name": "Template",
- "dynamic": true,
- "info": "Use variables within curly brackets to extract column values for DataFrames or key values for Data.For example: `Name: {Name}, Age: {Age}, Country: {Country}`",
- "input_types": [
- "Message"
- ],
- "list": false,
- "list_add_label": "Add More",
- "load_from_db": false,
- "multiline": true,
- "name": "pattern",
- "override_skip": false,
- "password": false,
- "placeholder": "",
- "required": true,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_input": true,
- "trace_as_metadata": true,
- "track_in_telemetry": false,
- "type": "str",
- "value": "{text}"
- },
- "sep": {
- "_input_type": "MessageTextInput",
- "advanced": true,
- "api_editable": false,
- "display_name": "Separator",
- "dynamic": false,
- "info": "String used to separate rows/items.",
- "input_types": [
- "Message"
- ],
- "list": false,
- "list_add_label": "Add More",
- "load_from_db": false,
- "name": "sep",
- "override_skip": false,
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_input": true,
- "trace_as_metadata": true,
- "track_in_telemetry": false,
- "type": "str",
- "value": "\n"
- }
- },
- "tool_mode": false
- },
- "showNode": true,
- "type": "ParserComponent"
- },
- "dragging": false,
- "id": "ParserComponent-x6BS7",
- "position": {
- "x": 846.9539656485665,
- "y": 1195.8338615381288
- },
- "selected": false,
- "type": "genericNode"
- },
- {
- "data": {
- "id": "ext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-yrQui",
- "node": {
- "base_classes": [
- "JSON",
- "VectorStore"
- ],
- "beta": false,
- "bundle": "openrag",
- "conditional_paths": [],
- "custom_fields": {},
- "description": "Store and search documents using OpenSearch with multi-model hybrid semantic and keyword search. To search use the tools search_documents and raw_search. Search documents takes a query for vector search, for example\n {search_query: \"components in openrag\"}",
- "display_name": "OpenSearch (Multi-Model Multi-Embedding)",
- "documentation": "",
- "edited": false,
- "extension": "openrag",
- "extension_version": "0.0.0",
- "field_order": [
- "docs_metadata",
- "opensearch_url",
- "index_name",
- "engine",
- "space_type",
- "ef_construction",
- "m",
- "num_candidates",
- "ingest_data",
- "search_query",
- "should_cache_vector_store",
- "embedding",
- "embedding_model_name",
- "vector_field",
- "number_of_results",
- "filter_expression",
- "auth_mode",
- "username",
- "password",
- "jwt_token",
- "jwt_header",
- "bearer_prefix",
- "use_ssl",
- "verify_certs",
- "request_timeout",
- "max_retries",
- "openrag_ingest_url",
- "openrag_ingest_token",
- "openrag_ingest_run_id",
- "openrag_ingest_batch_size"
- ],
- "frozen": false,
- "icon": "OpenSearch",
- "last_updated": "2026-08-05T16:19:12.028Z",
- "legacy": false,
- "metadata": {
- "code_hash": "6c375fdaa9e7",
- "dependencies": {
- "dependencies": [
- {
- "name": "httpx",
- "version": "0.28.1"
- },
- {
- "name": "lfx",
- "version": "1.11.2"
- },
- {
- "name": "opensearchpy",
- "version": "3.2.0"
- },
- {
- "name": "config",
- "version": null
- },
- {
- "name": "tenacity",
- "version": "8.5.0"
- }
- ],
- "total_dependencies": 5
- },
- "module": "_lfx_ext.extra.openrag.opensearch_multimodal"
- },
- "minimized": false,
- "name": "OpenSearchVectorStoreComponentMultimodalMultiEmbedding",
- "namespaced_id": "ext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra",
- "output_types": [],
- "outputs": [
- {
- "allows_loop": false,
- "cache": true,
- "display_name": "Search Results",
- "group_outputs": false,
- "loop_types": null,
- "method": "search_documents",
- "name": "search_results",
- "options": null,
- "required_inputs": null,
- "selected": "JSON",
- "tool_mode": true,
- "types": [
- "JSON"
- ],
- "value": "__UNDEFINED__"
- },
- {
- "allows_loop": false,
- "cache": true,
- "display_name": "Raw Search",
- "group_outputs": false,
- "loop_types": null,
- "method": "raw_search",
- "name": "raw_search",
- "options": null,
- "required_inputs": null,
- "selected": "JSON",
- "tool_mode": true,
- "types": [
- "JSON"
- ],
- "value": "__UNDEFINED__"
- },
- {
- "allows_loop": false,
- "cache": true,
- "display_name": "Vector Store Connection",
- "group_outputs": false,
- "hidden": false,
- "loop_types": null,
- "method": "as_vector_store",
- "name": "vectorstoreconnection",
- "options": null,
- "required_inputs": null,
- "selected": "VectorStore",
- "tool_mode": true,
- "types": [
- "VectorStore"
- ],
- "value": "__UNDEFINED__"
- }
- ],
- "pinned": false,
- "template": {
- "_frontend_node_flow_id": {
- "value": "ebc01d31-1976-46ce-a385-b0240327226c"
- },
- "_frontend_node_folder_id": {
- "value": "203c7c12-9e1d-4561-bb14-16102afec154"
- },
- "_type": "Component",
- "auth_mode": {
- "_input_type": "DropdownInput",
- "advanced": false,
- "api_editable": false,
- "combobox": false,
- "dialog_inputs": {},
- "display_name": "Authentication Mode",
- "dynamic": false,
- "external_options": {},
- "info": "Authentication method: 'basic' for username/password authentication, 'jwt' for JSON Web Token (Bearer) authentication, or 'openrag' to delegate writes to the OpenRAG backend ingest callback (no direct OpenSearch credentials required — only OPENRAG_* fields).",
- "name": "auth_mode",
- "options": [
- "basic",
- "jwt",
- "openrag"
- ],
- "options_metadata": [],
- "override_skip": false,
- "placeholder": "",
- "real_time_refresh": true,
- "required": false,
- "show": true,
- "title_case": false,
- "toggle": false,
- "tool_mode": false,
- "trace_as_metadata": true,
- "track_in_telemetry": true,
- "type": "str",
- "value": "jwt"
- },
- "bearer_prefix": {
- "_input_type": "BoolInput",
- "advanced": true,
- "api_editable": false,
- "display_name": "Prefix 'Bearer '",
- "dynamic": false,
- "info": "",
- "list": false,
- "list_add_label": "Add More",
- "name": "bearer_prefix",
- "override_skip": false,
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_metadata": true,
- "track_in_telemetry": true,
- "type": "bool",
- "value": false
- },
- "code": {
- "advanced": true,
- "api_editable": false,
- "dynamic": true,
- "fileTypes": [],
- "file_path": "",
- "info": "",
- "list": false,
- "load_from_db": false,
- "multiline": true,
- "name": "code",
- "password": false,
- "placeholder": "",
- "required": true,
- "show": true,
- "title_case": false,
- "type": "code",
- "value": "from __future__ import annotations\n\nimport copy\nimport json\nimport uuid\nfrom concurrent.futures import ThreadPoolExecutor, as_completed\nfrom typing import Any\n\nimport httpx\nfrom lfx.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store\nfrom lfx.base.vectorstores.vector_store_connection_decorator import vector_store_connection\nfrom lfx.io import (\n BoolInput,\n DropdownInput,\n HandleInput,\n IntInput,\n MultilineInput,\n Output,\n SecretStrInput,\n StrInput,\n TableInput,\n)\nfrom lfx.log import logger\nfrom lfx.schema.data import Data\nfrom lfx.schema.dataframe import Table\nfrom opensearchpy import OpenSearch, helpers\nfrom opensearchpy.exceptions import OpenSearchException, RequestError\n\nREQUEST_TIMEOUT = 60\nMAX_RETRIES = 5\n\n# watsonx.ai surfaces rate-limit state via these (mostly non-standard) response\n# headers. The IBM SDK acts on the x-requests-limit-* family directly; we log\n# them on a failed embedding call to aid plan/region tuning.\n_WATSONX_RATE_LIMIT_HEADERS = (\n \"x-requests-limit-rate\",\n \"x-requests-limit-remaining\",\n \"x-requests-limit-reset\",\n \"Retry-After\",\n)\n\n\ndef _log_watsonx_rate_limit_headers(error: Exception) -> None:\n \"\"\"Best-effort diagnostic: log watsonx rate-limit headers from a failed call.\n\n The watsonx SDK raises ``ApiRequestFailure``, which carries the originating\n httpx/requests ``Response`` as ``.response``. On a 429 exhaustion we surface\n the documented rate-limit headers so operators can tune throughput.\n \"\"\"\n try:\n response = getattr(error, \"response\", None)\n headers = getattr(response, \"headers\", None)\n if not headers:\n return\n status = getattr(response, \"status_code\", \"unknown\")\n observed = {h: headers.get(h) for h in _WATSONX_RATE_LIMIT_HEADERS if headers.get(h) is not None}\n if str(status) == \"429\" or observed:\n logger.warning(f\"watsonx rate-limit response (status={status}): {observed}\")\n except Exception as log_error: # never let diagnostics mask the real error\n logger.debug(f\"Could not extract watsonx rate-limit headers: {log_error}\")\n\n\ndef normalize_model_name(model_name: str) -> str:\n \"\"\"Normalize embedding model name for use as field suffix.\n\n Converts model names to valid OpenSearch field names by replacing\n special characters and ensuring alphanumeric format.\n\n Args:\n model_name: Original embedding model name (e.g., \"text-embedding-3-small\")\n\n Returns:\n Normalized field suffix (e.g., \"text_embedding_3_small\")\n \"\"\"\n normalized = model_name.lower()\n # Replace common separators with underscores\n normalized = normalized.replace(\"-\", \"_\").replace(\":\", \"_\").replace(\"/\", \"_\").replace(\".\", \"_\")\n # Remove any non-alphanumeric characters except underscores\n normalized = \"\".join(c if c.isalnum() or c == \"_\" else \"_\" for c in normalized)\n # Remove duplicate underscores\n while \"__\" in normalized:\n normalized = normalized.replace(\"__\", \"_\")\n return normalized.strip(\"_\")\n\n\ndef get_embedding_field_name(model_name: str) -> str:\n \"\"\"Get the dynamic embedding field name for a model.\n\n Args:\n model_name: Embedding model name\n\n Returns:\n Field name in format: chunk_embedding_{normalized_model_name}\n \"\"\"\n logger.info(f\"chunk_embedding_{normalize_model_name(model_name)}\")\n return f\"chunk_embedding_{normalize_model_name(model_name)}\"\n\n\nUNTRUSTED_CHUNK_FENCE_START = \"<<<UNTRUSTED_DOC_CHUNK>>>\"\nUNTRUSTED_CHUNK_FENCE_END = \"<<<END_UNTRUSTED_DOC_CHUNK>>>\"\n\n\ndef fence_untrusted_text(text: str) -> str:\n \"\"\"Wrap retrieved document text in delimiters marking it as untrusted data.\n\n Retrieved chunk text can contain attacker-controlled natural-language\n instructions (indirect prompt injection, VULN-13906). Fencing it lets the\n system prompt tell the LLM to treat anything between these markers as\n data only, never as instructions or tool directives.\n\n Any literal fence markers already present in `text` are escaped first, so\n a poisoned chunk can't embed a fake end-of-fence marker to break out of\n the untrusted section and have its continuation misread as trusted.\n \"\"\"\n if not text:\n return text\n escaped = text.replace(\n UNTRUSTED_CHUNK_FENCE_START, \"\\\\\" + UNTRUSTED_CHUNK_FENCE_START\n ).replace(UNTRUSTED_CHUNK_FENCE_END, \"\\\\\" + UNTRUSTED_CHUNK_FENCE_END)\n return f\"{UNTRUSTED_CHUNK_FENCE_START}\\n{escaped}\\n{UNTRUSTED_CHUNK_FENCE_END}\"\n\n\n@vector_store_connection\nclass OpenSearchVectorStoreComponentMultimodalMultiEmbedding(LCVectorStoreComponent):\n \"\"\"OpenSearch Vector Store Component with Multi-Model Hybrid Search Capabilities.\n\n This component provides vector storage and retrieval using OpenSearch, combining semantic\n similarity search (KNN) with keyword-based search for optimal results. It supports:\n - Multiple embedding models per index with dynamic field names\n - Automatic detection and querying of all available embedding models\n - Parallel embedding generation for multi-model search\n - Document ingestion with model tracking\n - Advanced filtering and aggregations\n - Flexible authentication options\n\n Features:\n - Multi-model vector storage with dynamic fields (chunk_embedding_{model_name})\n - Hybrid search combining multiple KNN queries (dis_max) + keyword matching\n - Auto-detection of available models in the index\n - Parallel query embedding generation for all detected models\n - Vector storage with configurable engines (jvector, nmslib, faiss, lucene)\n - Flexible authentication (Basic auth, JWT tokens)\n\n Model Name Resolution:\n - Priority: deployment > model > model_name attributes\n - This ensures correct matching between embedding objects and index fields\n - When multiple embeddings are provided, specify embedding_model_name to select which one to use\n - During search, each detected model in the index is matched to its corresponding embedding object\n \"\"\"\n\n display_name: str = \"OpenSearch (Multi-Model Multi-Embedding)\"\n icon: str = \"OpenSearch\"\n description: str = (\n \"Store and search documents using OpenSearch with multi-model hybrid semantic and keyword search. \"\n \"To search use the tools search_documents and raw_search. \"\n \"Search documents takes a query for vector search, for example\\n\"\n ' {search_query: \"components in openrag\"}'\n )\n\n # Keys we consider baseline\n default_keys: list[str] = [\n \"opensearch_url\",\n \"index_name\",\n *[i.name for i in LCVectorStoreComponent.inputs], # search_query, add_documents, etc.\n \"embedding\",\n \"embedding_model_name\",\n \"vector_field\",\n \"number_of_results\",\n \"auth_mode\",\n \"username\",\n \"password\",\n \"jwt_token\",\n \"jwt_header\",\n \"bearer_prefix\",\n \"use_ssl\",\n \"verify_certs\",\n \"filter_expression\",\n \"engine\",\n \"space_type\",\n \"ef_construction\",\n \"m\",\n \"num_candidates\",\n \"docs_metadata\",\n \"request_timeout\",\n \"max_retries\",\n \"openrag_ingest_url\",\n \"openrag_ingest_token\",\n \"openrag_ingest_run_id\",\n \"openrag_ingest_batch_size\",\n ]\n _openrag_ingest_global_placeholders = {\n \"openrag_ingest_url\": \"OPENRAG_INGEST_URL\",\n \"openrag_ingest_token\": \"OPENRAG_INGEST_TOKEN\",\n \"openrag_ingest_run_id\": \"OPENRAG_INGEST_RUN_ID\",\n }\n\n inputs = [\n TableInput(\n name=\"docs_metadata\",\n display_name=\"Document Metadata\",\n info=(\n \"Additional metadata key-value pairs to be added to all ingested documents. \"\n \"Useful for tagging documents with source information, categories, or other custom attributes.\"\n ),\n table_schema=[\n {\n \"name\": \"key\",\n \"display_name\": \"Key\",\n \"type\": \"str\",\n \"description\": \"Key name\",\n },\n {\n \"name\": \"value\",\n \"display_name\": \"Value\",\n \"type\": \"str\",\n \"description\": \"Value of the metadata\",\n },\n ],\n value=[],\n input_types=[\"Data\", \"JSON\"],\n ),\n StrInput(\n name=\"opensearch_url\",\n display_name=\"OpenSearch URL\",\n value=\"http://localhost:9200\",\n info=(\n \"The connection URL for your OpenSearch cluster \"\n \"(e.g., http://localhost:9200 for local development or your cloud endpoint).\"\n ),\n ),\n StrInput(\n name=\"index_name\",\n display_name=\"Index Name\",\n value=\"langflow\",\n info=(\n \"The OpenSearch index name where documents will be stored and searched. \"\n \"Will be created automatically if it doesn't exist.\"\n ),\n ),\n DropdownInput(\n name=\"engine\",\n display_name=\"Vector Engine\",\n options=[\"nmslib\", \"faiss\", \"lucene\", \"jvector\"],\n value=\"jvector\",\n info=(\n \"Vector search engine for similarity calculations. 'nmslib' works with standard \"\n \"OpenSearch. 'jvector' requires OpenSearch 2.9+. 'lucene' requires index.knn: true. \"\n \"Amazon OpenSearch Serverless only supports 'nmslib' or 'faiss'.\"\n ),\n advanced=True,\n ),\n DropdownInput(\n name=\"space_type\",\n display_name=\"Distance Metric\",\n options=[\"l2\", \"l1\", \"cosinesimil\", \"linf\", \"innerproduct\"],\n value=\"l2\",\n info=(\n \"Distance metric for calculating vector similarity. 'l2' (Euclidean) is most common, \"\n \"'cosinesimil' for cosine similarity, 'innerproduct' for dot product.\"\n ),\n advanced=True,\n ),\n IntInput(\n name=\"ef_construction\",\n display_name=\"EF Construction\",\n value=512,\n info=(\n \"Size of the dynamic candidate list during index construction. \"\n \"Higher values improve recall but increase indexing time and memory usage.\"\n ),\n advanced=True,\n ),\n IntInput(\n name=\"m\",\n display_name=\"M Parameter\",\n value=16,\n info=(\n \"Number of bidirectional connections for each vector in the HNSW graph. \"\n \"Higher values improve search quality but increase memory usage and indexing time.\"\n ),\n advanced=True,\n ),\n IntInput(\n name=\"num_candidates\",\n display_name=\"Candidate Pool Size\",\n value=1000,\n info=(\n \"Number of approximate neighbors to consider for each KNN query. \"\n \"Some OpenSearch deployments do not support this parameter; set to 0 to disable.\"\n ),\n advanced=True,\n ),\n *LCVectorStoreComponent.inputs, # includes search_query, add_documents, etc.\n HandleInput(\n name=\"embedding\", display_name=\"Embedding\", input_types=[\"Embeddings\"], is_list=True\n ),\n StrInput(\n name=\"embedding_model_name\",\n display_name=\"Embedding Model Name\",\n value=\"\",\n info=(\n \"Name of the embedding model to use for ingestion. This selects which embedding from the list \"\n \"will be used to embed documents. Matches on deployment, model, model_id, or model_name. \"\n \"For duplicate deployments, use combined format: 'deployment:model' \"\n \"(e.g., 'text-embedding-ada-002:text-embedding-3-large'). \"\n \"Leave empty to use the first embedding. Error message will show all available identifiers.\"\n ),\n advanced=False,\n ),\n StrInput(\n name=\"vector_field\",\n display_name=\"Legacy Vector Field Name\",\n value=\"chunk_embedding\",\n advanced=True,\n info=(\n \"Legacy field name for backward compatibility. New documents use dynamic fields \"\n \"(chunk_embedding_{model_name}) based on the embedding_model_name.\"\n ),\n ),\n IntInput(\n name=\"number_of_results\",\n display_name=\"Default Result Limit\",\n value=10,\n advanced=True,\n info=(\n \"Default maximum number of search results to return when no limit is \"\n \"specified in the filter expression.\"\n ),\n ),\n MultilineInput(\n name=\"filter_expression\",\n display_name=\"Search Filters (JSON)\",\n value=\"\",\n info=(\n \"Optional JSON configuration for search filtering, result limits, and score thresholds.\\n\\n\"\n \"Format 1 - Explicit filters:\\n\"\n '{\"filter\": [{\"term\": {\"filename\":\"doc.pdf\"}}, '\n '{\"terms\":{\"owner\":[\"user1\",\"user2\"]}}], \"limit\": 10, \"score_threshold\": 1.6}\\n\\n'\n \"Format 2 - Context-style mapping:\\n\"\n '{\"data_sources\":[\"file.pdf\"], \"document_types\":[\"application/pdf\"], \"owners\":[\"user123\"]}\\n\\n'\n \"Use __IMPOSSIBLE_VALUE__ as placeholder to ignore specific filters.\"\n ),\n ),\n # ----- Auth controls (dynamic) -----\n DropdownInput(\n name=\"auth_mode\",\n display_name=\"Authentication Mode\",\n value=\"openrag\",\n options=[\"basic\", \"jwt\", \"openrag\"],\n info=(\n \"Authentication method: 'basic' for username/password authentication, \"\n \"'jwt' for JSON Web Token (Bearer) authentication, or 'openrag' to \"\n \"delegate writes to the OpenRAG backend ingest callback (no direct \"\n \"OpenSearch credentials required — only OPENRAG_* fields).\"\n ),\n real_time_refresh=True,\n advanced=False,\n ),\n StrInput(\n name=\"username\",\n display_name=\"Username\",\n value=\"admin\",\n show=True,\n ),\n SecretStrInput(\n name=\"password\",\n display_name=\"OpenSearch Password\",\n value=\"OPENSEARCH_PASSWORD\",\n load_from_db=True,\n show=True,\n ),\n SecretStrInput(\n name=\"jwt_token\",\n display_name=\"JWT Token\",\n value=\"JWT\",\n load_from_db=False,\n show=False,\n info=(\n \"Valid JSON Web Token for authentication. \"\n \"Will be sent in the Authorization header (with optional 'Bearer ' prefix).\"\n ),\n required=False\n ),\n StrInput(\n name=\"jwt_header\",\n display_name=\"JWT Header Name\",\n value=\"Authorization\",\n show=False,\n advanced=True,\n ),\n BoolInput(\n name=\"bearer_prefix\",\n display_name=\"Prefix 'Bearer '\",\n value=False,\n show=False,\n advanced=True,\n ),\n # ----- TLS -----\n BoolInput(\n name=\"use_ssl\",\n display_name=\"Use SSL/TLS\",\n value=True,\n advanced=True,\n info=\"Enable SSL/TLS encryption for secure connections to OpenSearch.\",\n ),\n BoolInput(\n name=\"verify_certs\",\n display_name=\"Verify SSL Certificates\",\n value=False,\n advanced=True,\n info=(\n \"Verify SSL certificates when connecting. \"\n \"Disable for self-signed certificates in development environments.\"\n ),\n ),\n # ----- Timeout / Retry -----\n StrInput(\n name=\"request_timeout\",\n display_name=\"Request Timeout (seconds)\",\n value=\"60\",\n advanced=True,\n info=(\n \"Time in seconds to wait for a response from OpenSearch. \"\n \"Increase for large bulk ingestion or complex hybrid queries.\"\n ),\n ),\n StrInput(\n name=\"max_retries\",\n display_name=\"Max Retries\",\n value=\"3\",\n advanced=True,\n info=\"Number of retries for failed connections before raising an error.\",\n ),\n StrInput(\n name=\"openrag_ingest_url\",\n display_name=\"OpenRAG Ingest URL\",\n value=\"OPENRAG_INGEST_URL\",\n load_from_db=True,\n input_types=[\"Text\", \"Message\"],\n advanced=True,\n info=\"Internal OpenRAG callback URL for backend-owned document indexing.\",\n ),\n SecretStrInput(\n name=\"openrag_ingest_token\",\n display_name=\"OpenRAG Ingest Token\",\n value=\"OPENRAG_INGEST_TOKEN\",\n load_from_db=True,\n input_types=[\"Text\", \"Message\"],\n advanced=True,\n info=\"Short-lived token used only for OpenRAG ingest callbacks.\",\n ),\n StrInput(\n name=\"openrag_ingest_run_id\",\n display_name=\"OpenRAG Ingest Run ID\",\n value=\"OPENRAG_INGEST_RUN_ID\",\n load_from_db=True,\n input_types=[\"Text\", \"Message\"],\n advanced=True,\n ),\n IntInput(\n name=\"openrag_ingest_batch_size\",\n display_name=\"OpenRAG Ingest Batch Size\",\n value=100,\n advanced=True,\n ),\n ]\n outputs = [\n Output(\n display_name=\"Search Results\",\n name=\"search_results\",\n method=\"search_documents\",\n ),\n Output(display_name=\"Raw Search\", name=\"raw_search\", method=\"raw_search\"),\n ]\n\n def raw_search(self, query: str | dict | None = None) -> Data:\n \"\"\"Execute a raw OpenSearch query against the target index.\n\n Args:\n query (dict[str, Any]): The OpenSearch query DSL dictionary.\n\n Returns:\n Data: Search results as a Data object.\n\n Raises:\n ValueError: If 'query' is not a valid OpenSearch query (must be a non-empty dict).\n \"\"\"\n raw_query = query if query is not None else self.search_query\n\n if raw_query is None or (isinstance(raw_query, str) and not raw_query.strip()):\n self.log(\"No query provided for raw search - returning empty results\")\n return Data(data={})\n\n if isinstance(raw_query, dict):\n query_body = copy.deepcopy(raw_query)\n elif isinstance(raw_query, str):\n s = raw_query.strip()\n\n # First, optimistically try to parse as JSON DSL\n try:\n query_body = json.loads(s)\n except json.JSONDecodeError:\n # Fallback: treat as a basic text query over common fields\n query_body = {\n \"query\": {\n \"multi_match\": {\n \"query\": s,\n \"fields\": [\"text^2\", \"filename^1.5\"],\n \"type\": \"best_fields\",\n \"fuzziness\": \"AUTO\",\n }\n }\n }\n else:\n msg = f\"Unsupported raw_search query type: {type(raw_query)!r}\"\n raise TypeError(msg)\n\n filter_obj = self._parse_filter_expression()\n filter_clauses = self._coerce_filter_clauses(filter_obj)\n\n if filter_clauses:\n if \"query\" in query_body:\n original_query = query_body[\"query\"]\n query_body[\"query\"] = {\n \"bool\": {\n \"must\": [original_query],\n \"filter\": filter_clauses,\n }\n }\n else:\n query_body[\"query\"] = {\n \"bool\": {\n \"must\": [{\"match_all\": {}}],\n \"filter\": filter_clauses,\n }\n }\n\n if filter_obj:\n # Apply limit if not already set in the raw query\n if \"size\" not in query_body:\n limit = self._resolve_limit(filter_obj, default_limit=None)\n if limit is not None:\n query_body[\"size\"] = limit\n\n # Apply score_threshold / scoreThreshold as min_score if not already set\n if \"min_score\" not in query_body:\n\n score_threshold = self._resolve_score_threshold(filter_obj)\n if score_threshold is not None:\n\n query_body[\"min_score\"] = score_threshold\n\n client = self.build_client()\n logger.info(f\"query: {query_body}\")\n resp = client.search(\n index=self.index_name,\n body=query_body,\n params={\"terminate_after\": 0},\n )\n # Remove any _source keys whose value is a list of floats (embedding vectors)\n # Minimum length threshold to identify embedding vectors\n min_vector_length = 100\n\n def is_vector(val):\n # Accepts if it's a list of numbers (float or int) and has reasonable vector length\n return (\n isinstance(val, list)\n and len(val) > min_vector_length\n and all(isinstance(x, (float, int)) for x in val)\n )\n\n if \"hits\" in resp and \"hits\" in resp[\"hits\"]:\n for hit in resp[\"hits\"][\"hits\"]:\n source = hit.get(\"_source\")\n if isinstance(source, dict):\n keys_to_remove = [k for k, v in source.items() if is_vector(v)]\n for k in keys_to_remove:\n source.pop(k)\n if \"text\" in source:\n source[\"text\"] = fence_untrusted_text(source[\"text\"])\n logger.info(f\"Raw search response (all embedding vectors removed): {resp}\")\n return Data(**resp)\n\n def _get_embedding_model_name(self, embedding_obj=None) -> str:\n \"\"\"Get the embedding model name from component config or embedding object.\n\n Priority: deployment > model > model_id > model_name\n This ensures we use the actual model being deployed, not just the configured model.\n Supports multiple embedding providers (OpenAI, Watsonx, Cohere, etc.)\n\n Args:\n embedding_obj: Specific embedding object to get name from (optional)\n\n Returns:\n Embedding model name\n\n Raises:\n ValueError: If embedding model name cannot be determined\n \"\"\"\n # First try explicit embedding_model_name input\n if hasattr(self, \"embedding_model_name\") and self.embedding_model_name:\n return self.embedding_model_name.strip()\n\n # Try to get from provided embedding object\n if embedding_obj:\n # Priority: deployment > model > model_id > model_name\n if hasattr(embedding_obj, \"deployment\") and embedding_obj.deployment:\n return str(embedding_obj.deployment)\n if hasattr(embedding_obj, \"model\") and embedding_obj.model:\n return str(embedding_obj.model)\n if hasattr(embedding_obj, \"model_id\") and embedding_obj.model_id:\n return str(embedding_obj.model_id)\n if hasattr(embedding_obj, \"model_name\") and embedding_obj.model_name:\n return str(embedding_obj.model_name)\n\n # Try to get from embedding component (legacy single embedding)\n if hasattr(self, \"embedding\") and self.embedding:\n # Handle list of embeddings\n if isinstance(self.embedding, list) and len(self.embedding) > 0:\n first_emb = self.embedding[0]\n if hasattr(first_emb, \"deployment\") and first_emb.deployment:\n return str(first_emb.deployment)\n if hasattr(first_emb, \"model\") and first_emb.model:\n return str(first_emb.model)\n if hasattr(first_emb, \"model_id\") and first_emb.model_id:\n return str(first_emb.model_id)\n if hasattr(first_emb, \"model_name\") and first_emb.model_name:\n return str(first_emb.model_name)\n # Handle single embedding\n elif not isinstance(self.embedding, list):\n if hasattr(self.embedding, \"deployment\") and self.embedding.deployment:\n return str(self.embedding.deployment)\n if hasattr(self.embedding, \"model\") and self.embedding.model:\n return str(self.embedding.model)\n if hasattr(self.embedding, \"model_id\") and self.embedding.model_id:\n return str(self.embedding.model_id)\n if hasattr(self.embedding, \"model_name\") and self.embedding.model_name:\n return str(self.embedding.model_name)\n\n msg = (\n \"Could not determine embedding model name. \"\n \"Please set the 'embedding_model_name' field or ensure the embedding component \"\n \"has a 'deployment', 'model', 'model_id', or 'model_name' attribute.\"\n )\n raise ValueError(msg)\n\n # ---------- helper functions for index management ----------\n def _default_text_mapping(\n self,\n dim: int,\n engine: str = \"jvector\",\n space_type: str = \"l2\",\n ef_search: int = 512,\n ef_construction: int = 100,\n m: int = 16,\n vector_field: str = \"vector_field\",\n ) -> dict[str, Any]:\n \"\"\"Create the default OpenSearch index mapping for vector search.\n\n This method generates the index configuration with k-NN settings optimized\n for approximate nearest neighbor search using the specified vector engine.\n Includes the embedding_model keyword field for tracking which model was used.\n\n Args:\n dim: Dimensionality of the vector embeddings\n engine: Vector search engine (jvector, nmslib, faiss, lucene)\n space_type: Distance metric for similarity calculation\n ef_search: Size of dynamic list used during search\n ef_construction: Size of dynamic list used during index construction\n m: Number of bidirectional links for each vector\n vector_field: Name of the field storing vector embeddings\n\n Returns:\n Dictionary containing OpenSearch index mapping configuration\n \"\"\"\n return {\n \"settings\": {\"index\": {\"knn\": True, \"knn.algo_param.ef_search\": ef_search}},\n \"mappings\": {\n \"properties\": {\n vector_field: {\n \"type\": \"knn_vector\",\n \"dimension\": dim,\n \"method\": {\n \"name\": \"disk_ann\",\n \"space_type\": space_type,\n \"engine\": engine,\n \"parameters\": {\"ef_construction\": ef_construction, \"m\": m},\n },\n },\n \"embedding_model\": {\"type\": \"keyword\"}, # Track which model was used\n \"embedding_dimensions\": {\"type\": \"integer\"},\n }\n },\n }\n\n def _ensure_embedding_field_mapping(\n self,\n client: OpenSearch,\n index_name: str,\n field_name: str,\n dim: int,\n engine: str,\n space_type: str,\n ef_construction: int,\n m: int,\n ) -> None:\n \"\"\"Lazily add a dynamic embedding field to the index if it doesn't exist.\n\n This allows adding new embedding models without recreating the entire index.\n Also ensures the embedding_model tracking field exists.\n\n Note: Some OpenSearch versions/configurations have issues with dynamically adding\n knn_vector mappings (NullPointerException). This method checks if the field\n already exists before attempting to add it, and gracefully skips if the field\n is already properly configured.\n\n Args:\n client: OpenSearch client instance\n index_name: Target index name\n field_name: Dynamic field name for this embedding model\n dim: Vector dimensionality\n engine: Vector search engine\n space_type: Distance metric\n ef_construction: Construction parameter\n m: HNSW parameter\n \"\"\"\n # First, check if the field already exists and is properly mapped\n properties = self._get_index_properties(client)\n if self._is_knn_vector_field(properties, field_name):\n # Field already exists as knn_vector - verify dimensions match\n existing_dim = self._get_field_dimension(properties, field_name)\n if existing_dim is not None and existing_dim != dim:\n logger.warning(\n f\"Field '{field_name}' exists with dimension {existing_dim}, \"\n f\"but current embedding has dimension {dim}. Using existing mapping.\"\n )\n else:\n logger.info(\n f\"[OpenSearchMultimodel] Field '{field_name}' already exists\"\n f\"as knn_vector with matching dimensions - skipping mapping update\"\n )\n return\n\n # Field doesn't exist, try to add the mapping\n try:\n mapping = {\n \"properties\": {\n field_name: {\n \"type\": \"knn_vector\",\n \"dimension\": dim,\n \"method\": {\n \"name\": \"disk_ann\",\n \"space_type\": space_type,\n \"engine\": engine,\n \"parameters\": {\"ef_construction\": ef_construction, \"m\": m},\n },\n },\n # Also ensure the embedding_model tracking field exists as keyword\n \"embedding_model\": {\"type\": \"keyword\"},\n \"embedding_dimensions\": {\"type\": \"integer\"},\n }\n }\n client.indices.put_mapping(index=index_name, body=mapping)\n logger.info(f\"Added/updated embedding field mapping: {field_name}\")\n except RequestError as e:\n error_str = str(e).lower()\n if \"invalid engine\" in error_str and \"jvector\" in error_str:\n msg = (\n \"The 'jvector' engine is not available in your OpenSearch installation. \"\n \"Use 'nmslib' or 'faiss' for standard OpenSearch, or upgrade to OpenSearch 2.9+.\"\n )\n raise ValueError(msg) from e\n if \"index.knn\" in error_str:\n msg = (\n \"The index has index.knn: false. Delete the existing index and let the \"\n \"component recreate it, or create a new index with a different name.\"\n )\n raise ValueError(msg) from e\n raise\n except Exception as e:\n # Check if this is the known OpenSearch k-NN NullPointerException issue\n error_str = str(e).lower()\n if \"null\" in error_str or \"nullpointerexception\" in error_str:\n logger.warning(\n f\"[OpenSearchMultimodel] Could not add embedding field mapping for {field_name}\"\n f\"due to OpenSearch k-NN plugin issue: {e}. \"\n f\"This is a known issue with some OpenSearch versions. \"\n f\"[OpenSearchMultimodel] Skipping mapping update. \"\n f\"Please ensure the index has the correct mapping for KNN search to work.\"\n )\n # Skip and continue - ingestion will proceed, but KNN search may fail if mapping doesn't exist\n return\n logger.warning(\n f\"[OpenSearchMultimodel] Could not add embedding field mapping for {field_name}: {e}\"\n )\n raise\n\n # Verify the field was added correctly\n properties = self._get_index_properties(client)\n if not self._is_knn_vector_field(properties, field_name):\n msg = f\"Field '{field_name}' is not mapped as knn_vector. Current mapping: {properties.get(field_name)}\"\n logger.error(msg)\n raise ValueError(msg)\n\n def _validate_aoss_with_engines(self, *, is_aoss: bool, engine: str) -> None:\n \"\"\"Validate engine compatibility with Amazon OpenSearch Serverless (AOSS).\n\n Amazon OpenSearch Serverless has restrictions on which vector engines\n can be used. This method ensures the selected engine is compatible.\n\n Args:\n is_aoss: Whether the connection is to Amazon OpenSearch Serverless\n engine: The selected vector search engine\n\n Raises:\n ValueError: If AOSS is used with an incompatible engine\n \"\"\"\n if is_aoss and engine not in {\"nmslib\", \"faiss\"}:\n msg = \"Amazon OpenSearch Service Serverless only supports `nmslib` or `faiss` engines\"\n raise ValueError(msg)\n\n def _is_aoss_enabled(self, http_auth: Any) -> bool:\n \"\"\"Determine if Amazon OpenSearch Serverless (AOSS) is being used.\n\n Args:\n http_auth: The HTTP authentication object\n\n Returns:\n True if AOSS is enabled, False otherwise\n \"\"\"\n return (\n http_auth is not None and hasattr(http_auth, \"service\") and http_auth.service == \"aoss\"\n )\n\n @staticmethod\n def _openrag_input_to_str(value: Any) -> str:\n if value is None:\n return \"\"\n if hasattr(value, \"get_secret_value\"):\n value = value.get_secret_value()\n if hasattr(value, \"text\"):\n value = value.text\n return str(value or \"\").strip()\n\n def _openrag_callback_value(self, attr_name: str) -> str:\n value = self._openrag_input_to_str(getattr(self, attr_name, \"\"))\n if value == self._openrag_ingest_global_placeholders.get(attr_name):\n return \"\"\n return value\n\n def _openrag_ingest_callback_config(self) -> tuple[str, str, str] | None:\n url = self._openrag_callback_value(\"openrag_ingest_url\")\n token = self._openrag_callback_value(\"openrag_ingest_token\")\n ingest_run_id = self._openrag_callback_value(\"openrag_ingest_run_id\")\n\n if not url and not token and not ingest_run_id:\n return None\n if not url or not token or not ingest_run_id:\n msg = \"OpenRAG ingest callback requires url, token, and ingest_run_id.\"\n raise ValueError(msg)\n\n logger.debug(\n \"[OpenRAG callback config] configured for ingest_run_id=%s (url_len=%d, token_len=%d)\",\n ingest_run_id,\n len(url),\n len(token),\n )\n return url, token, ingest_run_id\n\n def _post_openrag_ingest_batches(\n self,\n *,\n requests: list[dict],\n vector_field: str,\n text_field: str,\n ) -> None:\n callback_config = self._openrag_ingest_callback_config()\n if callback_config is None:\n return\n\n url, token, ingest_run_id = callback_config\n batch_size = max(self._parse_int_param(\"openrag_ingest_batch_size\", 100), 1)\n timeout = self._parse_int_param(\"request_timeout\", REQUEST_TIMEOUT)\n headers = {\"Authorization\": f\"Bearer {token}\"}\n\n logger.debug(\n f\"[OpenRAG ingest POST] total_chunks={len(requests)} batch_size={batch_size} timeout_s={timeout}\"\n )\n\n with httpx.Client(timeout=timeout) as client:\n total_batches = (len(requests) + batch_size - 1) // batch_size\n for batch_number, start in enumerate(range(0, len(requests), batch_size), start=1):\n batch = requests[start : start + batch_size]\n final = batch_number == total_batches\n payload = {\n \"ingest_run_id\": ingest_run_id,\n \"batch_id\": batch_number,\n \"final\": final,\n \"chunks\": [\n self._openrag_chunk_payload(\n request,\n vector_field=vector_field,\n text_field=text_field,\n )\n for request in batch\n ],\n }\n logger.debug(\n f\"[OpenRAG ingest POST] -> batch={batch_number}/{total_batches} \"\n f\"chunks={len(payload['chunks'])} final={final}\"\n )\n response = client.post(url, json=payload, headers=headers)\n logger.debug(f\"[OpenRAG ingest POST resp] batch={batch_number} status={response.status_code}\")\n if response.status_code >= 400:\n msg = (\n \"OpenRAG ingest callback failed \"\n f\"(batch={batch_number}, status={response.status_code})\"\n )\n logger.warning(msg)\n raise RuntimeError(msg)\n\n logger.debug(f\"Posted {len(requests)} chunks to OpenRAG backend ingest callback.\")\n\n @staticmethod\n def _openrag_chunk_payload(\n request: dict,\n *,\n vector_field: str,\n text_field: str,\n ) -> dict:\n metadata = {\n key: value\n for key, value in request.items()\n if key not in {\"_op_type\", \"_index\", \"_id\", \"id\", vector_field, text_field}\n }\n page = metadata.get(\"page\")\n if isinstance(page, str) and page.isdigit():\n page = int(page)\n return {\n \"id\": request.get(\"_id\") or request.get(\"id\"),\n \"text\": request.get(text_field, \"\"),\n \"vector\": request[vector_field],\n \"page\": page if isinstance(page, int) else None,\n \"metadata\": metadata,\n }\n\n def _bulk_ingest_embeddings(\n self,\n client: OpenSearch,\n index_name: str,\n embeddings: list[list[float]],\n texts: list[str],\n metadatas: list[dict] | None = None,\n ids: list[str] | None = None,\n vector_field: str = \"vector_field\",\n text_field: str = \"text\",\n embedding_model: str = \"unknown\",\n mapping: dict | None = None,\n max_chunk_bytes: int | None = 1 * 1024 * 1024,\n *,\n is_aoss: bool = False,\n ) -> list[str]:\n \"\"\"Efficiently ingest multiple documents with embeddings into OpenSearch.\n\n This method uses bulk operations to insert documents with their vector\n embeddings and metadata into the specified OpenSearch index. Each document\n is tagged with the embedding_model name for tracking.\n\n Args:\n client: OpenSearch client instance\n index_name: Target index for document storage\n embeddings: List of vector embeddings for each document\n texts: List of document texts\n metadatas: Optional metadata dictionaries for each document\n ids: Optional document IDs (UUIDs generated if not provided)\n vector_field: Field name for storing vector embeddings\n text_field: Field name for storing document text\n embedding_model: Name of the embedding model used\n mapping: Optional index mapping configuration\n max_chunk_bytes: Maximum size per bulk request chunk\n is_aoss: Whether using Amazon OpenSearch Serverless\n\n Returns:\n List of document IDs that were successfully ingested\n \"\"\"\n logger.debug(f\"[OpenSearchMultimodel] Bulk ingesting embeddings for {index_name}\")\n if not mapping:\n mapping = {}\n\n requests = []\n return_ids = []\n vector_dimensions = len(embeddings[0]) if embeddings else None\n\n for i, text in enumerate(texts):\n metadata = metadatas[i] if metadatas else {}\n if vector_dimensions is not None and \"embedding_dimensions\" not in metadata:\n metadata = {**metadata, \"embedding_dimensions\": vector_dimensions}\n\n # Normalize ACL fields that may arrive as JSON strings from flows\n for key in (\"allowed_users\", \"allowed_groups\", \"allowed_principals\"):\n value = metadata.get(key)\n if isinstance(value, str):\n try:\n parsed = json.loads(value)\n if isinstance(parsed, list):\n metadata[key] = parsed\n except (json.JSONDecodeError, TypeError):\n # Leave value as-is if it isn't valid JSON\n pass\n\n metadata_document_id = str(metadata.get(\"document_id\") or \"\").strip()\n if metadata_document_id and metadata_document_id.lower() != \"none\":\n generated_id = f\"{metadata_document_id}_{i}\"\n else:\n generated_id = str(uuid.uuid4())\n _id = ids[i] if ids else generated_id\n request = {\n \"_op_type\": \"index\",\n \"_index\": index_name,\n vector_field: embeddings[i],\n text_field: text,\n \"embedding_model\": embedding_model, # Track which model was used\n **metadata,\n }\n if is_aoss:\n request[\"id\"] = _id\n else:\n request[\"_id\"] = _id\n requests.append(request)\n return_ids.append(_id)\n if metadatas:\n self.log(f\"Sample metadata: {metadatas[0] if metadatas else {}}\")\n if self._openrag_ingest_callback_config() is not None:\n self._post_openrag_ingest_batches(\n requests=requests,\n vector_field=vector_field,\n text_field=text_field,\n )\n return return_ids\n try:\n helpers.bulk(client, requests, max_chunk_bytes=max_chunk_bytes)\n except Exception as bulk_error:\n if \"Unsupported request type for filter level DLS\" not in str(bulk_error):\n raise\n logger.warning(\n \"[OpenSearchMultimodel] Bulk ingest is blocked by filter-level DLS; \"\n \"falling back to per-document index requests.\"\n )\n self._index_embeddings_individually(client, requests)\n return return_ids\n\n def _index_embeddings_individually(\n self,\n client: OpenSearch,\n requests: list[dict],\n ) -> None:\n \"\"\"Index documents one at a time when OpenSearch DLS rejects bulk writes.\"\"\"\n for request in requests:\n document_id = request.get(\"_id\") or request.get(\"id\")\n body = {\n key: value\n for key, value in request.items()\n if key not in {\"_op_type\", \"_index\", \"_id\", \"id\"}\n }\n client.index(index=request[\"_index\"], id=document_id, body=body)\n\n def _log_index_admin_skip(self, operation: str, error: Exception) -> None:\n \"\"\"Log index-admin operations that may be blocked under filter-level DLS.\"\"\"\n logger.warning(\n f\"[OpenSearchMultimodel] Could not run index-admin operation '{operation}': {error}. \"\n \"Assuming the backend pre-created the required index/mapping and continuing.\"\n )\n\n # ---------- param helpers ----------\n def _parse_int_param(self, attr_name: str, default: int) -> int:\n \"\"\"Parse a string attribute to int, returning *default* on failure.\"\"\"\n raw = getattr(self, attr_name, None)\n if raw is None or str(raw).strip() == \"\":\n return default\n try:\n value = int(str(raw).strip())\n except ValueError:\n logger.warning(\n f\"Invalid integer value '{raw}' for {attr_name}, using default {default}\"\n )\n return default\n\n if value < 0:\n logger.warning(f\"Negative value '{raw}' for {attr_name}, using default {default}\")\n return default\n\n return value\n\n # ---------- auth / client ----------\n def _build_auth_kwargs(self) -> dict[str, Any]:\n \"\"\"Build authentication configuration for OpenSearch client.\n\n Constructs the appropriate authentication parameters based on the\n selected auth mode (basic username/password or JWT token).\n\n Returns:\n Dictionary containing authentication configuration\n\n Raises:\n ValueError: If required authentication parameters are missing\n \"\"\"\n mode = (self.auth_mode or \"basic\").strip().lower()\n if mode == \"jwt\":\n token = (self.jwt_token or \"\").strip()\n if not token:\n msg = \"Auth Mode is 'jwt' but no jwt_token was provided.\"\n raise ValueError(msg)\n header_name = (self.jwt_header or \"Authorization\").strip()\n header_value = f\"Bearer {token}\" if self.bearer_prefix else token\n return {\"headers\": {header_name: header_value}}\n if mode == \"openrag\":\n # Writes are delegated to the OpenRAG backend ingest callback,\n # so no direct OpenSearch credentials are needed. Only the\n # OPENRAG_* fields are required for ingestion to function.\n url = self._openrag_callback_value(\"openrag_ingest_url\")\n token = self._openrag_callback_value(\"openrag_ingest_token\")\n ingest_run_id = self._openrag_callback_value(\"openrag_ingest_run_id\")\n missing = [\n name\n for name, value in (\n (\"openrag_ingest_url\", url),\n (\"openrag_ingest_token\", token),\n (\"openrag_ingest_run_id\", ingest_run_id),\n )\n if not (value or \"\").strip()\n ]\n if missing:\n msg = (\n \"Auth Mode is 'openrag' but required OPENRAG_* fields are \"\n f\"missing: {', '.join(missing)}.\"\n )\n raise ValueError(msg)\n return {}\n user = (self.username or \"\").strip()\n pwd = (self._openrag_input_to_str(self.password) or \"\").strip()\n if pwd == \"OPENSEARCH_PASSWORD\" or not pwd:\n from config.settings import get_opensearch_password\n pwd = get_opensearch_password() or \"\"\n if not user or not pwd:\n msg = \"Auth Mode is 'basic' but username/password are missing.\"\n raise ValueError(msg)\n return {\"http_auth\": (user, pwd)}\n\n def build_client(self) -> OpenSearch:\n \"\"\"Create and configure an OpenSearch client instance.\n\n Returns:\n Configured OpenSearch client ready for operations\n \"\"\"\n logger.debug(\"[OpenSearchMultimodel] Building OpenSearch client\")\n auth_kwargs = self._build_auth_kwargs()\n return OpenSearch(\n hosts=[self.opensearch_url],\n use_ssl=self.use_ssl,\n verify_certs=self.verify_certs,\n ssl_assert_hostname=False,\n ssl_show_warn=False,\n timeout=self._parse_int_param(\"request_timeout\", REQUEST_TIMEOUT),\n max_retries=self._parse_int_param(\"max_retries\", MAX_RETRIES),\n retry_on_timeout=True,\n **auth_kwargs,\n )\n\n @check_cached_vector_store\n def build_vector_store(self) -> OpenSearch:\n # Return raw OpenSearch client as our \"vector store.\"\n client = self.build_client()\n\n # Check if we're in ingestion-only mode (no search query)\n has_search_query = bool((self.search_query or \"\").strip())\n if not has_search_query:\n logger.debug(\n \"[OpenSearchMultimodel] Ingestion-only mode activated: search operations will be skipped\"\n )\n logger.debug(\"[OpenSearchMultimodel] Starting ingestion mode...\")\n\n logger.debug(f\"[OpenSearchMultimodel] Embedding: {self.embedding}\")\n self._add_documents_to_vector_store(client=client)\n return client\n\n # ---------- ingest ----------\n def _add_documents_to_vector_store(self, client: OpenSearch) -> None:\n \"\"\"Process and ingest documents into the OpenSearch vector store.\n\n This method handles the complete document ingestion pipeline:\n - Prepares document data and metadata\n - Generates vector embeddings using the selected model\n - Creates appropriate index mappings with dynamic field names\n - Bulk inserts documents with vectors and model tracking\n\n Args:\n client: OpenSearch client for performing operations\n \"\"\"\n logger.debug(\"[OpenSearchMultimodel][INGESTION] _add_documents_to_vector_store called\")\n # Convert DataFrame to Data if needed using parent's method\n self.ingest_data = self._prepare_ingest_data()\n\n logger.debug(\n f\"[OpenSearchMultimodel][INGESTION] ingest_data type: \"\n f\"{type(self.ingest_data)}, length: {len(self.ingest_data) if self.ingest_data else 0}\"\n )\n logger.debug(\n f\"[OpenSearchMultimodel][INGESTION] ingest_data content: \"\n f\"{self.ingest_data[:2] if self.ingest_data and len(self.ingest_data) > 0 else 'empty'}\"\n )\n\n docs = self.ingest_data or []\n if not docs:\n logger.debug(\"Ingestion complete: No documents provided\")\n return\n\n if not self.embedding:\n msg = \"Embedding handle is required to embed documents.\"\n raise ValueError(msg)\n\n # Normalize embedding to list first\n embeddings_list = self.embedding if isinstance(self.embedding, list) else [self.embedding]\n\n # Filter out None values (fail-safe mode) - do this BEFORE checking if empty\n embeddings_list = [e for e in embeddings_list if e is not None]\n\n # NOW check if we have any valid embeddings left after filtering\n if not embeddings_list:\n logger.warning(\n \"All embeddings returned None (fail-safe mode enabled). Skipping document ingestion.\"\n )\n self.log(\n \"Embedding returned None (fail-safe mode enabled). Skipping document ingestion.\"\n )\n return\n\n logger.debug(\n f\"[OpenSearchMultimodel][INGESTION] Valid embeddings after filtering: {len(embeddings_list)}\"\n )\n self.log(\n f\"[OpenSearchMultimodel][INGESTION] Available embedding models: {len(embeddings_list)}\"\n )\n\n # Select the embedding to use for ingestion\n selected_embedding = None\n embedding_model = None\n\n # If embedding_model_name is specified, find matching embedding\n if (\n hasattr(self, \"embedding_model_name\")\n and self.embedding_model_name\n and self.embedding_model_name.strip()\n ):\n target_model_name = self.embedding_model_name.strip()\n self.log(f\"Looking for embedding model: {target_model_name}\")\n\n for emb_obj in embeddings_list:\n # Check all possible model identifiers (deployment, model, model_id, model_name)\n # Also check available_models list from EmbeddingsWithModels\n possible_names = []\n deployment = getattr(emb_obj, \"deployment\", None)\n model = getattr(emb_obj, \"model\", None)\n model_id = getattr(emb_obj, \"model_id\", None)\n model_name = getattr(emb_obj, \"model_name\", None)\n available_models_attr = getattr(emb_obj, \"available_models\", None)\n\n if deployment:\n possible_names.append(str(deployment))\n if model:\n possible_names.append(str(model))\n if model_id:\n possible_names.append(str(model_id))\n if model_name:\n possible_names.append(str(model_name))\n\n # Also add combined identifier\n if deployment and model and deployment != model:\n possible_names.append(f\"{deployment}:{model}\")\n\n # Add all models from available_models dict\n if available_models_attr and isinstance(available_models_attr, dict):\n possible_names.extend(\n str(model_key).strip()\n for model_key in available_models_attr\n if model_key and str(model_key).strip()\n )\n\n # Match if target matches any of the possible names\n if target_model_name in possible_names:\n # Check if target is in available_models dict - use dedicated instance\n if (\n available_models_attr\n and isinstance(available_models_attr, dict)\n and target_model_name in available_models_attr\n ):\n # Use the dedicated embedding instance from the dict\n selected_embedding = available_models_attr[target_model_name]\n embedding_model = target_model_name\n self.log(\n f\"Found dedicated embedding instance for '{embedding_model}' in available_models dict\"\n )\n else:\n # Traditional identifier match\n selected_embedding = emb_obj\n embedding_model = self._get_embedding_model_name(emb_obj)\n self.log(\n f\"Found matching embedding model: {embedding_model} (matched on: {target_model_name})\"\n )\n break\n\n if not selected_embedding:\n # Build detailed list of available embeddings with all their identifiers\n available_info = []\n for idx, emb in enumerate(embeddings_list):\n emb_type = type(emb).__name__\n identifiers = []\n deployment = getattr(emb, \"deployment\", None)\n model = getattr(emb, \"model\", None)\n model_id = getattr(emb, \"model_id\", None)\n model_name = getattr(emb, \"model_name\", None)\n available_models_attr = getattr(emb, \"available_models\", None)\n\n if deployment:\n identifiers.append(f\"deployment='{deployment}'\")\n if model:\n identifiers.append(f\"model='{model}'\")\n if model_id:\n identifiers.append(f\"model_id='{model_id}'\")\n if model_name:\n identifiers.append(f\"model_name='{model_name}'\")\n\n # Add combined identifier as an option\n if deployment and model and deployment != model:\n identifiers.append(f\"combined='{deployment}:{model}'\")\n\n # Add available_models dict if present\n if available_models_attr and isinstance(available_models_attr, dict):\n identifiers.append(f\"available_models={list(available_models_attr.keys())}\")\n\n available_info.append(\n f\" [{idx}] {emb_type}: {', '.join(identifiers) if identifiers else 'No identifiers'}\"\n )\n\n msg = (\n f\"Embedding model '{target_model_name}' not found in available embeddings.\\n\\n\"\n f\"Available embeddings:\\n\" + \"\\n\".join(available_info) + \"\\n\\n\"\n \"Please set 'embedding_model_name' to one of the identifier values shown above \"\n \"(use the value after the '=' sign, without quotes).\\n\"\n \"For duplicate deployments, use the 'combined' format.\\n\"\n \"Or leave it empty to use the first embedding.\"\n )\n raise ValueError(msg)\n else:\n # Use first embedding if no model name specified\n selected_embedding = embeddings_list[0]\n embedding_model = self._get_embedding_model_name(selected_embedding)\n self.log(f\"No embedding_model_name specified, using first embedding: {embedding_model}\")\n\n dynamic_field_name = get_embedding_field_name(embedding_model)\n\n logger.info(f\"Selected embedding model for ingestion: '{embedding_model}'\")\n self.log(f\"Using embedding model for ingestion: {embedding_model}\")\n self.log(f\"Dynamic vector field: {dynamic_field_name}\")\n\n # Log embedding details for debugging\n if hasattr(selected_embedding, \"deployment\"):\n logger.info(f\"Embedding deployment: {selected_embedding.deployment}\")\n if hasattr(selected_embedding, \"model\"):\n logger.info(f\"Embedding model: {selected_embedding.model}\")\n if hasattr(selected_embedding, \"model_id\"):\n logger.info(f\"Embedding model_id: {selected_embedding.model_id}\")\n if hasattr(selected_embedding, \"dimensions\"):\n logger.info(f\"Embedding dimensions: {selected_embedding.dimensions}\")\n if hasattr(selected_embedding, \"available_models\"):\n logger.info(f\"Embedding available_models: {selected_embedding.available_models}\")\n\n # No model switching needed - each model in available_models has its own dedicated instance\n # The selected_embedding is already configured correctly for the target model\n logger.info(\n f\"Using embedding instance for '{embedding_model}' - pre-configured and ready to use\"\n )\n\n # Extract texts and metadata from documents\n texts = []\n metadatas = []\n # Process docs_metadata table input into a dict\n additional_metadata = {}\n logger.debug(f\"[LF] Docs metadata {self.docs_metadata}\")\n if hasattr(self, \"docs_metadata\") and self.docs_metadata:\n logger.info(f\"[LF] Docs metadata {self.docs_metadata}\")\n if isinstance(self.docs_metadata[-1], Data):\n logger.info(f\"[LF] Docs metadata is a Data object {self.docs_metadata}\")\n self.docs_metadata = self.docs_metadata[-1].data\n logger.info(f\"[LF] Docs metadata is a Data object {self.docs_metadata}\")\n additional_metadata.update(self.docs_metadata)\n else:\n for item in self.docs_metadata:\n if isinstance(item, dict) and \"key\" in item and \"value\" in item:\n additional_metadata[item[\"key\"]] = item[\"value\"]\n # Replace string \"None\" values with actual None\n for key, value in additional_metadata.items():\n if value == \"None\":\n additional_metadata[key] = None\n logger.info(f\"[LF] Additional metadata {additional_metadata}\")\n for doc_obj in docs:\n data_copy = json.loads(doc_obj.model_dump_json())\n text = data_copy.pop(doc_obj.text_key, doc_obj.default_value)\n texts.append(text)\n\n # Merge additional metadata from table input\n data_copy.update(additional_metadata)\n\n metadatas.append(data_copy)\n self.log(metadatas)\n\n # Determine whether the selected embedding is watsonx/IBM. The watsonx\n # SDK ships its own rate-limit machinery (input batching, proactive\n # x-requests-limit-* TokenBucket throttling, and jittered exponential\n # backoff on 429), so we lean on it instead of retrying on top of it.\n # The type-name check also covers watsonx-hosted, non-\"ibm/\" models\n # (e.g. intfloat/multilingual-e5-large).\n is_ibm = (embedding_model and \"ibm\" in str(embedding_model).lower()) or (\n selected_embedding and \"watsonx\" in type(selected_embedding).__name__.lower()\n )\n logger.debug(f\"Is IBM/watsonx embedding: {is_ibm}\")\n\n if is_ibm:\n\n # Hand the full batch to the SDK and let it batch/throttle/retry.\n # Retry attempts and base backoff are tunable via the SDK's own\n # WATSONX_MAX_RETRIES / WATSONX_DELAY_TIME environment variables.\n logger.info(\n f\"Embedding {len(texts)} chunks via watsonx SDK batch (SDK-managed throttle + 429 retry)\"\n )\n try:\n vectors: list[list[float]] = selected_embedding.embed_documents(texts)\n logger.info(f\"Successfully embedded {len(vectors)} chunks via watsonx SDK\")\n except Exception as embed_error:\n _log_watsonx_rate_limit_headers(embed_error)\n logger.error(\n f\"Failed to embed {len(texts)} chunks via watsonx SDK. Error: {embed_error}\",\n )\n raise\n\n else:\n # Non-watsonx providers (OpenAI, Ollama) lack the watsonx SDK's\n # built-in rate-limit handling, so embed per chunk in parallel with\n # a generic rate-limit-aware tenacity retry.\n vectors: list[list[float]] = [None] * len(texts)\n from tenacity import (\n retry,\n retry_if_exception,\n stop_after_attempt,\n wait_exponential,\n )\n\n def is_rate_limit_error(exception: Exception) -> bool:\n \"\"\"Check if exception is a rate limit error (429).\"\"\"\n error_str = str(exception).lower()\n return \"429\" in error_str or \"rate_limit\" in error_str or \"rate limit\" in error_str\n\n def is_other_retryable_error(exception: Exception) -> bool:\n \"\"\"Check if exception is a transient network error worth retrying.\"\"\"\n if is_rate_limit_error(exception):\n return False\n return isinstance(exception, (ConnectionError, TimeoutError, OSError))\n\n # Retry decorator for rate limit errors (longer backoff)\n retry_on_rate_limit = retry(\n retry=retry_if_exception(is_rate_limit_error),\n stop=stop_after_attempt(5),\n wait=wait_exponential(multiplier=2, min=2, max=30),\n reraise=True,\n before_sleep=lambda retry_state: logger.warning(\n f\"Rate limit hit for chunk (attempt {retry_state.attempt_number}/5), \"\n f\"backing off for {retry_state.next_action.sleep:.1f}s\"\n ),\n )\n\n # Retry decorator for other errors (shorter backoff)\n retry_on_other_errors = retry(\n retry=retry_if_exception(is_other_retryable_error),\n stop=stop_after_attempt(3),\n wait=wait_exponential(multiplier=1, min=1, max=8),\n reraise=True,\n before_sleep=lambda retry_state: logger.warning(\n f\"Error embedding chunk (attempt {retry_state.attempt_number}/3), \"\n f\"retrying in {retry_state.next_action.sleep:.1f}s: {retry_state.outcome.exception()}\"\n ),\n )\n\n def embed_chunk_with_retry(chunk_text: str, chunk_idx: int) -> list[float]:\n \"\"\"Embed a single chunk with rate-limit-aware retry logic.\"\"\"\n\n @retry_on_rate_limit\n @retry_on_other_errors\n def _embed(text: str) -> list[float]:\n return selected_embedding.embed_documents([text])[0]\n\n try:\n return _embed(chunk_text)\n except Exception as e:\n logger.error(\n f\"Failed to embed chunk {chunk_idx} after all retries: {e}\",\n error=str(e),\n )\n raise\n\n max_workers = min(max(len(texts), 1), 8)\n logger.debug(f\"Using parallel processing with {max_workers} workers\")\n\n with ThreadPoolExecutor(max_workers=max_workers) as executor:\n futures = {\n executor.submit(embed_chunk_with_retry, chunk, idx): idx\n for idx, chunk in enumerate(texts)\n }\n for future in as_completed(futures):\n idx = futures[future]\n vectors[idx] = future.result()\n\n if not vectors:\n self.log(f\"No vectors generated from documents for model {embedding_model}.\")\n return\n\n # Get vector dimension for mapping\n dim = len(vectors[0]) if vectors else 768 # default fallback\n use_openrag_ingest_callback = self._openrag_ingest_callback_config() is not None\n\n is_aoss = False\n mapping: dict | None = None\n\n engine = getattr(self, \"engine\", \"jvector\")\n\n if use_openrag_ingest_callback:\n self.log(\"Using OpenRAG backend ingest callback; skipping direct OpenSearch writes.\")\n else:\n # Check for AOSS\n auth_kwargs = self._build_auth_kwargs()\n is_aoss = self._is_aoss_enabled(auth_kwargs.get(\"http_auth\"))\n\n # Validate engine with AOSS\n self._validate_aoss_with_engines(is_aoss=is_aoss, engine=engine)\n\n # Create mapping with proper KNN settings\n space_type = getattr(self, \"space_type\", \"l2\")\n ef_construction = getattr(self, \"ef_construction\", 512)\n m = getattr(self, \"m\", 16)\n\n mapping = self._default_text_mapping(\n dim=dim,\n engine=engine,\n space_type=space_type,\n ef_construction=ef_construction,\n m=m,\n vector_field=dynamic_field_name, # Use dynamic field name\n )\n\n # Ensure index exists with baseline mapping (index.knn: true is required for vector search)\n index_exists = True\n try:\n index_exists = bool(client.indices.exists(index=self.index_name))\n except OpenSearchException as exists_error:\n self._log_index_admin_skip(\"indices.exists\", exists_error)\n\n try:\n if not index_exists:\n self.log(f\"Creating index '{self.index_name}' with base mapping\")\n client.indices.create(index=self.index_name, body=mapping)\n except RequestError as creation_error:\n if creation_error.error == \"resource_already_exists_exception\":\n pass # Index was created concurrently\n else:\n error_msg = str(creation_error).lower()\n if \"invalid engine\" in error_msg or \"illegal_argument\" in error_msg:\n if \"jvector\" in error_msg:\n msg = (\n \"The 'jvector' engine is not available in your OpenSearch installation. \"\n \"Use 'nmslib' or 'faiss' for standard OpenSearch, or upgrade to 2.9+.\"\n )\n raise ValueError(msg) from creation_error\n if \"index.knn\" in error_msg:\n msg = (\n \"The index has index.knn: false. Delete the existing index and let the \"\n \"component recreate it, or create a new index with a different name.\"\n )\n raise ValueError(msg) from creation_error\n logger.warning(f\"Failed to create index '{self.index_name}': {creation_error}\")\n raise\n\n # Ensure the dynamic field exists in the index\n self._ensure_embedding_field_mapping(\n client=client,\n index_name=self.index_name,\n field_name=dynamic_field_name,\n dim=dim,\n engine=engine,\n space_type=space_type,\n ef_construction=ef_construction,\n m=m,\n )\n\n self.log(\n f\"Indexing {len(texts)} documents into '{self.index_name}' with model '{embedding_model}'...\"\n )\n logger.info(f\"Will store embeddings in field: {dynamic_field_name}\")\n logger.info(f\"Will tag documents with embedding_model: {embedding_model}\")\n\n # Use the bulk ingestion with model tracking\n return_ids = self._bulk_ingest_embeddings(\n client=client,\n index_name=self.index_name,\n embeddings=vectors,\n texts=texts,\n metadatas=metadatas,\n vector_field=dynamic_field_name, # Use dynamic field name\n text_field=\"text\",\n embedding_model=embedding_model, # Track the model\n mapping=mapping,\n is_aoss=is_aoss,\n )\n self.log(metadatas)\n\n logger.info(\n f\"Ingestion complete: Successfully indexed {len(return_ids)} documents with model '{embedding_model}'\"\n )\n self.log(f\"Successfully indexed {len(return_ids)} documents with model {embedding_model}.\")\n\n # ---------- helpers for filters ----------\n def _is_placeholder_term(self, term_obj: dict) -> bool:\n # term_obj like {\"filename\": \"__IMPOSSIBLE_VALUE__\"}\n return any(v == \"__IMPOSSIBLE_VALUE__\" for v in term_obj.values())\n\n def _coerce_filter_clauses(self, filter_obj: dict | None) -> list[dict]:\n \"\"\"Convert filter expressions into OpenSearch-compatible filter clauses.\n\n This method accepts two filter formats and converts them to standardized\n OpenSearch query clauses:\n\n Format A - Explicit filters:\n {\"filter\": [{\"term\": {\"field\": \"value\"}}, {\"terms\": {\"field\": [\"val1\", \"val2\"]}}],\n \"limit\": 10, \"score_threshold\": 1.5}\n\n Format B - Context-style mapping:\n {\"data_sources\": [\"file1.pdf\"], \"document_types\": [\"pdf\"], \"owners\": [\"user1\"]}\n\n Args:\n filter_obj: Filter configuration dictionary or None\n\n Returns:\n List of OpenSearch filter clauses (term/terms objects)\n Placeholder values with \"__IMPOSSIBLE_VALUE__\" are ignored\n \"\"\"\n if not filter_obj:\n return []\n\n # If it is a string, try to parse it once\n if isinstance(filter_obj, str):\n try:\n filter_obj = json.loads(filter_obj)\n except json.JSONDecodeError:\n # Not valid JSON - treat as no filters\n return []\n\n # Case A: already an explicit list/dict under \"filter\"\n if \"filter\" in filter_obj:\n raw = filter_obj[\"filter\"]\n if isinstance(raw, dict):\n raw = [raw]\n explicit_clauses: list[dict] = []\n for f in raw or []:\n if (\n \"term\" in f\n and isinstance(f[\"term\"], dict)\n and not self._is_placeholder_term(f[\"term\"])\n ):\n explicit_clauses.append(f)\n elif \"terms\" in f and isinstance(f[\"terms\"], dict):\n field, vals = next(iter(f[\"terms\"].items()))\n if isinstance(vals, list) and len(vals) > 0:\n explicit_clauses.append(f)\n return explicit_clauses\n\n # Case B: convert context-style maps into clauses\n field_mapping = {\n \"data_sources\": \"filename\",\n \"document_types\": \"mimetype\",\n \"owners\": \"owner\",\n }\n context_clauses: list[dict] = []\n for k, values in filter_obj.items():\n if not isinstance(values, list):\n continue\n field = field_mapping.get(k, k)\n if len(values) == 0:\n # Match-nothing placeholder (kept to mirror your tool semantics)\n context_clauses.append({\"term\": {field: \"__IMPOSSIBLE_VALUE__\"}})\n elif len(values) == 1:\n if values[0] != \"__IMPOSSIBLE_VALUE__\":\n context_clauses.append({\"term\": {field: values[0]}})\n else:\n context_clauses.append({\"terms\": {field: values}})\n return context_clauses\n\n\n def _parse_filter_expression(self) -> dict | None:\n \"\"\"Parse and validate optional filter_expression JSON.\n\n Returns:\n Parsed JSON object as a dict, or None when unset/blank.\n\n Raises:\n ValueError: If JSON is invalid or does not decode to an object.\n \"\"\"\n filter_expression = getattr(self, \"filter_expression\", \"\")\n if not isinstance(filter_expression, str) or not filter_expression.strip():\n return None\n try:\n filter_obj = json.loads(filter_expression)\n except json.JSONDecodeError as e:\n msg = f\"Invalid filter_expression JSON: {e}\"\n raise ValueError(msg) from e\n\n if not isinstance(filter_obj, dict):\n msg = \"Invalid filter_expression JSON type: expected a JSON object.\"\n raise TypeError(msg)\n return filter_obj\n\n def _resolve_limit(self, filter_obj: dict | None, default_limit: int | None) -> int | None:\n \"\"\"Resolve an integer result limit from filter settings.\"\"\"\n if not filter_obj:\n return default_limit\n raw_limit = filter_obj.get(\"limit\", default_limit)\n if raw_limit is None:\n return None\n if isinstance(raw_limit, bool):\n msg = \"Invalid filter_expression.limit: expected a positive integer.\"\n raise TypeError(msg)\n try:\n limit = int(raw_limit)\n except (TypeError, ValueError) as e:\n msg = \"Invalid filter_expression.limit: expected a positive integer.\"\n raise ValueError(msg) from e\n if limit <= 0:\n msg = \"Invalid filter_expression.limit: expected a positive integer.\"\n raise ValueError(msg)\n return limit\n\n def _resolve_score_threshold(self, filter_obj: dict | None) -> float | None:\n \"\"\"Resolve optional positive min score from filter settings.\"\"\"\n if not filter_obj:\n return None\n score_threshold = filter_obj.get(\"score_threshold\")\n if score_threshold is None:\n score_threshold = filter_obj.get(\"scoreThreshold\")\n if not isinstance(score_threshold, (int, float)) or score_threshold <= 0:\n return None\n return float(score_threshold)\n\n def _detect_available_models(self, client: OpenSearch, filter_clauses: list[dict] | None = None) -> list[str]:\n\n \"\"\"Detect which embedding models have documents in the index.\n\n Uses aggregation to find all unique embedding_model values, optionally\n filtered to only documents matching the user's filter criteria.\n\n Args:\n client: OpenSearch client instance\n filter_clauses: Optional filter clauses to scope model detection\n\n Returns:\n List of embedding model names found in the index\n \"\"\"\n try:\n agg_query = {\n \"size\": 0,\n \"aggs\": {\"embedding_models\": {\"terms\": {\"field\": \"embedding_model\", \"size\": 10}}},\n }\n\n # Apply filters to model detection if any exist\n if filter_clauses:\n agg_query[\"query\"] = {\"bool\": {\"filter\": filter_clauses}}\n\n logger.debug(f\"Model detection query: {agg_query}\")\n result = client.search(\n index=self.index_name,\n body=agg_query,\n params={\"terminate_after\": 0},\n )\n buckets = result.get(\"aggregations\", {}).get(\"embedding_models\", {}).get(\"buckets\", [])\n models = [b[\"key\"] for b in buckets if b[\"key\"]]\n\n # Log detailed bucket info for debugging\n logger.info(\n f\"Detected embedding models in corpus: {models}\"\n + (f\" (with {len(filter_clauses)} filters)\" if filter_clauses else \"\")\n )\n if not models:\n total_hits = result.get(\"hits\", {}).get(\"total\", {})\n total_count = (\n total_hits.get(\"value\", 0) if isinstance(total_hits, dict) else total_hits\n )\n logger.warning(\n f\"No embedding_model values found in index '{self.index_name}'. \"\n f\"Total docs in index: {total_count}. \"\n f\"This may indicate documents were indexed without the embedding_model field.\"\n )\n except (OpenSearchException, KeyError, ValueError) as e:\n logger.warning(f\"Failed to detect embedding models: {e}\")\n # Fallback to current model\n fallback_model = self._get_embedding_model_name()\n logger.info(f\"Using fallback model: {fallback_model}\")\n return [fallback_model]\n else:\n return models\n\n def _get_index_properties(self, client: OpenSearch) -> dict[str, Any] | None:\n \"\"\"Retrieve flattened mapping properties for the current index.\"\"\"\n try:\n mapping = client.indices.get_mapping(index=self.index_name)\n except OpenSearchException as e:\n logger.warning(\n f\"Failed to fetch mapping for index '{self.index_name}': {e}. Proceeding without mapping metadata.\"\n )\n return None\n\n properties: dict[str, Any] = {}\n for index_data in mapping.values():\n props = index_data.get(\"mappings\", {}).get(\"properties\", {})\n if isinstance(props, dict):\n properties.update(props)\n return properties\n\n def _is_knn_vector_field(self, properties: dict[str, Any] | None, field_name: str) -> bool:\n \"\"\"Check whether the field is mapped as a knn_vector.\"\"\"\n if not field_name:\n return False\n if properties is None:\n logger.warning(\n f\"Mapping metadata unavailable; assuming field '{field_name}' is usable.\"\n )\n return True\n field_def = properties.get(field_name)\n if not isinstance(field_def, dict):\n return False\n if field_def.get(\"type\") == \"knn_vector\":\n return True\n\n nested_props = field_def.get(\"properties\")\n return bool(isinstance(nested_props, dict) and nested_props.get(\"type\") == \"knn_vector\")\n\n def _get_field_dimension(\n self, properties: dict[str, Any] | None, field_name: str\n ) -> int | None:\n \"\"\"Get the dimension of a knn_vector field from the index mapping.\n\n Args:\n properties: Index properties from mapping\n field_name: Name of the vector field\n\n Returns:\n Dimension of the field, or None if not found\n \"\"\"\n if not field_name or properties is None:\n return None\n\n field_def = properties.get(field_name)\n if not isinstance(field_def, dict):\n return None\n\n # Check direct knn_vector field\n if field_def.get(\"type\") == \"knn_vector\":\n return field_def.get(\"dimension\")\n\n # Check nested properties\n nested_props = field_def.get(\"properties\")\n if isinstance(nested_props, dict) and nested_props.get(\"type\") == \"knn_vector\":\n return nested_props.get(\"dimension\")\n\n return None\n\n def _get_filename_agg_field(self, index_properties: dict[str, Any] | None) -> str:\n \"\"\"Choose the appropriate field for filename aggregations.\"\"\"\n if not index_properties:\n return \"filename.keyword\"\n\n filename_def = index_properties.get(\"filename\")\n if not isinstance(filename_def, dict):\n return \"filename.keyword\"\n\n field_type = filename_def.get(\"type\")\n fields_def = filename_def.get(\"fields\", {})\n\n # Top-level keyword with no subfields\n if field_type == \"keyword\" and not isinstance(fields_def, dict):\n return \"filename\"\n\n # Text field with keyword subfield\n if isinstance(fields_def, dict) and \"keyword\" in fields_def:\n return \"filename.keyword\"\n\n # Fallback: aggregate on filename directly\n return \"filename\"\n\n # ---------- search (multi-model hybrid) ----------\n def search(self, query: str | None = None) -> list[dict[str, Any]]:\n \"\"\"Perform multi-model hybrid search combining multiple vector similarities and keyword matching.\n\n This method executes a sophisticated search that:\n 1. Auto-detects all embedding models present in the index\n 2. Generates query embeddings for ALL detected models in parallel\n 3. Combines multiple KNN queries using dis_max (picks best match)\n 4. Adds keyword search with fuzzy matching (30% weight)\n 5. Applies optional filtering and score thresholds\n 6. Returns aggregations for faceted search\n\n Search weights:\n - Semantic search (dis_max across all models): 70%\n - Keyword search: 30%\n\n Args:\n query: Search query string (used for both vector embedding and keyword search)\n\n Returns:\n List of search results with page_content, metadata, and relevance scores\n\n Raises:\n ValueError: If embedding component is not provided or filter JSON is invalid\n \"\"\"\n logger.info(self.ingest_data)\n client = self.build_client()\n q = (query or \"\").strip()\n\n # Parse optional filter expression\n filter_obj = self._parse_filter_expression()\n\n if not self.embedding:\n msg = \"Embedding is required to run hybrid search (KNN + keyword).\"\n raise ValueError(msg)\n\n # Check if embedding is None (fail-safe mode)\n if self.embedding is None or (\n isinstance(self.embedding, list) and all(e is None for e in self.embedding)\n ):\n logger.error(\"Embedding returned None (fail-safe mode enabled). Cannot perform search.\")\n return []\n\n # Build filter clauses first so we can use them in model detection\n filter_clauses = self._coerce_filter_clauses(filter_obj)\n\n # Detect available embedding models in the index (scoped by filters)\n available_models = self._detect_available_models(client, filter_clauses)\n\n if not available_models:\n logger.warning(\"No embedding models found in index, using current model\")\n available_models = [self._get_embedding_model_name()]\n\n # Generate embeddings for ALL detected models\n query_embeddings = {}\n\n # Normalize embedding to list\n embeddings_list = self.embedding if isinstance(self.embedding, list) else [self.embedding]\n # Filter out None values (fail-safe mode)\n embeddings_list = [e for e in embeddings_list if e is not None]\n\n if not embeddings_list:\n logger.error(\n \"No valid embeddings available after filtering None values (fail-safe mode). Cannot perform search.\"\n )\n return []\n\n # Create a comprehensive map of model names to embedding objects\n # Check all possible identifiers (deployment, model, model_id, model_name)\n # Also leverage available_models list from EmbeddingsWithModels\n # Handle duplicate identifiers by creating combined keys\n embedding_by_model = {}\n identifier_conflicts = {} # Track which identifiers have conflicts\n\n for idx, emb_obj in enumerate(embeddings_list):\n # Get all possible identifiers for this embedding\n identifiers = []\n deployment = getattr(emb_obj, \"deployment\", None)\n model = getattr(emb_obj, \"model\", None)\n model_id = getattr(emb_obj, \"model_id\", None)\n model_name = getattr(emb_obj, \"model_name\", None)\n dimensions = getattr(emb_obj, \"dimensions\", None)\n available_models_attr = getattr(emb_obj, \"available_models\", None)\n\n logger.info(\n f\"Embedding object {idx}: deployment={deployment}, model={model}, \"\n f\"model_id={model_id}, model_name={model_name}, dimensions={dimensions}, \"\n f\"available_models={available_models_attr}\"\n )\n\n # If this embedding has available_models dict, map all models to their dedicated instances\n if available_models_attr and isinstance(available_models_attr, dict):\n logger.info(\n f\"Embedding object {idx} provides {len(available_models_attr)} models via available_models dict\"\n )\n for model_name_key, dedicated_embedding in available_models_attr.items():\n if model_name_key and str(model_name_key).strip():\n model_str = str(model_name_key).strip()\n if model_str not in embedding_by_model:\n # Use the dedicated embedding instance from the dict\n embedding_by_model[model_str] = dedicated_embedding\n logger.info(\n f\"Mapped available model '{model_str}' to dedicated embedding instance\"\n )\n else:\n # Conflict detected - track it\n if model_str not in identifier_conflicts:\n identifier_conflicts[model_str] = [embedding_by_model[model_str]]\n identifier_conflicts[model_str].append(dedicated_embedding)\n logger.warning(\n f\"Available model '{model_str}' has conflict - used by multiple embeddings\"\n )\n\n # Also map traditional identifiers (for backward compatibility)\n if deployment:\n identifiers.append(str(deployment))\n if model:\n identifiers.append(str(model))\n if model_id:\n identifiers.append(str(model_id))\n if model_name:\n identifiers.append(str(model_name))\n\n # Map all identifiers to this embedding object\n for identifier in identifiers:\n if identifier not in embedding_by_model:\n embedding_by_model[identifier] = emb_obj\n logger.info(f\"Mapped identifier '{identifier}' to embedding object {idx}\")\n else:\n # Conflict detected - track it\n if identifier not in identifier_conflicts:\n identifier_conflicts[identifier] = [embedding_by_model[identifier]]\n identifier_conflicts[identifier].append(emb_obj)\n logger.warning(\n f\"Identifier '{identifier}' has conflict - used by multiple embeddings\"\n )\n\n # For embeddings with model+deployment, create combined identifier\n # This helps when deployment is the same but model differs\n if deployment and model and deployment != model:\n combined_id = f\"{deployment}:{model}\"\n if combined_id not in embedding_by_model:\n embedding_by_model[combined_id] = emb_obj\n logger.info(\n f\"Created combined identifier '{combined_id}' for embedding object {idx}\"\n )\n\n # Log conflicts\n if identifier_conflicts:\n logger.warning(\n f\"Found {len(identifier_conflicts)} conflicting identifiers. \"\n f\"Consider using combined format 'deployment:model' or specifying unique model names.\"\n )\n for conflict_id, emb_list in identifier_conflicts.items():\n logger.warning(\n f\" Conflict on '{conflict_id}': {len(emb_list)} embeddings use this identifier\"\n )\n\n logger.info(f\"Generating embeddings for {len(available_models)} models in index\")\n logger.info(f\"Available embedding identifiers: {list(embedding_by_model.keys())}\")\n self.log(f\"[SEARCH] Models detected in index: {available_models}\")\n self.log(f\"[SEARCH] Available embedding identifiers: {list(embedding_by_model.keys())}\")\n\n # Track matching status for debugging\n matched_models = []\n unmatched_models = []\n\n for model_name in available_models:\n try:\n # Check if we have an embedding object for this model\n if model_name in embedding_by_model:\n # Use the matching embedding object directly\n emb_obj = embedding_by_model[model_name]\n emb_deployment = getattr(emb_obj, \"deployment\", None)\n emb_model = getattr(emb_obj, \"model\", None)\n emb_model_id = getattr(emb_obj, \"model_id\", None)\n emb_dimensions = getattr(emb_obj, \"dimensions\", None)\n emb_available_models = getattr(emb_obj, \"available_models\", None)\n\n logger.info(\n f\"Using embedding object for model '{model_name}': \"\n f\"deployment={emb_deployment}, model={emb_model}, model_id={emb_model_id}, \"\n f\"dimensions={emb_dimensions}\"\n )\n\n # Check if this is a dedicated instance from available_models dict\n if emb_available_models and isinstance(emb_available_models, dict):\n logger.info(\n f\"Model '{model_name}' using dedicated instance from available_models dict \"\n f\"(pre-configured with correct model and dimensions)\"\n )\n\n # Use the embedding instance directly - no model switching needed!\n vec = emb_obj.embed_query(q)\n query_embeddings[model_name] = vec\n matched_models.append(model_name)\n logger.info(\n f\"Generated embedding for model: {model_name} (actual dimensions: {len(vec)})\"\n )\n self.log(f\"[MATCH] Model '{model_name}' - generated {len(vec)}-dim embedding\")\n else:\n # No matching embedding found for this model\n unmatched_models.append(model_name)\n logger.warning(\n f\"No matching embedding found for model '{model_name}'. \"\n f\"This model will be skipped. Available identifiers: {list(embedding_by_model.keys())}\"\n )\n self.log(\n f\"[NO MATCH] Model '{model_name}' - available: {list(embedding_by_model.keys())}\"\n )\n except (\n RuntimeError,\n ValueError,\n ConnectionError,\n TimeoutError,\n AttributeError,\n KeyError,\n ) as e:\n logger.warning(f\"Failed to generate embedding for {model_name}: {e}\")\n self.log(f\"[ERROR] Embedding generation failed for '{model_name}': {e}\")\n\n # Log summary of model matching\n logger.info(\n f\"Model matching summary: {len(matched_models)} matched, {len(unmatched_models)} unmatched\"\n )\n self.log(\n f\"[SUMMARY] Model matching: {len(matched_models)} matched, {len(unmatched_models)} unmatched\"\n )\n if unmatched_models:\n self.log(f\"[WARN] Unmatched models in index: {unmatched_models}\")\n\n if not query_embeddings:\n msg = (\n f\"Failed to generate embeddings for any model. \"\n f\"Index has models: {available_models}, but no matching embedding objects found. \"\n f\"Available embedding identifiers: {list(embedding_by_model.keys())}\"\n )\n self.log(f\"[FAIL] Search failed: {msg}\")\n raise ValueError(msg)\n\n index_properties = self._get_index_properties(client)\n legacy_vector_field = getattr(self, \"vector_field\", \"chunk_embedding\")\n\n # Build KNN queries for each model\n embedding_fields: list[str] = []\n knn_queries_with_candidates = []\n knn_queries_without_candidates = []\n\n raw_num_candidates = getattr(self, \"num_candidates\", 1000)\n try:\n num_candidates = int(raw_num_candidates) if raw_num_candidates is not None else 0\n except (TypeError, ValueError):\n num_candidates = 0\n use_num_candidates = num_candidates > 0\n\n for model_name, embedding_vector in query_embeddings.items():\n field_name = get_embedding_field_name(model_name)\n selected_field = field_name\n vector_dim = len(embedding_vector)\n\n # Only use the expected dynamic field - no legacy fallback\n # This prevents dimension mismatches between models\n if not self._is_knn_vector_field(index_properties, selected_field):\n logger.warning(\n f\"Skipping model {model_name}: field '{field_name}' is not mapped as knn_vector. \"\n f\"Documents must be indexed with this embedding model before querying.\"\n )\n self.log(\n f\"[SKIP] Field '{selected_field}' not a knn_vector - skipping model '{model_name}'\"\n )\n continue\n\n # Validate vector dimensions match the field dimensions\n field_dim = self._get_field_dimension(index_properties, selected_field)\n if field_dim is not None and field_dim != vector_dim:\n logger.error(\n f\"Dimension mismatch for model '{model_name}': \"\n f\"Query vector has {vector_dim} dimensions but field '{selected_field}' expects {field_dim}. \"\n f\"Skipping this model to prevent search errors.\"\n )\n self.log(\n f\"[DIM MISMATCH] Model '{model_name}': query={vector_dim} vs field={field_dim} - skipping\"\n )\n continue\n\n logger.info(\n f\"Adding KNN query for model '{model_name}': field='{selected_field}', \"\n f\"query_dims={vector_dim}, field_dims={field_dim or 'unknown'}\"\n )\n embedding_fields.append(selected_field)\n\n base_query = {\n \"knn\": {\n selected_field: {\n \"vector\": embedding_vector,\n \"k\": 50,\n }\n }\n }\n\n if use_num_candidates:\n query_with_candidates = copy.deepcopy(base_query)\n query_with_candidates[\"knn\"][selected_field][\"num_candidates\"] = num_candidates\n else:\n query_with_candidates = base_query\n\n knn_queries_with_candidates.append(query_with_candidates)\n knn_queries_without_candidates.append(base_query)\n\n if not knn_queries_with_candidates:\n # No valid fields found - this can happen when:\n # 1. Index is empty (no documents yet)\n # 2. Embedding model has changed and field doesn't exist yet\n # Return empty results instead of failing\n logger.warning(\n \"No valid knn_vector fields found for embedding models. \"\n \"This may indicate an empty index or missing field mappings. \"\n \"Returning empty search results.\"\n )\n self.log(\n f\"[WARN] No valid KNN queries could be built. \"\n f\"Query embeddings generated: {list(query_embeddings.keys())}, \"\n f\"but no matching knn_vector fields found in index.\"\n )\n return []\n\n # Build exists filter - document must have at least one embedding field\n exists_any_embedding = {\n \"bool\": {\n \"should\": [{\"exists\": {\"field\": f}} for f in set(embedding_fields)],\n \"minimum_should_match\": 1,\n }\n }\n\n # Combine user filters with exists filter\n all_filters = [*filter_clauses, exists_any_embedding]\n\n # Get limit and score threshold\n limit = self._resolve_limit(filter_obj, default_limit=self.number_of_results)\n score_threshold = self._resolve_score_threshold(filter_obj)\n\n # Determine the best aggregation field for filename based on index mapping\n filename_agg_field = self._get_filename_agg_field(index_properties)\n\n # Build multi-model hybrid query\n body = {\n \"query\": {\n \"bool\": {\n \"should\": [\n {\n \"dis_max\": {\n \"tie_breaker\": 0.0, # Take only the best match, no blending\n \"boost\": 0.7, # 70% weight for semantic search\n \"queries\": knn_queries_with_candidates,\n }\n },\n {\n \"multi_match\": {\n \"query\": q,\n \"fields\": [\"text^2\", \"filename^1.5\"],\n \"type\": \"best_fields\",\n \"fuzziness\": \"AUTO\",\n \"boost\": 0.3, # 30% weight for keyword search\n }\n },\n ],\n \"minimum_should_match\": 1,\n \"filter\": all_filters,\n }\n },\n \"aggs\": {\n \"data_sources\": {\"terms\": {\"field\": filename_agg_field, \"size\": 20}},\n \"document_types\": {\"terms\": {\"field\": \"mimetype\", \"size\": 10}},\n \"owners\": {\"terms\": {\"field\": \"owner\", \"size\": 10}},\n \"embedding_models\": {\"terms\": {\"field\": \"embedding_model\", \"size\": 10}},\n },\n \"_source\": [\n \"filename\",\n \"mimetype\",\n \"page\",\n \"text\",\n \"source_url\",\n \"owner\",\n \"embedding_model\",\n \"parser\",\n \"chunk_size\",\n \"chunk_overlap\",\n \"allowed_users\",\n \"allowed_groups\",\n \"allowed_principals\",\n ],\n \"size\": limit,\n }\n\n if score_threshold is not None:\n body[\"min_score\"] = score_threshold\n\n logger.info(\n f\"Executing multi-model hybrid search with {len(knn_queries_with_candidates)} embedding models: \"\n f\"{list(query_embeddings.keys())}\"\n )\n self.log(\n f\"[EXEC] Executing search with {len(knn_queries_with_candidates)} KNN queries, limit={limit}\"\n )\n self.log(f\"[EXEC] Embedding models used: {list(query_embeddings.keys())}\")\n self.log(f\"[EXEC] KNN fields being queried: {embedding_fields}\")\n\n try:\n resp = client.search(index=self.index_name, body=body, params={\"terminate_after\": 0})\n except RequestError as e:\n error_message = str(e)\n lowered = error_message.lower()\n if use_num_candidates and \"num_candidates\" in lowered:\n logger.warning(\n \"Retrying search without num_candidates parameter due to cluster capabilities\",\n error=error_message,\n )\n fallback_body = copy.deepcopy(body)\n try:\n fallback_body[\"query\"][\"bool\"][\"should\"][0][\"dis_max\"][\"queries\"] = (\n knn_queries_without_candidates\n )\n except (KeyError, IndexError, TypeError) as inner_err:\n raise e from inner_err\n resp = client.search(\n index=self.index_name,\n body=fallback_body,\n params={\"terminate_after\": 0},\n )\n elif \"knn_vector\" in lowered or (\"field\" in lowered and \"knn\" in lowered):\n fallback_vector = next(iter(query_embeddings.values()), None)\n if fallback_vector is None:\n raise\n fallback_field = legacy_vector_field or \"chunk_embedding\"\n logger.warning(\n \"KNN search failed for dynamic fields; falling back to legacy field '%s'.\",\n fallback_field,\n )\n fallback_body = copy.deepcopy(body)\n fallback_body[\"query\"][\"bool\"][\"filter\"] = filter_clauses\n knn_fallback = {\n \"knn\": {\n fallback_field: {\n \"vector\": fallback_vector,\n \"k\": 50,\n }\n }\n }\n if use_num_candidates:\n knn_fallback[\"knn\"][fallback_field][\"num_candidates\"] = num_candidates\n fallback_body[\"query\"][\"bool\"][\"should\"][0][\"dis_max\"][\"queries\"] = [knn_fallback]\n resp = client.search(\n index=self.index_name,\n body=fallback_body,\n params={\"terminate_after\": 0},\n )\n else:\n raise\n hits = resp.get(\"hits\", {}).get(\"hits\", [])\n\n logger.info(f\"Found {len(hits)} results\")\n self.log(f\"[RESULT] Search complete: {len(hits)} results found\")\n\n if len(hits) == 0:\n self.log(\n f\"[EMPTY] Debug info: \"\n f\"models_in_index={available_models}, \"\n f\"matched_models={matched_models}, \"\n f\"knn_fields={embedding_fields}, \"\n f\"filters={len(filter_clauses)} clauses\"\n )\n\n return [\n {\n \"page_content\": fence_untrusted_text(hit[\"_source\"].get(\"text\", \"\")),\n \"metadata\": {\n **{k: v for k, v in hit[\"_source\"].items() if k != \"text\"},\n \"chunk_id\": hit.get(\"_id\"),\n \"id\": hit.get(\"_id\"),\n \"score\": hit.get(\"_score\"),\n },\n \"score\": hit.get(\"_score\"),\n }\n for hit in hits\n ]\n\n def search_documents(self) -> list[Data]:\n\n \"\"\"Search documents and return results as a list of Data objects.\n\n This is the main interface method that performs the multi-model search using the\n configured search_query and returns results in a format that downstream Parser\n components and tool wrappers can consume directly without DataFrame string truncation.\n\n Always builds the vector store (triggering ingestion if needed), then performs\n search only if a query is provided.\n\n Returns:\n List containing search results with text and metadata\n\n Raises:\n Exception: If search operation fails\n \"\"\"\n\n try:\n # Always build/cache the vector store to ensure ingestion happens\n logger.info(f\"Search query: {self.search_query}\")\n if self._cached_vector_store is None:\n self.build_vector_store()\n\n # Only perform search if query is provided\n search_query = (self.search_query or \"\").strip()\n if not search_query:\n self.log(\"No search query provided - ingestion completed, returning empty results\")\n\n return []\n\n # Perform search with the provided query\n raw = self.search(search_query)\n raw_list = [Data(text=hit[\"page_content\"], **hit[\"metadata\"]) for hit in raw]\n return raw_list\n\n except Exception as e:\n self.log(f\"search_documents error: {e}\")\n raise\n\n # -------- dynamic UI handling (auth switch) --------\n async def update_build_config(\n self, build_config: dict, field_value: str, field_name: str | None = None\n ) -> dict:\n \"\"\"Dynamically update component configuration based on field changes.\n\n This method handles real-time UI updates, particularly for authentication\n mode changes that show/hide relevant input fields.\n\n Args:\n build_config: Current component configuration\n field_value: New value for the changed field\n field_name: Name of the field that changed\n\n Returns:\n Updated build configuration with appropriate field visibility\n \"\"\"\n try:\n if field_name == \"auth_mode\":\n mode = (field_value or \"basic\").strip().lower()\n is_basic = mode == \"basic\"\n is_jwt = mode == \"jwt\"\n is_openrag = mode == \"openrag\"\n\n build_config[\"username\"][\"show\"] = is_basic\n build_config[\"password\"][\"show\"] = is_basic\n\n build_config[\"jwt_token\"][\"show\"] = is_jwt\n build_config[\"jwt_header\"][\"show\"] = is_jwt\n build_config[\"bearer_prefix\"][\"show\"] = is_jwt\n\n build_config[\"username\"][\"required\"] = is_basic\n build_config[\"password\"][\"required\"] = is_basic\n\n # build_config[\"jwt_token\"][\"required\"] = is_jwt\n build_config[\"jwt_header\"][\"required\"] = is_jwt\n build_config[\"bearer_prefix\"][\"required\"] = False\n\n # In 'openrag' mode, expose the OPENRAG_* fields up front\n # since they are the only credentials required.\n for openrag_field in (\n \"openrag_ingest_url\",\n \"openrag_ingest_token\",\n \"openrag_ingest_run_id\",\n \"openrag_ingest_batch_size\",\n ):\n if openrag_field in build_config:\n build_config[openrag_field][\"advanced\"] = not is_openrag\n build_config[openrag_field][\"required\"] = (\n is_openrag and openrag_field != \"openrag_ingest_batch_size\"\n )\n\n if is_basic or is_openrag:\n build_config[\"jwt_token\"][\"value\"] = \"\"\n\n return build_config\n\n except (KeyError, ValueError) as e:\n self.log(f\"update_build_config error: {e}\")\n\n return build_config\n"
- },
- "docs_metadata": {
- "_input_type": "TableInput",
- "advanced": false,
+ "value": 100
+ },
+ "openrag_ingest_run_id": {
+ "_input_type": "StrInput",
+ "advanced": true,
"api_editable": false,
- "display_name": "Document Metadata",
+ "display_name": "OpenRAG Ingest Run ID",
"dynamic": false,
- "info": "Additional metadata key-value pairs to be added to all ingested documents. Useful for tagging documents with source information, categories, or other custom attributes.",
+ "info": "",
"input_types": [
- "Data",
- "JSON"
+ "Text",
+ "Message"
],
- "is_list": true,
+ "list": false,
"list_add_label": "Add More",
- "name": "docs_metadata",
+ "load_from_db": true,
+ "name": "openrag_ingest_run_id",
"override_skip": false,
"placeholder": "",
"required": false,
"show": true,
- "table_icon": "Table",
- "table_schema": [
- {
- "description": "Key name",
- "display_name": "Key",
- "formatter": "text",
- "name": "key",
- "type": "str"
- },
- {
- "description": "Value of the metadata",
- "display_name": "Value",
- "formatter": "text",
- "name": "value",
- "type": "str"
- }
- ],
"title_case": false,
"tool_mode": false,
"trace_as_metadata": true,
"track_in_telemetry": false,
- "trigger_icon": "Table",
- "trigger_text": "Open table",
- "type": "table",
- "value": []
+ "type": "str",
+ "value": "OPENRAG_INGEST_RUN_ID"
},
- "ef_construction": {
- "_input_type": "IntInput",
+ "openrag_ingest_token": {
+ "_input_type": "SecretStrInput",
"advanced": true,
"api_editable": false,
- "display_name": "EF Construction",
+ "display_name": "OpenRAG Ingest Token",
"dynamic": false,
- "info": "Size of the dynamic candidate list during index construction. Higher values improve recall but increase indexing time and memory usage.",
- "list": false,
- "list_add_label": "Add More",
- "name": "ef_construction",
+ "info": "Short-lived token used only for OpenRAG ingest callbacks.",
+ "input_types": [
+ "Text",
+ "Message"
+ ],
+ "load_from_db": true,
+ "name": "openrag_ingest_token",
"override_skip": false,
+ "password": true,
"placeholder": "",
"required": false,
"show": true,
"title_case": false,
- "tool_mode": false,
- "trace_as_metadata": true,
- "track_in_telemetry": true,
- "type": "int",
- "value": 512
+ "track_in_telemetry": false,
+ "type": "str",
+ "value": "OPENRAG_INGEST_TOKEN"
},
- "embedding": {
- "_input_type": "HandleInput",
- "advanced": false,
+ "openrag_ingest_url": {
+ "_input_type": "StrInput",
+ "advanced": true,
"api_editable": false,
- "display_name": "Embedding",
+ "display_name": "OpenRAG Ingest URL",
"dynamic": false,
- "info": "",
+ "info": "Internal OpenRAG callback URL for backend-owned document indexing.",
"input_types": [
- "Embeddings"
+ "Text",
+ "Message"
],
- "list": true,
+ "list": false,
"list_add_label": "Add More",
- "name": "embedding",
+ "load_from_db": true,
+ "name": "openrag_ingest_url",
"override_skip": false,
"placeholder": "",
"required": false,
"show": true,
"title_case": false,
+ "tool_mode": false,
"trace_as_metadata": true,
"track_in_telemetry": false,
- "type": "other",
- "value": ""
+ "type": "str",
+ "value": "OPENRAG_INGEST_URL"
},
- "embedding_model_name": {
+ "opensearch_url": {
"_input_type": "StrInput",
"advanced": false,
"api_editable": false,
- "display_name": "Embedding Model Name",
+ "display_name": "OpenSearch URL",
"dynamic": false,
- "info": "Name of the embedding model to use for ingestion. This selects which embedding from the list will be used to embed documents. Matches on deployment, model, model_id, or model_name. For duplicate deployments, use combined format: 'deployment:model' (e.g., 'text-embedding-ada-002:text-embedding-3-large'). Leave empty to use the first embedding. Error message will show all available identifiers.",
+ "info": "The connection URL for your OpenSearch cluster (e.g., http://localhost:9200 for local development or your cloud endpoint).",
"list": false,
"list_add_label": "Add More",
"load_from_db": true,
- "name": "embedding_model_name",
+ "name": "opensearch_url",
"override_skip": false,
"placeholder": "",
"required": false,
@@ -3104,79 +2077,86 @@
"trace_as_metadata": true,
"track_in_telemetry": false,
"type": "str",
- "value": "SELECTED_EMBEDDING_MODEL"
+ "value": "OPENSEARCH_URL"
},
- "engine": {
- "_input_type": "DropdownInput",
+ "password": {
+ "_input_type": "SecretStrInput",
+ "advanced": false,
+ "api_editable": false,
+ "display_name": "OpenSearch Password",
+ "dynamic": false,
+ "info": "",
+ "input_types": [],
+ "load_from_db": true,
+ "name": "password",
+ "override_skip": false,
+ "password": true,
+ "placeholder": "",
+ "required": false,
+ "show": false,
+ "title_case": false,
+ "track_in_telemetry": false,
+ "type": "str",
+ "value": "OPENSEARCH_PASSWORD"
+ },
+ "request_timeout": {
+ "_input_type": "StrInput",
"advanced": true,
"api_editable": false,
- "combobox": false,
- "dialog_inputs": {},
- "display_name": "Vector Engine",
+ "display_name": "Request Timeout (seconds)",
"dynamic": false,
- "external_options": {},
- "info": "Vector search engine for similarity calculations. 'nmslib' works with standard OpenSearch. 'jvector' requires OpenSearch 2.9+. 'lucene' requires index.knn: true. Amazon OpenSearch Serverless only supports 'nmslib' or 'faiss'.",
- "name": "engine",
- "options": [
- "nmslib",
- "faiss",
- "lucene",
- "jvector"
- ],
- "options_metadata": [],
+ "info": "Time in seconds to wait for a response from OpenSearch. Increase for large bulk ingestion or complex hybrid queries.",
+ "list": false,
+ "list_add_label": "Add More",
+ "load_from_db": false,
+ "name": "request_timeout",
"override_skip": false,
"placeholder": "",
"required": false,
"show": true,
"title_case": false,
- "toggle": false,
"tool_mode": false,
"trace_as_metadata": true,
- "track_in_telemetry": true,
+ "track_in_telemetry": false,
"type": "str",
- "value": "jvector"
+ "value": "60"
},
- "filter_expression": {
- "_input_type": "MultilineInput",
+ "search_query": {
+ "_input_type": "QueryInput",
"advanced": false,
- "ai_enabled": false,
"api_editable": false,
- "copy_field": false,
- "display_name": "Search Filters (JSON)",
+ "display_name": "Search Query",
"dynamic": false,
- "info": "Optional JSON configuration for search filtering, result limits, and score thresholds.\n\nFormat 1 - Explicit filters:\n{\"filter\": [{\"term\": {\"filename\":\"doc.pdf\"}}, {\"terms\":{\"owner\":[\"user1\",\"user2\"]}}], \"limit\": 10, \"score_threshold\": 1.6}\n\nFormat 2 - Context-style mapping:\n{\"data_sources\":[\"file.pdf\"], \"document_types\":[\"application/pdf\"], \"owners\":[\"user123\"]}\n\nUse __IMPOSSIBLE_VALUE__ as placeholder to ignore specific filters.",
+ "info": "Enter a query to run a similarity search.",
"input_types": [
"Message"
],
"list": false,
"list_add_label": "Add More",
"load_from_db": false,
- "multiline": true,
- "name": "filter_expression",
+ "name": "search_query",
"override_skip": false,
- "password": false,
- "placeholder": "",
+ "placeholder": "Enter a query...",
"required": false,
"show": true,
"title_case": false,
- "tool_mode": false,
+ "tool_mode": true,
"trace_as_input": true,
"trace_as_metadata": true,
"track_in_telemetry": false,
- "type": "str",
- "value": ""
+ "type": "query",
+ "value": "\"\""
},
- "index_name": {
- "_input_type": "StrInput",
- "advanced": false,
+ "should_cache_vector_store": {
+ "_input_type": "BoolInput",
+ "advanced": true,
"api_editable": false,
- "display_name": "Index Name",
+ "display_name": "Cache Vector Store",
"dynamic": false,
- "info": "The OpenSearch index name where documents will be stored and searched. Will be created automatically if it doesn't exist.",
+ "info": "If True, the vector store will be cached for the current build of the component. This is useful for components that have multiple output methods and want to share the same vector store.",
"list": false,
"list_add_label": "Add More",
- "load_from_db": true,
- "name": "index_name",
+ "name": "should_cache_vector_store",
"override_skip": false,
"placeholder": "",
"required": false,
@@ -3184,88 +2164,116 @@
"title_case": false,
"tool_mode": false,
"trace_as_metadata": true,
- "track_in_telemetry": false,
- "type": "str",
- "value": "OPENSEARCH_INDEX_NAME"
+ "track_in_telemetry": true,
+ "type": "bool",
+ "value": true
},
- "ingest_data": {
- "_input_type": "HandleInput",
- "advanced": false,
+ "space_type": {
+ "_input_type": "DropdownInput",
+ "advanced": true,
"api_editable": false,
- "display_name": "Ingest Data",
+ "combobox": false,
+ "dialog_inputs": {},
+ "display_name": "Distance Metric",
"dynamic": false,
- "info": "",
- "input_types": [
- "Data",
- "DataFrame",
- "Table"
+ "external_options": {},
+ "info": "Distance metric for calculating vector similarity. 'l2' (Euclidean) is most common, 'cosinesimil' for cosine similarity, 'innerproduct' for dot product.",
+ "name": "space_type",
+ "options": [
+ "l2",
+ "l1",
+ "cosinesimil",
+ "linf",
+ "innerproduct"
],
- "list": true,
+ "options_metadata": [],
+ "override_skip": false,
+ "placeholder": "",
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "toggle": false,
+ "tool_mode": false,
+ "trace_as_metadata": true,
+ "track_in_telemetry": true,
+ "type": "str",
+ "value": "l2"
+ },
+ "use_ssl": {
+ "_input_type": "BoolInput",
+ "advanced": true,
+ "api_editable": false,
+ "display_name": "Use SSL/TLS",
+ "dynamic": false,
+ "info": "Enable SSL/TLS encryption for secure connections to OpenSearch.",
+ "list": false,
"list_add_label": "Add More",
- "name": "ingest_data",
+ "name": "use_ssl",
"override_skip": false,
"placeholder": "",
"required": false,
"show": true,
"title_case": false,
+ "tool_mode": false,
"trace_as_metadata": true,
- "track_in_telemetry": false,
- "type": "other",
- "value": ""
+ "track_in_telemetry": true,
+ "type": "bool",
+ "value": true
},
- "is_refresh": false,
- "jwt_header": {
+ "username": {
"_input_type": "StrInput",
- "advanced": true,
+ "advanced": false,
"api_editable": false,
- "display_name": "JWT Header Name",
+ "display_name": "Username",
"dynamic": false,
"info": "",
"list": false,
"list_add_label": "Add More",
"load_from_db": false,
- "name": "jwt_header",
+ "name": "username",
"override_skip": false,
- "placeholder": "",
- "required": true,
- "show": true,
+ "placeholder": "",
+ "required": false,
+ "show": false,
"title_case": false,
"tool_mode": false,
"trace_as_metadata": true,
"track_in_telemetry": false,
"type": "str",
- "value": "Authorization"
+ "value": "admin"
},
- "jwt_token": {
- "_input_type": "SecretStrInput",
- "advanced": false,
+ "vector_field": {
+ "_input_type": "StrInput",
+ "advanced": true,
"api_editable": false,
- "display_name": "JWT Token",
+ "display_name": "Legacy Vector Field Name",
"dynamic": false,
- "info": "Valid JSON Web Token for authentication. Will be sent in the Authorization header (with optional 'Bearer ' prefix).",
- "input_types": [],
- "load_from_db": true,
- "name": "jwt_token",
+ "info": "Legacy field name for backward compatibility. New documents use dynamic fields (chunk_embedding_{model_name}) based on the embedding_model_name.",
+ "list": false,
+ "list_add_label": "Add More",
+ "load_from_db": false,
+ "name": "vector_field",
"override_skip": false,
- "password": true,
"placeholder": "",
"required": false,
"show": true,
"title_case": false,
+ "tool_mode": false,
+ "trace_as_metadata": true,
"track_in_telemetry": false,
"type": "str",
- "value": "JWT"
+ "value": "chunk_embedding"
},
- "m": {
- "_input_type": "IntInput",
+ "verify_certs": {
+ "_input_type": "BoolInput",
"advanced": true,
"api_editable": false,
- "display_name": "M Parameter",
+ "display_name": "Verify SSL Certificates",
"dynamic": false,
- "info": "Number of bidirectional connections for each vector in the HNSW graph. Higher values improve search quality but increase memory usage and indexing time.",
+ "info": "Verify SSL certificates when connecting. Disable for self-signed certificates in development environments.",
"list": false,
"list_add_label": "Add More",
- "name": "m",
+ "name": "verify_certs",
"override_skip": false,
"placeholder": "",
"required": false,
@@ -3274,20 +2282,102 @@
"tool_mode": false,
"trace_as_metadata": true,
"track_in_telemetry": true,
- "type": "int",
- "value": 16
+ "type": "bool",
+ "value": false
+ }
+ },
+ "tool_mode": false
+ },
+ "selected_output": "search_results",
+ "showNode": false,
+ "type": "ext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra"
+ },
+ "dragging": false,
+ "id": "ext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-yrQui",
+ "measured": {
+ "height": 139,
+ "width": 192
+ },
+ "position": {
+ "x": 427.43787902817417,
+ "y": 1385.8198377353997
+ },
+ "selected": false,
+ "type": "genericNode"
+ },
+ {
+ "data": {
+ "id": "OpenAICompatibleEmbedding-CdOpv",
+ "node": {
+ "base_classes": [
+ "Embeddings"
+ ],
+ "beta": false,
+ "conditional_paths": [],
+ "custom_fields": {},
+ "description": "Embeddings via OpenRAG's OpenAI-compatible /v1 proxy. Uses the same base URL and hop token as the chat component.",
+ "display_name": "OpenRAG Embeddings",
+ "documentation": "",
+ "edited": false,
+ "field_order": [
+ "model_name",
+ "api_key",
+ "api_base",
+ "dimensions",
+ "chunk_size"
+ ],
+ "frozen": false,
+ "icon": "OpenRAG",
+ "legacy": false,
+ "metadata": {
+ "code_hash": "cc257e587747",
+ "dependencies": {
+ "dependencies": [
+ {
+ "name": "langchain_openai",
+ "version": "1.5.2"
+ },
+ {
+ "name": "lfx",
+ "version": "1.11.2"
+ }
+ ],
+ "total_dependencies": 2
},
- "max_retries": {
+ "module": "custom_components.openrag_embeddings"
+ },
+ "minimized": false,
+ "output_types": [],
+ "outputs": [
+ {
+ "allows_loop": false,
+ "cache": true,
+ "display_name": "Embedding Model",
+ "group_outputs": false,
+ "method": "build_embeddings",
+ "name": "embeddings",
+ "selected": "Embeddings",
+ "tool_mode": true,
+ "types": [
+ "Embeddings"
+ ],
+ "value": "__UNDEFINED__"
+ }
+ ],
+ "pinned": false,
+ "template": {
+ "_type": "Component",
+ "api_base": {
"_input_type": "StrInput",
- "advanced": true,
+ "advanced": false,
"api_editable": false,
- "display_name": "Max Retries",
+ "display_name": "OpenAI API Base",
"dynamic": false,
- "info": "Number of retries for failed connections before raising an error.",
+ "info": "Must end with /v1 (for example http://openrag-backend:8000/v1). Bound to OPENRAG_LLM_BASE_URL at runtime. Same URL as chat.",
"list": false,
"list_add_label": "Add More",
- "load_from_db": false,
- "name": "max_retries",
+ "load_from_db": true,
+ "name": "api_base",
"override_skip": false,
"placeholder": "",
"required": false,
@@ -3297,39 +2387,38 @@
"trace_as_metadata": true,
"track_in_telemetry": false,
"type": "str",
- "value": "3"
+ "value": "OPENRAG_LLM_BASE_URL"
},
- "num_candidates": {
- "_input_type": "IntInput",
- "advanced": true,
+ "api_key": {
+ "_input_type": "SecretStrInput",
+ "advanced": false,
"api_editable": false,
- "display_name": "Candidate Pool Size",
+ "display_name": "OpenRAG LLM Token",
"dynamic": false,
- "info": "Number of approximate neighbors to consider for each KNN query. Some OpenSearch deployments do not support this parameter; set to 0 to disable.",
- "list": false,
- "list_add_label": "Add More",
- "name": "num_candidates",
+ "info": "Hop token from OPENRAG_LLM_TOKEN. Same token as the chat component.",
+ "input_types": [],
+ "load_from_db": true,
+ "name": "api_key",
"override_skip": false,
+ "password": true,
"placeholder": "",
"required": false,
"show": true,
"title_case": false,
- "tool_mode": false,
- "trace_as_metadata": true,
- "track_in_telemetry": true,
- "type": "int",
- "value": 1000
+ "track_in_telemetry": false,
+ "type": "str",
+ "value": "OPENRAG_LLM_TOKEN"
},
- "number_of_results": {
+ "chunk_size": {
"_input_type": "IntInput",
"advanced": true,
"api_editable": false,
- "display_name": "Default Result Limit",
+ "display_name": "Chunk Size",
"dynamic": false,
- "info": "Default maximum number of search results to return when no limit is specified in the filter expression.",
+ "info": "",
"list": false,
"list_add_label": "Add More",
- "name": "number_of_results",
+ "name": "chunk_size",
"override_skip": false,
"placeholder": "",
"required": false,
@@ -3339,44 +2428,37 @@
"trace_as_metadata": true,
"track_in_telemetry": true,
"type": "int",
- "value": 10
+ "value": 1000
},
- "openrag_ingest_batch_size": {
- "_input_type": "IntInput",
+ "code": {
"advanced": true,
"api_editable": false,
- "display_name": "OpenRAG Ingest Batch Size",
- "dynamic": false,
+ "dynamic": true,
+ "fileTypes": [],
+ "file_path": "",
"info": "",
"list": false,
- "list_add_label": "Add More",
- "name": "openrag_ingest_batch_size",
- "override_skip": false,
+ "load_from_db": false,
+ "multiline": true,
+ "name": "code",
+ "password": false,
"placeholder": "",
- "required": false,
+ "required": true,
"show": true,
"title_case": false,
- "tool_mode": false,
- "trace_as_metadata": true,
- "track_in_telemetry": true,
- "type": "int",
- "value": 100
+ "type": "code",
+ "value": "\"\"\"OpenAI-compatible embeddings that talk to the OpenRAG `/v1` proxy.\n\nEmbeddings work the same way as chat: Langflow never holds upstream vendor\nkeys. At runtime OpenRAG injects:\n\n- ``OPENRAG_LLM_TOKEN`` — the same short-lived hop token as chat\n- ``OPENRAG_LLM_BASE_URL`` — the same ``http://<backend>/v1`` base URL\n- ``SELECTED_EMBEDDING_MODEL`` — configured embedding model id\n\n``OpenAIEmbeddings`` posts to ``{base_url}/embeddings``. The backend gateway\nroutes by the configured embedding provider (which can differ from the chat\nprovider).\n\"\"\"\n\nfrom __future__ import annotations\n\nfrom typing import Any\n\nfrom langchain_openai import OpenAIEmbeddings\nfrom lfx.base.embeddings.model import LCEmbeddingsModel\nfrom lfx.field_typing import Embeddings\nfrom lfx.io import IntInput, SecretStrInput, StrInput\n\n# Names must match src/api/settings/langflow_sync.py + src/utils/langflow_headers.py\nOPENRAG_LLM_BASE_URL_VAR = \"OPENRAG_LLM_BASE_URL\"\nOPENRAG_LLM_TOKEN_VAR = \"OPENRAG_LLM_TOKEN\"\nSELECTED_EMBEDDING_MODEL_VAR = \"SELECTED_EMBEDDING_MODEL\"\n\n\ndef _as_str(value: object) -> str | None:\n if value is None:\n return None\n getter = getattr(value, \"get_secret_value\", None)\n if callable(getter):\n value = getter()\n text = str(value).strip()\n return text or None\n\n\nclass OpenAICompatibleEmbeddingComponent(LCEmbeddingsModel):\n display_name = \"OpenRAG Embeddings\"\n description = (\n \"Embeddings via OpenRAG's OpenAI-compatible /v1 proxy. \"\n \"Uses the same base URL and hop token as the chat component.\"\n )\n icon = \"OpenRAG\"\n name = \"OpenAICompatibleEmbedding\"\n\n inputs = [\n StrInput(\n name=\"model_name\",\n display_name=\"Model Name\",\n info=\"Embedding model id. Bound to SELECTED_EMBEDDING_MODEL at runtime.\",\n value=SELECTED_EMBEDDING_MODEL_VAR,\n load_from_db=True,\n ),\n SecretStrInput(\n name=\"api_key\",\n display_name=\"OpenRAG LLM Token\",\n info=\"Hop token from OPENRAG_LLM_TOKEN. Same token as the chat component.\",\n value=OPENRAG_LLM_TOKEN_VAR,\n required=False,\n load_from_db=True,\n ),\n StrInput(\n name=\"api_base\",\n display_name=\"OpenAI API Base\",\n info=(\n \"Must end with /v1 (for example http://openrag-backend:8000/v1). \"\n \"Bound to OPENRAG_LLM_BASE_URL at runtime. Same URL as chat.\"\n ),\n value=OPENRAG_LLM_BASE_URL_VAR,\n load_from_db=True,\n ),\n IntInput(\n name=\"dimensions\",\n display_name=\"Dimensions\",\n info=\"Output dimensions when the embedding model supports it.\",\n advanced=True,\n ),\n IntInput(\n name=\"chunk_size\",\n display_name=\"Chunk Size\",\n advanced=True,\n value=1000,\n ),\n ]\n\n def build_embeddings(self) -> Embeddings:\n api_key = _as_str(self.api_key)\n api_base = _as_str(self.api_base)\n if api_base:\n api_base = api_base.rstrip(\"/\")\n\n kwargs: dict[str, Any] = {\n \"model\": self.model_name,\n # `OpenAIEmbeddings.deployment` defaults to the class-level default of\n # `model` — the literal \"text-embedding-ada-002\" — for every instance,\n # whatever model is actually configured. The OpenSearch component keys\n # its embedding lookup on `deployment` as well as `model`, so leaving\n # the default in place registers this object under ada-002 too, and a\n # 768-dim vector then gets aimed at a 1536-dim ada-002 vector field.\n # Only Azure reads this field, so pinning it to the real model is inert\n # at request time and keeps the component's identity honest.\n \"deployment\": self.model_name,\n \"api_key\": api_key,\n \"base_url\": api_base or None,\n # Skip tiktoken context checks so non-OpenAI model ids still work.\n \"check_embedding_ctx_length\": False,\n }\n chunk_size = getattr(self, \"chunk_size\", None)\n if chunk_size:\n kwargs[\"chunk_size\"] = chunk_size\n dimensions = getattr(self, \"dimensions\", None)\n if dimensions:\n kwargs[\"dimensions\"] = dimensions\n return OpenAIEmbeddings(**kwargs)\n"
},
- "openrag_ingest_run_id": {
- "_input_type": "StrInput",
+ "dimensions": {
+ "_input_type": "IntInput",
"advanced": true,
"api_editable": false,
- "display_name": "OpenRAG Ingest Run ID",
+ "display_name": "Dimensions",
"dynamic": false,
- "info": "",
- "input_types": [
- "Text",
- "Message"
- ],
+ "info": "Output dimensions when the embedding model supports it.",
"list": false,
"list_add_label": "Add More",
- "load_from_db": true,
- "name": "openrag_ingest_run_id",
+ "name": "dimensions",
"override_skip": false,
"placeholder": "",
"required": false,
@@ -3384,70 +2466,148 @@
"title_case": false,
"tool_mode": false,
"trace_as_metadata": true,
- "track_in_telemetry": false,
- "type": "str",
- "value": "OPENRAG_INGEST_RUN_ID"
+ "track_in_telemetry": true,
+ "type": "int",
+ "value": 0
},
- "openrag_ingest_token": {
- "_input_type": "SecretStrInput",
- "advanced": true,
+ "model_name": {
+ "_input_type": "StrInput",
+ "advanced": false,
"api_editable": false,
- "display_name": "OpenRAG Ingest Token",
+ "display_name": "Model Name",
"dynamic": false,
- "info": "Short-lived token used only for OpenRAG ingest callbacks.",
- "input_types": [
- "Text",
- "Message"
- ],
+ "info": "Embedding model id. Bound to SELECTED_EMBEDDING_MODEL at runtime.",
+ "list": false,
+ "list_add_label": "Add More",
"load_from_db": true,
- "name": "openrag_ingest_token",
+ "name": "model_name",
"override_skip": false,
- "password": true,
"placeholder": "",
"required": false,
"show": true,
"title_case": false,
+ "tool_mode": false,
+ "trace_as_metadata": true,
"track_in_telemetry": false,
"type": "str",
- "value": "OPENRAG_INGEST_TOKEN"
+ "value": "SELECTED_EMBEDDING_MODEL"
+ }
+ },
+ "tool_mode": false
+ },
+ "showNode": false,
+ "type": "OpenAICompatibleEmbedding"
+ },
+ "dragging": false,
+ "id": "OpenAICompatibleEmbedding-CdOpv",
+ "measured": {
+ "height": 52,
+ "width": 192
+ },
+ "position": {
+ "x": -59.381270855785424,
+ "y": 1384.3606108469412
+ },
+ "selected": false,
+ "type": "genericNode"
+ },
+ {
+ "data": {
+ "id": "OpenAICompatibleLLM-0PA0e",
+ "node": {
+ "base_classes": [
+ "LanguageModel",
+ "Message"
+ ],
+ "beta": false,
+ "conditional_paths": [],
+ "custom_fields": {},
+ "description": "Chat model via OpenRAG's OpenAI-compatible /v1 proxy. Base URL and hop token come from global variables at runtime.",
+ "display_name": "OpenRAG LLM",
+ "documentation": "",
+ "edited": false,
+ "field_order": [
+ "input_value",
+ "system_message",
+ "stream",
+ "model_name",
+ "api_key",
+ "api_base",
+ "temperature",
+ "max_tokens",
+ "seed"
+ ],
+ "frozen": false,
+ "icon": "OpenRAG",
+ "legacy": false,
+ "metadata": {
+ "code_hash": "c71fbff77a9e",
+ "dependencies": {
+ "dependencies": [
+ {
+ "name": "langchain_openai",
+ "version": "1.5.2"
+ },
+ {
+ "name": "lfx",
+ "version": "1.11.2"
+ }
+ ],
+ "total_dependencies": 2
},
- "openrag_ingest_url": {
- "_input_type": "StrInput",
- "advanced": true,
- "api_editable": false,
- "display_name": "OpenRAG Ingest URL",
- "dynamic": false,
- "info": "Internal OpenRAG callback URL for backend-owned document indexing.",
- "input_types": [
- "Text",
+ "keywords": [
+ "model",
+ "llm",
+ "language model",
+ "large language model"
+ ],
+ "module": "custom_components.openrag_llm"
+ },
+ "minimized": false,
+ "output_types": [],
+ "outputs": [
+ {
+ "allows_loop": false,
+ "cache": true,
+ "display_name": "Model Response",
+ "group_outputs": false,
+ "method": "text_response",
+ "name": "text_output",
+ "selected": "Message",
+ "tool_mode": true,
+ "types": [
"Message"
],
- "list": false,
- "list_add_label": "Add More",
- "load_from_db": true,
- "name": "openrag_ingest_url",
- "override_skip": false,
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_metadata": true,
- "track_in_telemetry": false,
- "type": "str",
- "value": "OPENRAG_INGEST_URL"
+ "value": "__UNDEFINED__"
},
- "opensearch_url": {
+ {
+ "allows_loop": false,
+ "cache": true,
+ "display_name": "Language Model",
+ "group_outputs": false,
+ "method": "build_model",
+ "name": "model_output",
+ "tool_mode": true,
+ "types": [
+ "LanguageModel"
+ ],
+ "value": "__UNDEFINED__"
+ }
+ ],
+ "pinned": false,
+ "template": {
+ "_type": "Component",
+ "api_base": {
"_input_type": "StrInput",
"advanced": false,
"api_editable": false,
- "display_name": "OpenSearch URL",
+ "display_name": "OpenAI API Base",
"dynamic": false,
- "info": "The connection URL for your OpenSearch cluster (e.g., http://localhost:9200 for local development or your cloud endpoint).",
+ "info": "Must end with /v1 (for example http://openrag-backend:8000/v1). Bound to OPENRAG_LLM_BASE_URL at runtime. Same URL as embeddings.",
"list": false,
"list_add_label": "Add More",
"load_from_db": true,
- "name": "opensearch_url",
+ "name": "api_base",
"override_skip": false,
"placeholder": "",
"required": false,
@@ -3457,86 +2617,83 @@
"trace_as_metadata": true,
"track_in_telemetry": false,
"type": "str",
- "value": "OPENSEARCH_URL"
+ "value": "OPENRAG_LLM_BASE_URL"
},
- "password": {
+ "api_key": {
"_input_type": "SecretStrInput",
"advanced": false,
"api_editable": false,
- "display_name": "OpenSearch Password",
+ "display_name": "OpenRAG LLM Token",
"dynamic": false,
- "info": "",
+ "info": "Hop token from OPENRAG_LLM_TOKEN. OpenRAG injects this per Langflow run.",
"input_types": [],
"load_from_db": true,
- "name": "password",
+ "name": "api_key",
"override_skip": false,
"password": true,
"placeholder": "",
"required": false,
- "show": false,
+ "show": true,
"title_case": false,
"track_in_telemetry": false,
"type": "str",
- "value": "OPENSEARCH_PASSWORD"
+ "value": "OPENRAG_LLM_TOKEN"
},
- "request_timeout": {
- "_input_type": "StrInput",
+ "code": {
"advanced": true,
"api_editable": false,
- "display_name": "Request Timeout (seconds)",
- "dynamic": false,
- "info": "Time in seconds to wait for a response from OpenSearch. Increase for large bulk ingestion or complex hybrid queries.",
+ "dynamic": true,
+ "fileTypes": [],
+ "file_path": "",
+ "info": "",
"list": false,
- "list_add_label": "Add More",
"load_from_db": false,
- "name": "request_timeout",
- "override_skip": false,
+ "multiline": true,
+ "name": "code",
+ "password": false,
"placeholder": "",
- "required": false,
+ "required": true,
"show": true,
"title_case": false,
- "tool_mode": false,
- "trace_as_metadata": true,
- "track_in_telemetry": false,
- "type": "str",
- "value": "60"
+ "type": "code",
+ "value": "\"\"\"OpenAI-compatible chat model that talks to the OpenRAG `/v1` proxy.\n\nLangflow never holds upstream vendor keys. At runtime OpenRAG injects:\n\n- ``OPENRAG_LLM_TOKEN`` — short-lived hop token (Authorization Bearer)\n- ``OPENRAG_LLM_BASE_URL`` — ``http://<backend>/v1``\n- ``SELECTED_LANGUAGE_MODEL`` — configured chat model id\n\n``ChatOpenAI`` posts to ``{base_url}/chat/completions``. The backend gateway\nthen calls the real vendor (OpenAI, Anthropic, Watsonx, Ollama, or any other\nLiteLLM provider). Embeddings use the same base URL and hop token; see\n``openai_compatible_embedding.py``.\n\"\"\"\n\nfrom __future__ import annotations\n\nfrom typing import Any\n\nfrom langchain_openai import ChatOpenAI\nfrom lfx.base.models.model import LCModelComponent\nfrom lfx.field_typing.constants import LanguageModel\nfrom lfx.field_typing.range_spec import RangeSpec\nfrom lfx.inputs.inputs import BoolInput, StrInput\nfrom lfx.io import IntInput, MessageInput, MultilineInput, SecretStrInput, SliderInput\n\n# Names must match src/api/settings/langflow_sync.py + src/utils/langflow_headers.py\nOPENRAG_LLM_BASE_URL_VAR = \"OPENRAG_LLM_BASE_URL\"\nOPENRAG_LLM_TOKEN_VAR = \"OPENRAG_LLM_TOKEN\"\nSELECTED_LANGUAGE_MODEL_VAR = \"SELECTED_LANGUAGE_MODEL\"\n\n\ndef _as_str(value: object) -> str | None:\n if value is None:\n return None\n getter = getattr(value, \"get_secret_value\", None)\n if callable(getter):\n value = getter()\n text = str(value).strip()\n return text or None\n\n\nclass OpenAICompatibleLLMComponent(LCModelComponent):\n display_name = \"OpenRAG LLM\"\n description = (\n \"Chat model via OpenRAG's OpenAI-compatible /v1 proxy. \"\n \"Base URL and hop token come from global variables at runtime.\"\n )\n icon = \"OpenRAG\"\n name = \"OpenAICompatibleLLM\"\n\n inputs = [\n MessageInput(\n name=\"input_value\",\n display_name=\"Input\",\n info=\"The input text to send to the model\",\n ),\n MultilineInput(\n name=\"system_message\",\n display_name=\"System Message\",\n info=\"A system message that helps set the behavior of the assistant\",\n advanced=False,\n ),\n BoolInput(\n name=\"stream\",\n display_name=\"Stream\",\n info=\"Whether to stream the response\",\n value=False,\n advanced=True,\n ),\n StrInput(\n name=\"model_name\",\n display_name=\"Model Name\",\n info=\"Chat model id. Bound to SELECTED_LANGUAGE_MODEL at runtime.\",\n value=SELECTED_LANGUAGE_MODEL_VAR,\n load_from_db=True,\n ),\n SecretStrInput(\n name=\"api_key\",\n display_name=\"OpenRAG LLM Token\",\n info=\"Hop token from OPENRAG_LLM_TOKEN. OpenRAG injects this per Langflow run.\",\n value=OPENRAG_LLM_TOKEN_VAR,\n required=False,\n load_from_db=True,\n ),\n StrInput(\n name=\"api_base\",\n display_name=\"OpenAI API Base\",\n info=(\n \"Must end with /v1 (for example http://openrag-backend:8000/v1). \"\n \"Bound to OPENRAG_LLM_BASE_URL at runtime. Same URL as embeddings.\"\n ),\n value=OPENRAG_LLM_BASE_URL_VAR,\n load_from_db=True,\n ),\n SliderInput(\n name=\"temperature\",\n display_name=\"Temperature\",\n value=0.1,\n info=\"Controls randomness in responses\",\n range_spec=RangeSpec(min=0, max=1, step=0.01),\n advanced=True,\n ),\n IntInput(\n name=\"max_tokens\",\n display_name=\"Max Tokens\",\n info=\"Maximum number of tokens to generate. Leave empty for the model default.\",\n advanced=True,\n ),\n IntInput(\n name=\"seed\",\n display_name=\"Seed\",\n info=\"The seed controls the reproducibility of the job.\",\n advanced=True,\n value=1,\n ),\n ]\n\n def build_model(self) -> LanguageModel:\n api_key = _as_str(self.api_key)\n api_base = _as_str(self.api_base)\n if api_base:\n api_base = api_base.rstrip(\"/\")\n\n kwargs: dict[str, Any] = {\n \"model\": self.model_name,\n \"api_key\": api_key,\n \"base_url\": api_base or None,\n \"streaming\": bool(getattr(self, \"stream\", False)),\n }\n max_tokens = getattr(self, \"max_tokens\", None)\n if max_tokens:\n kwargs[\"max_tokens\"] = max_tokens\n temperature = getattr(self, \"temperature\", None)\n if temperature is not None:\n kwargs[\"temperature\"] = temperature\n seed = getattr(self, \"seed\", None)\n if seed is not None:\n kwargs[\"seed\"] = seed\n return ChatOpenAI(**kwargs)\n"
},
- "search_query": {
- "_input_type": "QueryInput",
+ "input_value": {
+ "_input_type": "MessageInput",
"advanced": false,
"api_editable": false,
- "display_name": "Search Query",
+ "display_name": "Input",
"dynamic": false,
- "info": "Enter a query to run a similarity search.",
+ "info": "The input text to send to the model",
"input_types": [
"Message"
],
"list": false,
"list_add_label": "Add More",
"load_from_db": false,
- "name": "search_query",
+ "name": "input_value",
"override_skip": false,
- "placeholder": "Enter a query...",
+ "placeholder": "",
"required": false,
"show": true,
"title_case": false,
- "tool_mode": true,
+ "tool_mode": false,
"trace_as_input": true,
"trace_as_metadata": true,
"track_in_telemetry": false,
- "type": "query",
- "value": "\"\""
+ "type": "str",
+ "value": ""
},
- "should_cache_vector_store": {
- "_input_type": "BoolInput",
+ "max_tokens": {
+ "_input_type": "IntInput",
"advanced": true,
"api_editable": false,
- "display_name": "Cache Vector Store",
+ "display_name": "Max Tokens",
"dynamic": false,
- "info": "If True, the vector store will be cached for the current build of the component. This is useful for components that have multiple output methods and want to share the same vector store.",
+ "info": "Maximum number of tokens to generate. Leave empty for the model default.",
"list": false,
"list_add_label": "Add More",
- "name": "should_cache_vector_store",
+ "name": "max_tokens",
"override_skip": false,
"placeholder": "",
"required": false,
@@ -3545,50 +2702,41 @@
"tool_mode": false,
"trace_as_metadata": true,
"track_in_telemetry": true,
- "type": "bool",
- "value": true
+ "type": "int",
+ "value": 0
},
- "space_type": {
- "_input_type": "DropdownInput",
- "advanced": true,
+ "model_name": {
+ "_input_type": "StrInput",
+ "advanced": false,
"api_editable": false,
- "combobox": false,
- "dialog_inputs": {},
- "display_name": "Distance Metric",
+ "display_name": "Model Name",
"dynamic": false,
- "external_options": {},
- "info": "Distance metric for calculating vector similarity. 'l2' (Euclidean) is most common, 'cosinesimil' for cosine similarity, 'innerproduct' for dot product.",
- "name": "space_type",
- "options": [
- "l2",
- "l1",
- "cosinesimil",
- "linf",
- "innerproduct"
- ],
- "options_metadata": [],
+ "info": "Chat model id. Bound to SELECTED_LANGUAGE_MODEL at runtime.",
+ "list": false,
+ "list_add_label": "Add More",
+ "load_from_db": true,
+ "name": "model_name",
"override_skip": false,
"placeholder": "",
"required": false,
"show": true,
"title_case": false,
- "toggle": false,
"tool_mode": false,
"trace_as_metadata": true,
- "track_in_telemetry": true,
+ "track_in_telemetry": false,
"type": "str",
- "value": "l2"
+ "value": "SELECTED_LANGUAGE_MODEL"
},
- "use_ssl": {
- "_input_type": "BoolInput",
+ "seed": {
+ "_input_type": "IntInput",
"advanced": true,
"api_editable": false,
- "display_name": "Use SSL/TLS",
+ "display_name": "Seed",
"dynamic": false,
- "info": "Enable SSL/TLS encryption for secure connections to OpenSearch.",
+ "info": "The seed controls the reproducibility of the job.",
"list": false,
"list_add_label": "Add More",
- "name": "use_ssl",
+ "name": "seed",
"override_skip": false,
"placeholder": "",
"required": false,
@@ -3597,95 +2745,116 @@
"tool_mode": false,
"trace_as_metadata": true,
"track_in_telemetry": true,
- "type": "bool",
- "value": true
+ "type": "int",
+ "value": 1
},
- "username": {
- "_input_type": "StrInput",
- "advanced": false,
+ "stream": {
+ "_input_type": "BoolInput",
+ "advanced": true,
"api_editable": false,
- "display_name": "Username",
+ "display_name": "Stream",
"dynamic": false,
- "info": "",
+ "info": "Whether to stream the response",
"list": false,
"list_add_label": "Add More",
- "load_from_db": false,
- "name": "username",
+ "name": "stream",
"override_skip": false,
"placeholder": "",
"required": false,
- "show": false,
+ "show": true,
"title_case": false,
"tool_mode": false,
"trace_as_metadata": true,
- "track_in_telemetry": false,
- "type": "str",
- "value": "admin"
+ "track_in_telemetry": true,
+ "type": "bool",
+ "value": false
},
- "vector_field": {
- "_input_type": "StrInput",
- "advanced": true,
+ "system_message": {
+ "_input_type": "MultilineInput",
+ "advanced": false,
+ "ai_enabled": false,
"api_editable": false,
- "display_name": "Legacy Vector Field Name",
+ "copy_field": false,
+ "display_name": "System Message",
"dynamic": false,
- "info": "Legacy field name for backward compatibility. New documents use dynamic fields (chunk_embedding_{model_name}) based on the embedding_model_name.",
+ "info": "A system message that helps set the behavior of the assistant",
+ "input_types": [
+ "Message"
+ ],
"list": false,
"list_add_label": "Add More",
"load_from_db": false,
- "name": "vector_field",
+ "multiline": true,
+ "name": "system_message",
"override_skip": false,
+ "password": false,
"placeholder": "",
"required": false,
"show": true,
"title_case": false,
"tool_mode": false,
+ "trace_as_input": true,
"trace_as_metadata": true,
"track_in_telemetry": false,
"type": "str",
- "value": "chunk_embedding"
+ "value": ""
},
- "verify_certs": {
- "_input_type": "BoolInput",
+ "temperature": {
+ "_input_type": "SliderInput",
"advanced": true,
"api_editable": false,
- "display_name": "Verify SSL Certificates",
+ "display_name": "Temperature",
"dynamic": false,
- "info": "Verify SSL certificates when connecting. Disable for self-signed certificates in development environments.",
- "list": false,
- "list_add_label": "Add More",
- "name": "verify_certs",
+ "info": "Controls randomness in responses",
+ "max_label": "",
+ "max_label_icon": "",
+ "min_label": "",
+ "min_label_icon": "",
+ "name": "temperature",
"override_skip": false,
"placeholder": "",
+ "range_spec": {
+ "max": 1,
+ "min": 0,
+ "step": 0.01,
+ "step_type": "float"
+ },
"required": false,
"show": true,
+ "slider_buttons": false,
+ "slider_buttons_options": [],
+ "slider_input": false,
"title_case": false,
"tool_mode": false,
- "trace_as_metadata": true,
- "track_in_telemetry": true,
- "type": "bool",
- "value": false
+ "track_in_telemetry": false,
+ "type": "slider",
+ "value": 0.1
}
},
"tool_mode": false
},
- "selected_output": "search_results",
- "showNode": true,
- "type": "ext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra"
+ "selected_output": "text_output",
+ "showNode": false,
+ "type": "OpenAICompatibleLLM"
},
"dragging": false,
- "id": "ext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-yrQui",
+ "id": "OpenAICompatibleLLM-0PA0e",
+ "measured": {
+ "height": 80,
+ "width": 192
+ },
"position": {
- "x": 312.88860073524836,
- "y": 764.4292322011722
+ "x": 1470.6414570903364,
+ "y": 1498.1551806347672
},
"selected": false,
"type": "genericNode"
}
],
"viewport": {
- "x": 183.79766761613433,
- "y": -199.9316452753764,
- "zoom": 0.4783040790459365
+ "x": 211.431330721966,
+ "y": -432.1026236483732,
+ "zoom": 0.6372803136596301
}
},
"description": "OpenRAG OpenSearch Nudges generator, based on the OpenSearch documents and the chat history.",
@@ -3693,7 +2862,7 @@
"id": "ebc01d31-1976-46ce-a385-b0240327226c",
"is_component": false,
"last_tested_version": "0.11.2",
- "locked": true,
+ "locked": false,
"name": "OpenRAG OpenSearch Nudges Flow",
"tags": [
"assistants",
diff --git a/flows/openrag_url_mcp.json b/flows/openrag_url_mcp.json
index 89614f8fc..42f60a7d3 100644
--- a/flows/openrag_url_mcp.json
+++ b/flows/openrag_url_mcp.json
@@ -182,61 +182,59 @@
},
{
"animated": false,
- "className": "",
"data": {
"sourceHandle": {
- "dataType": "EmbeddingModel",
- "id": "EmbeddingModel-4xlif",
- "name": "embeddings",
+ "dataType": "SplitText",
+ "id": "SplitText-QIKhg",
+ "name": "dataframe",
"output_types": [
- "Embeddings"
+ "Table"
]
},
"targetHandle": {
- "fieldName": "embedding",
- "id": "ext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-D6eM3",
+ "fieldName": "ingest_data",
+ "id": "OpenSearchVectorStoreComponentMultimodalMultiEmbedding-dihKf",
"inputTypes": [
- "Embeddings"
+ "Data",
+ "DataFrame",
+ "Table"
],
"type": "other"
}
},
- "id": "xy-edge__EmbeddingModel-4xlif{œdataTypeœ:œEmbeddingModelœ,œidœ:œEmbeddingModel-4xlifœ,œnameœ:œembeddingsœ,œoutput_typesœ:[œEmbeddingsœ]}-ext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-D6eM3{œfieldNameœ:œembeddingœ,œidœ:œext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-D6eM3œ,œinputTypesœ:[œEmbeddingsœ],œtypeœ:œotherœ}",
+ "id": "xy-edge__SplitText-QIKhg{œdataTypeœ:œSplitTextœ,œidœ:œSplitText-QIKhgœ,œnameœ:œdataframeœ,œoutput_typesœ:[œTableœ]}-OpenSearchVectorStoreComponentMultimodalMultiEmbedding-dihKf{œfieldNameœ:œingest_dataœ,œidœ:œOpenSearchVectorStoreComponentMultimodalMultiEmbedding-dihKfœ,œinputTypesœ:[œDataœ,œDataFrameœ,œTableœ],œtypeœ:œotherœ}",
"selected": false,
- "source": "EmbeddingModel-4xlif",
- "sourceHandle": "{œdataTypeœ:œEmbeddingModelœ,œidœ:œEmbeddingModel-4xlifœ,œnameœ:œembeddingsœ,œoutput_typesœ:[œEmbeddingsœ]}",
- "target": "ext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-D6eM3",
- "targetHandle": "{œfieldNameœ:œembeddingœ,œidœ:œext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-D6eM3œ,œinputTypesœ:[œEmbeddingsœ],œtypeœ:œotherœ}"
+ "source": "SplitText-QIKhg",
+ "sourceHandle": "{œdataTypeœ:œSplitTextœ,œidœ:œSplitText-QIKhgœ,œnameœ:œdataframeœ,œoutput_typesœ:[œTableœ]}",
+ "target": "OpenSearchVectorStoreComponentMultimodalMultiEmbedding-dihKf",
+ "targetHandle": "{œfieldNameœ:œingest_dataœ,œidœ:œOpenSearchVectorStoreComponentMultimodalMultiEmbedding-dihKfœ,œinputTypesœ:[œDataœ,œDataFrameœ,œTableœ],œtypeœ:œotherœ}"
},
{
"animated": false,
- "className": "",
"data": {
"sourceHandle": {
- "dataType": "SplitText",
- "id": "SplitText-QIKhg",
- "name": "dataframe",
+ "dataType": "OpenAICompatibleEmbedding",
+ "id": "OpenAICompatibleEmbedding-aIHce",
+ "name": "embeddings",
"output_types": [
- "Table"
+ "Embeddings"
]
},
"targetHandle": {
- "fieldName": "ingest_data",
- "id": "ext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-D6eM3",
+ "fieldName": "embedding",
+ "id": "OpenSearchVectorStoreComponentMultimodalMultiEmbedding-dihKf",
"inputTypes": [
- "Data",
- "DataFrame",
- "Table"
+ "Embeddings"
],
"type": "other"
}
},
- "id": "xy-edge__SplitText-QIKhg{œdataTypeœ:œSplitTextœ,œidœ:œSplitText-QIKhgœ,œnameœ:œdataframeœ,œoutput_typesœ:[œTableœ]}-ext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-D6eM3{œfieldNameœ:œingest_dataœ,œidœ:œext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-D6eM3œ,œinputTypesœ:[œDataœ,œDataFrameœ,œTableœ],œtypeœ:œotherœ}",
+ "id": "xy-edge__OpenAICompatibleEmbedding-aIHce{œdataTypeœ:œOpenAICompatibleEmbeddingœ,œidœ:œOpenAICompatibleEmbedding-aIHceœ,œnameœ:œembeddingsœ,œoutput_typesœ:[œEmbeddingsœ]}-OpenSearchVectorStoreComponentMultimodalMultiEmbedding-dihKf{œfieldNameœ:œembeddingœ,œidœ:œOpenSearchVectorStoreComponentMultimodalMultiEmbedding-dihKfœ,œinputTypesœ:[œEmbeddingsœ],œtypeœ:œotherœ}",
"selected": false,
- "source": "SplitText-QIKhg",
- "sourceHandle": "{œdataTypeœ:œSplitTextœ,œidœ:œSplitText-QIKhgœ,œnameœ:œdataframeœ,œoutput_typesœ:[œTableœ]}",
- "target": "ext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-D6eM3",
- "targetHandle": "{œfieldNameœ:œingest_dataœ,œidœ:œext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-D6eM3œ,œinputTypesœ:[œDataœ,œDataFrameœ,œTableœ],œtypeœ:œotherœ}"
+ "source": "OpenAICompatibleEmbedding-aIHce",
+ "sourceHandle": "{œdataTypeœ:œOpenAICompatibleEmbeddingœ,œidœ:œOpenAICompatibleEmbedding-aIHceœ,œnameœ:œembeddingsœ,œoutput_typesœ:[œEmbeddingsœ]}",
+ "target": "OpenSearchVectorStoreComponentMultimodalMultiEmbedding-dihKf",
+ "targetHandle": "{œfieldNameœ:œembeddingœ,œidœ:œOpenSearchVectorStoreComponentMultimodalMultiEmbedding-dihKfœ,œinputTypesœ:[œEmbeddingsœ],œtypeœ:œotherœ}"
}
],
"nodes": [
@@ -498,13 +496,18 @@
"tool_mode": false
},
"selected_output": "chunks",
+ "showNode": false,
"type": "SplitText"
},
"dragging": false,
"id": "SplitText-QIKhg",
+ "measured": {
+ "height": 80,
+ "width": 192
+ },
"position": {
- "x": 2332.4637753484953,
- "y": 1432.2596523183522
+ "x": 2022.4035325410573,
+ "y": 1615.010391456511
},
"positionAbsolute": {
"x": 1683.4543896546102,
@@ -941,14 +944,18 @@
"tool_mode": false
},
"selected_output": "page_results",
- "showNode": true,
+ "showNode": false,
"type": "URLComponent"
},
"dragging": false,
"id": "URLComponent-lnA0q",
+ "measured": {
+ "height": 52,
+ "width": 192
+ },
"position": {
- "x": 1096.8262171482047,
- "y": 1435.8586464311813
+ "x": 1115.3066289711646,
+ "y": 1622.0353383977624
},
"selected": false,
"type": "genericNode"
@@ -1235,14 +1242,18 @@
},
"tool_mode": false
},
- "showNode": true,
+ "showNode": false,
"type": "ChatInput"
},
"dragging": false,
"id": "ChatInput-sskrk",
+ "measured": {
+ "height": 52,
+ "width": 192
+ },
"position": {
- "x": 682.6862404451078,
- "y": 1455.821005659169
+ "x": 827.8885363214571,
+ "y": 1622.940629214967
},
"selected": false,
"type": "genericNode"
@@ -1540,9 +1551,13 @@
},
"dragging": false,
"id": "ChatOutput-0XHyo",
+ "measured": {
+ "height": 52,
+ "width": 192
+ },
"position": {
- "x": 3588.211427790188,
- "y": 1759.283136230774
+ "x": 2675.9026631331253,
+ "y": 1625.0395041941492
},
"selected": false,
"type": "genericNode"
@@ -2817,726 +2832,71 @@
"advanced": false,
"ai_enabled": false,
"api_editable": false,
- "copy_field": false,
- "display_name": "Text",
- "dynamic": false,
- "info": "The input text to process.",
- "input_types": [
- "Message"
- ],
- "list": false,
- "list_add_label": "Add More",
- "load_from_db": false,
- "multiline": true,
- "name": "text_input",
- "override_skip": false,
- "password": false,
- "placeholder": "",
- "required": false,
- "show": false,
- "title_case": false,
- "tool_mode": false,
- "trace_as_input": true,
- "trace_as_metadata": true,
- "track_in_telemetry": false,
- "type": "str",
- "value": ""
- },
- "text_input_2": {
- "_input_type": "MultilineInput",
- "advanced": false,
- "ai_enabled": false,
- "api_editable": false,
- "copy_field": false,
- "display_name": "Second Text Input",
- "dynamic": true,
- "info": "Second text to join with the first text.",
- "input_types": [
- "Message"
- ],
- "list": false,
- "list_add_label": "Add More",
- "load_from_db": false,
- "multiline": true,
- "name": "text_input_2",
- "override_skip": false,
- "password": false,
- "placeholder": "",
- "required": false,
- "show": false,
- "title_case": false,
- "tool_mode": false,
- "trace_as_input": true,
- "trace_as_metadata": true,
- "track_in_telemetry": false,
- "type": "str",
- "value": ""
- },
- "use_regex": {
- "_input_type": "BoolInput",
- "advanced": false,
- "api_editable": false,
- "display_name": "Use Regex",
- "dynamic": true,
- "info": "Whether to treat search pattern as regex.",
- "list": false,
- "list_add_label": "Add More",
- "name": "use_regex",
- "override_skip": false,
- "placeholder": "",
- "required": false,
- "show": false,
- "title_case": false,
- "tool_mode": false,
- "trace_as_metadata": true,
- "track_in_telemetry": true,
- "type": "bool",
- "value": false
- }
- },
- "tool_mode": false
- },
- "showNode": true,
- "type": "Operations"
- },
- "dragging": false,
- "id": "Operations-uhog5",
- "position": {
- "x": 3160.0211180473734,
- "y": 1481.6904008526296
- },
- "selected": false,
- "type": "genericNode"
- },
- {
- "data": {
- "_connectionMode": false,
- "id": "EmbeddingModel-4xlif",
- "node": {
- "base_classes": [
- "Embeddings"
- ],
- "beta": false,
- "conditional_paths": [],
- "custom_fields": {},
- "description": "Generate embeddings using a specified provider.",
- "display_name": "Embedding Model",
- "documentation": "https://docs.langflow.org/components-embedding-models",
- "edited": false,
- "field_order": [
- "model",
- "model_name",
- "provider",
- "api_key",
- "api_base",
- "base_url_ibm_watsonx",
- "project_id",
- "ollama_base_url",
- "dimensions",
- "chunk_size",
- "request_timeout",
- "max_retries",
- "show_progress_bar",
- "model_kwargs",
- "truncate_input_tokens",
- "input_text"
- ],
- "frozen": false,
- "icon": "binary",
- "last_updated": "2026-07-30T17:16:03.625Z",
- "legacy": false,
- "lf_version": "0.11.1rc0",
- "metadata": {
- "code_hash": "0780e9bbc5fa",
- "dependencies": {
- "dependencies": [
- {
- "name": "lfx",
- "version": null
- }
- ],
- "total_dependencies": 1
- },
- "module": "lfx.components.models_and_agents.embedding_model.EmbeddingModelComponent"
- },
- "minimized": false,
- "output_types": [],
- "outputs": [
- {
- "allows_loop": false,
- "cache": true,
- "display_name": "Embedding Model",
- "group_outputs": false,
- "hidden": null,
- "loop_types": null,
- "method": "build_embeddings",
- "name": "embeddings",
- "options": null,
- "required_inputs": null,
- "selected": "Embeddings",
- "tool_mode": true,
- "types": [
- "Embeddings"
- ],
- "value": "__UNDEFINED__"
- }
- ],
- "pinned": false,
- "template": {
- "_frontend_node_flow_id": {
- "value": "72c3d17c-2dac-4a73-b48a-6518473d7830"
- },
- "_frontend_node_folder_id": {
- "value": "203c7c12-9e1d-4561-bb14-16102afec154"
- },
- "_type": "Component",
- "api_base": {
- "_input_type": "MessageTextInput",
- "advanced": true,
- "api_editable": false,
- "display_name": "API Base URL",
- "dynamic": false,
- "info": "Base URL for the API. Leave empty for default.",
- "input_types": [
- "Message"
- ],
- "list": false,
- "list_add_label": "Add More",
- "load_from_db": false,
- "name": "api_base",
- "override_skip": false,
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_input": true,
- "trace_as_metadata": true,
- "track_in_telemetry": false,
- "type": "str",
- "value": ""
- },
- "api_key": {
- "_input_type": "SecretStrInput",
- "advanced": true,
- "api_editable": false,
- "display_name": "API Key",
- "dynamic": false,
- "info": "Overrides global provider settings. Leave blank to use your pre-configured API Key.",
- "input_types": [],
- "load_from_db": false,
- "name": "api_key",
- "override_skip": false,
- "password": true,
- "placeholder": "",
- "real_time_refresh": true,
- "required": false,
- "show": true,
- "title_case": false,
- "track_in_telemetry": false,
- "type": "str",
- "value": ""
- },
- "base_url_ibm_watsonx": {
- "_input_type": "DropdownInput",
- "advanced": true,
- "api_editable": false,
- "combobox": true,
- "dialog_inputs": {},
- "display_name": "watsonx API Endpoint",
- "dynamic": false,
- "external_options": {},
- "info": "The base URL of the API (IBM watsonx.ai only)",
- "load_from_db": false,
- "name": "base_url_ibm_watsonx",
- "options": [
- "https://us-south.ml.cloud.ibm.com",
- "https://eu-de.ml.cloud.ibm.com",
- "https://eu-gb.ml.cloud.ibm.com",
- "https://au-syd.ml.cloud.ibm.com",
- "https://jp-tok.ml.cloud.ibm.com",
- "https://ca-tor.ml.cloud.ibm.com"
- ],
- "options_metadata": [],
- "override_skip": false,
- "placeholder": "",
- "real_time_refresh": true,
- "required": false,
- "show": false,
- "title_case": false,
- "toggle": false,
- "tool_mode": false,
- "trace_as_metadata": true,
- "track_in_telemetry": true,
- "type": "str",
- "value": "https://us-south.ml.cloud.ibm.com"
- },
- "chunk_size": {
- "_input_type": "IntInput",
- "advanced": true,
- "api_editable": false,
- "display_name": "Chunk Size",
- "dynamic": false,
- "info": "",
- "list": false,
- "list_add_label": "Add More",
- "name": "chunk_size",
- "override_skip": false,
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_metadata": true,
- "track_in_telemetry": true,
- "type": "int",
- "value": 1000
- },
- "code": {
- "advanced": true,
- "api_editable": false,
- "dynamic": true,
- "fileTypes": [],
- "file_path": "",
- "info": "",
- "list": false,
- "load_from_db": false,
- "multiline": true,
- "name": "code",
- "password": false,
- "placeholder": "",
- "required": true,
- "show": true,
- "title_case": false,
- "type": "code",
- "value": "from lfx.base.embeddings.model import LCEmbeddingsModel\nfrom lfx.base.models.unified_models import (\n get_embedding_model_options,\n get_embeddings,\n handle_model_input_update,\n)\nfrom lfx.base.models.watsonx_constants import IBM_WATSONX_URLS\nfrom lfx.components.models_and_agents.model_selection import apply_model_overrides\nfrom lfx.field_typing import Embeddings\nfrom lfx.io import (\n BoolInput,\n DictInput,\n DropdownInput,\n FloatInput,\n IntInput,\n MessageTextInput,\n ModelInput,\n SecretStrInput,\n StrInput,\n)\n\n\nclass EmbeddingModelComponent(LCEmbeddingsModel):\n display_name = \"Embedding Model\"\n description = \"Generate embeddings using a specified provider.\"\n documentation: str = \"https://docs.langflow.org/components-embedding-models\"\n icon = \"binary\"\n name = \"EmbeddingModel\"\n category = \"models\"\n\n def update_build_config(self, build_config: dict, field_value: str, field_name: str | None = None):\n \"\"\"Dynamically update build config with user-filtered model options.\"\"\"\n return handle_model_input_update(\n self,\n dict(build_config),\n field_value,\n field_name,\n cache_key_prefix=\"embedding_model_options\",\n get_options_func=get_embedding_model_options,\n )\n\n inputs = [\n ModelInput(\n name=\"model\",\n display_name=\"Embedding Model\",\n info=\"Select your model provider\",\n real_time_refresh=True,\n required=True,\n model_type=\"embedding\",\n input_types=[\"Embeddings\"], # Override default to accept Embeddings instead of LanguageModel\n ),\n StrInput(\n name=\"model_name\",\n display_name=\"Model Name Override\",\n info=(\n \"Optional embedding model name to use instead of the selected model. \"\n \"Can be set from a global variable for runtime model selection.\"\n ),\n advanced=True,\n load_from_db=False,\n ),\n StrInput(\n name=\"provider\",\n display_name=\"Provider Override\",\n info=(\n \"Optional provider to use with Model Name Override. Leave blank to use the selected model's provider.\"\n ),\n advanced=True,\n load_from_db=False,\n ),\n SecretStrInput(\n name=\"api_key\",\n display_name=\"API Key\",\n info=\"Overrides global provider settings. Leave blank to use your pre-configured API Key.\",\n real_time_refresh=True,\n advanced=True,\n ),\n MessageTextInput(\n name=\"api_base\",\n display_name=\"API Base URL\",\n info=\"Base URL for the API. Leave empty for default.\",\n advanced=True,\n ),\n # Watson-specific inputs\n DropdownInput(\n name=\"base_url_ibm_watsonx\",\n display_name=\"watsonx API Endpoint\",\n info=\"The base URL of the API (IBM watsonx.ai only)\",\n options=IBM_WATSONX_URLS,\n value=IBM_WATSONX_URLS[0],\n combobox=True,\n show=False,\n real_time_refresh=True,\n ),\n MessageTextInput(\n name=\"project_id\",\n display_name=\"Project ID\",\n info=\"IBM watsonx.ai Project ID (required for IBM watsonx.ai)\",\n show=False,\n ),\n # Ollama-specific input\n StrInput(\n name=\"ollama_base_url\",\n display_name=\"Ollama API URL\",\n info=\"Endpoint of the Ollama API (Ollama only)\",\n show=False,\n real_time_refresh=True,\n ),\n IntInput(\n name=\"dimensions\",\n display_name=\"Dimensions\",\n info=\"The number of dimensions the resulting output embeddings should have. \"\n \"Only supported by certain models.\",\n advanced=True,\n ),\n IntInput(\n name=\"chunk_size\",\n display_name=\"Chunk Size\",\n advanced=True,\n value=1000,\n ),\n FloatInput(\n name=\"request_timeout\",\n display_name=\"Request Timeout\",\n advanced=True,\n ),\n IntInput(\n name=\"max_retries\",\n display_name=\"Max Retries\",\n advanced=True,\n value=3,\n ),\n BoolInput(\n name=\"show_progress_bar\",\n display_name=\"Show Progress Bar\",\n advanced=True,\n ),\n DictInput(\n name=\"model_kwargs\",\n display_name=\"Model Kwargs\",\n advanced=True,\n info=(\n \"Additional keyword arguments to pass to the model. Only used by providers that support this parameter \"\n \"(e.g. OpenAI, Google Generative AI). \"\n \"Ignored for providers that do not include it in their parameter mapping.\"\n ),\n ),\n IntInput(\n name=\"truncate_input_tokens\",\n display_name=\"Truncate Input Tokens\",\n advanced=True,\n value=200,\n show=False,\n ),\n BoolInput(\n name=\"input_text\",\n display_name=\"Include the original text in the output\",\n value=True,\n advanced=True,\n show=False,\n ),\n ]\n\n def build_embeddings(self) -> Embeddings:\n \"\"\"Build and return an embeddings instance based on the selected model.\"\"\"\n model = apply_model_overrides(\n self.model,\n model_name=getattr(self, \"model_name\", None),\n provider=getattr(self, \"provider\", None),\n user_id=self.user_id,\n get_options=get_embedding_model_options,\n )\n return get_embeddings(\n model=model,\n user_id=self.user_id,\n api_key=self.api_key,\n api_base=self.api_base,\n dimensions=self.dimensions,\n chunk_size=self.chunk_size,\n request_timeout=self.request_timeout,\n max_retries=self.max_retries,\n show_progress_bar=self.show_progress_bar,\n model_kwargs=self.model_kwargs,\n watsonx_url=getattr(self, \"base_url_ibm_watsonx\", None),\n watsonx_project_id=getattr(self, \"project_id\", None),\n watsonx_truncate_input_tokens=getattr(self, \"truncate_input_tokens\", None),\n watsonx_input_text=getattr(self, \"input_text\", None),\n ollama_base_url=getattr(self, \"ollama_base_url\", None),\n )\n"
- },
- "dimensions": {
- "_input_type": "IntInput",
- "advanced": true,
- "api_editable": false,
- "display_name": "Dimensions",
- "dynamic": false,
- "info": "The number of dimensions the resulting output embeddings should have. Only supported by certain models.",
- "list": false,
- "list_add_label": "Add More",
- "name": "dimensions",
- "override_skip": false,
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_metadata": true,
- "track_in_telemetry": true,
- "type": "int",
- "value": 0
- },
- "input_text": {
- "_input_type": "BoolInput",
- "advanced": true,
- "api_editable": false,
- "display_name": "Include the original text in the output",
- "dynamic": false,
- "info": "",
- "list": false,
- "list_add_label": "Add More",
- "name": "input_text",
- "override_skip": false,
- "placeholder": "",
- "required": false,
- "show": false,
- "title_case": false,
- "tool_mode": false,
- "trace_as_metadata": true,
- "track_in_telemetry": true,
- "type": "bool",
- "value": true
- },
- "is_refresh": true,
- "max_retries": {
- "_input_type": "IntInput",
- "advanced": true,
- "api_editable": false,
- "display_name": "Max Retries",
- "dynamic": false,
- "info": "",
- "list": false,
- "list_add_label": "Add More",
- "name": "max_retries",
- "override_skip": false,
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_metadata": true,
- "track_in_telemetry": true,
- "type": "int",
- "value": 3
- },
- "model": {
- "_input_type": "ModelInput",
- "advanced": true,
- "api_editable": false,
- "display_name": "Embedding Model",
- "dynamic": false,
- "external_options": {
- "fields": {
- "data": {
- "node": {
- "display_name": "Connect other models",
- "icon": "CornerDownLeft",
- "name": "connect_other_models"
- }
- }
- }
- },
- "info": "Select your model provider",
- "input_types": [
- "Embeddings"
- ],
- "list": false,
- "list_add_label": "Add More",
- "model_type": "embedding",
- "name": "model",
- "options": [
- {
- "category": "OpenAI",
- "icon": "OpenAI",
- "metadata": {
- "embedding_class": "OpenAIEmbeddings",
- "model_type": "embeddings",
- "param_mapping": {
- "api_base": "base_url",
- "api_key": "api_key",
- "chunk_size": "chunk_size",
- "dimensions": "dimensions",
- "max_retries": "max_retries",
- "model": "model",
- "model_kwargs": "model_kwargs",
- "request_timeout": "timeout",
- "show_progress_bar": "show_progress_bar"
- }
- },
- "name": "text-embedding-3-large",
- "provider": "OpenAI"
- },
- {
- "category": "OpenAI",
- "icon": "OpenAI",
- "metadata": {
- "embedding_class": "OpenAIEmbeddings",
- "model_type": "embeddings",
- "param_mapping": {
- "api_base": "base_url",
- "api_key": "api_key",
- "chunk_size": "chunk_size",
- "dimensions": "dimensions",
- "max_retries": "max_retries",
- "model": "model",
- "model_kwargs": "model_kwargs",
- "request_timeout": "timeout",
- "show_progress_bar": "show_progress_bar"
- }
- },
- "name": "text-embedding-3-small",
- "provider": "OpenAI"
- },
- {
- "category": "OpenAI",
- "icon": "OpenAI",
- "metadata": {
- "embedding_class": "OpenAIEmbeddings",
- "model_type": "embeddings",
- "param_mapping": {
- "api_base": "base_url",
- "api_key": "api_key",
- "chunk_size": "chunk_size",
- "dimensions": "dimensions",
- "max_retries": "max_retries",
- "model": "model",
- "model_kwargs": "model_kwargs",
- "request_timeout": "timeout",
- "show_progress_bar": "show_progress_bar"
- }
- },
- "name": "text-embedding-ada-002",
- "provider": "OpenAI"
- },
- {
- "category": "IBM WatsonX",
- "icon": "WatsonxAI",
- "metadata": {
- "embedding_class": "WatsonxEmbeddings",
- "model_type": "embeddings",
- "param_mapping": {
- "api_key": "apikey",
- "model_id": "model_id",
- "project_id": "project_id",
- "request_timeout": "request_timeout",
- "space_id": "space_id",
- "url": "url"
- }
- },
- "name": "ibm/granite-embedding-278m-multilingual",
- "provider": "IBM WatsonX"
- },
- {
- "category": "IBM WatsonX",
- "icon": "WatsonxAI",
- "metadata": {
- "embedding_class": "WatsonxEmbeddings",
- "model_type": "embeddings",
- "param_mapping": {
- "api_key": "apikey",
- "model_id": "model_id",
- "project_id": "project_id",
- "request_timeout": "request_timeout",
- "space_id": "space_id",
- "url": "url"
- }
- },
- "name": "ibm/slate-125m-english-rtrvr-v2",
- "provider": "IBM WatsonX"
- },
- {
- "category": "IBM WatsonX",
- "icon": "WatsonxAI",
- "metadata": {
- "embedding_class": "WatsonxEmbeddings",
- "model_type": "embeddings",
- "param_mapping": {
- "api_key": "apikey",
- "model_id": "model_id",
- "project_id": "project_id",
- "request_timeout": "request_timeout",
- "space_id": "space_id",
- "url": "url"
- }
- },
- "name": "ibm/slate-30m-english-rtrvr-v2",
- "provider": "IBM WatsonX"
- },
- {
- "category": "IBM WatsonX",
- "icon": "WatsonxAI",
- "metadata": {
- "embedding_class": "WatsonxEmbeddings",
- "model_type": "embeddings",
- "param_mapping": {
- "api_key": "apikey",
- "model_id": "model_id",
- "project_id": "project_id",
- "request_timeout": "request_timeout",
- "space_id": "space_id",
- "url": "url"
- }
- },
- "name": "intfloat/multilingual-e5-large",
- "provider": "IBM WatsonX"
- }
- ],
- "override_skip": false,
- "placeholder": "Setup Provider",
- "real_time_refresh": true,
- "refresh_button": true,
- "required": true,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_input": true,
- "track_in_telemetry": false,
- "type": "model",
- "value": [
- {
- "icon": "OpenAI",
- "metadata": {
- "embedding_class": "OpenAIEmbeddings",
- "model_type": "embeddings",
- "param_mapping": {
- "api_base": "base_url",
- "api_key": "api_key",
- "chunk_size": "chunk_size",
- "dimensions": "dimensions",
- "max_retries": "max_retries",
- "model": "model",
- "model_kwargs": "model_kwargs",
- "request_timeout": "timeout",
- "show_progress_bar": "show_progress_bar"
- }
- },
- "name": "text-embedding-3-large",
- "provider": "OpenAI"
- }
- ]
- },
- "model_kwargs": {
- "_input_type": "DictInput",
- "advanced": true,
- "api_editable": false,
- "display_name": "Model Kwargs",
- "dynamic": false,
- "info": "Additional keyword arguments to pass to the model. Only used by providers that support this parameter (e.g. OpenAI, Google Generative AI). Ignored for providers that do not include it in their parameter mapping.",
- "list": false,
- "list_add_label": "Add More",
- "name": "model_kwargs",
- "override_skip": false,
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_input": true,
- "track_in_telemetry": false,
- "type": "dict",
- "value": {}
- },
- "model_name": {
- "_input_type": "StrInput",
- "advanced": false,
- "api_editable": false,
- "display_name": "Model Name Override",
- "dynamic": false,
- "info": "Optional embedding model name to use instead of the selected model. Can be set from a global variable for runtime model selection.",
- "list": false,
- "list_add_label": "Add More",
- "load_from_db": true,
- "name": "model_name",
- "override_skip": false,
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_metadata": true,
- "track_in_telemetry": false,
- "type": "str",
- "value": "SELECTED_EMBEDDING_MODEL"
- },
- "ollama_base_url": {
- "_input_type": "StrInput",
- "advanced": false,
- "api_editable": false,
- "display_name": "Ollama API URL",
- "dynamic": false,
- "info": "Endpoint of the Ollama API (Ollama only)",
- "list": false,
- "list_add_label": "Add More",
- "load_from_db": false,
- "name": "ollama_base_url",
- "override_skip": false,
- "placeholder": "",
- "real_time_refresh": true,
- "required": false,
- "show": false,
- "title_case": false,
- "tool_mode": false,
- "trace_as_metadata": true,
- "track_in_telemetry": false,
- "type": "str",
- "value": ""
- },
- "project_id": {
- "_input_type": "MessageTextInput",
- "advanced": true,
- "api_editable": false,
- "display_name": "Project ID",
- "dynamic": false,
- "info": "IBM watsonx.ai Project ID (required for IBM watsonx.ai)",
- "input_types": [
- "Message"
- ],
- "list": false,
- "list_add_label": "Add More",
- "load_from_db": true,
- "name": "project_id",
- "override_skip": false,
- "placeholder": "",
- "required": false,
- "show": false,
- "title_case": false,
- "tool_mode": false,
- "trace_as_input": true,
- "trace_as_metadata": true,
- "track_in_telemetry": false,
- "type": "str",
- "value": "WATSONX_PROJECT_ID"
- },
- "provider": {
- "_input_type": "StrInput",
- "advanced": false,
- "api_editable": false,
- "display_name": "Provider Override",
- "dynamic": false,
- "info": "Optional provider to use with Model Name Override. Leave blank to use the selected model's provider.",
- "list": false,
- "list_add_label": "Add More",
- "load_from_db": true,
- "name": "provider",
- "override_skip": false,
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_metadata": true,
- "track_in_telemetry": false,
- "type": "str",
- "value": "SELECTED_EMBEDDING_MODEL_PROVIDER"
- },
- "request_timeout": {
- "_input_type": "FloatInput",
- "advanced": true,
- "api_editable": false,
- "display_name": "Request Timeout",
+ "copy_field": false,
+ "display_name": "Text",
"dynamic": false,
- "info": "",
+ "info": "The input text to process.",
+ "input_types": [
+ "Message"
+ ],
"list": false,
"list_add_label": "Add More",
- "name": "request_timeout",
+ "load_from_db": false,
+ "multiline": true,
+ "name": "text_input",
"override_skip": false,
+ "password": false,
"placeholder": "",
"required": false,
- "show": true,
+ "show": false,
"title_case": false,
"tool_mode": false,
+ "trace_as_input": true,
"trace_as_metadata": true,
- "track_in_telemetry": true,
- "type": "float",
+ "track_in_telemetry": false,
+ "type": "str",
"value": ""
},
- "show_progress_bar": {
- "_input_type": "BoolInput",
- "advanced": true,
+ "text_input_2": {
+ "_input_type": "MultilineInput",
+ "advanced": false,
+ "ai_enabled": false,
"api_editable": false,
- "display_name": "Show Progress Bar",
- "dynamic": false,
- "info": "",
+ "copy_field": false,
+ "display_name": "Second Text Input",
+ "dynamic": true,
+ "info": "Second text to join with the first text.",
+ "input_types": [
+ "Message"
+ ],
"list": false,
"list_add_label": "Add More",
- "name": "show_progress_bar",
+ "load_from_db": false,
+ "multiline": true,
+ "name": "text_input_2",
"override_skip": false,
+ "password": false,
"placeholder": "",
"required": false,
- "show": true,
+ "show": false,
"title_case": false,
"tool_mode": false,
+ "trace_as_input": true,
"trace_as_metadata": true,
- "track_in_telemetry": true,
- "type": "bool",
- "value": false
+ "track_in_telemetry": false,
+ "type": "str",
+ "value": ""
},
- "truncate_input_tokens": {
- "_input_type": "IntInput",
- "advanced": true,
+ "use_regex": {
+ "_input_type": "BoolInput",
+ "advanced": false,
"api_editable": false,
- "display_name": "Truncate Input Tokens",
- "dynamic": false,
- "info": "",
+ "display_name": "Use Regex",
+ "dynamic": true,
+ "info": "Whether to treat search pattern as regex.",
"list": false,
"list_add_label": "Add More",
- "name": "truncate_input_tokens",
+ "name": "use_regex",
"override_skip": false,
"placeholder": "",
"required": false,
@@ -3545,20 +2905,24 @@
"tool_mode": false,
"trace_as_metadata": true,
"track_in_telemetry": true,
- "type": "int",
- "value": 200
+ "type": "bool",
+ "value": false
}
},
"tool_mode": false
},
"showNode": false,
- "type": "EmbeddingModel"
+ "type": "Operations"
},
"dragging": false,
- "id": "EmbeddingModel-4xlif",
+ "id": "Operations-uhog5",
+ "measured": {
+ "height": 52,
+ "width": 192
+ },
"position": {
- "x": 2444.1500041374215,
- "y": 2107.674145700942
+ "x": 2376.4766535070735,
+ "y": 1459.7730731731808
},
"selected": false,
"type": "genericNode"
@@ -4912,14 +4276,18 @@
},
"tool_mode": false
},
- "showNode": true,
+ "showNode": false,
"type": "Operations"
},
"dragging": false,
"id": "Operations-jsRu6",
+ "measured": {
+ "height": 52,
+ "width": 192
+ },
"position": {
- "x": 1516.6788573085516,
- "y": 1370.0763185443127
+ "x": 1393.4815933361858,
+ "y": 1620.5940492140244
},
"selected": false,
"type": "genericNode"
@@ -6273,36 +5641,243 @@
},
"tool_mode": false
},
- "showNode": true,
+ "showNode": false,
"type": "Operations"
},
"dragging": false,
"id": "Operations-fX1Im",
+ "measured": {
+ "height": 52,
+ "width": 192
+ },
+ "position": {
+ "x": 1701.888054410499,
+ "y": 1622.9090207014667
+ },
+ "selected": false,
+ "type": "genericNode"
+ },
+ {
+ "data": {
+ "id": "OpenAICompatibleEmbedding-aIHce",
+ "node": {
+ "base_classes": [
+ "Embeddings"
+ ],
+ "beta": false,
+ "conditional_paths": [],
+ "custom_fields": {},
+ "description": "Embeddings via OpenRAG's OpenAI-compatible /v1 proxy. Uses the same base URL and hop token as the chat component.",
+ "display_name": "OpenRAG Embeddings",
+ "documentation": "",
+ "edited": false,
+ "field_order": [
+ "model_name",
+ "api_key",
+ "api_base",
+ "dimensions",
+ "chunk_size"
+ ],
+ "frozen": false,
+ "icon": "OpenRAG",
+ "legacy": false,
+ "metadata": {
+ "code_hash": "cc257e587747",
+ "dependencies": {
+ "dependencies": [
+ {
+ "name": "langchain_openai",
+ "version": "1.5.2"
+ },
+ {
+ "name": "lfx",
+ "version": "1.11.2"
+ }
+ ],
+ "total_dependencies": 2
+ },
+ "module": "custom_components.openrag_embeddings"
+ },
+ "minimized": false,
+ "output_types": [],
+ "outputs": [
+ {
+ "allows_loop": false,
+ "cache": true,
+ "display_name": "Embedding Model",
+ "group_outputs": false,
+ "method": "build_embeddings",
+ "name": "embeddings",
+ "selected": "Embeddings",
+ "tool_mode": true,
+ "types": [
+ "Embeddings"
+ ],
+ "value": "__UNDEFINED__"
+ }
+ ],
+ "pinned": false,
+ "template": {
+ "_type": "Component",
+ "api_base": {
+ "_input_type": "StrInput",
+ "advanced": false,
+ "api_editable": false,
+ "display_name": "OpenAI API Base",
+ "dynamic": false,
+ "info": "Must end with /v1 (for example http://openrag-backend:8000/v1). Bound to OPENRAG_LLM_BASE_URL at runtime. Same URL as chat.",
+ "list": false,
+ "list_add_label": "Add More",
+ "load_from_db": true,
+ "name": "api_base",
+ "override_skip": false,
+ "placeholder": "",
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "tool_mode": false,
+ "trace_as_metadata": true,
+ "track_in_telemetry": false,
+ "type": "str",
+ "value": "OPENRAG_LLM_BASE_URL"
+ },
+ "api_key": {
+ "_input_type": "SecretStrInput",
+ "advanced": false,
+ "api_editable": false,
+ "display_name": "OpenRAG LLM Token",
+ "dynamic": false,
+ "info": "Hop token from OPENRAG_LLM_TOKEN. Same token as the chat component.",
+ "input_types": [],
+ "load_from_db": true,
+ "name": "api_key",
+ "override_skip": false,
+ "password": true,
+ "placeholder": "",
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "track_in_telemetry": false,
+ "type": "str",
+ "value": "OPENRAG_LLM_TOKEN"
+ },
+ "chunk_size": {
+ "_input_type": "IntInput",
+ "advanced": true,
+ "api_editable": false,
+ "display_name": "Chunk Size",
+ "dynamic": false,
+ "info": "",
+ "list": false,
+ "list_add_label": "Add More",
+ "name": "chunk_size",
+ "override_skip": false,
+ "placeholder": "",
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "tool_mode": false,
+ "trace_as_metadata": true,
+ "track_in_telemetry": true,
+ "type": "int",
+ "value": 1000
+ },
+ "code": {
+ "advanced": true,
+ "api_editable": false,
+ "dynamic": true,
+ "fileTypes": [],
+ "file_path": "",
+ "info": "",
+ "list": false,
+ "load_from_db": false,
+ "multiline": true,
+ "name": "code",
+ "password": false,
+ "placeholder": "",
+ "required": true,
+ "show": true,
+ "title_case": false,
+ "type": "code",
+ "value": "\"\"\"OpenAI-compatible embeddings that talk to the OpenRAG `/v1` proxy.\n\nEmbeddings work the same way as chat: Langflow never holds upstream vendor\nkeys. At runtime OpenRAG injects:\n\n- ``OPENRAG_LLM_TOKEN`` — the same short-lived hop token as chat\n- ``OPENRAG_LLM_BASE_URL`` — the same ``http://<backend>/v1`` base URL\n- ``SELECTED_EMBEDDING_MODEL`` — configured embedding model id\n\n``OpenAIEmbeddings`` posts to ``{base_url}/embeddings``. The backend gateway\nroutes by the configured embedding provider (which can differ from the chat\nprovider).\n\"\"\"\n\nfrom __future__ import annotations\n\nfrom typing import Any\n\nfrom langchain_openai import OpenAIEmbeddings\nfrom lfx.base.embeddings.model import LCEmbeddingsModel\nfrom lfx.field_typing import Embeddings\nfrom lfx.io import IntInput, SecretStrInput, StrInput\n\n# Names must match src/api/settings/langflow_sync.py + src/utils/langflow_headers.py\nOPENRAG_LLM_BASE_URL_VAR = \"OPENRAG_LLM_BASE_URL\"\nOPENRAG_LLM_TOKEN_VAR = \"OPENRAG_LLM_TOKEN\"\nSELECTED_EMBEDDING_MODEL_VAR = \"SELECTED_EMBEDDING_MODEL\"\n\n\ndef _as_str(value: object) -> str | None:\n if value is None:\n return None\n getter = getattr(value, \"get_secret_value\", None)\n if callable(getter):\n value = getter()\n text = str(value).strip()\n return text or None\n\n\nclass OpenAICompatibleEmbeddingComponent(LCEmbeddingsModel):\n display_name = \"OpenRAG Embeddings\"\n description = (\n \"Embeddings via OpenRAG's OpenAI-compatible /v1 proxy. \"\n \"Uses the same base URL and hop token as the chat component.\"\n )\n icon = \"OpenRAG\"\n name = \"OpenAICompatibleEmbedding\"\n\n inputs = [\n StrInput(\n name=\"model_name\",\n display_name=\"Model Name\",\n info=\"Embedding model id. Bound to SELECTED_EMBEDDING_MODEL at runtime.\",\n value=SELECTED_EMBEDDING_MODEL_VAR,\n load_from_db=True,\n ),\n SecretStrInput(\n name=\"api_key\",\n display_name=\"OpenRAG LLM Token\",\n info=\"Hop token from OPENRAG_LLM_TOKEN. Same token as the chat component.\",\n value=OPENRAG_LLM_TOKEN_VAR,\n required=False,\n load_from_db=True,\n ),\n StrInput(\n name=\"api_base\",\n display_name=\"OpenAI API Base\",\n info=(\n \"Must end with /v1 (for example http://openrag-backend:8000/v1). \"\n \"Bound to OPENRAG_LLM_BASE_URL at runtime. Same URL as chat.\"\n ),\n value=OPENRAG_LLM_BASE_URL_VAR,\n load_from_db=True,\n ),\n IntInput(\n name=\"dimensions\",\n display_name=\"Dimensions\",\n info=\"Output dimensions when the embedding model supports it.\",\n advanced=True,\n ),\n IntInput(\n name=\"chunk_size\",\n display_name=\"Chunk Size\",\n advanced=True,\n value=1000,\n ),\n ]\n\n def build_embeddings(self) -> Embeddings:\n api_key = _as_str(self.api_key)\n api_base = _as_str(self.api_base)\n if api_base:\n api_base = api_base.rstrip(\"/\")\n\n kwargs: dict[str, Any] = {\n \"model\": self.model_name,\n # `OpenAIEmbeddings.deployment` defaults to the class-level default of\n # `model` — the literal \"text-embedding-ada-002\" — for every instance,\n # whatever model is actually configured. The OpenSearch component keys\n # its embedding lookup on `deployment` as well as `model`, so leaving\n # the default in place registers this object under ada-002 too, and a\n # 768-dim vector then gets aimed at a 1536-dim ada-002 vector field.\n # Only Azure reads this field, so pinning it to the real model is inert\n # at request time and keeps the component's identity honest.\n \"deployment\": self.model_name,\n \"api_key\": api_key,\n \"base_url\": api_base or None,\n # Skip tiktoken context checks so non-OpenAI model ids still work.\n \"check_embedding_ctx_length\": False,\n }\n chunk_size = getattr(self, \"chunk_size\", None)\n if chunk_size:\n kwargs[\"chunk_size\"] = chunk_size\n dimensions = getattr(self, \"dimensions\", None)\n if dimensions:\n kwargs[\"dimensions\"] = dimensions\n return OpenAIEmbeddings(**kwargs)\n"
+ },
+ "dimensions": {
+ "_input_type": "IntInput",
+ "advanced": true,
+ "api_editable": false,
+ "display_name": "Dimensions",
+ "dynamic": false,
+ "info": "Output dimensions when the embedding model supports it.",
+ "list": false,
+ "list_add_label": "Add More",
+ "name": "dimensions",
+ "override_skip": false,
+ "placeholder": "",
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "tool_mode": false,
+ "trace_as_metadata": true,
+ "track_in_telemetry": true,
+ "type": "int",
+ "value": 0
+ },
+ "model_name": {
+ "_input_type": "StrInput",
+ "advanced": false,
+ "api_editable": false,
+ "display_name": "Model Name",
+ "dynamic": false,
+ "info": "Embedding model id. Bound to SELECTED_EMBEDDING_MODEL at runtime.",
+ "list": false,
+ "list_add_label": "Add More",
+ "load_from_db": true,
+ "name": "model_name",
+ "override_skip": false,
+ "placeholder": "",
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "tool_mode": false,
+ "trace_as_metadata": true,
+ "track_in_telemetry": false,
+ "type": "str",
+ "value": "SELECTED_EMBEDDING_MODEL"
+ }
+ },
+ "tool_mode": false
+ },
+ "showNode": false,
+ "type": "OpenAICompatibleEmbedding"
+ },
+ "dragging": false,
+ "id": "OpenAICompatibleEmbedding-aIHce",
+ "measured": {
+ "height": 52,
+ "width": 192
+ },
"position": {
- "x": 1917.4709329555637,
- "y": 1390.8717018547147
+ "x": 2026.2607693884997,
+ "y": 1754.074435768159
},
"selected": false,
"type": "genericNode"
},
{
"data": {
- "id": "ext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-D6eM3",
+ "id": "OpenSearchVectorStoreComponentMultimodalMultiEmbedding-dihKf",
"node": {
"base_classes": [
"JSON",
"VectorStore"
],
"beta": false,
- "bundle": "openrag",
"conditional_paths": [],
"custom_fields": {},
"description": "Store and search documents using OpenSearch with multi-model hybrid semantic and keyword search. To search use the tools search_documents and raw_search. Search documents takes a query for vector search, for example\n {search_query: \"components in openrag\"}",
"display_name": "OpenSearch (Multi-Model Multi-Embedding)",
"documentation": "",
"edited": false,
- "extension": "openrag",
- "extension_version": "0.0.0",
"field_order": [
"docs_metadata",
"opensearch_url",
@@ -6337,7 +5912,7 @@
],
"frozen": false,
"icon": "OpenSearch",
- "last_updated": "2026-08-05T16:16:03.322Z",
+ "last_updated": "2026-08-18T22:49:22.128Z",
"legacy": false,
"metadata": {
"code_hash": "6c375fdaa9e7",
@@ -6369,8 +5944,6 @@
"module": "_lfx_ext.extra.openrag.opensearch_multimodal"
},
"minimized": false,
- "name": "OpenSearchVectorStoreComponentMultimodalMultiEmbedding",
- "namespaced_id": "ext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra",
"output_types": [],
"outputs": [
{
@@ -6432,7 +6005,7 @@
"value": "72c3d17c-2dac-4a73-b48a-6518473d7830"
},
"_frontend_node_folder_id": {
- "value": "203c7c12-9e1d-4561-bb14-16102afec154"
+ "value": "e861a230-a49b-41ef-82de-5f825ea9ab51"
},
"_type": "Component",
"auth_mode": {
@@ -6684,7 +6257,7 @@
"info": "The OpenSearch index name where documents will be stored and searched. Will be created automatically if it doesn't exist.",
"list": false,
"list_add_label": "Add More",
- "load_from_db": true,
+ "load_from_db": false,
"name": "index_name",
"override_skip": false,
"placeholder": "",
@@ -6695,7 +6268,7 @@
"trace_as_metadata": true,
"track_in_telemetry": false,
"type": "str",
- "value": "OPENSEARCH_INDEX_NAME"
+ "value": "langflow"
},
"ingest_data": {
"_input_type": "HandleInput",
@@ -6955,7 +6528,7 @@
"info": "The connection URL for your OpenSearch cluster (e.g., http://localhost:9200 for local development or your cloud endpoint).",
"list": false,
"list_add_label": "Add More",
- "load_from_db": true,
+ "load_from_db": false,
"name": "opensearch_url",
"override_skip": false,
"placeholder": "",
@@ -6966,7 +6539,7 @@
"trace_as_metadata": true,
"track_in_telemetry": false,
"type": "str",
- "value": "OPENSEARCH_URL"
+ "value": "http://localhost:9200"
},
"password": {
"_input_type": "SecretStrInput",
@@ -7178,31 +6751,35 @@
"tool_mode": false
},
"selected_output": "search_results",
- "showNode": true,
+ "showNode": false,
"type": "ext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra"
},
"dragging": false,
- "id": "ext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra-D6eM3",
+ "id": "OpenSearchVectorStoreComponentMultimodalMultiEmbedding-dihKf",
+ "measured": {
+ "height": 188,
+ "width": 192
+ },
"position": {
- "x": 2759.252152496372,
- "y": 1353.207638077407
+ "x": 2376.807670689636,
+ "y": 1551.0689633093473
},
"selected": false,
"type": "genericNode"
}
],
"viewport": {
- "x": -68.2665033451334,
- "y": -269.25441306974096,
- "zoom": 0.3565064293410352
+ "x": -124.03162115587827,
+ "y": -303.56751934671684,
+ "zoom": 0.3650080026636323
}
},
"description": "This flow is to ingest the URL to open search.",
"endpoint_name": null,
"id": "72c3d17c-2dac-4a73-b48a-6518473d7830",
"is_component": false,
- "mcp_enabled": true,
"last_tested_version": "0.11.2",
+ "mcp_enabled": true,
"locked": true,
"name": "OpenSearch URL Ingestion Flow",
"tags": [
diff --git a/frontend/app/api/mutations/useOnboardingMutation.ts b/frontend/app/api/mutations/useOnboardingMutation.ts
index a21b5ca0f..bd300dec3 100644
--- a/frontend/app/api/mutations/useOnboardingMutation.ts
+++ b/frontend/app/api/mutations/useOnboardingMutation.ts
@@ -22,6 +22,7 @@ export interface OnboardingVariables {
watsonx_endpoint?: string;
watsonx_project_id?: string;
ollama_endpoint?: string;
+ provider_credentials?: Record<string, Record<string, string>>;
}
interface OnboardingResponse {
diff --git a/frontend/app/api/mutations/useUpdateSettingsMutation.ts b/frontend/app/api/mutations/useUpdateSettingsMutation.ts
index 7c9981390..8f8e8820a 100644
--- a/frontend/app/api/mutations/useUpdateSettingsMutation.ts
+++ b/frontend/app/api/mutations/useUpdateSettingsMutation.ts
@@ -53,6 +53,8 @@ export interface UpdateSettingsRequest {
remove_watsonx_config?: boolean;
// Bypass the "this provider's embedding models are still in use" guard.
force_remove?: boolean;
+ provider_credentials?: Record<string, Record<string, string>>;
+ remove_provider_config?: string;
}
export interface AffectedEmbeddingModel {
diff --git a/frontend/app/api/queries/useGetModelsQuery.ts b/frontend/app/api/queries/useGetModelsQuery.ts
index 9c1360302..ba7d1861b 100644
--- a/frontend/app/api/queries/useGetModelsQuery.ts
+++ b/frontend/app/api/queries/useGetModelsQuery.ts
@@ -3,6 +3,7 @@ import {
useQuery,
useQueryClient,
} from "@tanstack/react-query";
+import type { CatalogModel } from "@/app/settings/_helpers/catalog-models";
import { formatProviderErrorMessage } from "@/lib/chat-stream-errors";
import { useGetSettingsQuery } from "./useGetSettingsQuery";
@@ -281,3 +282,59 @@ export const useGetCurrentProviderModelsQuery = (
return openaiModels;
}
};
+
+export interface CatalogCredentialField {
+ key: string;
+ label: string;
+ placeholder?: string | null;
+ tooltip?: string | null;
+ required: boolean;
+ field_type: string;
+ options?: unknown;
+ default_value?: unknown;
+}
+
+export interface CatalogProvider {
+ key: string;
+ name: string;
+ credential_fields: CatalogCredentialField[];
+ model_placeholder: string | null;
+ models: CatalogModel[];
+ embedding_models: CatalogModel[];
+}
+
+export interface ModelCatalogResponse {
+ providers: CatalogProvider[];
+}
+
+/**
+ * LiteLLM's bundled model list, grouped by provider. Static for the tab's
+ * lifetime — same as openrag-next's `/agent/model-catalog` fetch.
+ */
+export const useGetModelCatalogQuery = (
+ options?: Omit<UseQueryOptions<ModelCatalogResponse>, "queryKey" | "queryFn">,
+) => {
+ const queryClient = useQueryClient();
+
+ return useQuery(
+ {
+ queryKey: ["models", "catalog"] as const,
+ queryFn: async (): Promise<ModelCatalogResponse> => {
+ const response = await fetch("/api/models/catalog");
+ if (response.ok) {
+ return (await response.json()) as ModelCatalogResponse;
+ }
+ return throwModelsFetchError(
+ response,
+ "Failed to fetch the model catalogue",
+ );
+ },
+ staleTime: Number.POSITIVE_INFINITY,
+ gcTime: Number.POSITIVE_INFINITY,
+ refetchOnWindowFocus: false,
+ retry: false,
+ ...options,
+ },
+ queryClient,
+ );
+};
diff --git a/frontend/app/api/queries/useGetSettingsQuery.ts b/frontend/app/api/queries/useGetSettingsQuery.ts
index b19882906..f4b54505f 100644
--- a/frontend/app/api/queries/useGetSettingsQuery.ts
+++ b/frontend/app/api/queries/useGetSettingsQuery.ts
@@ -54,6 +54,14 @@ export interface ProviderSettings {
local?: {
configured?: boolean;
};
+ custom?: Record<
+ string,
+ {
+ configured?: boolean;
+ credential_values?: Record<string, string>;
+ secret_fields?: string[];
+ }
+ >;
}
export interface OnboardingState {
diff --git a/frontend/app/onboarding/_components/model-features.tsx b/frontend/app/onboarding/_components/model-features.tsx
new file mode 100644
index 000000000..7f3ed3f59
--- /dev/null
+++ b/frontend/app/onboarding/_components/model-features.tsx
@@ -0,0 +1,202 @@
+"use client";
+
+import {
+ Braces,
+ Brain,
+ Cpu,
+ Database,
+ Eye,
+ FileText,
+ Globe,
+ ListChecks,
+ type LucideIcon,
+ Mic,
+ Wrench,
+} from "lucide-react";
+import type { CatalogModel } from "@/app/settings/_helpers/catalog-models";
+import {
+ ALL_CAPABILITIES,
+ formatContext,
+ formatPrice,
+ formatTokens,
+ type ModelCapability,
+ PRIMARY_CAPABILITIES,
+ supports,
+} from "@/app/settings/_helpers/model-info";
+import AnthropicLogo from "@/components/icons/anthropic-logo";
+import IBMLogo from "@/components/icons/ibm-logo";
+import OllamaLogo from "@/components/icons/ollama-logo";
+import OpenAILogo from "@/components/icons/openai-logo";
+import { cn } from "@/lib/utils";
+
+const ICONS: Record<ModelCapability, LucideIcon> = {
+ function_calling: Wrench,
+ vision: Eye,
+ reasoning: Brain,
+ structured_output: Braces,
+ prompt_caching: Database,
+ pdf_input: FileText,
+ web_search: Globe,
+ audio_input: Mic,
+ computer_use: Cpu,
+ parallel_tools: ListChecks,
+};
+
+export function CapabilityStrip({ model }: { model: CatalogModel }) {
+ return (
+ // A visual summary inside a listbox option: the option is named after its
+ // model, and the full capability breakdown is announced by `ModelFeatures`
+ // once a model is selected. Announcing each icon here would only bury the
+ // model name in the option's label.
+ <span aria-hidden="true" className="ml-auto flex items-center gap-1">
+ {PRIMARY_CAPABILITIES.map(({ key, label }) => {
+ const Icon = ICONS[key];
+ const enabled = supports(model, key);
+ return (
+ <span
+ key={key}
+ title={`${label}: ${enabled ? "supported" : "unsupported"}`}
+ className="inline-flex"
+ >
+ <Icon
+ className={cn(
+ "h-3.5 w-3.5",
+ enabled ? "text-primary" : "text-muted-foreground/35",
+ )}
+ />
+ </span>
+ );
+ })}
+ {formatContext(model.max_input_tokens) && (
+ <span className="ml-1 text-xs text-muted-foreground">
+ {formatContext(model.max_input_tokens)}
+ </span>
+ )}
+ </span>
+ );
+}
+
+function Fact({ label, value }: { label: string; value: string }) {
+ return (
+ <div className="bg-muted/40 p-2">
+ <div className="text-[10px] uppercase tracking-wide text-muted-foreground">
+ {label}
+ </div>
+ <div className="mt-0.5 text-mmd tabular-nums">{value}</div>
+ </div>
+ );
+}
+
+const PROVIDER_LOGOS: Record<
+ string,
+ React.ComponentType<{ className?: string }>
+> = {
+ openai: OpenAILogo,
+ anthropic: AnthropicLogo,
+ watsonx: IBMLogo,
+ ollama: OllamaLogo,
+};
+
+function ProviderMark({ provider, name }: { provider?: string; name: string }) {
+ const Logo = provider ? PROVIDER_LOGOS[provider] : undefined;
+ return (
+ <span
+ aria-hidden="true"
+ data-provider={provider}
+ className="grid h-16 w-16 shrink-0 place-items-center border border-border bg-white"
+ >
+ {Logo ? (
+ <Logo className="h-10 w-10 text-black" />
+ ) : (
+ <span className="font-mono text-lg font-semibold tracking-wide text-muted-foreground">
+ {(provider || name).slice(0, 2).toUpperCase()}
+ </span>
+ )}
+ </span>
+ );
+}
+
+export function ModelFeatures({
+ model,
+ providerName,
+ provider,
+}: {
+ model: CatalogModel;
+ providerName: string;
+ provider?: string;
+}) {
+ const facts = [
+ ["Provider", providerName],
+ ["Context", formatTokens(model.max_input_tokens)],
+ ["Max output", formatTokens(model.max_output_tokens)],
+ [
+ "Input",
+ model.input_cost_per_token == null
+ ? "—"
+ : `${formatPrice(model.input_cost_per_token)} /M`,
+ ],
+ [
+ "Output",
+ model.output_cost_per_token == null
+ ? "—"
+ : `${formatPrice(model.output_cost_per_token)} /M`,
+ ],
+ ];
+ if (model.cache_read_input_token_cost != null) {
+ facts.push([
+ "Cached input",
+ `${formatPrice(model.cache_read_input_token_cost)} /M`,
+ ]);
+ }
+
+ return (
+ <div className="space-y-3 border border-border p-3">
+ <div className="flex items-center gap-3">
+ <ProviderMark provider={provider} name={providerName} />
+ <div className="min-w-0">
+ <p className="truncate font-medium leading-tight">{model.model}</p>
+ <p className="truncate text-mmd text-muted-foreground">
+ {providerName}
+ </p>
+ </div>
+ </div>
+ <div className="grid grid-cols-2 gap-px bg-border">
+ {facts.map(([label, value]) => (
+ <Fact key={label} label={label} value={value} />
+ ))}
+ </div>
+ <ul className="flex flex-wrap gap-1.5">
+ {ALL_CAPABILITIES.map(({ key, label, hint }) => {
+ const Icon = ICONS[key];
+ const enabled = supports(model, key);
+ return (
+ <li
+ key={key}
+ title={hint}
+ className={cn(
+ "inline-flex items-center gap-1 border px-1.5 py-0.5 text-xs",
+ enabled
+ ? "border-primary/40 text-foreground"
+ : "border-border text-muted-foreground/50",
+ )}
+ >
+ <Icon className="h-3 w-3" />
+ {label}
+ </li>
+ );
+ })}
+ </ul>
+ {model.mode !== "embedding" && !supports(model, "function_calling") && (
+ <p className="border-l-2 border-destructive pl-2 text-mmd text-muted-foreground">
+ This model does not advertise function calling, so it may not be able
+ to run the OpenRAG agent tools.
+ </p>
+ )}
+ {model.deprecation_date && (
+ <p className="border-l-2 border-warning pl-2 text-mmd text-muted-foreground">
+ Retires {model.deprecation_date}.
+ </p>
+ )}
+ </div>
+ );
+}
diff --git a/frontend/app/onboarding/_components/model-selector.tsx b/frontend/app/onboarding/_components/model-selector.tsx
index ecb43d5d1..af5905acb 100644
--- a/frontend/app/onboarding/_components/model-selector.tsx
+++ b/frontend/app/onboarding/_components/model-selector.tsx
@@ -1,12 +1,13 @@
"use client";
import { CheckIcon, ChevronsUpDownIcon } from "lucide-react";
-import { useEffect, useId, useState } from "react";
+import { useDeferredValue, useEffect, useId, useMemo, useState } from "react";
+import type { CatalogModel } from "@/app/settings/_helpers/catalog-models";
+import { MODELS_PER_PROVIDER } from "@/app/settings/_helpers/model-info";
import { Badge } from "@/components/ui/badge";
import { Button, type ButtonProps } from "@/components/ui/button";
import {
Command,
- CommandEmpty,
CommandGroup,
CommandInput,
CommandItem,
@@ -18,16 +19,21 @@ import {
PopoverTrigger,
} from "@/components/ui/popover";
import { cn } from "@/lib/utils";
+import { CapabilityStrip } from "./model-features";
export type ModelOption = {
value: string;
label: string;
default?: boolean;
provider?: string;
+ model?: CatalogModel;
+ icon?: React.ReactNode;
};
export type GroupedModelOption = {
group: string;
+ /** Provider key for custom entries typed under this group. */
+ provider?: string;
options: ModelOption[];
icon?: React.ReactNode;
};
@@ -36,6 +42,8 @@ export interface ModelSelectorProps extends ButtonProps {
options?: ModelOption[];
groupedOptions?: GroupedModelOption[];
value: string;
+ /** Disambiguates the same model id hosted by more than one vendor. */
+ selectedProvider?: string;
icon?: React.ReactNode;
placeholder?: string;
searchPlaceholder?: string;
@@ -46,10 +54,34 @@ export interface ModelSelectorProps extends ButtonProps {
defaultOpen?: boolean;
}
+function optionProvider(
+ option: ModelOption,
+ group?: GroupedModelOption,
+): string | undefined {
+ return option.provider ?? group?.provider;
+}
+
+function isSelectedRow(
+ option: ModelOption,
+ value: string,
+ selectedProvider?: string,
+ group?: GroupedModelOption,
+): boolean {
+ if (option.value !== value) {
+ return false;
+ }
+ if (!selectedProvider) {
+ return true;
+ }
+ const provider = optionProvider(option, group);
+ return !provider || provider === selectedProvider;
+}
+
export function ModelSelector({
options,
groupedOptions,
value = "",
+ selectedProvider,
onValueChange,
icon,
placeholder = "Select model...",
@@ -73,17 +105,89 @@ export function ModelSelector({
}
const [searchValue, setSearchValue] = useState("");
+ // The option filter runs on the trimmed, lowercased search text, so the
+ // custom entry has to use the trimmed text too — otherwise typing trailing
+ // whitespace both defeats the duplicate check and stores a model id with
+ // whitespace in it.
+ const customValue = searchValue.trim();
+ const deferredSearch = useDeferredValue(customValue.toLowerCase());
const listboxId = useId();
+ // Groups the user chose to expand past MODELS_PER_PROVIDER.
+ const [expandedGroups, setExpandedGroups] = useState<Set<string>>(
+ () => new Set(),
+ );
+ const toggleGroup = (group: string) =>
+ setExpandedGroups((previous) => {
+ const next = new Set(previous);
+ if (!next.delete(group)) next.add(group);
+ return next;
+ });
// Flatten grouped options or use regular options
const allOptions =
groupedOptions?.flatMap((group) => group.options) || options || [];
+ const allowCustomEntry = !!custom;
- // Find the group icon for the selected value
const selectedOptionGroup = groupedOptions?.find((group) =>
- group.options.some((opt) => opt.value === value),
+ selectedProvider
+ ? group.provider === selectedProvider
+ : group.options.some((opt) => opt.value === value),
+ );
+ const selectedOption = allOptions.find((option) =>
+ isSelectedRow(option, value, selectedProvider, selectedOptionGroup),
);
- const selectedIcon = selectedOptionGroup?.icon || icon;
+ const selectedIcon =
+ selectedOption?.icon || selectedOptionGroup?.icon || icon;
+
+ const visibleGroups = useMemo(() => {
+ if (!groupedOptions) return undefined;
+ const matched = groupedOptions.flatMap((group) => {
+ const providerMatches = group.group
+ .toLowerCase()
+ .includes(deferredSearch);
+ const matches = deferredSearch
+ ? group.options.filter(
+ (option) =>
+ providerMatches ||
+ option.label.toLowerCase().includes(deferredSearch),
+ )
+ : group.options;
+ if (deferredSearch && matches.length === 0) return [];
+ // Collapsed groups show a preview; the trailing row expands them. The cap
+ // applies while searching too, so without that row a search would drop
+ // matches with nothing on screen to say so.
+ const options = expandedGroups.has(group.group)
+ ? matches
+ : matches.slice(0, MODELS_PER_PROVIDER);
+ return [{ ...group, options, matchCount: matches.length }];
+ });
+ return matched.slice(0, 40);
+ }, [deferredSearch, groupedOptions, expandedGroups]);
+ const visibleOptions = useMemo(() => {
+ if (groupedOptions) return [];
+ const source = options ?? [];
+ if (!deferredSearch) return source.slice(0, 40);
+ return source
+ .filter((option) => option.label.toLowerCase().includes(deferredSearch))
+ .slice(0, 100);
+ }, [deferredSearch, groupedOptions, options]);
+
+ // `shouldFilter={false}` means cmdk's own item count no longer reflects the
+ // manual filtering above, so `CommandEmpty` cannot be trusted to appear.
+ // Decide the empty state from the collections that actually render.
+ const showCustomEntry = allowCustomEntry && !!customValue;
+ // Grouped custom rows live inside a group, so a search that filters every
+ // group away also takes the custom entry with it. Offer it on its own so a
+ // model that is not in the catalogue can still be typed.
+ const showUngroupedCustomEntry =
+ showCustomEntry && !!groupedOptions && (visibleGroups?.length ?? 0) === 0;
+ const showFlatCustomEntry =
+ showCustomEntry &&
+ !groupedOptions &&
+ !allOptions.some((option) => option.value === customValue);
+ const hasVisibleRows = groupedOptions
+ ? (visibleGroups?.length ?? 0) > 0 || showUngroupedCustomEntry
+ : visibleOptions.length > 0 || showFlatCustomEntry;
useEffect(() => {
if (
@@ -103,7 +207,7 @@ export function ModelSelector({
<Button
variant={variant}
role="combobox"
- disabled={disabled || allOptions.length === 0}
+ disabled={disabled || (allOptions.length === 0 && !allowCustomEntry)}
aria-expanded={open}
aria-controls={listboxId}
className={cn(
@@ -116,8 +220,7 @@ export function ModelSelector({
{value ? (
<div className="flex items-center gap-2">
{selectedIcon && <div className="w-4 h-4">{selectedIcon}</div>}
- {allOptions.find((framework) => framework.value === value)
- ?.label || value}
+ {selectedOption?.label || value}
{custom &&
value &&
!allOptions.find((framework) => framework.value === value) && (
@@ -126,7 +229,7 @@ export function ModelSelector({
</Badge>
)}
</div>
- ) : allOptions.length === 0 ? (
+ ) : allOptions.length === 0 && !allowCustomEntry ? (
noOptionsPlaceholder
) : (
placeholder
@@ -139,7 +242,7 @@ export function ModelSelector({
className="p-0 w-[var(--radix-popover-trigger-width)]"
onOpenAutoFocus={(e) => e.preventDefault()}
>
- <Command>
+ <Command shouldFilter={false}>
<CommandInput
placeholder={searchPlaceholder}
value={searchValue}
@@ -150,66 +253,198 @@ export function ModelSelector({
className="max-h-[300px] overflow-y-auto"
onWheel={(e) => e.stopPropagation()}
>
- <CommandEmpty>{noOptionsPlaceholder}</CommandEmpty>
+ {!hasVisibleRows && (
+ <div className="py-6 text-center text-sm">
+ {noOptionsPlaceholder}
+ </div>
+ )}
{groupedOptions ? (
- groupedOptions.map((group) => (
- <CommandGroup
- key={group.group}
- heading={
- <div className="flex items-center gap-2">
- {group.icon && (
- <div className="w-4 h-4">{group.icon}</div>
+ <>
+ {visibleGroups?.map((group) => {
+ const groupProvider =
+ group.provider ?? group.options[0]?.provider;
+ const showCustom =
+ showCustomEntry &&
+ !group.options.some(
+ (option) => option.value === customValue,
+ );
+ return (
+ <CommandGroup
+ key={group.group}
+ data-testid={
+ groupProvider
+ ? `model-group-${groupProvider}`
+ : undefined
+ }
+ heading={
+ <div className="flex items-center gap-2">
+ {group.icon && (
+ <div className="w-4 h-4">{group.icon}</div>
+ )}
+ <span>{group.group}</span>
+ </div>
+ }
+ >
+ {group.options.length === 0 && !showCustom ? (
+ <CommandItem
+ disabled
+ className="text-muted-foreground ml-6"
+ >
+ No models available. Search to enter a custom model.
+ </CommandItem>
+ ) : (
+ group.options.map((option) => {
+ const itemProvider = option.provider ?? groupProvider;
+ const itemKey = itemProvider
+ ? `${itemProvider}:${option.value}`
+ : option.value;
+ return (
+ <CommandItem
+ key={itemKey}
+ value={itemKey}
+ // The capability icons and the context-length
+ // badge below are descendants of this option, so
+ // without an explicit label the accessible name
+ // becomes "<model> Tools: supported ... 128K".
+ // Name the option after the model it selects.
+ aria-label={option.label}
+ data-testid={`model-option-${option.value}`}
+ onSelect={() => {
+ if (
+ option.value !== value ||
+ itemProvider !== selectedProvider
+ ) {
+ onValueChange(option.value, itemProvider);
+ }
+ setOpen(false);
+ }}
+ >
+ <CheckIcon
+ className={cn(
+ "mr-2 h-4 w-4",
+ isSelectedRow(
+ option,
+ value,
+ selectedProvider,
+ group,
+ )
+ ? "opacity-100"
+ : "opacity-0",
+ )}
+ />
+ <div className="flex items-center gap-2">
+ {option.icon && (
+ <span className="h-4 w-4">{option.icon}</span>
+ )}
+ {option.label}
+ </div>
+ {option.model && (
+ <CapabilityStrip model={option.model} />
+ )}
+ </CommandItem>
+ );
+ })
)}
- <span>{group.group}</span>
- </div>
- }
- >
- {group.options.length === 0 ? (
+ {group.matchCount > MODELS_PER_PROVIDER && (
+ <CommandItem
+ value={`__toggle-${group.group}`}
+ aria-label={
+ group.options.length < group.matchCount
+ ? `Show ${group.matchCount - group.options.length} more ${group.group} models`
+ : `Show fewer ${group.group} models`
+ }
+ data-testid={
+ groupProvider
+ ? `model-group-toggle-${groupProvider}`
+ : undefined
+ }
+ className="text-xs text-muted-foreground"
+ onSelect={() => toggleGroup(group.group)}
+ >
+ {group.options.length < group.matchCount
+ ? `Show ${group.matchCount - group.options.length} more`
+ : "Show fewer"}
+ </CommandItem>
+ )}
+ {showCustom && (
+ <CommandItem
+ value={`${group.group}-${customValue}`}
+ aria-label={customValue}
+ data-testid={`model-custom-option-${customValue}`}
+ onSelect={() => {
+ if (
+ customValue !== value ||
+ groupProvider !== selectedProvider
+ ) {
+ onValueChange(customValue, groupProvider);
+ }
+ setOpen(false);
+ }}
+ >
+ <CheckIcon
+ className={cn(
+ "mr-2 h-4 w-4",
+ value === customValue &&
+ (!selectedProvider ||
+ selectedProvider === groupProvider)
+ ? "opacity-100"
+ : "opacity-0",
+ )}
+ />
+ <div className="flex items-center gap-2">
+ {customValue}
+ <span className="text-xs text-foreground p-1 rounded-md bg-muted">
+ Custom
+ </span>
+ </div>
+ </CommandItem>
+ )}
+ </CommandGroup>
+ );
+ })}
+ {showUngroupedCustomEntry && (
+ <CommandGroup>
<CommandItem
- disabled
- className="text-muted-foreground ml-6"
+ value={customValue}
+ aria-label={customValue}
+ data-testid={`model-custom-option-${customValue}`}
+ onSelect={() => {
+ if (customValue !== value) {
+ onValueChange(customValue, selectedProvider);
+ }
+ setOpen(false);
+ }}
>
- No models available
+ <CheckIcon
+ className={cn(
+ "mr-2 h-4 w-4",
+ value === customValue ? "opacity-100" : "opacity-0",
+ )}
+ />
+ <div className="flex items-center gap-2">
+ {customValue}
+ <span className="text-xs text-foreground p-1 rounded-md bg-muted">
+ Custom
+ </span>
+ </div>
</CommandItem>
- ) : (
- group.options.map((option) => (
- <CommandItem
- key={option.value}
- value={option.value}
- data-testid={`model-option-${option.value}`}
- onSelect={(currentValue) => {
- if (currentValue !== value) {
- onValueChange(currentValue, option.provider);
- }
- setOpen(false);
- }}
- >
- <CheckIcon
- className={cn(
- "mr-2 h-4 w-4",
- value === option.value
- ? "opacity-100"
- : "opacity-0",
- )}
- />
- <div className="flex items-center gap-2">
- {option.label}
- </div>
- </CommandItem>
- ))
- )}
- </CommandGroup>
- ))
+ </CommandGroup>
+ )}
+ </>
) : (
<CommandGroup>
- {allOptions.map((option) => (
+ {visibleOptions.map((option) => (
<CommandItem
key={option.value}
value={option.value}
+ aria-label={option.label}
data-testid={`model-option-${option.value}`}
- onSelect={(currentValue) => {
- if (currentValue !== value) {
- onValueChange(currentValue, option.provider);
+ onSelect={() => {
+ if (
+ option.value !== value ||
+ option.provider !== selectedProvider
+ ) {
+ onValueChange(option.value, option.provider);
}
setOpen(false);
}}
@@ -217,43 +452,45 @@ export function ModelSelector({
<CheckIcon
className={cn(
"mr-2 h-4 w-4",
- value === option.value ? "opacity-100" : "opacity-0",
+ isSelectedRow(option, value, selectedProvider)
+ ? "opacity-100"
+ : "opacity-0",
)}
/>
<div className="flex items-center gap-2">
+ {option.icon && (
+ <span className="h-4 w-4">{option.icon}</span>
+ )}
{option.label}
</div>
</CommandItem>
))}
- {custom &&
- searchValue &&
- !allOptions.find(
- (option) => option.value === searchValue,
- ) && (
- <CommandItem
- value={searchValue}
- data-testid={`model-custom-option-${searchValue}`}
- onSelect={(currentValue) => {
- if (currentValue !== value) {
- onValueChange(currentValue);
- }
- setOpen(false);
- }}
- >
- <CheckIcon
- className={cn(
- "mr-2 h-4 w-4",
- value === searchValue ? "opacity-100" : "opacity-0",
- )}
- />
- <div className="flex items-center gap-2">
- {searchValue}
- <span className="text-xs text-foreground p-1 rounded-md bg-muted">
- Custom
- </span>
- </div>
- </CommandItem>
- )}
+ {showFlatCustomEntry && (
+ <CommandItem
+ value={customValue}
+ aria-label={customValue}
+ data-testid={`model-custom-option-${customValue}`}
+ onSelect={() => {
+ if (customValue !== value) {
+ onValueChange(customValue);
+ }
+ setOpen(false);
+ }}
+ >
+ <CheckIcon
+ className={cn(
+ "mr-2 h-4 w-4",
+ value === customValue ? "opacity-100" : "opacity-0",
+ )}
+ />
+ <div className="flex items-center gap-2">
+ {customValue}
+ <span className="text-xs text-foreground p-1 rounded-md bg-muted">
+ Custom
+ </span>
+ </div>
+ </CommandItem>
+ )}
</CommandGroup>
)}
</CommandList>
diff --git a/frontend/app/settings/_components/agent-settings-section.tsx b/frontend/app/settings/_components/agent-settings-section.tsx
index 50c9e25be..8210c8d78 100644
--- a/frontend/app/settings/_components/agent-settings-section.tsx
+++ b/frontend/app/settings/_components/agent-settings-section.tsx
@@ -4,12 +4,7 @@ import { ArrowUpRight, Loader2 } from "lucide-react";
import { usePathname, useRouter, useSearchParams } from "next/navigation";
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { toast } from "sonner";
-import {
- useGetAnthropicModelsQuery,
- useGetIBMModelsQuery,
- useGetOllamaModelsQuery,
- useGetOpenAIModelsQuery,
-} from "@/app/api/queries/useGetModelsQuery";
+import { useGetModelCatalogQuery } from "@/app/api/queries/useGetModelsQuery";
import { useGetSettingsQuery } from "@/app/api/queries/useGetSettingsQuery";
import { ConfirmationDialog } from "@/components/confirmation-dialog";
import { LabelWrapper } from "@/components/label-wrapper";
@@ -31,7 +26,12 @@ import { DEFAULT_AGENT_SETTINGS, UI_CONSTANTS } from "@/lib/constants";
import { resolveLangflowEditUrl } from "@/lib/url-utils";
import { cn } from "@/lib/utils";
import { useUpdateSettingsMutation } from "../../api/mutations/useUpdateSettingsMutation";
+import { ModelFeatures } from "../../onboarding/_components/model-features";
import { ModelSelector } from "../../onboarding/_components/model-selector";
+import {
+ findGroupedSelection,
+ groupedCatalogOptions,
+} from "../_helpers/catalog-models";
import { getModelLogo } from "../_helpers/model-helpers";
import { LangflowIcon } from "./langflow-icon";
@@ -54,92 +54,46 @@ export function AgentSettingsSection() {
enabled: isAuthenticated || isNoAuthMode,
});
- const { data: openaiModels, isLoading: openaiLoading } =
- useGetOpenAIModelsQuery(
- { apiKey: "" },
- { enabled: settings?.providers?.openai?.configured === true },
- );
- const { data: anthropicModels, isLoading: anthropicLoading } =
- useGetAnthropicModelsQuery(
- { apiKey: "" },
- { enabled: settings?.providers?.anthropic?.configured === true },
- );
- const { data: ollamaModels, isLoading: ollamaLoading } =
- useGetOllamaModelsQuery(
- { endpoint: settings?.providers?.ollama?.endpoint },
- {
- enabled:
- settings?.providers?.ollama?.configured === true &&
- !!settings?.providers?.ollama?.endpoint,
- },
- );
- const { data: watsonxModels, isLoading: watsonxLoading } =
- useGetIBMModelsQuery(
- {
- endpoint: settings?.providers?.watsonx?.endpoint,
- apiKey: "",
- projectId: settings?.providers?.watsonx?.project_id,
- },
- {
- enabled:
- settings?.providers?.watsonx?.configured === true &&
- !!settings?.providers?.watsonx?.endpoint &&
- !!settings?.providers?.watsonx?.project_id,
- },
- );
+ const {
+ data: catalog,
+ isLoading: catalogLoading,
+ // The catalogue query does not retry, so a failed fetch leaves the groups
+ // empty. Without this flag the selector would tell the user to configure a
+ // provider when the real problem is that the catalogue never loaded.
+ isError: catalogError,
+ } = useGetModelCatalogQuery({
+ enabled: isAuthenticated || isNoAuthMode,
+ });
+
+ const configuredProviders = useMemo(
+ () => ({
+ openai: settings.providers?.openai?.configured === true,
+ anthropic: settings.providers?.anthropic?.configured === true,
+ ollama: settings.providers?.ollama?.configured === true,
+ watsonx: settings.providers?.watsonx?.configured === true,
+ ...Object.fromEntries(
+ Object.entries(settings.providers?.custom ?? {}).map(
+ ([provider, value]) => [provider, value.configured === true],
+ ),
+ ),
+ }),
+ [settings.providers],
+ );
const groupedLlmModels = useMemo(
() =>
- [
- {
- group: "OpenAI",
- provider: "openai",
- icon: getModelLogo("", "openai"),
- models: openaiModels?.language_models || [],
- configured: settings.providers?.openai?.configured === true,
- },
- {
- group: "Anthropic",
- provider: "anthropic",
- icon: getModelLogo("", "anthropic"),
- models: anthropicModels?.language_models || [],
- configured: settings.providers?.anthropic?.configured === true,
- },
- {
- group: "Ollama",
- provider: "ollama",
- icon: getModelLogo("", "ollama"),
- models: ollamaModels?.language_models || [],
- configured: settings.providers?.ollama?.configured === true,
- },
- {
- group: "IBM watsonx.ai",
- provider: "watsonx",
- icon: getModelLogo("", "watsonx"),
- models: watsonxModels?.language_models || [],
- configured: settings.providers?.watsonx?.configured === true,
- },
- ]
- .filter((p) => p.configured)
- .map((p) => ({
- group: p.group,
- icon: p.icon,
- options: p.models.map((m) => ({ ...m, provider: p.provider })),
- })),
- [
- openaiModels?.language_models,
- anthropicModels?.language_models,
- ollamaModels?.language_models,
- watsonxModels?.language_models,
- settings.providers?.openai?.configured,
- settings.providers?.anthropic?.configured,
- settings.providers?.ollama?.configured,
- settings.providers?.watsonx?.configured,
- ],
+ groupedCatalogOptions(catalog, configuredProviders, "language").map(
+ (group) => ({
+ group: group.group,
+ provider: group.key,
+ icon: getModelLogo("", group.key),
+ options: group.options,
+ }),
+ ),
+ [catalog, configuredProviders],
);
- const isLoadingAnyLlmModels =
- openaiLoading || anthropicLoading || ollamaLoading || watsonxLoading;
+ const isLoadingAnyLlmModels = catalogLoading;
const updateSettingsMutation = useUpdateSettingsMutation({
onSuccess: () => {
@@ -154,6 +108,13 @@ export function AgentSettingsSection() {
() => groupedLlmModels.flatMap((g) => g.options),
[groupedLlmModels],
);
+ const selectedLlmMatch = findGroupedSelection(
+ groupedLlmModels,
+ settings.agent?.llm_model,
+ settings.agent?.llm_provider,
+ );
+ const selectedLlm = selectedLlmMatch?.option;
+ const selectedLlmGroup = selectedLlmMatch?.group;
const handleModelChange = useCallback(
(newModel: string, provider?: string) => {
@@ -349,16 +310,31 @@ export function AgentSettingsSection() {
>
<ModelSelector
groupedOptions={groupedLlmModels}
+ custom
noOptionsPlaceholder={
isLoadingAnyLlmModels
? "Loading models..."
- : "No language models detected. Configure a provider first."
+ : catalogError
+ ? "Could not load the model catalogue. Retry later."
+ : "No language models detected. Configure a provider first."
}
value={settings.agent?.llm_model || ""}
+ selectedProvider={settings.agent?.llm_provider}
onValueChange={handleModelChange}
defaultOpen={openLlmSelector}
/>
</LabelWrapper>
+ {settings.agent?.llm_model && selectedLlmGroup && (
+ <div className="mt-3">
+ <ModelFeatures
+ model={
+ selectedLlm?.model ?? { model: settings.agent.llm_model }
+ }
+ providerName={selectedLlmGroup.group}
+ provider={selectedLlmGroup.provider}
+ />
+ </div>
+ )}
</div>
<div className="space-y-2">
<LabelWrapper label="Agent Instructions" id="system-prompt">
diff --git a/frontend/app/settings/_components/anthropic-settings-form.tsx b/frontend/app/settings/_components/anthropic-settings-form.tsx
index 10f26ef37..98d3be5a1 100644
--- a/frontend/app/settings/_components/anthropic-settings-form.tsx
+++ b/frontend/app/settings/_components/anthropic-settings-form.tsx
@@ -41,7 +41,10 @@ export function AnthropicSettingsForm({
/>
</LabelWrapper>
{apiKeyError && (
- <p className="text-sm text-destructive min-w-0 [overflow-wrap:anywhere]">
+ <p
+ data-testid="provider-connection-error"
+ className="text-sm text-destructive min-w-0 [overflow-wrap:anywhere]"
+ >
{apiKeyError}
</p>
)}
diff --git a/frontend/app/settings/_components/ingest-settings-section.tsx b/frontend/app/settings/_components/ingest-settings-section.tsx
index 3518a56dd..08aa61fb6 100644
--- a/frontend/app/settings/_components/ingest-settings-section.tsx
+++ b/frontend/app/settings/_components/ingest-settings-section.tsx
@@ -3,12 +3,7 @@
import { ArrowUpRight, ChevronDown, Loader2, Minus, Plus } from "lucide-react";
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { toast } from "sonner";
-import {
- useGetAnthropicModelsQuery,
- useGetIBMModelsQuery,
- useGetOllamaModelsQuery,
- useGetOpenAIModelsQuery,
-} from "@/app/api/queries/useGetModelsQuery";
+import { useGetModelCatalogQuery } from "@/app/api/queries/useGetModelsQuery";
import { useGetSettingsQuery } from "@/app/api/queries/useGetSettingsQuery";
import { ConfirmationDialog } from "@/components/confirmation-dialog";
import { LabelWrapper } from "@/components/label-wrapper";
@@ -46,7 +41,15 @@ import { DEFAULT_KNOWLEDGE_SETTINGS } from "@/lib/constants";
import { resolveLangflowEditUrl } from "@/lib/url-utils";
import { cn } from "@/lib/utils";
import { useUpdateSettingsMutation } from "../../api/mutations/useUpdateSettingsMutation";
-import { ModelSelector } from "../../onboarding/_components/model-selector";
+import { ModelFeatures } from "../../onboarding/_components/model-features";
+import {
+ type GroupedModelOption,
+ ModelSelector,
+} from "../../onboarding/_components/model-selector";
+import {
+ findGroupedSelection,
+ groupedCatalogOptions,
+} from "../_helpers/catalog-models";
import { getModelLogo } from "../_helpers/model-helpers";
import { LangflowIcon } from "./langflow-icon";
@@ -96,171 +99,76 @@ export function IngestSettingsSection() {
const showVlmSettings = settings.show_vlm_settings ?? true;
- const { data: openaiModels, isLoading: openaiLoading } =
- useGetOpenAIModelsQuery(
- { apiKey: "" },
- { enabled: settings?.providers?.openai?.configured === true },
- );
- const { data: anthropicModels, isLoading: anthropicLoading } =
- useGetAnthropicModelsQuery(
- { apiKey: "" },
- { enabled: settings?.providers?.anthropic?.configured === true },
- );
- const { data: ollamaModels, isLoading: ollamaLoading } =
- useGetOllamaModelsQuery(
- { endpoint: settings?.providers?.ollama?.endpoint },
- {
- enabled:
- settings?.providers?.ollama?.configured === true &&
- !!settings?.providers?.ollama?.endpoint,
- },
- );
- const { data: watsonxModels, isLoading: watsonxLoading } =
- useGetIBMModelsQuery(
- {
- endpoint: settings?.providers?.watsonx?.endpoint,
- apiKey: "",
- projectId: settings?.providers?.watsonx?.project_id,
- },
- {
- enabled:
- settings?.providers?.watsonx?.configured === true &&
- !!settings?.providers?.watsonx?.endpoint &&
- !!settings?.providers?.watsonx?.project_id,
- },
- );
+ const {
+ data: catalog,
+ isLoading: catalogLoading,
+ // The catalogue query does not retry, so a failed fetch leaves the groups
+ // empty. Without this flag the selector would tell the user to configure a
+ // provider when the real problem is that the catalogue never loaded.
+ isError: catalogError,
+ } = useGetModelCatalogQuery({
+ enabled: isAuthenticated || isNoAuthMode,
+ });
+
+ const configuredProviders = useMemo(
+ () => ({
+ openai: settings.providers?.openai?.configured === true,
+ anthropic: settings.providers?.anthropic?.configured === true,
+ ollama: settings.providers?.ollama?.configured === true,
+ watsonx: settings.providers?.watsonx?.configured === true,
+ ...Object.fromEntries(
+ Object.entries(settings.providers?.custom ?? {}).map(
+ ([provider, value]) => [provider, value.configured === true],
+ ),
+ ),
+ }),
+ [settings.providers],
+ );
const groupedEmbeddingModels = useMemo(
() =>
- [
- {
- group: "OpenAI",
- provider: "openai",
- icon: getModelLogo("", "openai"),
- models: openaiModels?.embedding_models || [],
- configured: settings.providers?.openai?.configured === true,
- },
- {
- group: "Ollama",
- provider: "ollama",
- icon: getModelLogo("", "ollama"),
- models: ollamaModels?.embedding_models || [],
- configured: settings.providers?.ollama?.configured === true,
- },
- {
- group: "IBM watsonx.ai",
- provider: "watsonx",
- icon: getModelLogo("", "watsonx"),
- models: watsonxModels?.embedding_models || [],
- configured: settings.providers?.watsonx?.configured === true,
- },
- ]
- .filter((p) => p.configured)
- .map((p) => ({
- group: p.group,
- icon: p.icon,
- options: p.models.map((m) => ({ ...m, provider: p.provider })),
- })),
- [
- openaiModels?.embedding_models,
- ollamaModels?.embedding_models,
- watsonxModels?.embedding_models,
- settings.providers?.openai?.configured,
- settings.providers?.ollama?.configured,
- settings.providers?.watsonx?.configured,
- ],
+ groupedCatalogOptions(catalog, configuredProviders, "embedding").map(
+ (group) => ({
+ group: group.group,
+ provider: group.key,
+ icon: getModelLogo("", group.key),
+ options: group.options,
+ }),
+ ),
+ [catalog, configuredProviders],
);
- const isLoadingAnyEmbeddingModels =
- openaiLoading || ollamaLoading || watsonxLoading;
+ const isLoadingAnyEmbeddingModels = catalogLoading;
const groupedVlmModels = useMemo(() => {
- const list: any[] = [];
+ const list: GroupedModelOption[] = groupedCatalogOptions(
+ catalog,
+ configuredProviders,
+ "vision",
+ ).map((group) => ({
+ group: group.group,
+ provider: group.key,
+ icon: getModelLogo("", group.key),
+ options: group.options,
+ }));
- // 1. Local Models
if (settings.local_vlm_models && settings.local_vlm_models.length > 0) {
- list.push({
+ list.unshift({
group: "Local Models",
+ provider: "local",
icon: getModelLogo("", "local"),
options: settings.local_vlm_models.map((m: string) => ({
value: m,
- label: m.split("/").pop(),
+ label: m.split("/").pop() ?? m,
provider: "local",
})),
});
}
- // 2. OpenAI
- if (settings.providers?.openai?.configured) {
- const models = (openaiModels?.language_models || [])
- .filter((m: any) => m.supports_images === true)
- .map((m: any) => ({ ...m, provider: "openai" }));
- if (models.length > 0) {
- list.push({
- group: "OpenAI",
- icon: getModelLogo("", "openai"),
- options: models,
- });
- }
- }
-
- // 3. Anthropic
- if (settings.providers?.anthropic?.configured) {
- const models = (anthropicModels?.language_models || [])
- .filter((m: any) => m.supports_images === true)
- .map((m: any) => ({ ...m, provider: "anthropic" }));
- if (models.length > 0) {
- list.push({
- group: "Anthropic",
- icon: getModelLogo("", "anthropic"),
- options: models,
- });
- }
- }
-
- // 4. Ollama
- if (settings.providers?.ollama?.configured) {
- const models = (ollamaModels?.language_models || [])
- .filter((m: any) => m.supports_images === true)
- .map((m: any) => ({ ...m, provider: "ollama" }));
- if (models.length > 0) {
- list.push({
- group: "Ollama",
- icon: getModelLogo("", "ollama"),
- options: models,
- });
- }
- }
-
- // 5. IBM watsonx.ai
- if (settings.providers?.watsonx?.configured) {
- const models = (watsonxModels?.language_models || [])
- .filter((m: any) => m.supports_images === true)
- .map((m: any) => ({ ...m, provider: "watsonx" }));
- if (models.length > 0) {
- list.push({
- group: "IBM watsonx.ai",
- icon: getModelLogo("", "watsonx"),
- options: models,
- });
- }
- }
-
return list;
- }, [
- settings.local_vlm_models,
- settings.providers?.openai?.configured,
- settings.providers?.anthropic?.configured,
- settings.providers?.ollama?.configured,
- settings.providers?.watsonx?.configured,
- openaiModels?.language_models,
- anthropicModels?.language_models,
- ollamaModels?.language_models,
- watsonxModels?.language_models,
- ]);
+ }, [catalog, configuredProviders, settings.local_vlm_models]);
- const isLoadingAnyVlmModels =
- openaiLoading || anthropicLoading || ollamaLoading || watsonxLoading;
+ const isLoadingAnyVlmModels = catalogLoading;
const allVlmOptions = useMemo(
() => groupedVlmModels.flatMap((g) => g.options),
@@ -280,6 +188,13 @@ export function IngestSettingsSection() {
() => groupedEmbeddingModels.flatMap((g) => g.options),
[groupedEmbeddingModels],
);
+ const selectedEmbeddingMatch = findGroupedSelection(
+ groupedEmbeddingModels,
+ settings.knowledge?.embedding_model,
+ settings.knowledge?.embedding_provider,
+ );
+ const selectedEmbedding = selectedEmbeddingMatch?.option;
+ const selectedEmbeddingGroup = selectedEmbeddingMatch?.group;
const handleEmbeddingModelChange = useCallback(
(newModel: string, provider?: string) => {
@@ -402,28 +317,19 @@ export function IngestSettingsSection() {
useRegisterDirty("ingest-settings", userEdited && knowledgeIngestDirty);
+ // Resolve through the same map that builds the groups: the catalogue now
+ // contributes custom LiteLLM providers, so a hard-coded chain would report
+ // OpenAI's state for any provider outside the four legacy keys.
const providerConfigured =
settings.providers === undefined || settings.providers === null
? undefined
- : vlmProvider === "watsonx"
- ? settings.providers.watsonx?.configured === true
- : vlmProvider === "anthropic"
- ? settings.providers.anthropic?.configured === true
- : vlmProvider === "ollama"
- ? settings.providers.ollama?.configured === true
- : vlmProvider === "local"
- ? true
- : settings.providers.openai?.configured === true;
+ : vlmProvider === "local"
+ ? true
+ : configuredProviders[
+ vlmProvider as keyof typeof configuredProviders
+ ] === true;
const providerWarning = pictureDescriptions && providerConfigured === false;
- const providerLabel =
- vlmProvider === "watsonx"
- ? "IBM watsonx.ai"
- : vlmProvider === "anthropic"
- ? "Anthropic"
- : vlmProvider === "ollama"
- ? "Ollama"
- : "OpenAI";
const handleChunkSizeChange = (value: string) => {
setUserEdited(true);
@@ -655,15 +561,36 @@ export function IngestSettingsSection() {
>
<ModelSelector
groupedOptions={groupedEmbeddingModels}
+ custom
noOptionsPlaceholder={
isLoadingAnyEmbeddingModels
? "Loading models..."
- : "No embedding models detected. Configure a provider first."
+ : catalogError
+ ? "Could not load the model catalogue. Retry later."
+ : "No embedding models detected. Configure a provider first."
}
value={settings.knowledge?.embedding_model || ""}
+ selectedProvider={settings.knowledge?.embedding_provider}
onValueChange={handleEmbeddingModelChange}
/>
</LabelWrapper>
+ {settings.knowledge?.embedding_model && selectedEmbeddingGroup && (
+ <div className="mt-3">
+ <ModelFeatures
+ model={
+ selectedEmbedding?.model ?? {
+ model: settings.knowledge.embedding_model,
+ // Without an explicit mode the panel treats an
+ // off-catalogue embedding model as a language model and
+ // warns that it cannot run the agent tools.
+ mode: "embedding",
+ }
+ }
+ providerName={selectedEmbeddingGroup.group}
+ provider={selectedEmbeddingGroup.provider}
+ />
+ </div>
+ )}
</div>
<div className="grid grid-cols-2 gap-4">
<div className="space-y-2">
@@ -878,12 +805,16 @@ export function IngestSettingsSection() {
>
<ModelSelector
groupedOptions={groupedVlmModels}
+ custom
noOptionsPlaceholder={
isLoadingAnyVlmModels
? "Loading models..."
- : "No models detected. Configure OpenAI, Anthropic, Ollama, or IBM watsonx.ai first."
+ : catalogError
+ ? "Could not load the model catalogue. Retry later."
+ : "No models detected. Configure OpenAI, Anthropic, Ollama, or IBM watsonx.ai first."
}
value={vlmModel}
+ selectedProvider={vlmProvider}
onValueChange={handleVlmModelChange}
hasError={!!validationError}
disabled={!pictureDescriptions}
diff --git a/frontend/app/settings/_components/ollama-settings-form.tsx b/frontend/app/settings/_components/ollama-settings-form.tsx
index f8d96034f..ee9d7d4ff 100644
--- a/frontend/app/settings/_components/ollama-settings-form.tsx
+++ b/frontend/app/settings/_components/ollama-settings-form.tsx
@@ -40,7 +40,10 @@ export function OllamaSettingsForm({
/>
</LabelWrapper>
{endpointError && (
- <p className="text-sm text-destructive min-w-0 [overflow-wrap:anywhere]">
+ <p
+ data-testid="provider-connection-error"
+ className="text-sm text-destructive min-w-0 [overflow-wrap:anywhere]"
+ >
{endpointError}
</p>
)}
diff --git a/frontend/app/settings/_components/openai-settings-form.tsx b/frontend/app/settings/_components/openai-settings-form.tsx
index 4a6ad04ed..778e30f47 100644
--- a/frontend/app/settings/_components/openai-settings-form.tsx
+++ b/frontend/app/settings/_components/openai-settings-form.tsx
@@ -41,7 +41,10 @@ export function OpenAISettingsForm({
/>
</LabelWrapper>
{apiKeyError && (
- <p className="text-sm text-destructive min-w-0 [overflow-wrap:anywhere]">
+ <p
+ data-testid="provider-connection-error"
+ className="text-sm text-destructive min-w-0 [overflow-wrap:anywhere]"
+ >
{apiKeyError}
</p>
)}
diff --git a/frontend/app/settings/_components/watsonx-settings-form.tsx b/frontend/app/settings/_components/watsonx-settings-form.tsx
index 155f11b97..a5cc16497 100644
--- a/frontend/app/settings/_components/watsonx-settings-form.tsx
+++ b/frontend/app/settings/_components/watsonx-settings-form.tsx
@@ -141,7 +141,10 @@ export function WatsonxSettingsForm({
</p>
)}
{modelsError && (
- <p className="text-sm text-destructive min-w-0 [overflow-wrap:anywhere]">
+ <p
+ data-testid="provider-connection-error"
+ className="text-sm text-destructive min-w-0 [overflow-wrap:anywhere]"
+ >
{modelsError.message}
</p>
)}
diff --git a/frontend/app/settings/_helpers/catalog-models.test.ts b/frontend/app/settings/_helpers/catalog-models.test.ts
new file mode 100644
index 000000000..4a9906f25
--- /dev/null
+++ b/frontend/app/settings/_helpers/catalog-models.test.ts
@@ -0,0 +1,282 @@
+import assert from "node:assert/strict";
+import { describe, it } from "node:test";
+import {
+ findGroupedSelection,
+ groupedCatalogOptions,
+ mergeLiveCatalogOptions,
+ onboardingCatalogConfigured,
+ onboardingCredentialFields,
+ providerCredentialsSatisfied,
+ savedSecretFieldsForProvider,
+} from "./catalog-models";
+
+const catalog = {
+ providers: [
+ {
+ key: "openai",
+ name: "OpenAI",
+ credential_fields: [
+ {
+ key: "api_base",
+ label: "API Base",
+ required: false,
+ field_type: "text",
+ },
+ {
+ key: "organization",
+ label: "OpenAI Organization ID",
+ required: false,
+ field_type: "text",
+ },
+ {
+ key: "api_key",
+ label: "OpenAI API Key",
+ required: true,
+ field_type: "password",
+ },
+ ],
+ model_placeholder: "gpt-4o",
+ models: [
+ { model: "container", mode: "chat" },
+ { model: "ft:gpt-3.5-turbo", mode: "chat" },
+ { model: "gpt-4o", mode: "chat", capabilities: ["vision"] },
+ {
+ model: "gpt-4o-mini",
+ mode: "chat",
+ capabilities: ["function_calling"],
+ },
+ ],
+ embedding_models: [
+ { model: "text-embedding-3-small", mode: "embedding" },
+ ],
+ },
+ {
+ key: "anthropic",
+ name: "Anthropic",
+ credential_fields: [
+ {
+ key: "api_key",
+ label: "API Key",
+ required: false,
+ field_type: "password",
+ },
+ ],
+ model_placeholder: "claude-sonnet-4-5",
+ models: [
+ {
+ model: "claude-sonnet-4-5",
+ mode: "chat",
+ capabilities: ["vision"],
+ },
+ ],
+ embedding_models: [],
+ },
+ {
+ key: "gemini",
+ name: "Gemini",
+ credential_fields: [],
+ model_placeholder: "gemini-pro",
+ models: [{ model: "gemini-pro", mode: "chat" }],
+ embedding_models: [],
+ },
+ ],
+};
+
+describe("groupedCatalogOptions", () => {
+ it("keeps only configured OpenRAG providers", () => {
+ const groups = groupedCatalogOptions(
+ catalog,
+ { openai: true, anthropic: false },
+ "language",
+ );
+ assert.deepEqual(
+ groups.map((g) => g.key),
+ ["openai"],
+ );
+ assert.deepEqual(
+ groups[0].options.map((o) => o.value),
+ ["gpt-4o-mini", "gpt-4o", "container", "ft:gpt-3.5-turbo"],
+ );
+ assert.equal(groups[0].options[0].provider, "openai");
+ });
+
+ it("supports arbitrary configured LiteLLM providers", () => {
+ const groups = groupedCatalogOptions(
+ catalog,
+ { openai: true, anthropic: true, gemini: true },
+ "language",
+ );
+ assert.deepEqual(
+ groups.map((g) => g.key),
+ ["openai", "anthropic", "gemini"],
+ );
+ });
+
+ it("uses embedding_models for the ingest picker", () => {
+ const groups = groupedCatalogOptions(
+ catalog,
+ { openai: true, anthropic: true },
+ "embedding",
+ );
+ assert.equal(groups.length, 1);
+ assert.equal(groups[0].options[0].value, "text-embedding-3-small");
+ });
+
+ it("keeps empty groups when includeEmpty is set", () => {
+ const groups = groupedCatalogOptions(
+ catalog,
+ { openai: true, anthropic: true },
+ "embedding",
+ { includeEmpty: true },
+ );
+ assert.deepEqual(
+ groups.map((g) => g.key),
+ ["openai", "anthropic"],
+ );
+ assert.equal(groups[1].options.length, 0);
+ });
+
+ it("filters vision-capable chat models for the VLM picker", () => {
+ const groups = groupedCatalogOptions(catalog, { openai: true }, "vision");
+ assert.deepEqual(
+ groups[0].options.map((o) => o.value),
+ ["gpt-4o"],
+ );
+ });
+
+ it("does not auto-offer LiteLLM template rows ahead of a real chat model", () => {
+ const groups = groupedCatalogOptions(catalog, { openai: true }, "language");
+ assert.equal(groups[0].options[0].value, "gpt-4o-mini");
+ });
+
+ it("returns nothing when the catalogue has not loaded", () => {
+ assert.deepEqual(
+ groupedCatalogOptions(undefined, { openai: true }, "language"),
+ [],
+ );
+ });
+});
+
+describe("onboardingCatalogConfigured", () => {
+ it("does not filter the full onboarding catalogue", () => {
+ assert.equal(onboardingCatalogConfigured(true, true), undefined);
+ });
+});
+
+describe("onboardingCredentialFields", () => {
+ it("returns the complete provider field schema", () => {
+ const fields = onboardingCredentialFields(catalog, "openai");
+ assert.deepEqual(
+ fields.map((field) => field.key),
+ ["api_base", "organization", "api_key"],
+ );
+ assert.equal(fields[2].required, true);
+ });
+
+ it("preserves LiteLLM required flags", () => {
+ const fields = onboardingCredentialFields(catalog, "anthropic");
+ assert.equal(fields[0].key, "api_key");
+ assert.equal(fields[0].required, false);
+ });
+
+ it("falls back to generic key and base fields for an unknown provider", () => {
+ const fields = onboardingCredentialFields(catalog, "ollama");
+ assert.deepEqual(
+ fields.map((field) => field.key),
+ ["api_key", "api_base"],
+ );
+ });
+});
+
+describe("mergeLiveCatalogOptions", () => {
+ it("appends live rows the catalogue does not already list", () => {
+ const groups = groupedCatalogOptions(
+ catalog,
+ { openai: true },
+ "embedding",
+ );
+ const merged = mergeLiveCatalogOptions(groups, "openai", [
+ {
+ value: "text-embedding-3-small",
+ label: "text-embedding-3-small",
+ provider: "openai",
+ },
+ { value: "nomic-embed", label: "nomic-embed", provider: "openai" },
+ ]);
+ assert.deepEqual(
+ merged[0].options.map((option) => option.value),
+ ["text-embedding-3-small", "nomic-embed"],
+ );
+ });
+});
+
+describe("findGroupedSelection", () => {
+ it("disambiguates the same model id across providers", () => {
+ const overlap = {
+ providers: [
+ {
+ key: "openai",
+ name: "OpenAI",
+ models: [{ model: "gpt-4o", mode: "chat" }],
+ },
+ {
+ key: "azure",
+ name: "Azure",
+ models: [{ model: "gpt-4o", mode: "chat" }],
+ },
+ ],
+ };
+ const groups = groupedCatalogOptions(
+ overlap,
+ { openai: true, azure: true },
+ "language",
+ );
+ const openai = findGroupedSelection(groups, "gpt-4o", "openai");
+ const azure = findGroupedSelection(groups, "gpt-4o", "azure");
+ assert.equal(openai?.group.key, "openai");
+ assert.equal(azure?.group.key, "azure");
+ assert.equal(openai?.option?.provider, "openai");
+ assert.equal(azure?.option?.provider, "azure");
+ });
+
+ it("still resolves by model name when no provider is given", () => {
+ const groups = groupedCatalogOptions(
+ catalog,
+ { openai: true, anthropic: true },
+ "language",
+ );
+ const selected = findGroupedSelection(groups, "claude-sonnet-4-5");
+ assert.equal(selected?.group.key, "anthropic");
+ });
+});
+
+describe("providerCredentialsSatisfied", () => {
+ it("reuses a legacy OpenAI key without another paste", () => {
+ assert.equal(
+ savedSecretFieldsForProvider(
+ { openai: { has_api_key: true } },
+ "openai",
+ ).includes("api_key"),
+ true,
+ );
+ assert.equal(
+ providerCredentialsSatisfied(
+ { openai: { has_api_key: true, configured: true } },
+ "openai",
+ catalog,
+ ),
+ true,
+ );
+ });
+
+ it("still requires a key when nothing is saved", () => {
+ assert.equal(
+ providerCredentialsSatisfied(
+ { openai: { has_api_key: false } },
+ "openai",
+ catalog,
+ ),
+ false,
+ );
+ });
+});
diff --git a/frontend/app/settings/_helpers/catalog-models.ts b/frontend/app/settings/_helpers/catalog-models.ts
new file mode 100644
index 000000000..2984a2058
--- /dev/null
+++ b/frontend/app/settings/_helpers/catalog-models.ts
@@ -0,0 +1,363 @@
+export interface CatalogSelectOption {
+ value: string;
+ label: string;
+ provider: string;
+ default?: boolean;
+ model?: CatalogModel;
+}
+
+/**
+ * Structural subset of the LiteLLM catalogue payload. Kept local so this
+ * helper stays importable from node:test without pulling react-query.
+ */
+export interface CatalogModel {
+ model: string;
+ mode?: string | null;
+ capabilities?: string[];
+ max_input_tokens?: number;
+ max_output_tokens?: number;
+ input_cost_per_token?: number;
+ output_cost_per_token?: number;
+ cache_read_input_token_cost?: number;
+ deprecation_date?: string;
+}
+
+export interface CatalogCredentialField {
+ key: string;
+ label: string;
+ placeholder?: string | null;
+ tooltip?: string | null;
+ required: boolean;
+ field_type: string;
+ options?: unknown;
+ default_value?: unknown;
+}
+
+interface CatalogProvider {
+ key: string;
+ name?: string;
+ models?: CatalogModel[];
+ embedding_models?: CatalogModel[];
+ credential_fields?: CatalogCredentialField[];
+}
+
+interface ModelCatalogResponse {
+ providers: CatalogProvider[];
+}
+
+export type SettingsCatalogProvider = string;
+
+export type CatalogModelKind = "language" | "embedding" | "vision";
+
+export interface CatalogOptionGroup {
+ key: SettingsCatalogProvider;
+ group: string;
+ options: CatalogSelectOption[];
+}
+
+function modelsForKind(
+ provider: CatalogProvider,
+ kind: CatalogModelKind,
+): CatalogModel[] {
+ if (kind === "embedding") {
+ return provider.embedding_models ?? [];
+ }
+ const chat = provider.models ?? [];
+ if (kind === "vision") {
+ return chat.filter((entry) => entry.capabilities?.includes("vision"));
+ }
+ return chat;
+}
+
+function toOption(entry: CatalogModel, provider: string): CatalogSelectOption {
+ return {
+ value: entry.model,
+ label: entry.model,
+ provider,
+ model: entry,
+ };
+}
+
+/** Models onboarding actually validates (chat + tools / a real embedding). */
+const PREFERRED_LANGUAGE_MODELS = [
+ "gpt-4o-mini",
+ "gpt-4o",
+ "gpt-4.1-mini",
+ "gpt-4.1",
+ "claude-sonnet-4-6",
+ "claude-sonnet-4-5",
+];
+const PREFERRED_EMBEDDING_MODELS = [
+ "text-embedding-3-small",
+ "text-embedding-3-large",
+];
+
+function optionRank(
+ option: CatalogSelectOption,
+ kind: CatalogModelKind,
+): Array<number | string> {
+ const name = option.value;
+ const lower = name.toLowerCase();
+ const caps = option.model?.capabilities ?? [];
+ const preferred =
+ kind === "embedding"
+ ? PREFERRED_EMBEDDING_MODELS
+ : PREFERRED_LANGUAGE_MODELS;
+ const preferredIndex = preferred.indexOf(name);
+ return [
+ lower.startsWith("ft:") ? 1 : 0,
+ caps.length === 0 ? 1 : 0,
+ kind === "language" && !caps.includes("function_calling") ? 1 : 0,
+ kind === "vision" && !caps.includes("vision") ? 1 : 0,
+ preferredIndex === -1 ? preferred.length : preferredIndex,
+ name,
+ ];
+}
+
+function compareCatalogOptions(
+ left: CatalogSelectOption,
+ right: CatalogSelectOption,
+ kind: CatalogModelKind,
+): number {
+ const leftRank = optionRank(left, kind);
+ const rightRank = optionRank(right, kind);
+ for (let index = 0; index < leftRank.length; index += 1) {
+ if (leftRank[index] < rightRank[index]) return -1;
+ if (leftRank[index] > rightRank[index]) return 1;
+ }
+ return 0;
+}
+
+function groupProviderKey(group: {
+ key?: string;
+ provider?: string;
+}): string | undefined {
+ return group.provider ?? group.key;
+}
+
+/**
+ * Resolve a picker row by provider + model. The same LiteLLM model id can
+ * appear under many vendors; name-only lookup always returns the first one.
+ */
+export function findGroupedSelection<
+ G extends {
+ key?: string;
+ provider?: string;
+ options: Array<{
+ value: string;
+ provider?: string;
+ model?: CatalogModel;
+ }>;
+ },
+>(
+ groups: G[],
+ model: string | undefined,
+ provider?: string,
+): { group: G; option: G["options"][number] | undefined } | undefined {
+ if (provider) {
+ const group = groups.find((entry) => groupProviderKey(entry) === provider);
+ if (!group) {
+ return undefined;
+ }
+ return {
+ group,
+ option: model
+ ? group.options.find((option) => option.value === model)
+ : undefined,
+ };
+ }
+ if (!model) {
+ return undefined;
+ }
+ const group = groups.find((entry) =>
+ entry.options.some((option) => option.value === model),
+ );
+ if (!group) {
+ return undefined;
+ }
+ return {
+ group,
+ option: group.options.find((option) => option.value === model),
+ };
+}
+
+/** Catalogue rows for one configured provider, mapped to ModelSelector options. */
+export function groupedCatalogOptions(
+ catalog: ModelCatalogResponse | undefined,
+ configured: Partial<Record<string, boolean | undefined>> | undefined,
+ kind: CatalogModelKind,
+ options?: { includeEmpty?: boolean },
+): CatalogOptionGroup[] {
+ if (!catalog?.providers?.length) {
+ return [];
+ }
+ const groups: CatalogOptionGroup[] = [];
+ for (const provider of catalog.providers) {
+ const key = provider.key;
+ if (configured && !configured[key]) {
+ continue;
+ }
+ const modelOptions = modelsForKind(provider, kind)
+ .map((entry) => toOption(entry, key))
+ .sort((left, right) => compareCatalogOptions(left, right, kind));
+ if (modelOptions.length === 0 && !options?.includeEmpty) {
+ continue;
+ }
+ groups.push({
+ key,
+ group: provider.name || key,
+ options: modelOptions,
+ });
+ }
+ return groups;
+}
+
+/**
+ * Onboarding lists every OpenRAG-credentialed provider, even before the
+ * operator has saved a key — they are here to configure one.
+ */
+export function onboardingCatalogConfigured(
+ _isEmbedding: boolean,
+ _isCloudBrand: boolean,
+): undefined {
+ return undefined;
+}
+
+/** Append live /models/{provider} rows that the catalogue does not already list. */
+export function mergeLiveCatalogOptions(
+ groups: CatalogOptionGroup[],
+ provider: string | undefined,
+ live: CatalogSelectOption[],
+): CatalogOptionGroup[] {
+ if (!provider || live.length === 0) {
+ return groups;
+ }
+ return groups.map((group) => {
+ if (group.key !== provider) {
+ return group;
+ }
+ const seen = new Set(group.options.map((option) => option.value));
+ const extra = live.filter((option) => !seen.has(option.value));
+ if (extra.length === 0) {
+ return group;
+ }
+ return { ...group, options: [...group.options, ...extra] };
+ });
+}
+
+/**
+ * Credential controls for onboarding come directly from LiteLLM's provider
+ * schema. The backend persists and encrypts arbitrary field keys.
+ */
+export interface SavedProviderSnapshot {
+ configured?: boolean;
+ has_api_key?: boolean;
+ endpoint?: string;
+ project_id?: string;
+ credential_values?: Record<string, string>;
+ secret_fields?: string[];
+}
+
+export interface SavedProvidersSnapshot {
+ openai?: SavedProviderSnapshot;
+ anthropic?: SavedProviderSnapshot;
+ watsonx?: SavedProviderSnapshot;
+ ollama?: SavedProviderSnapshot;
+ custom?: Record<string, SavedProviderSnapshot>;
+}
+
+/** Secrets already stored for this vendor — including the four legacy slots. */
+export function savedSecretFieldsForProvider(
+ providers: SavedProvidersSnapshot | undefined,
+ provider: string,
+): string[] {
+ if (!providers || !provider) {
+ return [];
+ }
+ const fields = new Set(providers.custom?.[provider]?.secret_fields ?? []);
+ if (provider === "openai" && providers.openai?.has_api_key) {
+ fields.add("api_key");
+ }
+ if (provider === "anthropic" && providers.anthropic?.has_api_key) {
+ fields.add("api_key");
+ }
+ if (provider === "watsonx" && providers.watsonx?.has_api_key) {
+ fields.add("api_key");
+ }
+ return [...fields];
+}
+
+export function savedCredentialValuesForProvider(
+ providers: SavedProvidersSnapshot | undefined,
+ provider: string,
+): Record<string, string> {
+ const values = {
+ ...(providers?.custom?.[provider]?.credential_values ?? {}),
+ };
+ if (provider === "watsonx") {
+ if (providers?.watsonx?.endpoint) {
+ values.api_base ??= providers.watsonx.endpoint;
+ }
+ if (providers?.watsonx?.project_id) {
+ values.project_id ??= providers.watsonx.project_id;
+ }
+ }
+ if (provider === "ollama" && providers?.ollama?.endpoint) {
+ values.api_base ??= providers.ollama.endpoint;
+ }
+ return values;
+}
+
+/** True when onboarding can reuse credentials already saved for this vendor. */
+export function providerCredentialsSatisfied(
+ providers: SavedProvidersSnapshot | undefined,
+ provider: string,
+ catalog: ModelCatalogResponse | undefined,
+): boolean {
+ if (!providers || !provider) {
+ return false;
+ }
+ const required = onboardingCredentialFields(catalog, provider).filter(
+ (field) => field.required,
+ );
+ const secrets = new Set(savedSecretFieldsForProvider(providers, provider));
+ const values = savedCredentialValuesForProvider(providers, provider);
+ if (required.length === 0) {
+ return Boolean(
+ secrets.size > 0 ||
+ Object.keys(values).length > 0 ||
+ providers.custom?.[provider]?.configured ||
+ (provider === "openai" && providers.openai?.configured) ||
+ (provider === "anthropic" && providers.anthropic?.configured) ||
+ (provider === "watsonx" && providers.watsonx?.configured) ||
+ (provider === "ollama" && providers.ollama?.configured),
+ );
+ }
+ return required.every(
+ (field) => Boolean(values[field.key]?.trim()) || secrets.has(field.key),
+ );
+}
+
+export function onboardingCredentialFields(
+ catalog: ModelCatalogResponse | undefined,
+ provider: SettingsCatalogProvider,
+): CatalogCredentialField[] {
+ return (
+ catalog?.providers?.find((entry) => entry.key === provider)
+ ?.credential_fields ?? [
+ {
+ key: "api_key",
+ label: "API key",
+ required: false,
+ field_type: "password",
+ },
+ {
+ key: "api_base",
+ label: "API base",
+ placeholder: "https://...",
+ required: false,
+ field_type: "text",
+ },
+ ]
+ );
+}
diff --git a/frontend/app/settings/_helpers/model-helpers.tsx b/frontend/app/settings/_helpers/model-helpers.tsx
index e658a3888..cd8d4f3ef 100644
--- a/frontend/app/settings/_helpers/model-helpers.tsx
+++ b/frontend/app/settings/_helpers/model-helpers.tsx
@@ -42,7 +42,7 @@ export interface ModelOption {
}
// Helper function to get model logo based on provider or model name
-export function getModelLogo(modelValue: string, provider?: ModelProvider) {
+export function getModelLogo(modelValue: string, provider?: string) {
// First check by provider
if (provider === "openai") {
return <OpenAILogo className="w-4 h-4" />;
@@ -76,6 +76,23 @@ export function getModelLogo(modelValue: string, provider?: ModelProvider) {
<path d="M1 15h3" />
</svg>
);
+ } else if (provider) {
+ return (
+ <svg
+ xmlns="http://www.w3.org/2000/svg"
+ viewBox="0 0 24 24"
+ fill="none"
+ stroke="currentColor"
+ strokeWidth="2"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ className="w-4 h-4 text-muted-foreground"
+ >
+ <path d="M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z" />
+ <polyline points="3.27 6.96 12 12.01 20.73 6.96" />
+ <line x1="12" y1="22.08" x2="12" y2="12" />
+ </svg>
+ );
}
// Fallback to model name analysis
diff --git a/frontend/app/settings/_helpers/model-info.ts b/frontend/app/settings/_helpers/model-info.ts
new file mode 100644
index 000000000..d96b2e353
--- /dev/null
+++ b/frontend/app/settings/_helpers/model-info.ts
@@ -0,0 +1,63 @@
+import type { CatalogModel } from "./catalog-models";
+
+export const MODELS_PER_PROVIDER = 3;
+
+export const PRIMARY_CAPABILITIES = [
+ { key: "function_calling", label: "Tools", hint: "Can call tools" },
+ { key: "vision", label: "Vision", hint: "Accepts images" },
+ { key: "reasoning", label: "Reasoning", hint: "Extended thinking" },
+] as const;
+
+export const SECONDARY_CAPABILITIES = [
+ {
+ key: "structured_output",
+ label: "Structured output",
+ hint: "Supports JSON schemas",
+ },
+ {
+ key: "prompt_caching",
+ label: "Prompt caching",
+ hint: "Caches shared prompt prefixes",
+ },
+ { key: "pdf_input", label: "PDF input", hint: "Accepts PDFs" },
+ { key: "web_search", label: "Web search", hint: "Provider-side web search" },
+ { key: "audio_input", label: "Audio in", hint: "Accepts audio" },
+ { key: "computer_use", label: "Computer use", hint: "Can drive a screen" },
+ {
+ key: "parallel_tools",
+ label: "Parallel tools",
+ hint: "Can call tools in parallel",
+ },
+] as const;
+
+export const ALL_CAPABILITIES = [
+ ...PRIMARY_CAPABILITIES,
+ ...SECONDARY_CAPABILITIES,
+];
+
+export type ModelCapability = (typeof ALL_CAPABILITIES)[number]["key"];
+
+export function supports(model: CatalogModel, capability: ModelCapability) {
+ return model.capabilities?.includes(capability) ?? false;
+}
+
+export function formatContext(tokens?: number): string {
+ if (!tokens) return "";
+ if (tokens >= 1_000_000) {
+ const millions = tokens / 1_000_000;
+ return `${millions % 1 === 0 ? millions : millions.toFixed(1)}M`;
+ }
+ if (tokens >= 1_000) return `${Math.round(tokens / 1_000)}K`;
+ return String(tokens);
+}
+
+export function formatPrice(perToken?: number): string {
+ if (perToken == null) return "—";
+ const perMillion = perToken * 1_000_000;
+ if (perMillion === 0) return "Free";
+ return `$${perMillion < 1 ? perMillion.toFixed(3) : perMillion.toFixed(2)}`;
+}
+
+export function formatTokens(tokens?: number): string {
+ return tokens ? tokens.toLocaleString() : "—";
+}
diff --git a/frontend/components/cloud-picker/ingest-settings.tsx b/frontend/components/cloud-picker/ingest-settings.tsx
index 684dc84f5..b5f352c95 100644
--- a/frontend/components/cloud-picker/ingest-settings.tsx
+++ b/frontend/components/cloud-picker/ingest-settings.tsx
@@ -2,13 +2,10 @@
import { ChevronRight } from "lucide-react";
import { useMemo } from "react";
-import {
- useGetIBMModelsQuery,
- useGetOllamaModelsQuery,
- useGetOpenAIModelsQuery,
-} from "@/app/api/queries/useGetModelsQuery";
+import { useGetModelCatalogQuery } from "@/app/api/queries/useGetModelsQuery";
import { useGetSettingsQuery } from "@/app/api/queries/useGetSettingsQuery";
import type { ModelOption } from "@/app/onboarding/_components/model-selector";
+import { groupedCatalogOptions } from "@/app/settings/_helpers/catalog-models";
import {
getFallbackModels,
type ModelProvider,
@@ -72,32 +69,25 @@ export const IngestSettings = ({
const currentProvider = (apiSettings.knowledge?.embedding_provider ||
"openai") as ModelProvider;
- // Fetch available models based on provider
- const { data: openaiModelsData } = useGetOpenAIModelsQuery(undefined, {
- enabled: (isAuthenticated || isNoAuthMode) && currentProvider === "openai",
- });
-
- const { data: ollamaModelsData } = useGetOllamaModelsQuery(undefined, {
- enabled: (isAuthenticated || isNoAuthMode) && currentProvider === "ollama",
- });
-
- const { data: ibmModelsData } = useGetIBMModelsQuery(undefined, {
- enabled: (isAuthenticated || isNoAuthMode) && currentProvider === "watsonx",
+ const { data: catalog } = useGetModelCatalogQuery({
+ enabled: isAuthenticated || isNoAuthMode,
});
- // Select the appropriate models data based on provider
- const modelsData =
- currentProvider === "openai"
- ? openaiModelsData
- : currentProvider === "ollama"
- ? ollamaModelsData
- : currentProvider === "watsonx"
- ? ibmModelsData
- : openaiModelsData;
+ // `groupedCatalogOptions` keys off the provider string, so a generic LiteLLM
+ // provider resolves here too; restricting this to the four legacy keys hid
+ // the catalogue models of every custom embedding provider. An unknown
+ // provider simply yields no group and falls through to `getFallbackModels`.
+ const catalogEmbeddingModels = useMemo(
+ () =>
+ groupedCatalogOptions(
+ catalog,
+ { [currentProvider]: true },
+ "embedding",
+ )[0]?.options ?? [],
+ [catalog, currentProvider],
+ );
- const defaultEmbedding = modelsData?.embedding_models?.find(
- (m) => m.default,
- )?.value;
+ const defaultEmbedding = catalogEmbeddingModels[0]?.value;
const defaultSettings: IngestSettingsType = {
...knowledgeToIngestSettings(apiSettings.knowledge),
@@ -113,9 +103,10 @@ export const IngestSettings = ({
const embeddingSelectOptions = useMemo(() => {
const fallbackList = (getFallbackModels(currentProvider).embedding ??
[]) as ModelOption[];
- const fromApi = modelsData?.embedding_models;
let base: ModelOption[] =
- fromApi && fromApi.length > 0 ? [...fromApi] : [...fallbackList];
+ catalogEmbeddingModels.length > 0
+ ? [...catalogEmbeddingModels]
+ : [...fallbackList];
const v = currentSettings.embeddingModel?.trim();
if (!v) {
return base.length > 0
@@ -131,11 +122,7 @@ export const IngestSettings = ({
base = [{ value: v, label: v }, ...base];
}
return base;
- }, [
- currentProvider,
- modelsData?.embedding_models,
- currentSettings.embeddingModel,
- ]);
+ }, [currentProvider, catalogEmbeddingModels, currentSettings.embeddingModel]);
const selectEmbeddingValue =
embeddingSelectOptions.some(
diff --git a/frontend/tests/pages/Settings.ts b/frontend/tests/pages/Settings.ts
index 7aef5b945..24614b651 100644
--- a/frontend/tests/pages/Settings.ts
+++ b/frontend/tests/pages/Settings.ts
@@ -43,10 +43,14 @@ export class Settings {
this.page.getByRole("button", { name: "Remove" });
private readonly removeAnywayButton = () =>
this.page.getByRole("button", { name: "Remove Anyway" });
- private readonly watsonxConnectionErrorMessage = () =>
- this.page.locator('[role="dialog"] .text-destructive').first();
- private readonly openaiConnectionErrorMessage = () =>
- this.page.locator('[role="dialog"] .text-destructive').first();
+ // The dialog's Remove button is also styled `.text-destructive`, so the old
+ // selector matched it and made `successToast.or(errorMsg)` ambiguous under
+ // Playwright strict mode. Target the error element itself.
+ private readonly providerConnectionErrorMessage = () =>
+ this.page
+ .locator('[role="dialog"]')
+ .getByTestId("provider-connection-error")
+ .first();
/**
* Get locator for configure button by provider name
@@ -364,16 +368,10 @@ export class Settings {
await this.watsonxProjectIDInput().fill(projectId);
await this.apiKeyInput().fill(apiKey);
await this.saveModelProviderButton().click();
- const successToast = this.getToastByText(
+ await this.awaitProviderConfigResult(
+ "Watsonx.ai",
"IBM watsonx.ai successfully configured",
);
- const errorMsg = this.watsonxConnectionErrorMessage();
- await expect(successToast.or(errorMsg)).toBeVisible({ timeout: 30000 });
- if (await errorMsg.isVisible()) {
- throw new Error(
- `Watsonx.ai configuration failed: ${await errorMsg.textContent()}`,
- );
- }
logger.info("Watsonx.ai configuration completed");
await expect(editBtn).toBeEnabled();
}
@@ -388,6 +386,38 @@ export class Settings {
}
}
+ /**
+ * Wait for a provider dialog to report success or a connection error.
+ *
+ * Racing two locators with `.or()` fails under strict mode as soon as either
+ * side matches more than one node, so poll the two outcomes explicitly.
+ */
+ private async awaitProviderConfigResult(
+ provider: string,
+ successText: string,
+ ) {
+ const successToast = this.getToastByText(successText);
+ const errorMsg = this.providerConnectionErrorMessage();
+
+ await expect
+ .poll(
+ async () => {
+ if (await errorMsg.isVisible().catch(() => false)) return "error";
+ if (await successToast.isVisible().catch(() => false))
+ return "success";
+ return "pending";
+ },
+ { timeout: 30000 },
+ )
+ .not.toBe("pending");
+
+ if (await errorMsg.isVisible().catch(() => false)) {
+ throw new Error(
+ `${provider} configuration failed: ${await errorMsg.textContent()}`,
+ );
+ }
+ }
+
/**
* Remove model provider configuration
*/
@@ -452,16 +482,10 @@ export class Settings {
const apiKey = config.openaiApiKey;
await this.apiKeyInput().fill(apiKey);
await this.saveModelProviderButton().click();
- const successToast = this.getToastByText(
+ await this.awaitProviderConfigResult(
+ "OpenAI",
"OpenAI successfully configured",
);
- const errorMsg = this.openaiConnectionErrorMessage();
- await expect(successToast.or(errorMsg)).toBeVisible({ timeout: 30000 });
- if (await errorMsg.isVisible()) {
- throw new Error(
- `OpenAI configuration failed: ${await errorMsg.textContent()}`,
- );
- }
logger.info("OpenAI configuration completed");
await expect(editBtn).toBeEnabled();
}
@@ -505,7 +529,9 @@ export class Settings {
logger.info(
"Verify that watsonx.ai configuration failed due to invalid credentials",
);
- await expect(this.watsonxConnectionErrorMessage()).toBeVisible();
+ await expect(this.providerConnectionErrorMessage()).toBeVisible({
+ timeout: 30000,
+ });
}
}
}
diff --git a/kubernetes/helm/openrag/templates/langflow/langflow-dotenv.yaml b/kubernetes/helm/openrag/templates/langflow/langflow-dotenv.yaml
index b2b669378..5673808b1 100644
--- a/kubernetes/helm/openrag/templates/langflow/langflow-dotenv.yaml
+++ b/kubernetes/helm/openrag/templates/langflow/langflow-dotenv.yaml
@@ -52,11 +52,10 @@ stringData:
{{- end }}
# Model Provider API Keys / Endpoints
- {{- if .Values.llmProviders.openai.apiKey }}
- OPENAI_API_KEY={{ .Values.llmProviders.openai.apiKey | quote }}
- {{- else }}
+ # OPENAI_API_KEY stays empty in Langflow. OpenRAG injects a hop token at runtime.
OPENAI_API_KEY="None"
- {{- end }}
+ OPENRAG_LLM_TOKEN="None"
+ OPENRAG_LLM_BASE_URL="None"
{{- if .Values.llmProviders.anthropic.apiKey }}
ANTHROPIC_API_KEY={{ .Values.llmProviders.anthropic.apiKey | quote }}
{{- else }}
diff --git a/kubernetes/helm/openrag/values.yaml b/kubernetes/helm/openrag/values.yaml
index 592cf6349..a4eb94b7a 100644
--- a/kubernetes/helm/openrag/values.yaml
+++ b/kubernetes/helm/openrag/values.yaml
@@ -195,7 +195,7 @@ langflow:
host: "https://cloud.langfuse.com"
# Variables to expose to flows
- variablesToGetFromEnvironment: "JWT,OPENRAG-QUERY-FILTER,OPENSEARCH_PASSWORD,OPENSEARCH_URL,OPENSEARCH_INDEX_NAME,DOCLING_SERVE_URL,DOCLING_SERVE_VERIFY_SSL,DOCLING_TASK_ID,OWNER,OWNER_NAME,OWNER_EMAIL,CONNECTOR_TYPE,DOCUMENT_ID,SOURCE_URL,ALLOWED_USERS,ALLOWED_GROUPS,ALLOWED_PRINCIPALS,FILENAME,MIMETYPE,FILESIZE,SELECTED_EMBEDDING_MODEL,OPENAI_API_KEY,ANTHROPIC_API_KEY,WATSONX_APIKEY,WATSONX_URL,WATSONX_PROJECT_ID,OLLAMA_BASE_URL,OPENRAG_INGEST_URL,OPENRAG_INGEST_TOKEN,OPENRAG_INGEST_RUN_ID,OPENRAG_INGEST_BATCH_SIZE"
+ variablesToGetFromEnvironment: "JWT,OPENRAG-QUERY-FILTER,OPENSEARCH_PASSWORD,OPENSEARCH_URL,OPENSEARCH_INDEX_NAME,DOCLING_SERVE_URL,DOCLING_SERVE_VERIFY_SSL,DOCLING_TASK_ID,OWNER,OWNER_NAME,OWNER_EMAIL,CONNECTOR_TYPE,DOCUMENT_ID,SOURCE_URL,ALLOWED_USERS,ALLOWED_GROUPS,ALLOWED_PRINCIPALS,FILENAME,MIMETYPE,FILESIZE,SELECTED_EMBEDDING_MODEL,OPENAI_API_KEY,OPENRAG_LLM_TOKEN,OPENRAG_LLM_BASE_URL,ANTHROPIC_API_KEY,WATSONX_APIKEY,WATSONX_URL,WATSONX_PROJECT_ID,OLLAMA_BASE_URL,OPENRAG_INGEST_URL,OPENRAG_INGEST_TOKEN,OPENRAG_INGEST_RUN_ID,OPENRAG_INGEST_BATCH_SIZE"
# Probes
livenessProbe:
diff --git a/kubernetes/operator/internal/controller/env.go b/kubernetes/operator/internal/controller/env.go
index 7103c3d2e..f75cf5b8f 100644
--- a/kubernetes/operator/internal/controller/env.go
+++ b/kubernetes/operator/internal/controller/env.go
@@ -34,7 +34,7 @@ func NewEnvVarManager() *EnvVarManager {
"LANGFLOW_DATABASE_URL": "sqlite:////app/data/langflow.db",
// Variables to expose to Langflow components
- "LANGFLOW_VARIABLES_TO_GET_FROM_ENVIRONMENT": "JWT,OPENRAG_QUERY_FILTER,OPENSEARCH_PASSWORD,OPENSEARCH_URL,OPENSEARCH_INDEX_NAME,DOCLING_SERVE_URL,DOCLING_SERVE_VERIFY_SSL,DOCLING_TASK_ID,OWNER,OWNER_NAME,OWNER_EMAIL,CONNECTOR_TYPE,DOCUMENT_ID,SOURCE_URL,ALLOWED_USERS,ALLOWED_GROUPS,ALLOWED_PRINCIPALS,FILENAME,MIMETYPE,FILESIZE,SELECTED_EMBEDDING_MODEL,OPENAI_API_KEY,ANTHROPIC_API_KEY,WATSONX_API_KEY,WATSONX_ENDPOINT,WATSONX_PROJECT_ID,OLLAMA_BASE_URL,OPENRAG_INGEST_URL,OPENRAG_INGEST_TOKEN,OPENRAG_INGEST_RUN_ID,OPENRAG_INGEST_BATCH_SIZE",
+ "LANGFLOW_VARIABLES_TO_GET_FROM_ENVIRONMENT": "JWT,OPENRAG_QUERY_FILTER,OPENSEARCH_PASSWORD,OPENSEARCH_URL,OPENSEARCH_INDEX_NAME,DOCLING_SERVE_URL,DOCLING_SERVE_VERIFY_SSL,DOCLING_TASK_ID,OWNER,OWNER_NAME,OWNER_EMAIL,CONNECTOR_TYPE,DOCUMENT_ID,SOURCE_URL,ALLOWED_USERS,ALLOWED_GROUPS,ALLOWED_PRINCIPALS,FILENAME,MIMETYPE,FILESIZE,SELECTED_EMBEDDING_MODEL,OPENAI_API_KEY,OPENRAG_LLM_TOKEN,OPENRAG_LLM_BASE_URL,ANTHROPIC_API_KEY,WATSONX_API_KEY,WATSONX_ENDPOINT,WATSONX_PROJECT_ID,OLLAMA_BASE_URL,OPENRAG_INGEST_URL,OPENRAG_INGEST_TOKEN,OPENRAG_INGEST_RUN_ID,OPENRAG_INGEST_BATCH_SIZE",
// Authentication and user management
"LANGFLOW_SKIP_AUTH_AUTO_LOGIN": "true",
@@ -87,14 +87,16 @@ func NewEnvVarManager() *EnvVarManager {
"DOCLING_SERVE_VERIFY_SSL": "false",
// Provider API keys (defaults to None, overridden by CR spec)
- "OPENAI_API_KEY": "None",
- "ANTHROPIC_API_KEY": "None",
- "WATSONX_API_KEY": "None",
- "OLLAMA_BASE_URL": "None",
- "WATSONX_ENDPOINT": "https://us-south.ml.cloud.ibm.com",
- "WATSONX_PROJECT_ID": "None",
- "LLM_MODEL": "ibm/granite-3-2-8b-instruct",
- "LLM_PROVIDER": "watsonx",
+ "OPENAI_API_KEY": "None",
+ "OPENRAG_LLM_TOKEN": "None",
+ "OPENRAG_LLM_BASE_URL": "None",
+ "ANTHROPIC_API_KEY": "None",
+ "WATSONX_API_KEY": "None",
+ "OLLAMA_BASE_URL": "None",
+ "WATSONX_ENDPOINT": "https://us-south.ml.cloud.ibm.com",
+ "WATSONX_PROJECT_ID": "None",
+ "LLM_MODEL": "ibm/granite-3-2-8b-instruct",
+ "LLM_PROVIDER": "watsonx",
},
DefaultOpenRagBEEnvVars: map[string]string{
// Langflow connection
diff --git a/scripts/patch_langflow_openrag_bundle.py b/scripts/patch_langflow_openrag_bundle.py
new file mode 100644
index 000000000..d89eb7778
--- /dev/null
+++ b/scripts/patch_langflow_openrag_bundle.py
@@ -0,0 +1,180 @@
+#!/usr/bin/env python3
+"""Insert OpenRAG into Langflow's SIDEBAR_BUNDLES (source TS or built JS).
+
+Langflow only shows a Bundles sidebar group when ``SIDEBAR_BUNDLES[].name``
+matches the category key from ``custom_components/<folder>`` or the component
+index. Register both ``OpenRAG`` and ``openrag`` so either folder casing works.
+
+ { display_name: "OpenRAG", name: "OpenRAG", icon: "OpenRAG" }
+ { display_name: "OpenRAG", name: "openrag", icon: "OpenRAG" }
+"""
+
+from __future__ import annotations
+
+import re
+import sys
+from pathlib import Path
+
+_BUNDLE_NAMES = ("OpenRAG", "openrag")
+
+_ANCHORS = (
+ ("OpenAI", "openai", "OpenAI"),
+ ("Docling", "docling", "Docling"),
+ ("NVIDIA", "nvidia", "NVIDIA"),
+)
+
+_TEXT_SUFFIXES = {".ts", ".tsx", ".js", ".mjs", ".cjs", ".html"}
+
+_FRONTEND_ROOTS = (
+ Path("/app/src/frontend/src/utils/styleUtils.ts"),
+ Path("/app/src/backend/langflow/frontend"),
+ Path("/app/src/backend/base/langflow/frontend"),
+ Path("/app/langflow/frontend"),
+)
+
+
+def _field(key: str, value: str) -> str:
+ """Match ``key: "value"`` or ``"key":"value"`` (TS source or minified JSON-like JS)."""
+ return rf'["\']?{re.escape(key)}["\']?\s*:\s*["\']{re.escape(value)}["\']'
+
+
+def _has_bundle_name(text: str, name: str) -> bool:
+ return (
+ re.search(
+ rf"\{{(?=[^{{}}]*{_field('display_name', 'OpenRAG')})"
+ rf"(?=[^{{}}]*{_field('name', name)})"
+ rf"[^{{}}]*\}}",
+ text,
+ )
+ is not None
+ )
+
+
+def _missing_bundle_names(text: str) -> list[str]:
+ return [name for name in _BUNDLE_NAMES if not _has_bundle_name(text, name)]
+
+
+def _anchor(display: str, name: str, icon: str) -> re.Pattern[str]:
+ return re.compile(
+ rf"\{{(?=[^{{}}]*{_field('display_name', display)})"
+ rf"(?=[^{{}}]*{_field('name', name)})"
+ rf"(?=[^{{}}]*{_field('icon', icon)})"
+ rf"[^{{}}]+\}}"
+ rf"(?P<comma>\s*,)?"
+ )
+
+
+def _object_for(name: str, *, quoted_keys: bool, compact: bool) -> str:
+ if quoted_keys:
+ return f'{{"display_name":"OpenRAG","name":"{name}","icon":"OpenRAG"}}'
+ if compact:
+ return f'{{display_name:"OpenRAG",name:"{name}",icon:"OpenRAG"}}'
+ return f'{{ display_name: "OpenRAG", name: "{name}", icon: "OpenRAG" }}'
+
+
+def _entries_for(sample: str, names: list[str]) -> tuple[str, str]:
+ stripped = sample.lstrip()
+ quoted_keys = bool(re.search(r'["\']display_name["\']\s*:', sample))
+ compact = len(stripped) > 1 and stripped[1] not in " \n\t"
+ objects = [_object_for(name, quoted_keys=quoted_keys, compact=compact) for name in names]
+ if compact:
+ return "", ",".join(objects)
+ return "\n ", ",\n ".join(objects)
+
+
+def patch_text(text: str) -> str | None:
+ """Return patched text, or None when this blob has no SIDEBAR_BUNDLES anchor."""
+ missing = _missing_bundle_names(text)
+ if not missing:
+ return text
+
+ for display, name, icon in _ANCHORS:
+ match = _anchor(display, name, icon).search(text)
+ if match is None:
+ continue
+ sample = match.group(0)
+ comma = match.group("comma") or ","
+ separator, entries = _entries_for(sample, missing)
+ if sample.endswith(","):
+ replacement = f"{sample}{separator}{entries},"
+ else:
+ replacement = f"{sample}{comma}{separator}{entries}{comma}"
+ return text[: match.start()] + replacement + text[match.end() :]
+ return None
+
+
+def _iter_files(roots: list[Path]) -> list[Path]:
+ files: list[Path] = []
+ seen: set[Path] = set()
+ for root in roots:
+ if not root.exists():
+ continue
+ if root.is_file():
+ if root.suffix in _TEXT_SUFFIXES and root not in seen:
+ files.append(root)
+ seen.add(root)
+ continue
+ for path in root.rglob("*"):
+ if not path.is_file() or path.suffix not in _TEXT_SUFFIXES:
+ continue
+ resolved = path.resolve()
+ if resolved in seen:
+ continue
+ seen.add(resolved)
+ files.append(path)
+ return files
+
+
+def default_roots() -> list[Path]:
+ roots = list(_FRONTEND_ROOTS)
+ for base in (Path("/app/.venv/lib"), Path("/usr/local/lib")):
+ if not base.exists():
+ continue
+ roots.extend(base.glob("python*/site-packages/langflow/frontend"))
+ roots.extend(base.glob("python*/dist-packages/langflow/frontend"))
+ app = Path("/app")
+ if app.exists():
+ roots.extend(path for path in app.glob("**/frontend") if path.is_dir())
+ unique: list[Path] = []
+ seen: set[Path] = set()
+ for root in roots:
+ resolved = root.resolve() if root.exists() else root
+ if resolved in seen:
+ continue
+ seen.add(resolved)
+ unique.append(root)
+ return unique
+
+
+def patch_paths(roots: list[Path]) -> int:
+ patched = 0
+ found_anchor = False
+ for path in _iter_files(roots):
+ original = path.read_text(encoding="utf-8", errors="ignore")
+ updated = patch_text(original)
+ if updated is None:
+ continue
+ found_anchor = True
+ if updated == original:
+ patched += 1
+ continue
+ path.write_text(updated, encoding="utf-8")
+ patched += 1
+ print(f"Patched Langflow SIDEBAR_BUNDLES in {path}")
+ if not found_anchor:
+ searched = ", ".join(str(root) for root in roots)
+ raise SystemExit(
+ f"Could not find a SIDEBAR_BUNDLES anchor to insert OpenRAG. Looked in: {searched}"
+ )
+ return patched
+
+
+def main(argv: list[str] | None = None) -> int:
+ args = list(sys.argv[1:] if argv is None else argv)
+ roots = [Path(arg) for arg in args] if args else default_roots()
+ patch_paths(roots)
+ return 0
+
+
+if __name__ == "__main__":
+ raise SystemExit(main())
diff --git a/scripts/update_flow_components.py b/scripts/update_flow_components.py
index 8aaafd3a7..dd5345c82 100644
--- a/scripts/update_flow_components.py
+++ b/scripts/update_flow_components.py
@@ -4,20 +4,28 @@ Utility to sync embedded component code inside Langflow JSON files.
Given a Python source file (e.g. the OpenSearch component implementation) and
a target selector, this script updates every flow definition in ``./flows`` so
-that the component's ``template.code.value`` matches the supplied file.
+that the component's ``template.code.value`` matches the supplied file. It
+also refreshes ``metadata.code_hash`` (sha256 prefix, 12 chars) and can set
+``metadata.module``.
Example:
python scripts/update_flow_components.py \\
- --code-file flows/components/opensearch_multimodel.py \\
- --display-name \"OpenSearch (Multi-Model)\"
+ --code-file custom_components/openrag/opensearch_multimodal.py \\
+ --display-name "OpenSearch (Multi-Model Multi-Embedding)" \\
+ --set-module custom_components.OpenRAG.opensearch_multimodal.OpenSearchVectorStoreComponentMultimodalMultiEmbedding
"""
from __future__ import annotations
import argparse
+import hashlib
import json
+from collections.abc import Iterable
from pathlib import Path
-from typing import Iterable
+
+
+def _code_hash(source: str) -> str:
+ return hashlib.sha256(source.encode("utf-8")).hexdigest()[:12]
def load_code(source_path: Path) -> str:
@@ -27,7 +35,9 @@ def load_code(source_path: Path) -> str:
raise SystemExit(f"[error] code file not found: {source_path}") from exc
-def should_update_component(node: dict, *, display_name: str | None, metadata_module: str | None) -> bool:
+def should_update_component(
+ node: dict, *, display_name: str | None, metadata_module: str | None
+) -> bool:
node_data = node.get("data", {})
component = node_data.get("node", {})
@@ -45,7 +55,15 @@ def should_update_component(node: dict, *, display_name: str | None, metadata_mo
return isinstance(code_entry, dict) and "value" in code_entry
-def update_flow(flow_path: Path, code: str, *, display_name: str | None, metadata_module: str | None, dry_run: bool) -> bool:
+def update_flow(
+ flow_path: Path,
+ code: str,
+ *,
+ display_name: str | None,
+ metadata_module: str | None,
+ set_module: str | None,
+ dry_run: bool,
+) -> bool:
with flow_path.open(encoding="utf-8") as fh:
try:
data = json.load(fh)
@@ -53,18 +71,29 @@ def update_flow(flow_path: Path, code: str, *, display_name: str | None, metadat
raise SystemExit(f"[error] failed to parse {flow_path}: {exc}") from exc
changed = False
+ expected_hash = _code_hash(code)
for node in data.get("data", {}).get("nodes", []):
- if not should_update_component(node, display_name=display_name, metadata_module=metadata_module):
+ if not should_update_component(
+ node, display_name=display_name, metadata_module=metadata_module
+ ):
continue
- template = node["data"]["node"]["template"]
+ component = node["data"]["node"]
+ template = component["template"]
+ metadata = component.setdefault("metadata", {})
if template["code"]["value"] != code:
- if dry_run:
- changed = True
- else:
+ if not dry_run:
template["code"]["value"] = code
- changed = True
+ changed = True
+ if metadata.get("code_hash") != expected_hash:
+ if not dry_run:
+ metadata["code_hash"] = expected_hash
+ changed = True
+ if set_module and metadata.get("module") != set_module:
+ if not dry_run:
+ metadata["module"] = set_module
+ changed = True
if changed and not dry_run:
flow_path.write_text(
@@ -77,17 +106,40 @@ def update_flow(flow_path: Path, code: str, *, display_name: str | None, metadat
def iter_flow_files(flows_dir: Path) -> Iterable[Path]:
for path in sorted(flows_dir.glob("*.json")):
- if path.is_file():
+ if path.is_file() and path.name != "component_index.json":
yield path
def parse_args() -> argparse.Namespace:
- parser = argparse.ArgumentParser(description="Update embedded component code in Langflow JSON files.")
- parser.add_argument("--code-file", required=True, type=Path, help="Path to the Python file containing the component code.")
- parser.add_argument("--flows-dir", type=Path, default=Path("flows"), help="Directory containing Langflow JSON files.")
- parser.add_argument("--display-name", help="Component display_name to match (e.g. 'OpenSearch (Multi-Model)').")
+ parser = argparse.ArgumentParser(
+ description="Update embedded component code in Langflow JSON files."
+ )
+ parser.add_argument(
+ "--code-file",
+ required=True,
+ type=Path,
+ help="Path to the Python file containing the component code.",
+ )
+ parser.add_argument(
+ "--flows-dir",
+ type=Path,
+ default=Path("flows"),
+ help="Directory containing Langflow JSON files.",
+ )
+ parser.add_argument(
+ "--display-name",
+ help="Component display_name to match (e.g. 'OpenSearch (Multi-Model Multi-Embedding)').",
+ )
parser.add_argument("--metadata-module", help="Component metadata.module value to match.")
- parser.add_argument("--dry-run", action="store_true", help="Report which files would change without modifying them.")
+ parser.add_argument(
+ "--set-module",
+ help="Write this value to matching nodes' metadata.module (does not filter).",
+ )
+ parser.add_argument(
+ "--dry-run",
+ action="store_true",
+ help="Report which files would change without modifying them.",
+ )
args = parser.parse_args()
@@ -113,6 +165,7 @@ def main() -> None:
code,
display_name=args.display_name,
metadata_module=args.metadata_module,
+ set_module=args.set_module,
dry_run=args.dry_run,
)
if changed:
diff --git a/scripts/update_openrag_component_index.py b/scripts/update_openrag_component_index.py
new file mode 100644
index 000000000..1abab5589
--- /dev/null
+++ b/scripts/update_openrag_component_index.py
@@ -0,0 +1,492 @@
+#!/usr/bin/env python3
+"""Insert OpenRAG custom components into flows/component_index.json."""
+
+from __future__ import annotations
+
+import copy
+import hashlib
+import json
+from pathlib import Path
+
+ROOT = Path(__file__).resolve().parent.parent
+INDEX_PATH = ROOT / "flows" / "component_index.json"
+# The component sources live in the Langflow inline bundle; the former
+# ``flows/components`` copies were removed when the bundle became canonical.
+COMPONENTS_DIR = ROOT / "custom_components" / "openrag"
+INGEST_FLOW_PATH = ROOT / "flows" / "ingestion_flow.json"
+# Langflow uses this string as the sidebar category label.
+BUNDLE_NAME = "OpenRAG"
+OPENSEARCH_CLASS = "OpenSearchVectorStoreComponentMultimodalMultiEmbedding"
+OPENSEARCH_DISPLAY_NAME = "OpenSearch (Multi-Model Multi-Embedding)"
+# Langflow 1.11 ships a migration-table entry that rewrites the bare class name
+# ``OpenSearchVectorStoreComponentMultimodalMultiEmbedding`` to
+# ``ext:elastic:...@official`` on every flow load. Keying the index (and the flow
+# nodes) by our own canonical extension id keeps the node out of that rewrite;
+# ``ext:`` keys also alias back to the bare class name, so both forms resolve.
+OPENSEARCH_EXT_ID = f"ext:openrag:{OPENSEARCH_CLASS}@extra"
+OPENSEARCH_MODULE = "_lfx_ext.extra.openrag.opensearch_multimodal"
+
+
+def _code_hash(source: str) -> str:
+ return hashlib.sha256(source.encode("utf-8")).hexdigest()[:12]
+
+
+def _code_field(source: str) -> dict:
+ return {
+ "advanced": True,
+ "api_editable": False,
+ "dynamic": True,
+ "fileTypes": [],
+ "file_path": "",
+ "info": "",
+ "list": False,
+ "load_from_db": False,
+ "multiline": True,
+ "name": "code",
+ "password": False,
+ "placeholder": "",
+ "required": True,
+ "show": True,
+ "title_case": False,
+ "type": "code",
+ "value": source,
+ }
+
+
+def _str_input(
+ name: str,
+ display_name: str,
+ info: str,
+ *,
+ value: str = "",
+ load_from_db: bool = False,
+ advanced: bool = False,
+) -> dict:
+ return {
+ "_input_type": "StrInput",
+ "advanced": advanced,
+ "api_editable": False,
+ "display_name": display_name,
+ "dynamic": False,
+ "info": info,
+ "list": False,
+ "list_add_label": "Add More",
+ "load_from_db": load_from_db,
+ "name": name,
+ "override_skip": False,
+ "placeholder": "",
+ "required": False,
+ "show": True,
+ "title_case": False,
+ "tool_mode": False,
+ "trace_as_metadata": True,
+ "track_in_telemetry": False,
+ "type": "str",
+ "value": value,
+ }
+
+
+def _secret_input(name: str, display_name: str, info: str, *, value: str) -> dict:
+ return {
+ "_input_type": "SecretStrInput",
+ "advanced": False,
+ "api_editable": False,
+ "display_name": display_name,
+ "dynamic": False,
+ "info": info,
+ "input_types": [],
+ "load_from_db": True,
+ "name": name,
+ "override_skip": False,
+ "password": True,
+ "placeholder": "",
+ "required": False,
+ "show": True,
+ "title_case": False,
+ "track_in_telemetry": False,
+ "type": "str",
+ "value": value,
+ }
+
+
+def _int_input(name: str, display_name: str, info: str, *, value="", advanced: bool = True) -> dict:
+ return {
+ "_input_type": "IntInput",
+ "advanced": advanced,
+ "api_editable": False,
+ "display_name": display_name,
+ "dynamic": False,
+ "info": info,
+ "list": False,
+ "list_add_label": "Add More",
+ "name": name,
+ "override_skip": False,
+ "placeholder": "",
+ "required": False,
+ "show": True,
+ "title_case": False,
+ "tool_mode": False,
+ "trace_as_metadata": True,
+ "track_in_telemetry": True,
+ "type": "int",
+ "value": value,
+ }
+
+
+def _output(display_name: str, method: str, name: str, selected: str) -> dict:
+ return {
+ "allows_loop": False,
+ "cache": True,
+ "display_name": display_name,
+ "group_outputs": False,
+ "method": method,
+ "name": name,
+ "selected": selected,
+ "tool_mode": True,
+ "types": [selected],
+ "value": "__UNDEFINED__",
+ }
+
+
+def _component(
+ *,
+ source: str,
+ class_name: str,
+ display_name: str,
+ description: str,
+ module: str,
+ base_classes: list[str],
+ field_order: list[str],
+ outputs: list[dict],
+ template: dict,
+) -> dict:
+ template = {"_type": "Component", "code": _code_field(source), **template}
+ return {
+ "base_classes": base_classes,
+ "beta": False,
+ "conditional_paths": [],
+ "custom_fields": {},
+ "description": description,
+ "display_name": display_name,
+ "documentation": "",
+ "edited": False,
+ "field_order": field_order,
+ "frozen": False,
+ "icon": "OpenRAG",
+ "legacy": False,
+ "metadata": {
+ "code_hash": _code_hash(source),
+ "dependencies": {
+ "dependencies": [{"name": "lfx", "version": None}],
+ "total_dependencies": 1,
+ },
+ "module": module,
+ },
+ "minimized": False,
+ "output_types": [],
+ "outputs": outputs,
+ "pinned": False,
+ "template": template,
+ "tool_mode": False,
+ }
+
+
+def llm_component() -> dict:
+ source = (COMPONENTS_DIR / "openai_compatible_llm.py").read_text(encoding="utf-8")
+ return _component(
+ source=source,
+ class_name="OpenAICompatibleLLMComponent",
+ display_name="OpenRAG LLM",
+ description=(
+ "Chat model via OpenRAG's OpenAI-compatible /v1 proxy. "
+ "Base URL and hop token come from global variables at runtime."
+ ),
+ module="custom_components.OpenRAG.openai_compatible_llm.OpenAICompatibleLLMComponent",
+ base_classes=["LanguageModel", "Message"],
+ field_order=[
+ "input_value",
+ "system_message",
+ "stream",
+ "model_name",
+ "api_key",
+ "api_base",
+ "temperature",
+ "max_tokens",
+ "seed",
+ ],
+ outputs=[
+ _output("Model Response", "text_response", "text_output", "Message"),
+ _output("Language Model", "build_model", "model_output", "LanguageModel"),
+ ],
+ template={
+ "api_base": _str_input(
+ "api_base",
+ "OpenAI API Base",
+ "Must end with /v1 (for example http://openrag-backend:8000/v1). "
+ "Bound to OPENRAG_LLM_BASE_URL at runtime. Same URL as embeddings.",
+ value="OPENRAG_LLM_BASE_URL",
+ load_from_db=True,
+ ),
+ "api_key": _secret_input(
+ "api_key",
+ "OpenRAG LLM Token",
+ "Hop token from OPENRAG_LLM_TOKEN. OpenRAG injects this per Langflow run.",
+ value="OPENRAG_LLM_TOKEN",
+ ),
+ "input_value": {
+ "_input_type": "MessageInput",
+ "advanced": False,
+ "api_editable": False,
+ "display_name": "Input",
+ "dynamic": False,
+ "info": "The input text to send to the model",
+ "input_types": ["Message"],
+ "list": False,
+ "list_add_label": "Add More",
+ "load_from_db": False,
+ "name": "input_value",
+ "override_skip": False,
+ "placeholder": "",
+ "required": False,
+ "show": True,
+ "title_case": False,
+ "tool_mode": False,
+ "trace_as_input": True,
+ "trace_as_metadata": True,
+ "track_in_telemetry": False,
+ "type": "str",
+ "value": "",
+ },
+ "max_tokens": _int_input(
+ "max_tokens",
+ "Max Tokens",
+ "Maximum number of tokens to generate. Leave empty for the model default.",
+ ),
+ "model_name": _str_input(
+ "model_name",
+ "Model Name",
+ "Chat model id. Bound to SELECTED_LANGUAGE_MODEL at runtime.",
+ value="SELECTED_LANGUAGE_MODEL",
+ load_from_db=True,
+ ),
+ "seed": _int_input(
+ "seed",
+ "Seed",
+ "The seed controls the reproducibility of the job.",
+ value=1,
+ ),
+ "stream": {
+ "_input_type": "BoolInput",
+ "advanced": True,
+ "api_editable": False,
+ "display_name": "Stream",
+ "dynamic": False,
+ "info": "Whether to stream the response",
+ "list": False,
+ "list_add_label": "Add More",
+ "name": "stream",
+ "override_skip": False,
+ "placeholder": "",
+ "required": False,
+ "show": True,
+ "title_case": False,
+ "tool_mode": False,
+ "trace_as_metadata": True,
+ "track_in_telemetry": True,
+ "type": "bool",
+ "value": False,
+ },
+ "system_message": {
+ "_input_type": "MultilineInput",
+ "advanced": False,
+ "ai_enabled": False,
+ "api_editable": False,
+ "copy_field": False,
+ "display_name": "System Message",
+ "dynamic": False,
+ "info": "A system message that helps set the behavior of the assistant",
+ "input_types": ["Message"],
+ "list": False,
+ "list_add_label": "Add More",
+ "load_from_db": False,
+ "multiline": True,
+ "name": "system_message",
+ "override_skip": False,
+ "password": False,
+ "placeholder": "",
+ "required": False,
+ "show": True,
+ "title_case": False,
+ "tool_mode": False,
+ "trace_as_input": True,
+ "trace_as_metadata": True,
+ "track_in_telemetry": False,
+ "type": "str",
+ "value": "",
+ },
+ "temperature": {
+ "_input_type": "SliderInput",
+ "advanced": True,
+ "api_editable": False,
+ "display_name": "Temperature",
+ "dynamic": False,
+ "info": "Controls randomness in responses",
+ "max_label": "",
+ "max_label_icon": "",
+ "min_label": "",
+ "min_label_icon": "",
+ "name": "temperature",
+ "override_skip": False,
+ "placeholder": "",
+ "range_spec": {"max": 1.0, "min": 0.0, "step": 0.01, "step_type": "float"},
+ "required": False,
+ "show": True,
+ "slider_buttons": False,
+ "slider_buttons_options": [],
+ "slider_input": False,
+ "title_case": False,
+ "tool_mode": False,
+ "track_in_telemetry": False,
+ "type": "slider",
+ "value": 0.1,
+ },
+ },
+ )
+
+
+def opensearch_component() -> dict:
+ """Clone the shipped ingest-flow node and overlay canonical source + metadata.
+
+ The OpenSearch template is too large to reconstruct by hand. Cloning keeps
+ field_order, outputs, and OpenRAG ingest bindings in sync with the flow.
+ Icon stays OpenSearch (not the OpenRAG bundle icon used by the proxy nodes).
+ """
+ source = (COMPONENTS_DIR / "opensearch_multimodal.py").read_text(encoding="utf-8")
+ flow = json.loads(INGEST_FLOW_PATH.read_text(encoding="utf-8"))
+ node = next(
+ (
+ item["data"]["node"]
+ for item in flow.get("data", {}).get("nodes", [])
+ if item.get("data", {}).get("node", {}).get("display_name") == OPENSEARCH_DISPLAY_NAME
+ ),
+ None,
+ )
+ if node is None:
+ raise SystemExit(
+ f"[error] {INGEST_FLOW_PATH} has no node with display_name={OPENSEARCH_DISPLAY_NAME!r}"
+ )
+ component = copy.deepcopy(node)
+ component.setdefault("template", {}).setdefault("code", {})["value"] = source
+ component["edited"] = False
+ metadata = component.setdefault("metadata", {})
+ metadata["code_hash"] = _code_hash(source)
+ metadata["module"] = OPENSEARCH_MODULE
+ return component
+
+
+def embedding_component() -> dict:
+ source = (COMPONENTS_DIR / "openai_compatible_embedding.py").read_text(encoding="utf-8")
+ return _component(
+ source=source,
+ class_name="OpenAICompatibleEmbeddingComponent",
+ display_name="OpenRAG Embeddings",
+ description=(
+ "Embeddings via OpenRAG's OpenAI-compatible /v1 proxy. "
+ "Uses the same base URL and hop token as the chat component."
+ ),
+ module="custom_components.OpenRAG.openai_compatible_embedding.OpenAICompatibleEmbeddingComponent",
+ base_classes=["Embeddings"],
+ field_order=["model_name", "api_key", "api_base", "dimensions", "chunk_size"],
+ outputs=[_output("Embedding Model", "build_embeddings", "embeddings", "Embeddings")],
+ template={
+ "api_base": _str_input(
+ "api_base",
+ "OpenAI API Base",
+ "Must end with /v1 (for example http://openrag-backend:8000/v1). "
+ "Bound to OPENRAG_LLM_BASE_URL at runtime. Same URL as chat.",
+ value="OPENRAG_LLM_BASE_URL",
+ load_from_db=True,
+ ),
+ "api_key": _secret_input(
+ "api_key",
+ "OpenRAG LLM Token",
+ "Hop token from OPENRAG_LLM_TOKEN. Same token as the chat component.",
+ value="OPENRAG_LLM_TOKEN",
+ ),
+ "chunk_size": _int_input("chunk_size", "Chunk Size", "", value=1000),
+ "dimensions": _int_input(
+ "dimensions",
+ "Dimensions",
+ "Output dimensions when the embedding model supports it.",
+ ),
+ "model_name": _str_input(
+ "model_name",
+ "Model Name",
+ "Embedding model id. Bound to SELECTED_EMBEDDING_MODEL at runtime.",
+ value="SELECTED_EMBEDDING_MODEL",
+ load_from_db=True,
+ ),
+ },
+ )
+
+
+def _compute_sha256(index: dict) -> str:
+ """Reproduce Langflow's integrity digest for the component index.
+
+ Langflow hashes ``orjson.dumps(index_without_sha, option=OPT_SORT_KEYS)``.
+ The stdlib fallback must therefore emit UTF-8 directly: ``json.dumps``
+ defaults to ``ensure_ascii=True``, which escapes every non-ASCII character
+ and yields a different digest, so Langflow discards the index as
+ "SHA256 mismatch (file may be corrupted or tampered)" and silently falls
+ back to a dynamic scan that does not know about the OpenRAG bundle.
+ """
+ payload_obj = {key: value for key, value in index.items() if key != "sha256"}
+ try:
+ import orjson
+
+ payload = orjson.dumps(payload_obj, option=orjson.OPT_SORT_KEYS)
+ except ImportError:
+ payload = json.dumps(
+ payload_obj, sort_keys=True, separators=(",", ":"), ensure_ascii=False
+ ).encode("utf-8")
+ return hashlib.sha256(payload).hexdigest()
+
+
+def main() -> None:
+ index = json.loads(INDEX_PATH.read_text(encoding="utf-8"))
+ existing: dict[str, dict] = {}
+ for name, bundle in index["entries"]:
+ if name in {BUNDLE_NAME, "openrag"}:
+ existing.update(bundle)
+ # Drop the pre-``ext:`` key so regenerating never leaves both forms behind.
+ existing.pop(OPENSEARCH_CLASS, None)
+
+ openrag = {
+ **existing,
+ "OpenAICompatibleEmbeddingComponent": embedding_component(),
+ "OpenAICompatibleLLMComponent": llm_component(),
+ OPENSEARCH_EXT_ID: opensearch_component(),
+ }
+
+ entries = [entry for entry in index["entries"] if entry[0] not in {"openrag", BUNDLE_NAME}]
+ entries.append([BUNDLE_NAME, openrag])
+ entries.sort(key=lambda item: item[0].lower())
+ index["entries"] = entries
+ index["metadata"] = {
+ "num_modules": len(entries),
+ "num_components": sum(len(bundle) for _, bundle in entries),
+ }
+ index["sha256"] = _compute_sha256(index)
+ INDEX_PATH.write_text(
+ json.dumps(index, indent=2, ensure_ascii=False) + "\n",
+ encoding="utf-8",
+ )
+ print(
+ f"Updated {INDEX_PATH} "
+ f"({index['metadata']['num_modules']} modules, "
+ f"{index['metadata']['num_components']} components)"
+ )
+
+
+if __name__ == "__main__":
+ main()
diff --git a/src/api/models.py b/src/api/models.py
index 5c884ad1e..308c8e17c 100644
--- a/src/api/models.py
+++ b/src/api/models.py
@@ -215,3 +215,22 @@ async def get_ibm_models(
except Exception as e:
logger.error(f"Failed to get IBM models: {str(e)}")
return _models_error_response(e)
+
+
+async def get_model_catalog(
+ user: User = Depends(require_permission("providers:read")),
+):
+ """LiteLLM catalogue for the settings model dropdown. GET /models/catalog"""
+ from services.model_catalog import (
+ CATALOG_UNAVAILABLE_MESSAGE,
+ CatalogUnavailableError,
+ catalog,
+ )
+
+ try:
+ return JSONResponse(catalog(), headers={"Cache-Control": "private, max-age=3600"})
+ except CatalogUnavailableError as e:
+ # Log the cause, but never echo exception text back to the caller
+ # (CodeQL py/stack-trace-exposure).
+ logger.error("Model catalogue unavailable", error=str(e))
+ return JSONResponse({"error": CATALOG_UNAVAILABLE_MESSAGE}, status_code=503)
diff --git a/src/api/provider_health.py b/src/api/provider_health.py
index dddaeb6bd..8e3b514e5 100644
--- a/src/api/provider_health.py
+++ b/src/api/provider_health.py
@@ -9,6 +9,7 @@ from fastapi.responses import JSONResponse
from api.provider_validation import sanitize_provider_error_content, validate_provider_setup
from config.settings import get_openrag_config
from dependencies import require_permission
+from services.model_catalog import is_known_provider
from session_manager import User
from utils import provider_health_cache
from utils.logging_config import get_logger
@@ -19,6 +20,8 @@ logger = get_logger(__name__)
async def check_provider_health(
provider: str | None = None,
test_completion: bool = False,
+ model: str | None = None,
+ embedding_model_override: str | None = None,
user: User = Depends(require_permission("providers:read")),
):
"""
@@ -28,6 +31,13 @@ async def check_provider_health(
provider (optional): Provider to check ('openai', 'ollama', 'watsonx', 'anthropic').
If not provided, checks the currently configured provider.
test_completion (optional): If true, performs full validation with completion/embedding tests.
+ model (optional): Validate against this chat model instead of the configured one.
+ Generic LiteLLM providers are validated by issuing a real call, which
+ needs a model name; a provider that is not the selected LLM/embedding
+ provider has none, and one whose model names are deployment-specific
+ (Azure, Bedrock, SageMaker) cannot be validated against the catalogue's
+ generic names. Only meaningful together with ``provider``.
+ embedding_model_override (optional): Same, for validating an embedding model instead.
Returns:
200: Provider is healthy and validated
@@ -48,12 +58,11 @@ async def check_provider_health(
provider = current_config.agent.llm_provider
# Validate provider name
- valid_providers = ["openai", "ollama", "watsonx", "anthropic"]
- if provider not in valid_providers:
+ if not is_known_provider(provider):
return JSONResponse(
{
"status": "error",
- "message": f"Invalid provider: {provider}. Must be one of: {', '.join(valid_providers)}",
+ "message": f"Unknown LiteLLM provider: {provider}",
"provider": provider,
},
status_code=400,
@@ -67,6 +76,7 @@ async def check_provider_health(
api_key = getattr(provider_config, "api_key", None)
endpoint = getattr(provider_config, "endpoint", None)
project_id = getattr(provider_config, "project_id", None)
+ credentials = current_config.providers.credential_values(provider)
# Check if this provider is used for LLM or embedding
llm_model = (
@@ -79,6 +89,14 @@ async def check_provider_health(
if provider == current_config.knowledge.embedding_provider
else None
)
+
+ # An explicit model wins over whatever the provider happens to be
+ # selected for. Setting one clears the other so the validator
+ # tests exactly what the caller asked for rather than falling
+ # back to an embedding call for a chat model (or vice versa).
+ if model or embedding_model_override:
+ llm_model = model or None
+ embedding_model = embedding_model_override or None
except ValueError:
# Provider not found in configuration
return JSONResponse(
@@ -105,6 +123,8 @@ async def check_provider_health(
embedding_endpoint = getattr(embedding_provider_config, "endpoint", None)
embedding_project_id = getattr(embedding_provider_config, "project_id", None)
embedding_model = current_config.knowledge.embedding_model
+ credentials = current_config.providers.credential_values(provider)
+ embedding_credentials = current_config.providers.credential_values(embedding_provider)
# Short-circuit identical concurrent polls from the provider-health
# banner so we don't fan out N watsonx round-trips per poll cycle.
@@ -114,6 +134,7 @@ async def check_provider_health(
provider=provider,
embedding_provider=embedding_provider,
test_completion=test_completion,
+ credentials=credentials,
llm_model=llm_model,
embedding_model=embedding_model,
endpoint=endpoint,
@@ -122,6 +143,7 @@ async def check_provider_health(
embedding_api_key=embedding_api_key,
embedding_endpoint=embedding_endpoint,
embedding_project_id=embedding_project_id,
+ embedding_credentials=embedding_credentials,
)
cached_payload = provider_health_cache.get(health_cache_key)
if cached_payload is not None:
@@ -149,6 +171,10 @@ async def check_provider_health(
# Validate provider setup
if check_provider:
# Validate specific provider
+ # Generic LiteLLM providers keep their secrets in ``credentials``
+ # rather than the dedicated api_key/endpoint/project_id fields, so
+ # this must be forwarded or validating one from the providers page
+ # runs with no credentials at all.
await validate_provider_setup(
provider=provider,
api_key=api_key,
@@ -157,6 +183,7 @@ async def check_provider_health(
endpoint=endpoint,
project_id=project_id,
test_completion=test_completion,
+ credentials=credentials,
)
return JSONResponse(
@@ -188,6 +215,7 @@ async def check_provider_health(
endpoint=endpoint,
project_id=project_id,
test_completion=test_completion,
+ credentials=credentials,
)
except httpx.TimeoutException as e:
# Timeout means provider is busy, not misconfigured
@@ -222,6 +250,7 @@ async def check_provider_health(
endpoint=embedding_endpoint,
project_id=embedding_project_id,
test_completion=test_completion,
+ credentials=embedding_credentials,
)
except httpx.TimeoutException as e:
# Timeout means provider is busy, not misconfigured
diff --git a/src/api/provider_validation.py b/src/api/provider_validation.py
index 8864df992..e40805e07 100644
--- a/src/api/provider_validation.py
+++ b/src/api/provider_validation.py
@@ -576,6 +576,7 @@ async def validate_provider_setup(
endpoint: str = None,
project_id: str = None,
test_completion: bool = False,
+ credentials: dict[str, str] | None = None,
) -> None:
"""
Validate provider setup by testing completion with tool calling and embedding.
@@ -594,13 +595,27 @@ async def validate_provider_setup(
Exception: If validation fails, raises the original exception with the actual error message.
"""
provider_lower = provider.lower()
+ supplied = dict(credentials or {})
+ if api_key:
+ supplied.setdefault("api_key", api_key)
+ if endpoint:
+ supplied.setdefault("api_base", endpoint)
+ if project_id:
+ supplied.setdefault("project_id", project_id)
try:
logger.info(
f"Starting validation for provider: {provider_lower} (test_completion={test_completion})"
)
- if test_completion:
+ if provider_lower not in {"openai", "watsonx", "ollama", "anthropic"}:
+ await _test_litellm_provider(
+ provider=provider_lower,
+ credentials=supplied,
+ embedding_model=embedding_model,
+ llm_model=llm_model,
+ )
+ elif test_completion:
# Full validation with completion/embedding tests (consumes credits)
if embedding_model:
# Test embedding
@@ -637,6 +652,35 @@ async def validate_provider_setup(
raise
+async def _test_litellm_provider(
+ *,
+ provider: str,
+ credentials: dict[str, str],
+ embedding_model: str | None,
+ llm_model: str | None,
+) -> None:
+ """Validate arbitrary providers through the same LiteLLM adapter used at runtime."""
+ import litellm
+
+ model = embedding_model or llm_model
+ if not model:
+ raise ValueError("A model is required to validate the provider")
+ litellm_model = f"{provider}/{model}"
+ if embedding_model:
+ await litellm.aembedding(
+ model=litellm_model,
+ input="OpenRAG provider validation",
+ **credentials,
+ )
+ return
+ await litellm.acompletion(
+ model=litellm_model,
+ messages=[{"role": "user", "content": "Reply with OK."}],
+ max_tokens=4,
+ **credentials,
+ )
+
+
async def test_lightweight_health(
provider: str,
api_key: str = None,
diff --git a/src/api/settings/endpoints.py b/src/api/settings/endpoints.py
index 0823668ac..c60f9fbfb 100644
--- a/src/api/settings/endpoints.py
+++ b/src/api/settings/endpoints.py
@@ -38,6 +38,7 @@ from api.settings.models import (
AnthropicProviderConfig,
DoclingPresetBody,
DoclingPresetResponse,
+ GenericProviderConfig,
IngestionDefaultsConfig,
KnowledgeConfig,
OllamaProviderConfig,
@@ -96,6 +97,7 @@ from dependencies import (
require_permission,
)
from services.docling_service import DoclingConfig, get_docling_preset_configs
+from services.model_catalog import secret_field_keys
from services.rbac_service import is_rbac_enforced
from session_manager import User
from utils import provider_health_cache
@@ -107,6 +109,87 @@ from utils.version_utils import OPENRAG_VERSION
logger = get_logger(__name__)
+def _provider_key(provider: str | None) -> str:
+ """Normalize a provider name the way credential storage does.
+
+ `set_credentials` and `credential_values` both key off `strip().lower()`,
+ and `llm_provider`/`embedding_provider` no longer have a fixed pattern, so a
+ request carrying "Gemini" must still find the credentials submitted under
+ "gemini".
+ """
+ return (provider or "").strip().lower()
+
+
+def _custom_providers_for_settings(openrag_config) -> dict[str, GenericProviderConfig]:
+ """Public provider payloads: never drop a legacy secret when custom slots exist."""
+
+ def payload(
+ provider: str,
+ *,
+ configured: bool,
+ credential_values: dict[str, str] | None = None,
+ secret_fields: list[str] | None = None,
+ stored=None,
+ ) -> GenericProviderConfig:
+ values = dict(credential_values or {})
+ secrets = list(secret_fields or [])
+ if stored is not None:
+ secret_keys = secret_field_keys(provider)
+ values.update(
+ {key: value for key, value in stored.credentials.items() if key not in secret_keys}
+ )
+ secrets.extend(key for key in secret_keys if stored.credentials.get(key))
+ configured = configured or stored.configured
+ return GenericProviderConfig(
+ configured=configured,
+ credential_values={key: value for key, value in values.items() if value},
+ secret_fields=list(dict.fromkeys(secrets)),
+ )
+
+ providers = {
+ "openai": payload(
+ "openai",
+ configured=openrag_config.providers.openai.configured,
+ secret_fields=["api_key"] if openrag_config.providers.openai.api_key else [],
+ ),
+ "anthropic": payload(
+ "anthropic",
+ configured=openrag_config.providers.anthropic.configured,
+ secret_fields=["api_key"] if openrag_config.providers.anthropic.api_key else [],
+ ),
+ "watsonx": payload(
+ "watsonx",
+ configured=openrag_config.providers.watsonx.configured,
+ credential_values={
+ key: value
+ for key, value in {
+ "api_base": openrag_config.providers.watsonx.endpoint,
+ "project_id": openrag_config.providers.watsonx.project_id,
+ }.items()
+ if value
+ },
+ secret_fields=["api_key"] if openrag_config.providers.watsonx.api_key else [],
+ ),
+ "ollama": payload(
+ "ollama",
+ configured=openrag_config.providers.ollama.configured,
+ credential_values={"api_base": openrag_config.providers.ollama.endpoint}
+ if openrag_config.providers.ollama.endpoint
+ else {},
+ ),
+ }
+ for provider, stored in openrag_config.providers.custom.items():
+ previous = providers.get(provider)
+ providers[provider] = payload(
+ provider,
+ configured=previous.configured if previous else stored.configured,
+ credential_values=previous.credential_values if previous else {},
+ secret_fields=previous.secret_fields if previous else [],
+ stored=stored,
+ )
+ return providers
+
+
def _detect_local_vlm_models() -> list[str]:
from pathlib import Path
@@ -249,6 +332,7 @@ async def get_settings(
endpoint=openrag_config.providers.ollama.endpoint or None,
configured=openrag_config.providers.ollama.configured,
),
+ custom=_custom_providers_for_settings(openrag_config),
)
if show_providers
else None,
@@ -330,6 +414,8 @@ async def update_settings(
"watsonx_endpoint",
"watsonx_project_id",
"ollama_endpoint",
+ "provider_credentials",
+ "remove_provider_config",
]
should_validate = any(getattr(body, field) is not None for field in provider_fields)
@@ -372,7 +458,7 @@ async def update_settings(
# Validate LLM provider if being changed
if body.llm_provider is not None or body.llm_model is not None:
llm_provider = (
- body.llm_provider
+ body.llm_provider.strip().lower()
if body.llm_provider is not None
else current_config.agent.llm_provider
)
@@ -389,6 +475,16 @@ async def update_settings(
api_key = getattr(llm_provider_config, "api_key", None)
endpoint = getattr(llm_provider_config, "endpoint", None)
project_id = getattr(llm_provider_config, "project_id", None)
+ llm_provider_key = _provider_key(llm_provider)
+ submitted_credentials = {
+ _provider_key(name): values
+ for name, values in (body.provider_credentials or {}).items()
+ }
+ credentials = current_config.providers.credential_values(llm_provider_key)
+ credentials.update(submitted_credentials.get(llm_provider_key, {}))
+ api_key = credentials.get("api_key", api_key)
+ endpoint = credentials.get("api_base", endpoint)
+ project_id = credentials.get("project_id", project_id)
if (
getattr(body, f"{llm_provider}_api_key", None) is not None
@@ -406,13 +502,14 @@ async def update_settings(
llm_model=llm_model,
endpoint=endpoint,
project_id=project_id,
+ credentials=credentials,
)
logger.info(f"LLM provider validation successful for {llm_provider}")
# Validate embedding provider if being changed
if body.embedding_provider is not None or body.embedding_model is not None:
embedding_provider = (
- body.embedding_provider
+ body.embedding_provider.strip().lower()
if body.embedding_provider is not None
else current_config.knowledge.embedding_provider
)
@@ -431,6 +528,16 @@ async def update_settings(
api_key = getattr(embedding_provider_config, "api_key", None)
endpoint = getattr(embedding_provider_config, "endpoint", None)
project_id = getattr(embedding_provider_config, "project_id", None)
+ embedding_provider_key = _provider_key(embedding_provider)
+ submitted_credentials = {
+ _provider_key(name): values
+ for name, values in (body.provider_credentials or {}).items()
+ }
+ credentials = current_config.providers.credential_values(embedding_provider_key)
+ credentials.update(submitted_credentials.get(embedding_provider_key, {}))
+ api_key = credentials.get("api_key", api_key)
+ endpoint = credentials.get("api_base", endpoint)
+ project_id = credentials.get("project_id", project_id)
if (
getattr(body, f"{embedding_provider}_api_key", None) is not None
@@ -448,6 +555,7 @@ async def update_settings(
embedding_model=embedding_model,
endpoint=endpoint,
project_id=project_id,
+ credentials=credentials,
)
logger.info(
f"Embedding provider validation successful for {embedding_provider}"
@@ -724,6 +832,11 @@ async def update_settings(
# Update provider-specific settings
provider_updated = False
+ for provider, credentials in (body.provider_credentials or {}).items():
+ working_config.providers.set_credentials(provider, credentials)
+ config_updated = True
+ provider_updated = True
+
if body.openai_api_key is not None and body.openai_api_key.strip():
working_config.providers.openai.api_key = body.openai_api_key.strip()
working_config.providers.openai.configured = True
@@ -881,6 +994,31 @@ async def update_settings(
config_updated = True
provider_updated = True
+ if body.remove_provider_config:
+ provider = body.remove_provider_config.strip().lower()
+ if provider in working_config.providers.custom:
+ del working_config.providers.custom[provider]
+ if not working_config.providers.any_configured():
+ return JSONResponse(
+ {
+ "error": (
+ "Cannot remove provider configuration: "
+ "configure another model provider first."
+ )
+ },
+ status_code=400,
+ )
+ if working_config.agent.llm_provider == provider:
+ fallback = _first_configured_llm_provider(working_config, provider)
+ working_config.agent.llm_provider = fallback
+ working_config.agent.llm_model = _default_llm_model(fallback)
+ if working_config.knowledge.embedding_provider == provider:
+ fallback = _first_configured_embedding_provider(working_config, provider)
+ working_config.knowledge.embedding_provider = fallback
+ working_config.knowledge.embedding_model = _default_embedding_model(fallback)
+ config_updated = True
+ provider_updated = True
+
if provider_updated:
await TelemetryClient.send_event(
Category.SETTINGS_OPERATIONS, MessageId.ORB_SETTINGS_PROVIDER_CREDS
@@ -1060,6 +1198,10 @@ async def onboarding(
current_config.providers.ollama.configured = True
config_updated = True
+ for provider, credentials in (body.provider_credentials or {}).items():
+ current_config.providers.set_credentials(provider, credentials)
+ config_updated = True
+
# Mark providers as configured if they were chosen during onboarding
# Check LLM provider
if body.llm_provider:
@@ -1126,6 +1268,7 @@ async def onboarding(
endpoint=getattr(llm_provider_config, "endpoint", None),
project_id=getattr(llm_provider_config, "project_id", None),
test_completion=True, # Full validation with completion test - ensures provider health
+ credentials=current_config.providers.credential_values(llm_provider),
)
logger.info(
f"LLM provider setup validation completed successfully for {llm_provider}"
@@ -1146,6 +1289,7 @@ async def onboarding(
endpoint=getattr(embedding_provider_config, "endpoint", None),
project_id=getattr(embedding_provider_config, "project_id", None),
test_completion=True, # Full validation with completion test - ensures provider health
+ credentials=current_config.providers.credential_values(embedding_provider),
)
logger.info(
f"Embedding provider setup validation completed successfully for {embedding_provider}"
@@ -1180,6 +1324,7 @@ async def onboarding(
body.watsonx_endpoint,
body.watsonx_project_id,
body.ollama_endpoint,
+ body.provider_credentials,
]
)
diff --git a/src/api/settings/helpers.py b/src/api/settings/helpers.py
index b932f7c57..3b31b2ace 100644
--- a/src/api/settings/helpers.py
+++ b/src/api/settings/helpers.py
@@ -27,7 +27,19 @@ _EMBEDDING_PROVIDER_NAMES = ("openai", "watsonx", "ollama")
def _configured_provider_names(config, provider_names) -> list:
"""Return the provider names from `provider_names` marked configured in the OpenRAG config."""
providers = config.providers
- return [name for name in provider_names if getattr(providers, name).configured]
+ configured = [name for name in provider_names if getattr(providers, name).configured]
+ from services.model_catalog import catalog
+
+ entries = {entry["key"]: entry for entry in catalog()["providers"]}
+ embedding = tuple(provider_names) == _EMBEDDING_PROVIDER_NAMES
+ for provider, value in providers.custom.items():
+ entry = entries.get(provider)
+ supports_kind = bool(
+ entry and (entry["embedding_models"] if embedding else entry["models"])
+ )
+ if value.configured and supports_kind and provider not in configured:
+ configured.append(provider)
+ return configured
def _first_configured_llm_provider(config, excluding: str) -> str:
@@ -35,14 +47,25 @@ def _first_configured_llm_provider(config, excluding: str) -> str:
for p in _LLM_PROVIDER_NAMES:
if p != excluding and getattr(config.providers, p).configured:
return p
+ for provider, value in config.providers.custom.items():
+ if provider != excluding and value.configured:
+ return provider
return "openai"
def _first_configured_embedding_provider(config, excluding: str) -> str:
- """Return the first configured embedding provider (openai/watsonx/ollama) that isn't `excluding`, or "" if none."""
+ """Return the first configured embedding provider that isn't `excluding`, or "" if none."""
for p in _EMBEDDING_PROVIDER_NAMES:
if p != excluding and getattr(config.providers, p).configured:
return p
+ from services.model_catalog import catalog
+
+ entries = {entry["key"]: entry for entry in catalog()["providers"]}
+ for provider, value in config.providers.custom.items():
+ if provider != excluding and value.configured:
+ entry = entries.get(provider)
+ if entry and entry["embedding_models"]:
+ return provider
return ""
diff --git a/src/api/settings/langflow_sync.py b/src/api/settings/langflow_sync.py
index 258f09aea..ccc8d93f5 100644
--- a/src/api/settings/langflow_sync.py
+++ b/src/api/settings/langflow_sync.py
@@ -21,7 +21,6 @@ from api.settings.helpers import (
from config import settings
from config.settings import clients, get_openrag_config
from services.docling_service import get_docling_preset_configs
-from utils.langflow_headers import map_provider
from utils.logging_config import get_logger
logger = get_logger(__name__)
@@ -32,11 +31,10 @@ _background_tasks: set[asyncio.Task] = set()
LANGFLOW_CREDENTIAL_GLOBAL_VARIABLES = frozenset(
{
- "ANTHROPIC_API_KEY",
"JWT",
"OPENAI_API_KEY",
+ "OPENRAG_LLM_TOKEN",
"OPENSEARCH_PASSWORD",
- "WATSONX_APIKEY",
}
)
@@ -47,20 +45,18 @@ LANGFLOW_GENERIC_GLOBAL_VARIABLES = frozenset(
"DOCLING_TASK_ID",
"FILESIZE",
"MIMETYPE",
- "OLLAMA_BASE_URL",
"OPENRAG-QUERY-FILTER",
"OPENRAG_INGEST_BATCH_SIZE",
"OPENRAG_INGEST_RUN_ID",
"OPENRAG_INGEST_TOKEN",
"OPENRAG_INGEST_URL",
+ "OPENRAG_LLM_BASE_URL",
"OPENSEARCH_INDEX_NAME",
"OPENSEARCH_URL",
"SELECTED_EMBEDDING_MODEL",
"SELECTED_EMBEDDING_MODEL_PROVIDER",
"SELECTED_LANGUAGE_MODEL",
"SELECTED_LANGUAGE_MODEL_PROVIDER",
- "WATSONX_PROJECT_ID",
- "WATSONX_URL",
}
)
@@ -86,10 +82,7 @@ def _string_value(value) -> str:
def _required_generic_global_values(config) -> dict[str, str]:
knowledge = getattr(config, "knowledge", None)
- providers = getattr(config, "providers", None)
agent = getattr(config, "agent", None)
- watsonx = getattr(providers, "watsonx", None)
- ollama = getattr(providers, "ollama", None)
return {
"DOCLING_SERVE_URL": settings.get_langflow_docling_url(),
@@ -97,32 +90,41 @@ def _required_generic_global_values(config) -> dict[str, str]:
"DOCLING_TASK_ID": "None",
"FILESIZE": "0",
"MIMETYPE": "None",
- "OLLAMA_BASE_URL": _string_value(getattr(ollama, "endpoint", None)),
"OPENRAG-QUERY-FILTER": "{}",
"OPENRAG_INGEST_BATCH_SIZE": "100",
"OPENRAG_INGEST_RUN_ID": "OPENRAG_INGEST_RUN_ID",
"OPENRAG_INGEST_TOKEN": "OPENRAG_INGEST_TOKEN",
"OPENRAG_INGEST_URL": "OPENRAG_INGEST_URL",
+ "OPENRAG_LLM_BASE_URL": settings.get_langflow_llm_base_url(),
"OPENSEARCH_INDEX_NAME": _string_value(getattr(knowledge, "index_name", None))
or "documents",
"OPENSEARCH_URL": settings.get_langflow_opensearch_url(),
"SELECTED_EMBEDDING_MODEL": _string_value(getattr(knowledge, "embedding_model", None))
or "text-embedding-3-small",
- "SELECTED_EMBEDDING_MODEL_PROVIDER": map_provider(
- getattr(knowledge, "embedding_provider", None) or "openai"
- ),
+ "SELECTED_EMBEDDING_MODEL_PROVIDER": "OpenAI",
"SELECTED_LANGUAGE_MODEL": _string_value(getattr(agent, "llm_model", None))
or "gpt-4o-mini",
- "SELECTED_LANGUAGE_MODEL_PROVIDER": map_provider(
- getattr(agent, "llm_provider", None) or "openai"
- ),
- "WATSONX_PROJECT_ID": _string_value(getattr(watsonx, "project_id", None)),
- "WATSONX_URL": _string_value(getattr(watsonx, "endpoint", None)),
+ "SELECTED_LANGUAGE_MODEL_PROVIDER": "OpenAI",
}
+# Credential names that must exist so load_from_db fields resolve.
+# Langflow treats an empty Credential value as missing
+# (`"{name} variable not found."`). Keep a non-empty placeholder; runtime
+# headers overwrite it with the hop token on each Langflow run.
+LANGFLOW_RUNTIME_CREDENTIAL_PLACEHOLDERS = frozenset(
+ {
+ "OPENRAG_LLM_TOKEN",
+ }
+)
+LANGFLOW_RUNTIME_CREDENTIAL_PLACEHOLDER_VALUE = "None"
+
+
async def ensure_required_langflow_global_variables(config=None):
- """Ensure plain-string globals are Generic and remove any Apply To (default_fields) fields."""
+ """Ensure plain-string globals are Generic and remove any Apply To (default_fields) fields.
+
+ Credential placeholders stay non-empty so Langflow can resolve load_from_db fields.
+ """
config = config or get_openrag_config()
required_values = _required_generic_global_values(config)
@@ -251,9 +253,23 @@ async def ensure_required_langflow_global_variables(config=None):
"Failed to create Langflow global variable", variable_name=name, error=str(e)
)
+ # Non-fatal like every other Langflow call in this function: a transient
+ # failure here must not take down a startup path that never raised before.
+ for name in sorted(LANGFLOW_RUNTIME_CREDENTIAL_PLACEHOLDERS):
+ try:
+ await _upsert_langflow_global_variable(
+ name, LANGFLOW_RUNTIME_CREDENTIAL_PLACEHOLDER_VALUE
+ )
+ except Exception as e:
+ logger.warning(
+ "Failed to create Langflow credential placeholder",
+ variable_name=name,
+ error=str(e),
+ )
+
async def _update_langflow_global_variables(config, flows_service=None):
- """Update Langflow global variables for all configured providers"""
+ """Push model selection and the LLM proxy URL into Langflow. No provider secrets."""
errors: list[str] = []
async def _safe_upsert(name: str, value: str):
@@ -266,58 +282,24 @@ async def _update_langflow_global_variables(config, flows_service=None):
)
errors.append(f"{name}: {e}")
- providers = getattr(config, "providers", None)
-
- # WatsonX global variables
- watsonx = getattr(providers, "watsonx", None)
- if watsonx:
- if getattr(watsonx, "api_key", None):
- await _safe_upsert("WATSONX_APIKEY", watsonx.api_key)
-
- if getattr(watsonx, "project_id", None):
- await _safe_upsert("WATSONX_PROJECT_ID", watsonx.project_id)
-
- if getattr(watsonx, "endpoint", None):
- await _safe_upsert("WATSONX_URL", watsonx.endpoint)
-
- # OpenAI global variables
- openai = getattr(providers, "openai", None)
- if openai and getattr(openai, "api_key", None):
- await _safe_upsert("OPENAI_API_KEY", openai.api_key)
-
- # Anthropic global variables
- anthropic = getattr(providers, "anthropic", None)
- if anthropic and getattr(anthropic, "api_key", None):
- await _safe_upsert("ANTHROPIC_API_KEY", anthropic.api_key)
-
- # Ollama global variables
- ollama = getattr(providers, "ollama", None)
- if ollama and getattr(ollama, "endpoint", None):
- try:
- if not flows_service:
- flows_service = _get_flows_service()
-
- endpoint = await flows_service.resolve_ollama_url(ollama.endpoint, force_refresh=True)
- await _safe_upsert("OLLAMA_BASE_URL", endpoint)
- except Exception as e:
- logger.warning("Failed to resolve OLLAMA_BASE_URL", error=str(e))
- errors.append(f"OLLAMA_BASE_URL resolution: {e}")
+ await _safe_upsert("OPENRAG_LLM_BASE_URL", settings.get_langflow_llm_base_url())
+ # Every model runs through the OpenAI-compatible LLM proxy, so the provider
+ # is always "OpenAI" here and no provider secret is pushed to Langflow.
knowledge = getattr(config, "knowledge", None)
if getattr(knowledge, "embedding_model", None):
await _safe_upsert("SELECTED_EMBEDDING_MODEL", config.knowledge.embedding_model)
-
- if getattr(knowledge, "embedding_provider", None):
- mapped_provider = map_provider(config.knowledge.embedding_provider)
- await _safe_upsert("SELECTED_EMBEDDING_MODEL_PROVIDER", mapped_provider)
+ await _safe_upsert("SELECTED_EMBEDDING_MODEL_PROVIDER", "OpenAI")
agent = getattr(config, "agent", None)
if getattr(agent, "llm_model", None):
await _safe_upsert("SELECTED_LANGUAGE_MODEL", config.agent.llm_model)
+ await _safe_upsert("SELECTED_LANGUAGE_MODEL_PROVIDER", "OpenAI")
- if getattr(agent, "llm_provider", None):
- mapped_llm_provider = map_provider(config.agent.llm_provider)
- await _safe_upsert("SELECTED_LANGUAGE_MODEL_PROVIDER", mapped_llm_provider)
+ # Runtime headers overwrite these with the hop token on each Langflow run;
+ # they only need to exist and stay non-empty so load_from_db can resolve them.
+ for name in sorted(LANGFLOW_RUNTIME_CREDENTIAL_PLACEHOLDERS):
+ await _safe_upsert(name, LANGFLOW_RUNTIME_CREDENTIAL_PLACEHOLDER_VALUE)
if errors:
raise RuntimeError(f"Failed to update Langflow global variable(s): {', '.join(errors)}")
@@ -388,6 +370,26 @@ async def _update_mcp_server_urls(config, session_manager=None, flows_service=No
# Don't fail the entire settings update if MCP update fails
+async def _upsert_selected_model_variable(name: str, value: str | None) -> None:
+ """Push a SELECTED_*_MODEL global var, non-fatally.
+
+ Flows no longer carry per-provider embedding/LLM nodes for
+ `change_langflow_model_value` to patch — they use the single
+ OpenAI-compatible component that reads its model from this global variable.
+ That makes this the only channel by which a model change reaches a flow, so
+ it has to follow every model change, not just credential changes.
+ """
+ if not value:
+ return
+ try:
+ await _upsert_langflow_global_variable(name, value)
+ logger.info("Set global variable in Langflow", variable_name=name)
+ except Exception as e:
+ logger.warning(
+ "Failed to set global variable in Langflow", variable_name=name, error=str(e)
+ )
+
+
async def _update_langflow_model_values(
config,
flows_service,
@@ -404,6 +406,7 @@ async def _update_langflow_model_values(
effective_llm_model = llm_model # do not fall back; force caller to specify
else:
effective_llm_model = llm_model or config.agent.llm_model
+ await _upsert_selected_model_variable("SELECTED_LANGUAGE_MODEL", effective_llm_model)
result = await flows_service.change_langflow_model_value(
effective_llm_provider, llm_model=effective_llm_model, force_llm_update=True
)
@@ -426,6 +429,9 @@ async def _update_langflow_model_values(
)
else:
effective_embedding_model = embedding_model or config.knowledge.embedding_model
+ await _upsert_selected_model_variable(
+ "SELECTED_EMBEDDING_MODEL", effective_embedding_model
+ )
result = await flows_service.change_langflow_model_value(
effective_embedding_provider,
embedding_model=effective_embedding_model,
diff --git a/src/api/settings/models.py b/src/api/settings/models.py
index c8a761b22..1b4bf3b10 100644
--- a/src/api/settings/models.py
+++ b/src/api/settings/models.py
@@ -14,7 +14,7 @@ from services.docling_service import DoclingConfig
class SettingsUpdateBody(BaseModel):
llm_model: str | None = Field(None, min_length=1)
- llm_provider: str | None = Field(None, pattern="^(openai|anthropic|watsonx|ollama)$")
+ llm_provider: str | None = Field(None, min_length=1)
system_prompt: str | None = None
chunk_size: int | None = Field(None, gt=0)
chunk_overlap: int | None = Field(None, ge=0)
@@ -32,7 +32,7 @@ class SettingsUpdateBody(BaseModel):
vlm_timeout: int | None = Field(None, gt=0)
vlm_watsonx_api_version: str | None = Field(None, min_length=1)
embedding_model: str | None = Field(None, min_length=1)
- embedding_provider: str | None = Field(None, pattern="^(openai|watsonx|ollama)$")
+ embedding_provider: str | None = Field(None, min_length=1)
index_name: str | None = Field(None, min_length=1)
openai_api_key: str | None = Field(None, min_length=1)
anthropic_api_key: str | None = Field(None, min_length=1)
@@ -44,6 +44,8 @@ class SettingsUpdateBody(BaseModel):
remove_openai_config: bool | None = None
remove_anthropic_config: bool | None = None
remove_watsonx_config: bool | None = None
+ provider_credentials: dict[str, dict[str, str]] | None = None
+ remove_provider_config: str | None = None
# Explicit confirmation that the caller accepts removing a provider whose
# embedding models are still in use by indexed documents. Without this,
# the backend returns 409 and the frontend prompts the user.
@@ -51,9 +53,9 @@ class SettingsUpdateBody(BaseModel):
class OnboardingBody(BaseModel):
- llm_provider: str | None = Field(None, pattern="^(openai|anthropic|watsonx|ollama)$")
+ llm_provider: str | None = Field(None, min_length=1)
llm_model: str | None = Field(None, min_length=1)
- embedding_provider: str | None = Field(None, pattern="^(openai|watsonx|ollama)$")
+ embedding_provider: str | None = Field(None, min_length=1)
embedding_model: str | None = Field(None, min_length=1)
openai_api_key: str | None = Field(None, min_length=1)
anthropic_api_key: str | None = Field(None, min_length=1)
@@ -61,6 +63,7 @@ class OnboardingBody(BaseModel):
watsonx_endpoint: str | None = Field(None, min_length=1)
watsonx_project_id: str | None = Field(None, min_length=1)
ollama_endpoint: str | None = Field(None, min_length=1)
+ provider_credentials: dict[str, dict[str, str]] | None = None
class CitationDisplayData(BaseModel):
@@ -168,11 +171,18 @@ class OllamaProviderConfig(BaseModel):
configured: bool
+class GenericProviderConfig(BaseModel):
+ configured: bool
+ credential_values: dict[str, str] = Field(default_factory=dict)
+ secret_fields: list[str] = Field(default_factory=list)
+
+
class ProvidersConfig(BaseModel):
openai: OpenAIProviderConfig
anthropic: AnthropicProviderConfig
watsonx: WatsonXProviderConfig
ollama: OllamaProviderConfig
+ custom: dict[str, GenericProviderConfig] = Field(default_factory=dict)
class KnowledgeConfig(BaseModel):
diff --git a/src/api/v1/llm.py b/src/api/v1/llm.py
new file mode 100644
index 000000000..63053eb2e
--- /dev/null
+++ b/src/api/v1/llm.py
@@ -0,0 +1,115 @@
+"""OpenAI-compatible LLM proxy for Langflow and other OpenAI clients.
+
+Auth is a short-lived Langflow hop token (same family as ingest tokens),
+the user JWT, or an `orag_` API key. Provider secrets stay in OpenRAG.
+"""
+
+from typing import Any
+
+from fastapi import Depends, Request
+from fastapi.responses import JSONResponse, StreamingResponse
+
+from dependencies import require_llm_proxy_any_permission, require_llm_proxy_permission
+from services.llm_gateway import LlmGatewayError, chat_completions, embeddings
+from services.model_catalog import (
+ CATALOG_UNAVAILABLE_MESSAGE,
+ CatalogUnavailableError,
+ catalog,
+ openai_models_list,
+)
+from session_manager import User
+from utils.logging_config import get_logger
+
+logger = get_logger(__name__)
+
+_catalog_read = require_llm_proxy_any_permission(("providers:read", "chat:use", "knowledge:upload"))
+_embeddings_use = require_llm_proxy_any_permission(("chat:use", "knowledge:upload"))
+_chat_use = require_llm_proxy_permission("chat:use")
+
+
+def _openai_error(message: str, status_code: int, error_type: str = "invalid_request_error"):
+ return JSONResponse(
+ {"error": {"message": message, "type": error_type}},
+ status_code=status_code,
+ )
+
+
+def _gateway_error(exc: LlmGatewayError):
+ error_type = "invalid_request_error" if exc.status_code < 500 else "api_error"
+ if exc.detail != exc.message:
+ logger.error("LLM gateway error", status_code=exc.status_code, error=exc.detail)
+ return _openai_error(exc.message, exc.status_code, error_type)
+
+
+async def list_openai_models_endpoint(
+ user: User = Depends(_catalog_read),
+):
+ """OpenAI-compatible model inventory. GET /v1/models"""
+ try:
+ return JSONResponse(openai_models_list())
+ except CatalogUnavailableError as exc:
+ # Log the cause, but never echo exception text back to the caller
+ # (CodeQL py/stack-trace-exposure).
+ logger.error("Model catalogue unavailable", error=str(exc))
+ return _openai_error(CATALOG_UNAVAILABLE_MESSAGE, 503, "api_error")
+
+
+async def model_catalog_endpoint(
+ user: User = Depends(_catalog_read),
+):
+ """LiteLLM picker payload. GET /v1/model-catalog"""
+ try:
+ return JSONResponse(catalog(), headers={"Cache-Control": "private, max-age=3600"})
+ except CatalogUnavailableError as exc:
+ logger.error("Model catalogue unavailable", error=str(exc))
+ return JSONResponse({"error": CATALOG_UNAVAILABLE_MESSAGE}, status_code=503)
+
+
+async def _read_json_body(request: Request) -> dict[str, Any] | JSONResponse:
+ try:
+ body = await request.json()
+ except Exception:
+ return _openai_error("Request body must be valid JSON", 400)
+ if not isinstance(body, dict):
+ return _openai_error("Request body must be a JSON object", 400)
+ return body
+
+
+async def chat_completions_endpoint(
+ request: Request,
+ user: User = Depends(_chat_use),
+):
+ """OpenAI-compatible chat completions. POST /v1/chat/completions"""
+ body = await _read_json_body(request)
+ if isinstance(body, JSONResponse):
+ return body
+ try:
+ result = await chat_completions(body)
+ except LlmGatewayError as exc:
+ return _gateway_error(exc)
+ if body.get("stream"):
+ return StreamingResponse(
+ result,
+ media_type="text/event-stream",
+ headers={
+ "Cache-Control": "no-cache",
+ "Connection": "keep-alive",
+ "X-Accel-Buffering": "no",
+ },
+ )
+ return JSONResponse(result)
+
+
+async def embeddings_endpoint(
+ request: Request,
+ user: User = Depends(_embeddings_use),
+):
+ """OpenAI-compatible embeddings. POST /v1/embeddings"""
+ body = await _read_json_body(request)
+ if isinstance(body, JSONResponse):
+ return body
+ try:
+ result = await embeddings(body)
+ except LlmGatewayError as exc:
+ return _gateway_error(exc)
+ return JSONResponse(result)
diff --git a/src/api/v1/models.py b/src/api/v1/models.py
index 861e2c4b6..4e567b19b 100644
--- a/src/api/v1/models.py
+++ b/src/api/v1/models.py
@@ -10,13 +10,12 @@ from fastapi.responses import JSONResponse
from config.settings import get_openrag_config
from dependencies import get_models_service, require_api_key_permission
+from services.model_catalog import catalog, is_known_provider
from session_manager import User
from utils.logging_config import get_logger
logger = get_logger(__name__)
-VALID_PROVIDERS = frozenset({"openai", "anthropic", "ollama", "watsonx"})
-
async def _fetch_models(provider, config, models_service):
"""Fetch models for the given provider using config credentials."""
@@ -47,26 +46,61 @@ async def _fetch_models(provider, config, models_service):
models = await models_service.get_ollama_models(endpoint=endpoint)
return models, None
- # watsonx
- api_key = config.providers.watsonx.api_key
- endpoint = config.providers.watsonx.endpoint
- project_id = config.providers.watsonx.project_id
- if not api_key:
- return None, JSONResponse(
- {"error": "WatsonX API key not configured. Set it in Settings."}, status_code=400
- )
- if not endpoint:
- return None, JSONResponse(
- {"error": "WatsonX endpoint not configured. Set it in Settings."}, status_code=400
+ if provider == "watsonx":
+ api_key = config.providers.watsonx.api_key
+ endpoint = config.providers.watsonx.endpoint
+ project_id = config.providers.watsonx.project_id
+ if not api_key:
+ return None, JSONResponse(
+ {"error": "WatsonX API key not configured. Set it in Settings."},
+ status_code=400,
+ )
+ if not endpoint:
+ return None, JSONResponse(
+ {"error": "WatsonX endpoint not configured. Set it in Settings."},
+ status_code=400,
+ )
+ if not project_id:
+ return None, JSONResponse(
+ {"error": "WatsonX project ID not configured. Set it in Settings."},
+ status_code=400,
+ )
+ models = await models_service.get_ibm_models(
+ endpoint=endpoint, api_key=api_key, project_id=project_id
)
- if not project_id:
+ return models, None
+
+ provider_config = config.providers.get_provider_config(provider)
+ if not provider_config.configured:
return None, JSONResponse(
- {"error": "WatsonX project ID not configured. Set it in Settings."}, status_code=400
+ {"error": f"{provider} is not configured. Set it in Settings."},
+ status_code=400,
)
- models = await models_service.get_ibm_models(
- endpoint=endpoint, api_key=api_key, project_id=project_id
+ entry = next(
+ (item for item in catalog()["providers"] if item["key"] == provider),
+ None,
)
- return models, None
+ if entry is None:
+ return {"language_models": [], "embedding_models": []}, None
+ return {
+ "language_models": [
+ {
+ "value": model["model"],
+ "label": model["model"],
+ "default": False,
+ "supports_images": "vision" in model.get("capabilities", []),
+ }
+ for model in entry["models"]
+ ],
+ "embedding_models": [
+ {
+ "value": model["model"],
+ "label": model["model"],
+ "default": False,
+ }
+ for model in entry["embedding_models"]
+ ],
+ }, None
async def list_models_endpoint(
@@ -80,9 +114,9 @@ async def list_models_endpoint(
GET /v1/models/{provider}
"""
provider = provider.lower()
- if provider not in VALID_PROVIDERS:
+ if not is_known_provider(provider):
return JSONResponse(
- {"error": f"Invalid provider. Must be one of: {', '.join(sorted(VALID_PROVIDERS))}"},
+ {"error": f"Unknown LiteLLM provider: {provider}"},
status_code=400,
)
diff --git a/src/app/container.py b/src/app/container.py
index 0527aa23b..6276a5e7c 100644
--- a/src/app/container.py
+++ b/src/app/container.py
@@ -31,6 +31,7 @@ from services.ingest_preview_service import IngestPreviewService
from services.knowledge_filter_service import KnowledgeFilterService
from services.langflow_file_service import LangflowFileService
from services.langflow_ingest_token_service import LangflowIngestTokenService
+from services.langflow_llm_token_service import LangflowLlmTokenService
from services.langflow_mcp_service import LangflowMCPService
from services.models_service import ModelsService
from services.monitor_service import MonitorService
@@ -85,6 +86,7 @@ async def initialize_services():
models_service = ModelsService()
document_index_writer = DocumentIndexWriter()
langflow_ingest_token_service = LangflowIngestTokenService()
+ langflow_llm_token_service = LangflowLlmTokenService()
ingest_preview_service = IngestPreviewService()
document_service = DocumentService(
session_manager=session_manager,
@@ -228,6 +230,7 @@ async def initialize_services():
"langflow_file_service": langflow_file_service,
"document_index_writer": document_index_writer,
"langflow_ingest_token_service": langflow_ingest_token_service,
+ "langflow_llm_token_service": langflow_llm_token_service,
"auth_service": auth_service,
"connector_service": connector_service,
"group_acl_service": group_acl_service,
diff --git a/src/app/routes/internal.py b/src/app/routes/internal.py
index b427edfe7..70d454ec4 100644
--- a/src/app/routes/internal.py
+++ b/src/app/routes/internal.py
@@ -436,6 +436,9 @@ def register_internal_routes(app: FastAPI):
"/models/ollama", models.get_ollama_models, methods=["GET"], tags=["internal"]
)
app.add_api_route("/models/ibm", models.get_ibm_models, methods=["POST"], tags=["internal"])
+ app.add_api_route(
+ "/models/catalog", models.get_model_catalog, methods=["GET"], tags=["internal"]
+ )
# Onboarding endpoints
app.add_api_route("/onboarding", settings.onboarding, methods=["POST"], tags=["internal"])
diff --git a/src/app/routes/public_v1.py b/src/app/routes/public_v1.py
index 534689e40..690c8e8ef 100644
--- a/src/app/routes/public_v1.py
+++ b/src/app/routes/public_v1.py
@@ -14,6 +14,9 @@ from api.v1 import (
from api.v1 import (
knowledge_filters as v1_knowledge_filters,
)
+from api.v1 import (
+ llm as v1_llm,
+)
from api.v1 import (
models as v1_models,
)
@@ -96,7 +99,33 @@ def register_public_v1_routes(app: FastAPI):
tags=["public"],
)
- # Models endpoint
+ # OpenAI-compatible LLM proxy (Langflow and other OpenAI clients).
+ app.add_api_route(
+ "/v1/models",
+ v1_llm.list_openai_models_endpoint,
+ methods=["GET"],
+ tags=["public"],
+ )
+ app.add_api_route(
+ "/v1/model-catalog",
+ v1_llm.model_catalog_endpoint,
+ methods=["GET"],
+ tags=["public"],
+ )
+ app.add_api_route(
+ "/v1/chat/completions",
+ v1_llm.chat_completions_endpoint,
+ methods=["POST"],
+ tags=["public"],
+ )
+ app.add_api_route(
+ "/v1/embeddings",
+ v1_llm.embeddings_endpoint,
+ methods=["POST"],
+ tags=["public"],
+ )
+
+ # Models endpoint (per-provider live inventory; kept for SDK compatibility)
app.add_api_route(
"/v1/models/{provider}",
v1_models.list_models_endpoint,
diff --git a/src/auth/request_identity.py b/src/auth/request_identity.py
index 11014f91e..27ea55050 100644
--- a/src/auth/request_identity.py
+++ b/src/auth/request_identity.py
@@ -502,6 +502,20 @@ async def resolve_api_key_user(request: Request, api_key_service, session_manage
)
if raw_jwt and raw_jwt.strip():
token = raw_jwt[7:].strip() if raw_jwt.startswith("Bearer ") else raw_jwt.strip()
+ from services.langflow_llm_token_service import langflow_hop_audience
+
+ hop_aud = langflow_hop_audience(token)
+ if hop_aud:
+ raise HTTPException(
+ status_code=401,
+ detail={
+ "error": "langflow_hop_token",
+ "message": (
+ "This token is only valid for the Langflow callback it "
+ "was issued for, not for the rest of /v1."
+ ),
+ },
+ )
claims = resolve_jwt_claims(token)
sub = claims.get("sub") if claims else None
if sub:
diff --git a/src/config/config_manager.py b/src/config/config_manager.py
index 5e991f591..26e882e77 100644
--- a/src/config/config_manager.py
+++ b/src/config/config_manager.py
@@ -4,7 +4,7 @@ import os
import re
from dataclasses import asdict, dataclass, field
from pathlib import Path
-from typing import Any, Optional
+from typing import Any, Optional, Protocol
import yaml
@@ -104,6 +104,17 @@ def _sanitize_for_log(value: object) -> str:
return re.sub(r"[\r\n\t]", "_", str(value))
+class ProviderConfig(Protocol):
+ """Structural type shared by every provider config dataclass.
+
+ The concrete configs have no common base class, so a tuple mixing them
+ joins to ``object``; annotating against this protocol keeps ``configured``
+ visible to mypy without changing any dataclass field order.
+ """
+
+ configured: bool
+
+
@dataclass
class OpenAIConfig:
"""OpenAI provider configuration."""
@@ -139,6 +150,14 @@ class OllamaConfig:
configured: bool = False
+@dataclass
+class GenericProviderConfig:
+ """Credentials for any LiteLLM provider not covered by legacy fields."""
+
+ credentials: dict[str, str] = field(default_factory=dict)
+ configured: bool = False
+
+
@dataclass
class ProvidersConfig:
"""All provider configurations."""
@@ -147,10 +166,18 @@ class ProvidersConfig:
anthropic: AnthropicConfig
watsonx: WatsonXConfig
ollama: OllamaConfig
+ custom: dict[str, GenericProviderConfig] = field(default_factory=dict)
def any_configured(self) -> bool:
"""Return True if at least one provider is marked as configured."""
- return any(p.configured for p in (self.openai, self.anthropic, self.watsonx, self.ollama))
+ providers: tuple[ProviderConfig, ...] = (
+ self.openai,
+ self.anthropic,
+ self.watsonx,
+ self.ollama,
+ *self.custom.values(),
+ )
+ return any(p.configured for p in providers)
def get_provider_config(self, provider: str):
"""Get configuration for a specific provider."""
@@ -163,8 +190,70 @@ class ProvidersConfig:
return self.watsonx
elif provider_lower == "ollama":
return self.ollama
- else:
- raise ValueError(f"Unknown provider: {provider}")
+ return self.custom.get(provider_lower, GenericProviderConfig())
+
+ def set_credentials(self, provider: str, credentials: dict[str, str]) -> None:
+ """Upsert arbitrary LiteLLM credentials while preserving legacy config."""
+ key = provider.strip().lower()
+ clean = {
+ str(name): str(value).strip()
+ for name, value in credentials.items()
+ if str(name).strip() and str(value).strip()
+ }
+ if not clean:
+ # Every submitted value was blank. Creating the entry anyway would
+ # register a provider that reports `configured` with zero
+ # credentials, which then satisfies `any_configured()` and can be
+ # picked as a fallback provider and called with no key at all.
+ return
+ previous = self.custom.get(key, GenericProviderConfig())
+ previous.credentials.update(clean)
+ previous.configured = True
+ self.custom[key] = previous
+ if key == "openai":
+ self.openai.api_key = clean.get("api_key", self.openai.api_key)
+ self.openai.configured = bool(self.openai.api_key)
+ elif key == "anthropic":
+ self.anthropic.api_key = clean.get("api_key", self.anthropic.api_key)
+ self.anthropic.configured = bool(self.anthropic.api_key)
+ elif key == "watsonx":
+ self.watsonx.api_key = clean.get("api_key", self.watsonx.api_key)
+ self.watsonx.endpoint = clean.get("api_base", self.watsonx.endpoint)
+ self.watsonx.project_id = clean.get("project_id", self.watsonx.project_id)
+ self.watsonx.configured = bool(clean or self.watsonx.configured)
+ elif key == "ollama":
+ self.ollama.endpoint = clean.get("api_base", self.ollama.endpoint)
+ self.ollama.configured = bool(self.ollama.endpoint)
+
+ def credential_values(self, provider: str) -> dict[str, str]:
+ """Return LiteLLM keyword arguments for a configured provider."""
+ key = provider.strip().lower()
+ custom = dict(self.custom.get(key, GenericProviderConfig()).credentials)
+ if key == "openai":
+ if self.openai.api_key:
+ custom.setdefault("api_key", self.openai.api_key)
+ return custom
+ if key == "anthropic":
+ if self.anthropic.api_key:
+ custom.setdefault("api_key", self.anthropic.api_key)
+ return custom
+ if key == "watsonx":
+ legacy = {
+ name: value
+ for name, value in {
+ "api_key": self.watsonx.api_key,
+ "api_base": self.watsonx.endpoint,
+ "project_id": self.watsonx.project_id,
+ }.items()
+ if value
+ }
+ return {**legacy, **custom}
+ if key == "ollama":
+ endpoint = self.ollama.resolved_endpoint or self.ollama.endpoint
+ if endpoint:
+ custom.setdefault("api_base", endpoint)
+ return custom
+ return custom
@dataclass
@@ -255,12 +344,31 @@ class OpenRAGConfig:
new_data["api_key"] = decrypt_secret(new_data["api_key"])
return new_data
+ def _decrypt_custom_provider(provider: str, p_data: dict) -> GenericProviderConfig:
+ from services.model_catalog import secret_field_keys
+
+ credentials = dict(p_data.get("credentials") or {})
+ for key in secret_field_keys(provider):
+ if key in credentials:
+ credentials[key] = decrypt_secret(credentials[key])
+ return GenericProviderConfig(
+ credentials=credentials,
+ configured=bool(p_data.get("configured", credentials)),
+ )
+
+ custom_data = providers_data.get("custom", {})
+
return cls(
providers=ProvidersConfig(
openai=OpenAIConfig(**_decrypt_provider(providers_data.get("openai", {}))),
anthropic=AnthropicConfig(**_decrypt_provider(providers_data.get("anthropic", {}))),
watsonx=WatsonXConfig(**_decrypt_provider(providers_data.get("watsonx", {}))),
ollama=OllamaConfig(**_decrypt_provider(providers_data.get("ollama", {}))),
+ custom={
+ str(provider).lower(): _decrypt_custom_provider(str(provider), value)
+ for provider, value in custom_data.items()
+ if isinstance(value, dict)
+ },
),
knowledge=KnowledgeConfig(**data.get("knowledge", {})),
agent=AgentConfig(**data.get("agent", {})),
@@ -325,6 +433,7 @@ class ConfigManager:
"anthropic": {},
"watsonx": {},
"ollama": {},
+ "custom": {},
},
"knowledge": {},
"agent": {},
@@ -346,7 +455,7 @@ class ConfigManager:
# Merge file config
if "providers" in file_config:
- for provider in ["openai", "anthropic", "watsonx", "ollama"]:
+ for provider in ["openai", "anthropic", "watsonx", "ollama", "custom"]:
if provider in file_config["providers"]:
provider_data = file_config["providers"][provider]
# Check if api_key is unencrypted and we have a key
@@ -509,6 +618,14 @@ class ConfigManager:
for _provider_name, provider_config in providers.items():
if "api_key" in provider_config:
provider_config["api_key"] = encrypt_secret(provider_config["api_key"])
+ custom = providers.get("custom", {})
+ from services.model_catalog import secret_field_keys
+
+ for provider, provider_config in custom.items():
+ credentials = provider_config.get("credentials", {})
+ for key in secret_field_keys(provider):
+ if credentials.get(key):
+ credentials[key] = encrypt_secret(credentials[key])
with open(config_path, "w") as f:
yaml.dump(config_dict, f, default_flow_style=False, indent=2)
diff --git a/src/config/settings.py b/src/config/settings.py
index 25911386c..b7af138c8 100644
--- a/src/config/settings.py
+++ b/src/config/settings.py
@@ -120,6 +120,19 @@ OPENRAG_BACKEND_INTERNAL_URL = os.getenv(
f"http://openrag-backend:{OPENRAG_BACKEND_PORT}",
).rstrip("/")
+
+def get_langflow_llm_base_url() -> str:
+ """OpenAI-compatible base URL Langflow should call (must end with /v1).
+
+ Override with OPENRAG_LLM_PROXY_URL when Langflow cannot reach
+ OPENRAG_BACKEND_INTERNAL_URL (rare; same cases as a custom ingest router).
+ """
+ override = os.getenv("OPENRAG_LLM_PROXY_URL")
+ if override:
+ return override.rstrip("/")
+ return f"{OPENRAG_BACKEND_INTERNAL_URL}/v1"
+
+
# --- Backend ingestion-callback proxy router ------------------------------
# A standalone, minimal uvicorn app (spun up in the same process as the main
# backend, on its own port) that proxies ONLY the Langflow ingest callback
@@ -661,6 +674,19 @@ LANGFLOW_INGEST_CALLBACK_TTL_SECONDS = get_env_int(
)
LANGFLOW_INGEST_CALLBACK_BATCH_SIZE = get_env_int("LANGFLOW_INGEST_CALLBACK_BATCH_SIZE", 100)
+
+def get_langflow_llm_proxy_ttl_seconds() -> int:
+ """TTL for the Langflow → OpenRAG LLM hop token.
+
+ Defaults to the ingest-callback TTL so one Langflow ingest run can call
+ embeddings for the whole document. Override with LANGFLOW_LLM_PROXY_TTL_SECONDS.
+ """
+ return get_env_int(
+ "LANGFLOW_LLM_PROXY_TTL_SECONDS",
+ LANGFLOW_INGEST_CALLBACK_TTL_SECONDS,
+ )
+
+
OPENSEARCH_JWT_TTL_BUFFER_SECONDS = 300
@@ -1627,7 +1653,15 @@ class AppClients:
current_value = target_variable.get("value")
current_default_fields = target_variable.get("default_fields", [])
- if current_value == value and not current_default_fields:
+ # Langflow redacts Credential values on GET (null) and treats an
+ # empty stored value as "{name} variable not found." Always write
+ # when the visible value is missing so placeholders can heal, and
+ # rewrite whenever stale Apply To (default_fields) entries linger.
+ if (
+ current_value not in (None, "")
+ and current_value == value
+ and not current_default_fields
+ ):
logger.debug(
"Langflow global variable already up to date, skipping update",
variable_name=name,
diff --git a/src/dependencies.py b/src/dependencies.py
index 063970a5a..746bd1f68 100644
--- a/src/dependencies.py
+++ b/src/dependencies.py
@@ -82,6 +82,10 @@ __all__ = [
"get_knowledge_filter_service",
"get_langflow_file_service",
"get_langflow_ingest_token_service",
+ "get_langflow_llm_token_service",
+ "get_llm_proxy_user",
+ "require_llm_proxy_any_permission",
+ "require_llm_proxy_permission",
"get_models_service",
"get_monitor_service",
"get_optional_user",
@@ -170,6 +174,10 @@ def get_langflow_ingest_token_service(services: dict = Depends(get_services)):
return services["langflow_ingest_token_service"]
+def get_langflow_llm_token_service(services: dict = Depends(get_services)):
+ return services["langflow_llm_token_service"]
+
+
def get_models_service(services: dict = Depends(get_services)):
return services["models_service"]
@@ -178,6 +186,26 @@ def get_api_key_service(services: dict = Depends(get_services)):
return services["api_key_service"]
+async def get_llm_proxy_user(
+ request: Request,
+ token_service=Depends(get_langflow_llm_token_service),
+ api_key_service=Depends(get_api_key_service),
+ session_manager=Depends(get_session_manager),
+) -> User:
+ """Langflow hop token, then the normal /v1 JWT or orag_ key."""
+ raw = request.headers.get("authorization") or ""
+ token = raw[7:].strip() if raw.lower().startswith("bearer ") else raw.strip()
+ if token and not token.startswith("orag_"):
+ try:
+ user = token_service.validate_token(token)
+ except ValueError:
+ user = None
+ else:
+ request.state.user = user
+ return user
+ return await resolve_api_key_user(request, api_key_service, session_manager)
+
+
def get_file_service(services: dict = Depends(get_services)):
return services["file_service"]
@@ -294,6 +322,39 @@ def require_all_permissions(required_perms: Sequence[str]):
return _dep
+def require_llm_proxy_permission(perm: str):
+ """LLM proxy auth: Langflow hop token, or /v1 identity plus `perm`."""
+
+ async def _dep(
+ request: Request,
+ user: User = Depends(get_llm_proxy_user),
+ rbac=Depends(get_rbac_service),
+ ) -> User:
+ if user.provider == "langflow_llm":
+ return user
+ return await enforce_api_key_permission(request, user, rbac, perm)
+
+ return _dep
+
+
+def require_llm_proxy_any_permission(required_perms: Sequence[str]):
+ """LLM proxy auth: hop token, or /v1 identity plus any of `required_perms`."""
+ required = tuple(required_perms)
+ if not required:
+ raise ValueError("require_llm_proxy_any_permission requires at least one permission")
+
+ async def _dep(
+ request: Request,
+ user: User = Depends(get_llm_proxy_user),
+ rbac=Depends(get_rbac_service),
+ ) -> User:
+ if user.provider == "langflow_llm":
+ return user
+ return await enforce_api_key_any_permission(request, user, rbac, required)
+
+ return _dep
+
+
def require_api_key_permission(perm: str):
"""FastAPI dependency factory enforcing one /v1 permission."""
diff --git a/src/mcp_http/server.py b/src/mcp_http/server.py
index d147ffc91..09b5d53a4 100644
--- a/src/mcp_http/server.py
+++ b/src/mcp_http/server.py
@@ -155,13 +155,43 @@ COMPONENT_CUSTOMIZATIONS: dict[tuple[str, str], dict[str, str]] = {
"system prompt, and document processing options."
),
},
- # Models endpoint
+ # Models / LLM proxy
+ ("/v1/models", "GET"): {
+ "name": "openrag_list_openai_models",
+ "description": (
+ "List every language and embedding model OpenRAG can serve, in OpenAI "
+ "`GET /v1/models` format. Use this from an OpenAI-compatible client "
+ "pointed at the LLM proxy."
+ ),
+ },
+ ("/v1/model-catalog", "GET"): {
+ "name": "openrag_model_catalog",
+ "description": (
+ "LiteLLM provider/model catalogue used by the settings picker: "
+ "grouped models, capability flags, and credential field specs."
+ ),
+ },
+ ("/v1/chat/completions", "POST"): {
+ "name": "openrag_chat_completions",
+ "description": (
+ "OpenAI-compatible chat completions. OpenRAG routes to the configured "
+ "provider via LiteLLM. Send a Langflow hop token, user JWT, or orag_ "
+ "API key as Bearer."
+ ),
+ },
+ ("/v1/embeddings", "POST"): {
+ "name": "openrag_embeddings",
+ "description": (
+ "OpenAI-compatible embeddings. OpenRAG routes to the configured "
+ "embedding provider via LiteLLM."
+ ),
+ },
("/v1/models/{provider}", "GET"): {
"name": "openrag_list_models",
"description": (
"List available language models and embedding models for a provider. "
"Use this before updating settings to see which model values are valid. "
- "Provider must be one of: openai, anthropic, ollama, watsonx."
+ "Provider must be a configured LiteLLM provider key (e.g. openai, anthropic, ollama, watsonx)."
),
},
# Knowledge filters endpoints
diff --git a/src/services/chat_service.py b/src/services/chat_service.py
index af00e4054..a15b9567b 100644
--- a/src/services/chat_service.py
+++ b/src/services/chat_service.py
@@ -147,7 +147,11 @@ class ChatService:
# Add provider credentials to headers
await add_provider_credentials_to_headers(
- extra_headers, config, flows_service=self.flows_service, jwt_token=jwt_token
+ extra_headers,
+ config,
+ flows_service=self.flows_service,
+ jwt_token=jwt_token,
+ user_id=user_id,
)
# Get context variables for filters, limit, and threshold
from auth_context import (
@@ -278,7 +282,11 @@ class ChatService:
# Add provider credentials to headers
await add_provider_credentials_to_headers(
- extra_headers, config, flows_service=self.flows_service, jwt_token=jwt_token
+ extra_headers,
+ config,
+ flows_service=self.flows_service,
+ jwt_token=jwt_token,
+ user_id=user_id,
)
# Build the complete filter expression like the chat service does
@@ -579,7 +587,11 @@ class ChatService:
# Add provider credentials to headers
await add_provider_credentials_to_headers(
- extra_headers, config, flows_service=self.flows_service, jwt_token=jwt_token
+ extra_headers,
+ config,
+ flows_service=self.flows_service,
+ jwt_token=jwt_token,
+ user_id=user_id,
)
# Ensure the Langflow client exists; try lazy init if needed
diff --git a/src/services/default_docs_service.py b/src/services/default_docs_service.py
index 06100711a..7813cf635 100644
--- a/src/services/default_docs_service.py
+++ b/src/services/default_docs_service.py
@@ -205,7 +205,7 @@ async def _ingest_default_documents_langflow(
effective_jwt = session_manager.get_effective_jwt_token(anonymous_user.user_id, None)
default_tweaks = {
- "OpenSearchVectorStoreComponentMultimodalMultiEmbedding-By9U4": {
+ "OpenSearchVectorStoreComponentMultimodalMultiEmbedding-WaE28": {
"docs_metadata": [
{"key": "owner", "value": None},
{"key": "owner_name", "value": anonymous_user.name},
@@ -268,7 +268,7 @@ async def _ingest_default_documents_url_langflow(
effective_jwt = session_manager.get_effective_jwt_token(anonymous_user.user_id, None)
default_tweaks = {
- "OpenSearchVectorStoreComponentMultimodalMultiEmbedding-By9U4": {
+ "OpenSearchVectorStoreComponentMultimodalMultiEmbedding-dihKf": {
"docs_metadata": [
{"key": "owner", "value": None},
{"key": "owner_name", "value": anonymous_user.name},
diff --git a/src/services/flows_service.py b/src/services/flows_service.py
index 2f0b60d4a..2c31df845 100644
--- a/src/services/flows_service.py
+++ b/src/services/flows_service.py
@@ -1007,15 +1007,21 @@ class FlowsService:
Change dropdown values for provider-specific components across flows
Args:
- provider: The provider ("watsonx", "ollama", "openai", "anthropic")
+ provider: Any LiteLLM provider. Non-legacy providers use Langflow's
+ OpenAI-compatible component, which points at the OpenRAG proxy.
embedding_model: The embedding model name to set
llm_model: The LLM model name to set
force_embedding_update: If True, update embeddings even if model is None
force_llm_update: If True, update LLM even if model is None
flow_configs: Optional list of flow configs to update
"""
- if provider not in ["watsonx", "ollama", "openai", "anthropic"]:
- raise ValueError("provider must be 'watsonx', 'ollama', 'openai', or 'anthropic'")
+ from services.model_catalog import is_known_provider
+
+ if not is_known_provider(provider):
+ raise ValueError(f"Unknown LiteLLM provider: {provider}")
+ flow_provider = (
+ provider if provider in {"watsonx", "ollama", "openai", "anthropic"} else "openai"
+ )
try:
# Use provided flow_configs or default to all flows
@@ -1032,7 +1038,7 @@ class FlowsService:
tasks.append(
self._update_provider_components(
config,
- provider,
+ flow_provider,
embedding_model=embedding_model,
llm_model=llm_model,
force_embedding_update=force_embedding_update,
@@ -1386,38 +1392,18 @@ class FlowsService:
updated = True
- # Update provider-specific fields using Langflow global variable names.
- # "api_base" is the Ollama URL field on the Embedding Model component;
- # "ollama_base_url" is the equivalent field on the Language Model / Agent component.
- field_mappings = {
- "api_key": {
- "openai": "OPENAI_API_KEY",
- "watsonx": "WATSONX_APIKEY",
- "anthropic": "ANTHROPIC_API_KEY",
- },
- "api_base": {
- "ollama": "OLLAMA_BASE_URL",
- },
- "ollama_base_url": {
- "ollama": "OLLAMA_BASE_URL",
- },
- "base_url_ibm_watsonx": {
- "watsonx": "WATSONX_URL",
- },
- "project_id": {
- "watsonx": "WATSONX_PROJECT_ID",
- },
+ # Point every model component at the OpenRAG OpenAI-compatible proxy.
+ # Real provider secrets never leave OpenRAG; Langflow sends the caller JWT.
+ proxy_fields = {
+ "api_key": "OPENRAG_LLM_TOKEN",
+ "openai_api_key": "OPENRAG_LLM_TOKEN",
+ "api_base": "OPENRAG_LLM_BASE_URL",
+ "openai_api_base": "OPENRAG_LLM_BASE_URL",
}
-
- for field, mapping in field_mappings.items():
+ for field, global_name in proxy_fields.items():
if field in template:
- target_value = mapping.get(provider)
- if target_value:
- template[field]["value"] = target_value
- template[field]["load_from_db"] = True
- else:
- template[field]["value"] = ""
- template[field]["load_from_db"] = False
+ template[field]["value"] = global_name
+ template[field]["load_from_db"] = True
updated = True
return updated
diff --git a/src/services/langflow_file_service.py b/src/services/langflow_file_service.py
index 3fcf938d0..04f8c9a57 100644
--- a/src/services/langflow_file_service.py
+++ b/src/services/langflow_file_service.py
@@ -25,9 +25,9 @@ logger = get_logger(__name__)
class LangflowFileService:
- INGEST_OPENSEARCH_COMPONENT_ID = "OpenSearchVectorStoreComponentMultimodalMultiEmbedding-By9U4"
+ INGEST_OPENSEARCH_COMPONENT_ID = "OpenSearchVectorStoreComponentMultimodalMultiEmbedding-WaE28"
URL_INGEST_OPENSEARCH_COMPONENT_ID = (
- "OpenSearchVectorStoreComponentMultimodalMultiEmbedding-PMGGV"
+ "OpenSearchVectorStoreComponentMultimodalMultiEmbedding-dihKf"
)
def __init__(
@@ -548,7 +548,11 @@ class LangflowFileService:
# Add provider credentials as global variables for ingestion
await add_provider_credentials_to_headers(
- headers, config, flows_service=self.flows_service, jwt_token=jwt_token
+ headers,
+ config,
+ flows_service=self.flows_service,
+ jwt_token=jwt_token,
+ user_id=owner,
)
if self.ingest_token_service is None:
await self._ensure_langflow_ingest_index(embedding_model)
@@ -719,7 +723,11 @@ class LangflowFileService:
if tweaks:
payload["tweaks"] = tweaks
await add_provider_credentials_to_headers(
- headers, config, flows_service=self.flows_service, jwt_token=jwt_token
+ headers,
+ config,
+ flows_service=self.flows_service,
+ jwt_token=jwt_token,
+ user_id=owner,
)
if self.ingest_token_service is None:
await self._ensure_langflow_ingest_index(embedding_model)
diff --git a/src/services/langflow_llm_token_service.py b/src/services/langflow_llm_token_service.py
new file mode 100644
index 000000000..458e6f7b3
--- /dev/null
+++ b/src/services/langflow_llm_token_service.py
@@ -0,0 +1,124 @@
+"""Short-lived tokens for Langflow-to-backend LLM proxy calls.
+
+Same family as ingest tokens: minted per Langflow run, scoped to the LLM
+proxy, and useless on the rest of `/v1`. Langflow's OpenAI client sends the
+token as `Authorization: Bearer` (`OPENRAG_LLM_TOKEN`). SDK and MCP callers keep
+using the user JWT or an `orag_` key.
+"""
+
+from __future__ import annotations
+
+import time
+import uuid
+
+import jwt
+
+from services.langflow_ingest_token_service import _resolve_default_signing_config
+from session_manager import User
+from utils.logging_config import get_logger
+
+logger = get_logger(__name__)
+
+LANGFLOW_LLM_AUDIENCE = "openrag-langflow-llm"
+LANGFLOW_LLM_SCOPE = "llm:proxy"
+LANGFLOW_HOP_AUDIENCES = frozenset(
+ {
+ LANGFLOW_LLM_AUDIENCE,
+ "openrag-langflow-ingest",
+ }
+)
+
+
+def langflow_hop_audience(token: str) -> str | None:
+ """Unverified `aud` when `token` is a Langflow hop token, else None."""
+ if not token or token.startswith("orag_"):
+ return None
+ try:
+ claims = jwt.decode(
+ token,
+ options={"verify_signature": False, "verify_aud": False, "verify_exp": False},
+ )
+ except jwt.PyJWTError:
+ return None
+ aud = claims.get("aud")
+ values = aud if isinstance(aud, list) else [aud]
+ for value in values:
+ if value in LANGFLOW_HOP_AUDIENCES:
+ return str(value)
+ return None
+
+
+class LangflowLlmTokenService:
+ """Mint and validate per-run LLM proxy tokens.
+
+ A token is valid for many completions/embeddings calls during one Langflow
+ run. It is not one-shot; revoke is optional. Expiry is the bound.
+ """
+
+ audience = LANGFLOW_LLM_AUDIENCE
+ scope = LANGFLOW_LLM_SCOPE
+
+ def __init__(self, secret: str | None = None, ttl_seconds: int | None = None):
+ if secret is not None:
+ self._signing_key = secret
+ self._verification_key = secret
+ self.algorithm = "HS256"
+ else:
+ self._signing_key, self._verification_key, self.algorithm = (
+ _resolve_default_signing_config()
+ )
+ from config.settings import get_langflow_llm_proxy_ttl_seconds
+
+ self.ttl_seconds = max(ttl_seconds or get_langflow_llm_proxy_ttl_seconds(), 1)
+
+ def create_token(
+ self,
+ *,
+ user_id: str,
+ email: str | None = None,
+ name: str | None = None,
+ ) -> str:
+ now = int(time.time())
+ subject = (user_id or "").strip() or "anonymous"
+ payload = {
+ "aud": self.audience,
+ "scope": self.scope,
+ "jti": str(uuid.uuid4()),
+ "iat": now,
+ "exp": now + self.ttl_seconds,
+ "sub": subject,
+ "user_id": subject,
+ "email": (email or subject),
+ "name": (name or subject),
+ }
+ return jwt.encode(payload, self._signing_key, algorithm=self.algorithm)
+
+ def validate_token(self, token: str) -> User:
+ try:
+ payload = jwt.decode(
+ token,
+ self._verification_key,
+ algorithms=[self.algorithm],
+ audience=self.audience,
+ )
+ except jwt.PyJWTError as e:
+ logger.warning(
+ "Invalid Langflow LLM proxy token",
+ jwt_error=e.__class__.__name__,
+ detail=str(e),
+ )
+ raise ValueError("Invalid Langflow LLM proxy token") from e
+
+ if payload.get("scope") != self.scope:
+ raise ValueError("Langflow LLM proxy token has invalid scope")
+
+ user_id = str(payload.get("user_id") or payload.get("sub") or "").strip()
+ if not user_id:
+ raise ValueError("Langflow LLM proxy token is missing user_id")
+
+ return User(
+ user_id=user_id,
+ email=str(payload.get("email") or user_id),
+ name=str(payload.get("name") or user_id),
+ provider="langflow_llm",
+ )
diff --git a/src/services/llm_gateway.py b/src/services/llm_gateway.py
new file mode 100644
index 000000000..5d5a8f236
--- /dev/null
+++ b/src/services/llm_gateway.py
@@ -0,0 +1,874 @@
+"""OpenAI-compatible LLM gateway backed by the LiteLLM SDK.
+
+Langflow and other OpenAI clients call `/v1/chat/completions` and
+`/v1/embeddings`. This module owns provider secrets (from OpenRAG config) and
+routes by model prefix / configured provider. Callers never see upstream keys.
+"""
+
+from __future__ import annotations
+
+import json
+import re
+from collections.abc import AsyncIterator, Mapping
+from typing import Any, Literal
+
+from services.model_catalog import is_known_provider
+from utils.logging_config import get_logger
+
+logger = get_logger(__name__)
+
+_LITELLM_FORWARDED_PARAMS = (
+ "tools",
+ "tool_choice",
+ "temperature",
+ "top_p",
+ "max_tokens",
+ "max_completion_tokens",
+ "stop",
+ "presence_penalty",
+ "frequency_penalty",
+ "seed",
+ "response_format",
+ "parallel_tool_calls",
+ "n",
+ "user",
+ "logit_bias",
+ "stream_options",
+)
+
+
+class LlmGatewayError(Exception):
+ """Gateway failure. `status_code` is an HTTP status.
+
+ `message` is safe to return to the caller. `detail` carries the internal
+ text (upstream exception type and body) and is for logs only — returning it
+ is stack-trace exposure (CodeQL py/stack-trace-exposure).
+ """
+
+ def __init__(self, message: str, status_code: int = 400, detail: str | None = None):
+ super().__init__(message)
+ self.message = message
+ self.status_code = status_code
+ self.detail = detail or message
+
+
+def _get_config():
+ from config.settings import get_openrag_config
+
+ return get_openrag_config()
+
+
+#: Canonical separator between an OpenRAG provider tag and the model id.
+#: `/` cannot serve as one: watsonx hosts `openai/gpt-oss-120b`, whose own name
+#: begins with a provider key, so a `/`-split routes it to OpenAI and LiteLLM
+#: then rejects the bare `gpt-oss-120b`. No catalogue id has a provider-shaped
+#: prefix before a colon, so `provider:model` stays unambiguous even for ids
+#: that use colons themselves (`ollama:gpt-oss:120b-cloud`, `openai:ft:gpt-4`).
+PROVIDER_SEPARATOR = ":"
+
+
+def split_model_id(model: str) -> tuple[str | None, str]:
+ """Split an OpenRAG provider tag off a model id.
+
+ `provider:model` is the canonical form and is checked first. `provider/`
+ is still accepted so ids stored before the switch keep resolving, but only
+ when the remainder does not look like a provider-qualified name itself.
+ """
+ raw = (model or "").strip()
+
+ prefix, sep, rest = raw.partition(PROVIDER_SEPARATOR)
+ if sep and rest:
+ prefix_lower = prefix.lower()
+ if is_known_provider(prefix_lower):
+ return prefix_lower, rest
+
+ if "/" not in raw:
+ return None, raw
+
+ # A slash is ambiguous: it separates a legacy tag from its model, but it is
+ # also part of vendor-qualified names. When the whole string names exactly
+ # one catalogue model, that provider owns it — `openai/gpt-oss-120b` is
+ # watsonx's model, not OpenAI's `gpt-oss-120b`.
+ from services.model_catalog import catalog_owner
+
+ owner = catalog_owner(raw)
+ if owner:
+ return owner, raw
+
+ prefix, rest = raw.split("/", 1)
+ prefix_lower = prefix.lower()
+ if is_known_provider(prefix_lower):
+ return prefix_lower, rest
+ return None, raw
+
+
+def default_provider(kind: Literal["chat", "embedding"], config=None) -> str:
+ cfg = config or _get_config()
+ if kind == "embedding":
+ return (cfg.knowledge.embedding_provider or "openai").lower()
+ return (cfg.agent.llm_provider or "openai").lower()
+
+
+def default_model(kind: Literal["chat", "embedding"], config=None) -> str:
+ cfg = config or _get_config()
+ if kind == "embedding":
+ return cfg.knowledge.embedding_model or ""
+ return cfg.agent.llm_model or ""
+
+
+def provider_credentials(provider: str, config=None) -> dict[str, Any]:
+ """LiteLLM kwargs for any configured OpenRAG provider. Never logs secrets."""
+ cfg = config or _get_config()
+ key = (provider or "").strip().lower()
+ try:
+ prov = cfg.providers
+ except Exception as exc:
+ raise LlmGatewayError("LLM providers are not configured", 400) from exc
+
+ if hasattr(prov, "credential_values"):
+ credentials = prov.credential_values(key)
+ else:
+ provider_config = getattr(prov, key, None)
+ if provider_config is None:
+ credentials = {}
+ elif key == "watsonx":
+ credentials = {
+ name: value
+ for name, value in {
+ "api_key": getattr(provider_config, "api_key", None),
+ "api_base": getattr(provider_config, "endpoint", None),
+ "project_id": getattr(provider_config, "project_id", None),
+ }.items()
+ if value
+ }
+ elif key == "ollama":
+ endpoint = getattr(provider_config, "resolved_endpoint", None) or getattr(
+ provider_config, "endpoint", None
+ )
+ credentials = {"api_base": endpoint} if endpoint else {}
+ else:
+ api_key = getattr(provider_config, "api_key", None)
+ credentials = {"api_key": api_key} if api_key else {}
+ if key == "ollama" and credentials.get("api_base"):
+ from utils.container_utils import transform_localhost_url
+
+ credentials["api_base"] = transform_localhost_url(str(credentials["api_base"]))
+ custom = getattr(prov, "custom", {})
+ custom_config = custom.get(key) if isinstance(custom, dict) else None
+ configured = bool(getattr(custom_config, "configured", False))
+ if not credentials and not configured:
+ raise LlmGatewayError(
+ f"Provider {key!r} is not configured in OpenRAG. "
+ "Configure it in Settings or pick a model from a configured provider.",
+ 400,
+ )
+ return credentials
+
+
+def resolve_call(
+ model: str | None,
+ *,
+ kind: Literal["chat", "embedding"],
+ config=None,
+) -> tuple[str, str, dict[str, Any]]:
+ """Return `(litellm_model, provider, credentials)` for a request model id."""
+ cfg = config or _get_config()
+ requested = (model or "").strip() or default_model(kind, cfg)
+ if not requested:
+ raise LlmGatewayError("model is required", 400)
+
+ provider, name = split_model_id(requested)
+ if provider is None:
+ provider = default_provider(kind, cfg)
+ name = requested
+ credentials = provider_credentials(provider, cfg)
+ litellm_model = f"{provider}/{name}" if provider != "openai" else name
+ return litellm_model, provider, credentials
+
+
+_UPSTREAM_FAILURE_MESSAGE = "The model provider could not be reached. Please try again."
+_UPSTREAM_CREDENTIAL_MESSAGE = (
+ "The configured API key is invalid or has been revoked. Update it in Settings and retry."
+)
+
+
+#: Longest upstream explanation we will echo. Provider bodies can embed a whole
+#: model catalogue; past this the message stops being readable in a chat bubble.
+_MAX_UPSTREAM_MESSAGE_CHARS = 600
+
+#: Lines LiteLLM appends to its own exceptions that say nothing about the failure.
+_UPSTREAM_NOISE_MARKERS = (
+ "Give Feedback / Get Help",
+ "LiteLLM.Info:",
+ "For more information check:",
+ "For further information visit",
+ "During handling of the above exception",
+)
+
+#: Everything from here on is interpreter state, not provider explanation.
+_TRACEBACK_MARKERS = ("Traceback (most recent call last)", 'File "')
+
+_FILE_PATH_PATTERN = re.compile(r"(?:/[\w.\-]+)+\.py")
+#: Loopback and RFC1918 addresses — deployment topology, not provider explanation.
+_PRIVATE_HOST_PATTERN = re.compile(
+ r"\b(?:127(?:\.\d{1,3}){3}|10(?:\.\d{1,3}){3}|192\.168(?:\.\d{1,3}){2}"
+ r"|172\.(?:1[6-9]|2\d|3[01])(?:\.\d{1,3}){2}|localhost)\b"
+)
+_ANSI_PATTERN = re.compile(r"\x1b\[[0-9;]*m")
+
+
+def _call_label(provider: str, model: str) -> str:
+ """`provider/model` for humans, without repeating a prefix LiteLLM already added."""
+ if model and provider and not model.startswith(f"{provider}/"):
+ return f"{provider}/{model}"
+ return model or provider or "provider"
+
+
+def _json_bodies(text: str):
+ """Yield every JSON object embedded in `text`, outermost first."""
+ decoder = json.JSONDecoder()
+ index = text.find("{")
+ while index != -1:
+ try:
+ body, end = decoder.raw_decode(text, index)
+ except ValueError:
+ index = text.find("{", index + 1)
+ continue
+ yield body
+ index = text.find("{", end)
+
+
+def _provider_message(body: Any) -> str | None:
+ """The provider's own explanation out of one parsed error body."""
+ if not isinstance(body, dict):
+ return None
+ error = body.get("error")
+ if isinstance(error, dict) and isinstance(error.get("message"), str):
+ return error["message"]
+ if isinstance(error, str) and error.strip():
+ return error
+ errors = body.get("errors")
+ if isinstance(errors, list):
+ parts = [
+ item["message"]
+ for item in errors
+ if isinstance(item, dict) and isinstance(item.get("message"), str)
+ ]
+ if parts:
+ return "; ".join(parts)
+ for key in ("message", "detail"):
+ value = body.get(key)
+ if isinstance(value, str) and value.strip():
+ return value
+ return None
+
+
+def _is_provider_attributable(exc: BaseException | None) -> bool:
+ """True when the failure came from the provider call, not from our own code.
+
+ Anything LiteLLM raises describes the upstream request — it tags its
+ exceptions with `llm_provider`, and its transport wrappers live under the
+ `litellm` package. A `RuntimeError` from OpenRAG code does not, and its text
+ is ours to keep in the logs.
+ """
+ if exc is None:
+ return False
+ if getattr(exc, "llm_provider", None):
+ return True
+ return type(exc).__module__.split(".")[0] == "litellm"
+
+
+def _sanitise_upstream_detail(detail: str) -> str:
+ """Strip interpreter state out of an upstream failure, keep the explanation.
+
+ Traceback frames, local file paths, private addresses and LiteLLM's own
+ footer chatter are removed; what is left is collapsed and capped so it fits
+ a chat bubble. Credentials are already redacted by `_redact` before this
+ runs.
+ """
+ text = _ANSI_PATTERN.sub("", detail or "")
+ for marker in _TRACEBACK_MARKERS:
+ cut = text.find(marker)
+ if cut != -1:
+ text = text[:cut]
+ text = "\n".join(
+ line
+ for line in text.splitlines()
+ if not any(marker in line for marker in _UPSTREAM_NOISE_MARKERS)
+ )
+ text = _FILE_PATH_PATTERN.sub("<path>", text)
+ text = _PRIVATE_HOST_PATTERN.sub("<host>", text)
+ text = " ".join(text.split())
+ if len(text) > _MAX_UPSTREAM_MESSAGE_CHARS:
+ text = text[: _MAX_UPSTREAM_MESSAGE_CHARS - 1].rstrip() + "\u2026"
+ return text
+
+
+def _provider_error_text(detail: str, exc: BaseException | None) -> str | None:
+ """The provider's own words for a failure, or None when we cannot attribute it.
+
+ Providers explain themselves precisely — "Model 'x' is not supported for
+ this environment", "api_key is invalid" — and collapsing that into a fixed
+ literal leaves an operator with nothing to act on. But only text we can tie
+ to the upstream call earns a trip to the client: a JSON error body the
+ provider sent, or a LiteLLM exception, which always describes the request it
+ made. Anything else stays in the logs.
+ """
+ for body in _json_bodies(detail or ""):
+ message = _provider_message(body)
+ if message:
+ return message
+ if _is_provider_attributable(exc):
+ return detail
+ return None
+
+
+#: Upstream statuses worth passing through: a client can act on these itself.
+#: Everything else becomes 502 — an upstream 401/403 must not read as an OpenRAG
+#: auth failure, and an upstream 400 must not read as a bad request to us.
+_PASSTHROUGH_UPSTREAM_STATUSES = frozenset({408, 429, 503, 504})
+
+
+def _upstream_status_code(exc: BaseException) -> int:
+ """HTTP status for a failed upstream call, from the provider's own where useful."""
+ status = getattr(exc, "status_code", None)
+ if isinstance(status, int) and status in _PASSTHROUGH_UPSTREAM_STATUSES:
+ return status
+ return 502
+
+
+def _upstream_client_message(
+ detail: str, provider: str = "", model: str = "", exc: BaseException | None = None
+) -> str:
+ """Client-facing text for an upstream failure, naming the provider and cause.
+
+ Nothing is forwarded raw. `_provider_error_text` decides whether the failure
+ is the provider's to explain, and `_sanitise_upstream_detail` removes
+ traceback frames, paths and private addresses from what it returns — so the
+ caller sees the provider's own wording and which provider/model produced it,
+ and an unattributable failure still collapses to a fixed literal. A
+ credential failure keeps its actionable message so onboarding can tell the
+ user to fix the key.
+ """
+ from api.provider_validation import is_generic_upstream_error, is_provider_credential_error
+
+ label = _call_label(provider, model)
+ if is_provider_credential_error(detail):
+ return f"{_UPSTREAM_CREDENTIAL_MESSAGE} ({label})"
+ upstream = _provider_error_text(detail, exc)
+ upstream = _sanitise_upstream_detail(upstream) if upstream else ""
+ if not upstream or is_generic_upstream_error(upstream):
+ return f"{_UPSTREAM_FAILURE_MESSAGE} ({label})"
+ # lgtm[py/stack-trace-exposure] — provider error text only; traceback frames,
+ # file paths and private hosts are removed by _sanitise_upstream_detail.
+ return f"{label}: {upstream}"
+
+
+def _redact(message: str, credentials: Mapping[str, Any]) -> str:
+ redacted = message
+ for value in credentials.values():
+ if value and isinstance(value, str) and len(value) > 3:
+ redacted = redacted.replace(value, "[redacted]")
+ return redacted
+
+
+def _to_openai_dict(response: Any) -> dict[str, Any]:
+ if isinstance(response, dict):
+ return response
+ if hasattr(response, "model_dump"):
+ dumped = response.model_dump()
+ if isinstance(dumped, dict):
+ return dumped
+ if hasattr(response, "json"):
+ payload = response.json()
+ if isinstance(payload, str):
+ return json.loads(payload)
+ if isinstance(payload, dict):
+ return payload
+ return dict(response)
+
+
+def _chunk_payload(chunk: Any) -> str:
+ if hasattr(chunk, "model_dump_json"):
+ return chunk.model_dump_json()
+ if hasattr(chunk, "json"):
+ payload = chunk.json()
+ return payload if isinstance(payload, str) else json.dumps(payload)
+ if isinstance(chunk, dict):
+ return json.dumps(chunk)
+ return json.dumps({"data": str(chunk)})
+
+
+#: A payload wrapped more times than this is not a serialisation slip.
+_MAX_ARGUMENT_UNWRAPS = 3
+
+
+def _normalise_tool_arguments(value: Any) -> tuple[Any, bool]:
+ """Return `(arguments, repaired)`, unwrapping arguments serialised twice.
+
+ OpenAI's contract is that `function.arguments` is a string holding a JSON
+ *object*. Some models serialise the object and then serialise that string
+ again, sending `'"{\\"query\\": \\"x\\"}"'` where `'{"query": "x"}'` was
+ meant (watsonx `ibm/granite-4-h-small` does this; its stablemates on the
+ same deployment do not). Clients parse `arguments` exactly once, so they get
+ a `str` where a mapping is required: langchain-core rejects the tool call,
+ the agent sees no callable tool, and the run ends with no content at all.
+ Unwrapping is keyed on the payload opening with a quote, which a real
+ arguments object never does, so this is a no-op for well-behaved providers.
+ """
+ if isinstance(value, (dict, list)):
+ return json.dumps(value), True
+ if not isinstance(value, str) or not value.lstrip().startswith('"'):
+ return value, False
+ candidate = value
+ for _ in range(_MAX_ARGUMENT_UNWRAPS):
+ try:
+ decoded = json.loads(candidate)
+ except ValueError:
+ return value, False
+ if not isinstance(decoded, str):
+ return value, False
+ candidate = decoded
+ try:
+ inner = json.loads(candidate)
+ except ValueError:
+ continue
+ if isinstance(inner, (dict, list)):
+ return candidate, True
+ return value, False
+
+
+def _repair_tool_calls(tool_calls: Any, provider: str, model: str) -> int:
+ """Normalise `arguments` on every tool call in place. Returns how many changed."""
+ repaired = 0
+ for call in tool_calls or []:
+ if not isinstance(call, dict):
+ continue
+ function = call.get("function")
+ if not isinstance(function, dict):
+ continue
+ arguments, changed = _normalise_tool_arguments(function.get("arguments"))
+ if changed:
+ function["arguments"] = arguments
+ repaired += 1
+ if repaired:
+ logger.warning(
+ "Repaired double-encoded tool call arguments",
+ provider=provider,
+ model=model,
+ tool_calls=repaired,
+ )
+ return repaired
+
+
+def _repair_completion_payload(payload: dict[str, Any], provider: str, model: str) -> int:
+ repaired = 0
+ for choice in payload.get("choices") or []:
+ if not isinstance(choice, dict):
+ continue
+ message = choice.get("message")
+ if isinstance(message, dict):
+ repaired += _repair_tool_calls(message.get("tool_calls"), provider, model)
+ return repaired
+
+
+def _log_completion_shape(payload: dict[str, Any], provider: str, model: str) -> None:
+ """Record the shape of a non-streaming completion.
+
+ An empty completion is indistinguishable from a transport failure once it
+ reaches Langflow: the agent simply ends its loop and the user sees "The
+ server didn't return a response". Only metadata is logged — never message
+ content — so this stays safe to leave on.
+ """
+ try:
+ choices = payload.get("choices") or []
+ first = choices[0] if choices else {}
+ message = first.get("message") or {}
+ content = message.get("content") or ""
+ tool_calls = message.get("tool_calls") or []
+ finish_reason = first.get("finish_reason")
+ empty = not str(content).strip() and not tool_calls
+ log = logger.warning if empty else logger.info
+ log(
+ "LLM chat completion returned no content and no tool calls"
+ if empty
+ else "LLM chat completion",
+ provider=provider,
+ model=model,
+ finish_reason=finish_reason,
+ content_chars=len(str(content)),
+ tool_calls=len(tool_calls),
+ choices=len(choices),
+ )
+ except Exception: # diagnostics must never break a response
+ logger.debug("Could not summarise completion shape", exc_info=True)
+
+
+async def chat_completions(
+ body: Mapping[str, Any], *, config=None
+) -> dict[str, Any] | AsyncIterator[str]:
+ """OpenAI `POST /v1/chat/completions`. Streams SSE lines when `stream` is true."""
+ cfg = config or _get_config()
+ litellm_model, provider, credentials = resolve_call(body.get("model"), kind="chat", config=cfg)
+ kwargs = {key: body[key] for key in _LITELLM_FORWARDED_PARAMS if key in body}
+ stream = bool(body.get("stream"))
+ try:
+ import litellm
+
+ result = await litellm.acompletion(
+ model=litellm_model,
+ messages=list(body.get("messages") or []),
+ stream=stream,
+ # OpenAI-compatible clients send OpenAI's full parameter set, but
+ # providers accept different subsets — watsonx rejects
+ # `parallel_tool_calls`, `max_completion_tokens` and `logit_bias`,
+ # and LiteLLM raises UnsupportedParamsError rather than ignoring
+ # them. A proxy that fans out to many providers must degrade to the
+ # provider's capabilities instead of failing the request.
+ drop_params=True,
+ **credentials,
+ **kwargs,
+ )
+ except LlmGatewayError:
+ raise
+ except Exception as exc:
+ detail = _redact(f"{type(exc).__name__}: {exc}", credentials)
+ logger.error(
+ "LLM chat completions failed", provider=provider, model=litellm_model, error=detail
+ )
+ raise LlmGatewayError(
+ _upstream_client_message(detail, provider, litellm_model, exc),
+ _upstream_status_code(exc),
+ detail=detail,
+ ) from exc
+
+ if stream:
+ return _stream_sse(result, provider, litellm_model, credentials)
+ payload = _to_openai_dict(result)
+ _repair_completion_payload(payload, provider, litellm_model)
+ _log_completion_shape(payload, provider, litellm_model)
+ return payload
+
+
+class _StreamTally:
+ """Running totals for one streamed completion. Metadata only, no content."""
+
+ def __init__(self) -> None:
+ self.chunks = 0
+ self.content_chars = 0
+ self.tool_calls = 0
+ self.repaired_tool_calls = 0
+ self.finish_reason: str | None = None
+ self.error: str | None = None
+
+ def observe(self, payload: str) -> None:
+ try:
+ chunk = json.loads(payload)
+ except Exception:
+ return
+ self.chunks += 1
+ for choice in chunk.get("choices") or []:
+ if not isinstance(choice, dict):
+ continue
+ if choice.get("finish_reason"):
+ self.finish_reason = choice["finish_reason"]
+ delta = choice.get("delta") or {}
+ content = delta.get("content")
+ if isinstance(content, str):
+ self.content_chars += len(content)
+ self.tool_calls += len(delta.get("tool_calls") or [])
+
+
+class _ToolCallBuffer:
+ """Reassembles streamed tool calls so their `arguments` can be repaired.
+
+ A tool call arrives spread over many deltas: the opening one carries `id`
+ and `name`, the rest carry `arguments` fragments the client concatenates.
+ Whether those fragments concatenate into a usable object is only knowable
+ once they are all in hand — the first fragment of a double-encoded payload
+ (`'"{\\'`) is indistinguishable from a slow provider. So tool-call deltas are
+ held here, joined, normalised, and emitted as one complete tool-call delta
+ just before the finishing chunk. Content deltas are never buffered, so token
+ streaming is untouched.
+ """
+
+ def __init__(self) -> None:
+ self._calls: dict[tuple[int, int], dict[str, Any]] = {}
+ self._order: list[tuple[int, int]] = []
+
+ def __bool__(self) -> bool:
+ return bool(self._order)
+
+ def absorb(self, choice_index: int, tool_calls: Any) -> None:
+ for position, raw in enumerate(tool_calls or []):
+ if not isinstance(raw, dict):
+ continue
+ index = raw.get("index")
+ if not isinstance(index, int):
+ index = position
+ key = (choice_index, index)
+ call = self._calls.get(key)
+ if call is None:
+ call = {
+ "index": index,
+ "type": "function",
+ "function": {"name": "", "arguments": ""},
+ }
+ self._calls[key] = call
+ self._order.append(key)
+ if raw.get("id"):
+ call["id"] = raw["id"]
+ if raw.get("type"):
+ call["type"] = raw["type"]
+ function = raw.get("function")
+ if not isinstance(function, dict):
+ continue
+ name = function.get("name")
+ # Providers split at different granularities: some send the whole
+ # name once, some fragment it. Appending handles fragments; skipping
+ # an exact repeat handles providers that resend the full name.
+ if isinstance(name, str) and name and name != call["function"]["name"]:
+ call["function"]["name"] += name
+ arguments = function.get("arguments")
+ if isinstance(arguments, str):
+ call["function"]["arguments"] += arguments
+
+ def drain(self, provider: str, model: str) -> tuple[dict[int, list[dict[str, Any]]], int]:
+ """Take everything buffered, grouped by choice index, arguments repaired."""
+ grouped: dict[int, list[dict[str, Any]]] = {}
+ repaired = 0
+ for choice_index, _ in self._order:
+ grouped.setdefault(choice_index, [])
+ for key in self._order:
+ grouped[key[0]].append(self._calls[key])
+ for calls in grouped.values():
+ calls.sort(key=lambda call: call.get("index", 0))
+ repaired += _repair_tool_calls(calls, provider, model)
+ self._calls.clear()
+ self._order.clear()
+ return grouped, repaired
+
+
+def _tool_call_chunks(
+ template: Mapping[str, Any], grouped: Mapping[int, list[dict[str, Any]]]
+) -> list[dict[str, Any]]:
+ """One chunk per choice carrying that choice's complete tool calls."""
+ return [
+ {
+ "id": template.get("id"),
+ "object": template.get("object") or "chat.completion.chunk",
+ "created": template.get("created"),
+ "model": template.get("model"),
+ "choices": [
+ {
+ "index": choice_index,
+ "delta": {"role": "assistant", "tool_calls": calls},
+ "finish_reason": None,
+ }
+ ],
+ }
+ for choice_index, calls in grouped.items()
+ if calls
+ ]
+
+
+def _chunk_carries_nothing(chunk: Mapping[str, Any]) -> bool:
+ """True when a chunk has no payload left after its tool calls were held back."""
+ if chunk.get("usage"):
+ return False
+ choices = chunk.get("choices") or []
+ if not choices:
+ return False
+ for choice in choices:
+ if not isinstance(choice, dict):
+ return False
+ if choice.get("finish_reason"):
+ return False
+ delta = choice.get("delta")
+ if not isinstance(delta, dict):
+ return False
+ if any(value not in (None, "", [], {}) for value in delta.values()):
+ return False
+ return True
+
+
+def _empty_stream_message(provider: str, model: str, finish_reason: str | None) -> str:
+ """Client text for a completion that succeeded and said nothing."""
+ return (
+ f"{_call_label(provider, model)} accepted the request but returned no content and no "
+ f"tool calls (finish_reason: {finish_reason or 'none'}). Check that the model supports "
+ "the capabilities this request needs, or select a different model."
+ )
+
+
+def _error_frame(message: str, provider: str, model: str) -> str:
+ """SSE frame an OpenAI client turns back into a raised APIError."""
+ return (
+ "data: "
+ + json.dumps(
+ {
+ "error": {
+ "message": message,
+ "type": "api_error",
+ "code": "upstream_error",
+ "provider": provider,
+ "model": model,
+ }
+ }
+ )
+ + "\n\n"
+ )
+
+
+async def _aiter_stream(stream: Any):
+ if hasattr(stream, "__aiter__"):
+ async for chunk in stream:
+ yield chunk
+ else:
+ for chunk in stream:
+ yield chunk
+
+
+async def _stream_sse(
+ stream: Any,
+ provider: str = "",
+ model: str = "",
+ credentials: Mapping[str, Any] | None = None,
+) -> AsyncIterator[str]:
+ tally = _StreamTally()
+ buffer = _ToolCallBuffer()
+ template: dict[str, Any] = {}
+ try:
+ async for chunk in _aiter_stream(stream):
+ payload = _chunk_payload(chunk)
+ try:
+ data = json.loads(payload)
+ except ValueError:
+ tally.observe(payload)
+ yield f"data: {payload}\n\n"
+ continue
+ if not isinstance(data, dict):
+ tally.observe(payload)
+ yield f"data: {payload}\n\n"
+ continue
+ template = data
+
+ held = False
+ finishing = False
+ for choice in data.get("choices") or []:
+ if not isinstance(choice, dict):
+ continue
+ delta = choice.get("delta")
+ if isinstance(delta, dict) and delta.get("tool_calls"):
+ index = choice.get("index")
+ buffer.absorb(index if isinstance(index, int) else 0, delta["tool_calls"])
+ delta["tool_calls"] = None
+ held = True
+ if choice.get("finish_reason"):
+ finishing = True
+
+ if finishing and buffer:
+ grouped, repaired = buffer.drain(provider, model)
+ tally.repaired_tool_calls += repaired
+ for flushed in _tool_call_chunks(template, grouped):
+ out = json.dumps(flushed)
+ tally.observe(out)
+ yield f"data: {out}\n\n"
+
+ if held:
+ if _chunk_carries_nothing(data):
+ continue
+ payload = json.dumps(data)
+ tally.observe(payload)
+ yield f"data: {payload}\n\n"
+
+ # A provider that ends without a finish_reason still owes us its calls.
+ if buffer:
+ grouped, repaired = buffer.drain(provider, model)
+ tally.repaired_tool_calls += repaired
+ for flushed in _tool_call_chunks(template, grouped):
+ out = json.dumps(flushed)
+ tally.observe(out)
+ yield f"data: {out}\n\n"
+
+ # A 200 that carries nothing is indistinguishable from a dead connection
+ # by the time it reaches the UI, which can only say "the server didn't
+ # return a response". Name the call and its finish_reason instead, so
+ # the next person has something to search for.
+ if tally.content_chars == 0 and tally.tool_calls == 0:
+ tally.error = "empty completion"
+ logger.warning(
+ "LLM chat stream produced no content and no tool calls",
+ provider=provider,
+ model=model,
+ finish_reason=tally.finish_reason,
+ chunks=tally.chunks,
+ )
+ yield _error_frame(
+ _empty_stream_message(provider, model, tally.finish_reason), provider, model
+ )
+ except Exception as exc:
+ # Mid-stream failures used to surface as a truncated stream, which the
+ # UI could only report as "the server didn't return a response". Emit an
+ # OpenAI error frame instead: the client raises it with the provider's
+ # own wording, so the cause reaches the chat and the logs alike.
+ detail = _redact(f"{type(exc).__name__}: {exc}", credentials or {})
+ tally.error = detail
+ logger.error("LLM chat stream failed", provider=provider, model=model, error=detail)
+ yield _error_frame(_upstream_client_message(detail, provider, model, exc), provider, model)
+ finally:
+ close = getattr(stream, "aclose", None) or getattr(stream, "close", None)
+ if close is not None:
+ result = close()
+ if hasattr(result, "__await__"):
+ await result
+ _log_stream_shape(tally, provider, model)
+ yield "data: [DONE]\n\n"
+
+
+def _log_stream_shape(tally: _StreamTally, provider: str, model: str) -> None:
+ """Same diagnostic as `_log_completion_shape`, for the streaming path."""
+ try:
+ if tally.error:
+ return # already logged with its cause by the stream's error handler
+ empty = tally.content_chars == 0 and tally.tool_calls == 0
+ log = logger.warning if empty else logger.info
+ log(
+ "LLM chat stream produced no content and no tool calls" if empty else "LLM chat stream",
+ provider=provider,
+ model=model,
+ finish_reason=tally.finish_reason,
+ content_chars=tally.content_chars,
+ tool_calls=tally.tool_calls,
+ repaired_tool_calls=tally.repaired_tool_calls,
+ chunks=tally.chunks,
+ )
+ except Exception: # diagnostics must never break a stream
+ logger.debug("Could not summarise stream shape", exc_info=True)
+
+
+async def embeddings(body: Mapping[str, Any], *, config=None) -> dict[str, Any]:
+ """OpenAI `POST /v1/embeddings`."""
+ cfg = config or _get_config()
+ litellm_model, provider, credentials = resolve_call(
+ body.get("model"), kind="embedding", config=cfg
+ )
+ try:
+ import litellm
+
+ result = await litellm.aembedding(
+ model=litellm_model,
+ input=body.get("input"),
+ **credentials,
+ )
+ except LlmGatewayError:
+ raise
+ except Exception as exc:
+ detail = _redact(f"{type(exc).__name__}: {exc}", credentials)
+ logger.error("LLM embeddings failed", provider=provider, model=litellm_model, error=detail)
+ raise LlmGatewayError(
+ _upstream_client_message(detail, provider, litellm_model, exc),
+ _upstream_status_code(exc),
+ detail=detail,
+ ) from exc
+ return _to_openai_dict(result)
diff --git a/src/services/model_catalog.py b/src/services/model_catalog.py
new file mode 100644
index 000000000..c1da80405
--- /dev/null
+++ b/src/services/model_catalog.py
@@ -0,0 +1,363 @@
+"""LiteLLM model/provider catalogue for the settings picker and /v1/models.
+
+Two things come out of LiteLLM's own bundled data, so the list never has to be
+hand-maintained the way the four-provider live fetches used to be:
+
+- **models** from `litellm.model_cost` — models for OpenRAG's supported
+ providers, tagged with the provider they belong to. Chat/completion/responses
+ modes feed the agent picker; embedding mode feeds the ingest picker.
+- **credential fields** from `litellm/proxy/public_endpoints/provider_create_fields.json`
+ — the per-provider form spec. Unknown providers fall back to an API key and
+ a base URL.
+
+Both are read lazily and cached: `model_cost` is a few thousand entries and the
+JSON is ~100KB, so paying for it once per process beats a re-read per request.
+
+`function_calling` and `vision` are published as capability flags so the UI can
+filter (agent vs VLM) without a second live provider call.
+
+The public catalogue is intentionally limited to the providers OpenRAG exposes
+in its settings UI. Generic credential helpers remain available for future
+providers, and a model that is not in the catalogue can still be typed by hand.
+"""
+
+from __future__ import annotations
+
+import datetime
+import json
+from functools import lru_cache
+from typing import Any
+
+from utils.logging_config import get_logger
+
+logger = get_logger(__name__)
+
+TEXT_GENERATION_MODES = frozenset({"chat", "completion", "responses"})
+EMBEDDING_MODE = "embedding"
+SUPPORTED_PROVIDER_KEYS = frozenset({"openai", "anthropic", "watsonx", "ollama"})
+
+CAPABILITY_FLAGS: dict[str, str] = {
+ "supports_function_calling": "function_calling",
+ "supports_vision": "vision",
+ "supports_reasoning": "reasoning",
+ "supports_response_schema": "structured_output",
+ "supports_prompt_caching": "prompt_caching",
+ "supports_pdf_input": "pdf_input",
+ "supports_web_search": "web_search",
+ "supports_audio_input": "audio_input",
+ "supports_computer_use": "computer_use",
+ "supports_parallel_function_calling": "parallel_tools",
+}
+
+NUMERIC_FIELDS = (
+ "max_input_tokens",
+ "max_output_tokens",
+ "input_cost_per_token",
+ "output_cost_per_token",
+ "cache_read_input_token_cost",
+)
+
+GENERIC_CREDENTIAL_FIELDS: list[dict[str, Any]] = [
+ {
+ "key": "api_key",
+ "label": "API key",
+ "placeholder": None,
+ "tooltip": None,
+ "required": False,
+ "field_type": "password",
+ "options": None,
+ "default_value": None,
+ },
+ {
+ "key": "api_base",
+ "label": "API base",
+ "placeholder": "https://...",
+ "tooltip": "Only needed for a self-hosted or proxied endpoint.",
+ "required": False,
+ "field_type": "text",
+ "options": None,
+ "default_value": None,
+ },
+]
+
+KNOWN_FIELD_TYPES = frozenset({"text", "password", "select", "textarea", "upload"})
+
+
+class CatalogUnavailableError(RuntimeError):
+ """LiteLLM is not importable, so no catalogue can be built.
+
+ Its text names server-side deployment detail, so routes log it and return
+ ``CATALOG_UNAVAILABLE_MESSAGE`` to callers instead.
+ """
+
+
+# Client-facing stand-in for CatalogUnavailableError text.
+CATALOG_UNAVAILABLE_MESSAGE = "The model catalogue is temporarily unavailable."
+
+
+def _parse_deprecation(value: Any) -> datetime.date | None:
+ """LiteLLM's `deprecation_date`, when it is a real YYYY-MM-DD."""
+ if not value:
+ return None
+ try:
+ return datetime.date.fromisoformat(str(value))
+ except ValueError:
+ return None
+
+
+@lru_cache(maxsize=1)
+def _provider_field_specs() -> dict[str, dict[str, Any]]:
+ """provider key -> the raw entry from LiteLLM's provider_create_fields.json.
+
+ First entry wins on a duplicate `litellm_provider`. The file lists
+ `openai` twice — once as "OpenAI" and once as "OpenAI-Compatible
+ Endpoints", the latter marking api_base *required*. Keeping the last would
+ make plain OpenAI demand a base URL nobody needs to set.
+ """
+ from importlib.resources import files
+
+ path = (
+ files("litellm")
+ .joinpath("proxy")
+ .joinpath("public_endpoints")
+ .joinpath("provider_create_fields.json")
+ )
+ entries = json.loads(path.read_text(encoding="utf-8"))
+
+ specs: dict[str, dict[str, Any]] = {}
+ for entry in entries:
+ key = entry.get("litellm_provider")
+ if not key or key in specs:
+ continue
+ specs[key] = entry
+ return specs
+
+
+def _normalize_field(field: dict[str, Any]) -> dict[str, Any]:
+ field_type = str(field.get("field_type") or "text")
+ return {
+ "key": str(field.get("key") or ""),
+ "label": str(field.get("label") or field.get("key") or ""),
+ "placeholder": field.get("placeholder"),
+ "tooltip": field.get("tooltip"),
+ "required": bool(field.get("required")),
+ "field_type": field_type if field_type in KNOWN_FIELD_TYPES else "text",
+ "options": field.get("options"),
+ "default_value": field.get("default_value"),
+ }
+
+
+def credential_fields(provider: str) -> list[dict[str, Any]]:
+ """The form spec for `provider`, normalized, never empty."""
+ try:
+ spec = _provider_field_specs().get((provider or "").strip().lower())
+ except Exception:
+ logger.warning("Could not read LiteLLM's provider field specs", exc_info=True)
+ return [dict(field) for field in GENERIC_CREDENTIAL_FIELDS]
+ if not spec:
+ return [dict(field) for field in GENERIC_CREDENTIAL_FIELDS]
+ fields = [_normalize_field(field) for field in spec.get("credential_fields") or []]
+ fields = [field for field in fields if field["key"]]
+ return fields or [dict(field) for field in GENERIC_CREDENTIAL_FIELDS]
+
+
+def secret_field_keys(provider: str) -> set[str]:
+ return {
+ field["key"]
+ for field in credential_fields(provider)
+ if field["field_type"] in {"password", "textarea", "upload"}
+ }
+
+
+def required_field_keys(provider: str) -> list[str]:
+ return [field["key"] for field in credential_fields(provider) if field["required"]]
+
+
+def missing_required_fields(provider: str, supplied: set[str]) -> list[str]:
+ return [key for key in required_field_keys(provider) if key not in supplied]
+
+
+def _model_entry(name: str, info: dict[str, Any]) -> dict[str, Any]:
+ entry: dict[str, Any] = {"model": name, "mode": info.get("mode")}
+ for field in NUMERIC_FIELDS:
+ value = info.get(field)
+ if value is not None:
+ entry[field] = value
+ capabilities = [public for flag, public in CAPABILITY_FLAGS.items() if info.get(flag)]
+ if capabilities:
+ entry["capabilities"] = capabilities
+ deprecation = _parse_deprecation(info.get("deprecation_date"))
+ if deprecation is not None:
+ entry["deprecation_date"] = deprecation.isoformat()
+ return entry
+
+
+@lru_cache(maxsize=1)
+def _catalog() -> dict[str, Any]:
+ try:
+ import litellm
+ except Exception as exc:
+ raise CatalogUnavailableError("litellm is not installed on the server") from exc
+
+ specs = _provider_field_specs()
+ chat_by_provider: dict[str, list[dict[str, Any]]] = {}
+ embed_by_provider: dict[str, list[dict[str, Any]]] = {}
+
+ for model_id, info in litellm.model_cost.items():
+ if not isinstance(info, dict):
+ continue
+ provider = info.get("litellm_provider")
+ mode = info.get("mode")
+ if provider not in SUPPORTED_PROVIDER_KEYS:
+ continue
+ if mode in TEXT_GENERATION_MODES:
+ bucket = chat_by_provider
+ elif mode == EMBEDDING_MODE:
+ bucket = embed_by_provider
+ else:
+ continue
+ name = model_id[len(provider) + 1 :] if model_id.startswith(f"{provider}/") else model_id
+ if not name or name == "sample_spec":
+ continue
+ bucket.setdefault(provider, []).append(_model_entry(name, info))
+
+ providers = []
+ for key in sorted(SUPPORTED_PROVIDER_KEYS):
+ providers.append(
+ {
+ "key": key,
+ "name": (specs.get(key) or {}).get("provider_display_name") or key,
+ "credential_fields": credential_fields(key),
+ "model_placeholder": (specs.get(key) or {}).get("default_model_placeholder"),
+ "models": sorted(chat_by_provider.get(key, []), key=lambda entry: entry["model"]),
+ "embedding_models": sorted(
+ embed_by_provider.get(key, []), key=lambda entry: entry["model"]
+ ),
+ }
+ )
+ return {"providers": providers}
+
+
+@lru_cache(maxsize=2)
+def _catalog_for(today: datetime.date) -> dict[str, Any]:
+ """`_catalog()` with models the provider has already retired removed."""
+
+ def _keep(model: dict[str, Any]) -> bool:
+ retires = _parse_deprecation(model.get("deprecation_date"))
+ return retires is None or retires > today
+
+ providers = []
+ for provider in _catalog()["providers"]:
+ providers.append(
+ {
+ **provider,
+ "models": [model for model in provider["models"] if _keep(model)],
+ "embedding_models": [
+ model for model in provider["embedding_models"] if _keep(model)
+ ],
+ }
+ )
+ return {"providers": providers}
+
+
+def catalog(today: datetime.date | None = None) -> dict[str, Any]:
+ """Picker payload for OpenRAG's supported providers and their models."""
+ return _catalog_for(today or datetime.date.today())
+
+
+def is_known_provider(provider: str) -> bool:
+ """Whether LiteLLM recognises `provider` at all."""
+ key = (provider or "").strip().lower()
+ if not key:
+ return False
+ try:
+ import litellm
+
+ if key in {str(value) for value in litellm.provider_list}:
+ return True
+ except Exception:
+ logger.debug("Could not read litellm.provider_list", exc_info=True)
+ try:
+ return key in _provider_field_specs()
+ except Exception:
+ return False
+
+
+@lru_cache(maxsize=1)
+def _model_owners() -> dict[str, tuple[str, ...]]:
+ """Map every catalogue model id to the providers that serve it."""
+ owners: dict[str, set[str]] = {}
+ try:
+ providers = _catalog()["providers"]
+ except Exception:
+ return {}
+ for provider in providers:
+ for entry in (*provider["models"], *provider["embedding_models"]):
+ owners.setdefault(entry["model"], set()).add(provider["key"])
+ return {model: tuple(sorted(keys)) for model, keys in owners.items()}
+
+
+def catalog_owner(model: str) -> str | None:
+ """The single provider that serves `model`, if exactly one does.
+
+ Used to disambiguate vendor-qualified names such as `openai/gpt-oss-120b`,
+ which watsonx serves and whose own prefix names a different provider.
+ """
+ name = (model or "").strip()
+ if not name:
+ return None
+ try:
+ owners = _model_owners().get(name)
+ except Exception:
+ return None
+ return owners[0] if owners and len(owners) == 1 else None
+
+
+def PROVIDER_SEPARATOR_SAFE_CHECK() -> list[str]:
+ """Catalogue ids whose text before the first colon names a provider.
+
+ Empty today, which is what lets `provider:model` be parsed unambiguously.
+ Exposed so a test can fail loudly if a future model id breaks the property.
+ """
+ ambiguous = []
+ for model in _model_owners():
+ head, sep, rest = model.partition(":")
+ if sep and rest and is_known_provider(head.lower()):
+ ambiguous.append(model)
+ return sorted(ambiguous)
+
+
+def public_model_id(provider: str, model: str) -> str:
+ """The routable id for `model` as served by `/v1/models`.
+
+ `_catalog()` strips the provider prefix so the picker can show bare names,
+ but an unprefixed id sent back to `/v1/chat/completions` is resolved against
+ the *default* provider — an Anthropic model would then be called with the
+ OpenAI credentials. Re-attach the provider for every non-OpenAI provider so
+ the id round-trips through `resolve_call()`. OpenAI keeps bare names because
+ that is what OpenAI-compatible clients expect.
+
+ The tag uses `provider:model`, not `provider/model`: watsonx serves
+ `openai/gpt-oss-120b`, so a slash-joined id is indistinguishable from that
+ model's own name.
+ """
+ from services.llm_gateway import PROVIDER_SEPARATOR
+
+ return model if provider == "openai" else f"{provider}{PROVIDER_SEPARATOR}{model}"
+
+
+def openai_models_list(today: datetime.date | None = None) -> dict[str, Any]:
+ """OpenAI-compatible `GET /v1/models` body from the catalogue."""
+ data = []
+ for provider in catalog(today)["providers"]:
+ owner = provider["key"]
+ for entry in (*provider["models"], *provider["embedding_models"]):
+ data.append(
+ {
+ "id": public_model_id(owner, entry["model"]),
+ "object": "model",
+ "owned_by": owner,
+ "created": 0,
+ }
+ )
+ return {"object": "list", "data": data}
diff --git a/src/services/models_service.py b/src/services/models_service.py
index d8864c130..24f83615a 100644
--- a/src/services/models_service.py
+++ b/src/services/models_service.py
@@ -19,7 +19,23 @@ from utils.logging_config import get_logger
logger = get_logger(__name__)
-KNOWN_PREFIXES = ["openai", "ollama", "watsonx", "anthropic"]
+
+def _watsonx_rate_limited(failures: list[tuple[str, int, str]]) -> bool:
+ """Whether a watsonx model-list failure was really throttling.
+
+ watsonx wraps a throttled project-membership lookup in a 403
+ ``user_authorization_failed`` whose message embeds the original
+ ``{"code":429,"error":"Too Many Requests"}``, so the status code alone does
+ not identify it.
+ """
+ for _kind, status, body in failures:
+ if status == 429:
+ return True
+ text = (body or "").lower()
+ if '"code":429' in text or "too many requests" in text:
+ return True
+ return False
+
# OpenAI /v1/models is a flat inventory. These IDs are real products but not
# usable as OpenRAG agent LLMs (wrong modality / API surface).
@@ -187,6 +203,28 @@ class ModelsService:
except Exception as e:
logger.debug(f"Could not fetch WatsonX models for registry: {str(e)}")
+ from services.model_catalog import catalog
+
+ catalog_by_provider = {entry["key"]: entry for entry in catalog()["providers"]}
+ for provider, provider_config in config.providers.custom.items():
+ if not provider_config.configured:
+ continue
+ entry = catalog_by_provider.get(provider)
+ if entry is None:
+ continue
+ self.add_models(
+ {
+ "language_models": [
+ {"value": model["model"]} for model in entry["models"]
+ ],
+ "embedding_models": [
+ {"value": model["model"]} for model in entry["embedding_models"]
+ ],
+ },
+ provider,
+ new_registry,
+ )
+
ModelsService._model_provider_registry = new_registry
logger.info(
f"Model registry updated: {len(ModelsService._model_provider_registry)} models registered"
@@ -213,9 +251,13 @@ class ModelsService:
if not model_name:
return ""
- # Skip formatting if already has a known provider prefix
- if any(model_name.startswith(p + "/") for p in KNOWN_PREFIXES):
- return model_name
+ # Skip formatting if already has a known LiteLLM provider prefix.
+ if "/" in model_name:
+ from services.model_catalog import is_known_provider
+
+ prefix = model_name.split("/", 1)[0].lower()
+ if is_known_provider(prefix):
+ return model_name
# Check if provider is explicitly given and not "openai"
provider_lower = provider.lower() if provider else None
@@ -615,6 +657,8 @@ class ModelsService:
language_models = []
embedding_models = []
+ # (kind, status, body) for each model-list call that did not return 200.
+ fetch_failures: list[tuple[str, int, str]] = []
async with httpx.AsyncClient() as client:
# Fetch text chat models
@@ -650,6 +694,9 @@ class ModelsService:
}
)
else:
+ fetch_failures.append(
+ ("text chat", text_response.status_code, text_response.text)
+ )
logger.warning(
f"Failed to retrieve text chat models. Status: {text_response.status_code}, "
f"Response: {text_response.text[:200]}"
@@ -687,6 +734,9 @@ class ModelsService:
}
)
else:
+ fetch_failures.append(
+ ("embedding", embed_response.status_code, embed_response.text)
+ )
logger.warning(
f"Failed to retrieve embedding models. Status: {embed_response.status_code}, "
f"Response: {embed_response.text[:200]}"
@@ -700,14 +750,31 @@ class ModelsService:
logger.warning("No bearer token available - API key validation may have failed")
if not language_models and not embedding_models:
- # Provide more specific error message about missing models
- error_msg = (
- "API key is valid, but no models are available. "
- "This usually means your Watson Machine Learning (WML) project is not properly configured. "
- "Please ensure: (1) Your watsonx.ai project is associated with a WML service instance, "
- "and (2) The project has access to foundation models. "
- "Visit your watsonx.ai project settings to configure the WML service association."
- )
+ # An empty list means "misconfigured project" only when the calls
+ # actually succeeded. watsonx reports throttling as a 403 whose
+ # body carries the real {"code":429,"error":"Too Many Requests"},
+ # and blaming WML setup for that sends operators to the wrong page.
+ if _watsonx_rate_limited(fetch_failures):
+ error_msg = (
+ "watsonx.ai is rate limiting this account, so its model list "
+ "could not be retrieved. Wait a few minutes and try again."
+ )
+ elif fetch_failures:
+ statuses = ", ".join(
+ f"{kind} models: HTTP {status}" for kind, status, _ in fetch_failures
+ )
+ error_msg = (
+ f"watsonx.ai did not return a model list ({statuses}). "
+ "Check that the API key is authorized for the configured project."
+ )
+ else:
+ error_msg = (
+ "API key is valid, but no models are available. "
+ "This usually means your Watson Machine Learning (WML) project is not properly configured. "
+ "Please ensure: (1) Your watsonx.ai project is associated with a WML service instance, "
+ "and (2) The project has access to foundation models. "
+ "Visit your watsonx.ai project settings to configure the WML service association."
+ )
raise Exception(error_msg)
result = {
diff --git a/src/services/workspace_config_service.py b/src/services/workspace_config_service.py
index 167803886..e4a709b7d 100644
--- a/src/services/workspace_config_service.py
+++ b/src/services/workspace_config_service.py
@@ -395,6 +395,19 @@ class WorkspaceConfigService:
if isinstance(prov_data, dict) and "api_key" in prov_data and prov_data["api_key"]:
prov_data["api_key"] = encrypt_secret(prov_data["api_key"])
providers[prov_name] = prov_data
+ custom = providers.get("custom", {})
+ if isinstance(custom, dict):
+ from services.model_catalog import secret_field_keys
+
+ for provider, provider_data in custom.items():
+ if not isinstance(provider_data, dict):
+ continue
+ credentials = provider_data.get("credentials", {})
+ if not isinstance(credentials, dict):
+ continue
+ for key in secret_field_keys(provider):
+ if credentials.get(key):
+ credentials[key] = encrypt_secret(credentials[key])
sections = {
"providers": providers,
diff --git a/src/utils/langflow_headers.py b/src/utils/langflow_headers.py
index 63decdb39..5c3197b98 100644
--- a/src/utils/langflow_headers.py
+++ b/src/utils/langflow_headers.py
@@ -2,8 +2,6 @@
from urllib.parse import quote
-from utils.container_utils import transform_localhost_url
-
def map_provider(provider: str | None) -> str:
"""Map provider values to the formatted names expected by Langflow.
@@ -74,50 +72,34 @@ async def add_provider_credentials_to_headers(
config,
flows_service=None,
jwt_token: str = None,
+ user_id: str | None = None,
) -> None:
- """Add provider credentials to headers as Langflow global variables.
-
- Args:
- headers: Dictionary of headers to add credentials to
- config: OpenRAGConfig object containing provider configurations
- flows_service: Optional FlowsService instance to resolve Ollama URLs.
- jwt_token: Optional credential string (``'Basic <b64>'`` or ``'Bearer <jwt>'``).
- When IBM_AUTH_ENABLED, injected as Langflow global variables. Basic
- credentials additionally provide OPENSEARCH_USERNAME and OPENSEARCH_PASSWORD.
-
- NOTE: `headers` ends up holding raw API keys/JWTs after this call. Never log
- it directly (e.g. logger.info(..., headers=headers) / extra_headers=...) —
+ """Add Langflow global variables for the OpenRAG LLM proxy and infra URLs.
+
+ Provider API keys are NOT forwarded. Langflow's Language/Embedding Model
+ components (and the OpenRAG LLM/Embeddings custom components)
+ speak OpenAI-compatible HTTP to OpenRAG (`OPENRAG_LLM_BASE_URL`) and
+ authenticate with a short-lived hop token as `OPENRAG_LLM_TOKEN` — same
+ pattern as `OPENRAG_INGEST_TOKEN`, scoped to the LLM proxy only.
+ Chat and embeddings share that base URL and hop token.
+
+ NOTE: `headers` may hold a JWT after this call. Never log it directly —
use utils.logging_config.sanitize_headers() if a header dict must be logged.
"""
- # Add OpenAI credentials
- if config.providers.openai.api_key:
- headers["X-LANGFLOW-GLOBAL-VAR-OPENAI_API_KEY"] = str(config.providers.openai.api_key)
-
- # Add Anthropic credentials
- if config.providers.anthropic.api_key:
- headers["X-LANGFLOW-GLOBAL-VAR-ANTHROPIC_API_KEY"] = str(config.providers.anthropic.api_key)
-
- # Add WatsonX credentials
- if config.providers.watsonx.api_key:
- headers["X-LANGFLOW-GLOBAL-VAR-WATSONX_APIKEY"] = str(config.providers.watsonx.api_key)
-
- if config.providers.watsonx.project_id:
- headers["X-LANGFLOW-GLOBAL-VAR-WATSONX_PROJECT_ID"] = str(
- config.providers.watsonx.project_id
- )
-
- # Add Ollama endpoint (with localhost transformation)
- if config.providers.ollama.endpoint:
- if flows_service:
- ollama_endpoint = await flows_service.resolve_ollama_url(
- config.providers.ollama.endpoint
- )
- else:
- ollama_endpoint = transform_localhost_url(config.providers.ollama.endpoint)
- headers["X-LANGFLOW-GLOBAL-VAR-OLLAMA_BASE_URL"] = str(ollama_endpoint)
+ from config.settings import get_langflow_llm_base_url
+ from services.langflow_llm_token_service import LangflowLlmTokenService
+
+ headers["X-LANGFLOW-GLOBAL-VAR-OPENRAG_LLM_BASE_URL"] = get_langflow_llm_base_url()
+
+ subject = (user_id or "").strip() or "anonymous"
+ hop_token = LangflowLlmTokenService().create_token(user_id=subject)
+ headers["X-LANGFLOW-GLOBAL-VAR-OPENRAG_LLM_TOKEN"] = hop_token
+ # Stock Language/Embedding Model nodes still bind api_key to OPENAI_API_KEY.
+ headers["X-LANGFLOW-GLOBAL-VAR-OPENAI_API_KEY"] = hop_token
# Inject OpenSearch and Docling URLs and index name so Langflow flows always use the correct endpoints
from config.settings import (
+ IBM_AUTH_ENABLED,
get_index_name,
get_langflow_docling_url,
get_langflow_opensearch_url,
@@ -135,26 +117,26 @@ async def add_provider_credentials_to_headers(
if index_name:
headers["X-LANGFLOW-GLOBAL-VAR-OPENSEARCH_INDEX_NAME"] = index_name
- # IBM mode: inject OpenSearch Basic credentials as separate global vars
- from config.settings import IBM_AUTH_ENABLED
-
if IBM_AUTH_ENABLED and jwt_token:
headers.update(build_ibm_opensearch_vars(jwt_token, prefix="X-LANGFLOW-GLOBAL-VAR-"))
def build_model_provider_headers(config, embedding_model: str | None = None) -> dict[str, str]:
- """Build Langflow global variable headers for selected embedding and language models/providers."""
+ """Build Langflow global variable headers for selected models.
+
+ Provider is always OpenAI so Langflow uses its OpenAI-compatible client
+ against the OpenRAG LLM proxy. The real provider lives in OpenRAG config
+ and is applied by the gateway when it routes the model name.
+ """
emb_model = embedding_model or getattr(
getattr(config, "knowledge", None), "embedding_model", None
)
- emb_provider = getattr(getattr(config, "knowledge", None), "embedding_provider", None)
agent = getattr(config, "agent", None)
llm_model = getattr(agent, "llm_model", None)
- llm_provider = getattr(agent, "llm_provider", None)
return {
"X-LANGFLOW-GLOBAL-VAR-SELECTED_EMBEDDING_MODEL": str(emb_model or ""),
- "X-LANGFLOW-GLOBAL-VAR-SELECTED_EMBEDDING_MODEL_PROVIDER": map_provider(emb_provider),
+ "X-LANGFLOW-GLOBAL-VAR-SELECTED_EMBEDDING_MODEL_PROVIDER": "OpenAI",
"X-LANGFLOW-GLOBAL-VAR-SELECTED_LANGUAGE_MODEL": str(llm_model or ""),
- "X-LANGFLOW-GLOBAL-VAR-SELECTED_LANGUAGE_MODEL_PROVIDER": map_provider(llm_provider),
+ "X-LANGFLOW-GLOBAL-VAR-SELECTED_LANGUAGE_MODEL_PROVIDER": "OpenAI",
}
diff --git a/src/utils/provider_health_cache.py b/src/utils/provider_health_cache.py
index 9fae9db85..54376e49d 100644
--- a/src/utils/provider_health_cache.py
+++ b/src/utils/provider_health_cache.py
@@ -13,6 +13,8 @@ real outages and on-demand checks are never masked.
import asyncio
import hashlib
+import json
+from collections.abc import Mapping
from cachetools import TTLCache
@@ -31,6 +33,20 @@ def _fingerprint(value: str | None) -> str:
return hashlib.blake2b((value or "").encode(), digest_size=8).hexdigest() # nosec B324 # lgtm[py/weak-cryptographic-algorithm] — non-cryptographic cache key, not a security hash
+def _fingerprint_mapping(values: Mapping[str, str] | None) -> str:
+ """Fingerprint a provider's LiteLLM credential kwargs.
+
+ Generic providers carry their secrets here rather than in the dedicated
+ ``api_key``/``endpoint``/``project_id`` fields, so the key must cover them
+ too — otherwise rotating a custom provider's credentials would keep
+ serving the pre-rotation health verdict for the whole TTL. Sorted so dict
+ ordering never changes the key.
+ """
+ if not values:
+ return _fingerprint(None)
+ return _fingerprint(json.dumps(dict(sorted(values.items())), separators=(",", ":")))
+
+
def cache_key(
provider: str | None,
embedding_provider: str | None,
@@ -43,11 +59,14 @@ def cache_key(
embedding_api_key: str | None = None,
embedding_endpoint: str | None = None,
embedding_project_id: str | None = None,
+ credentials: Mapping[str, str] | None = None,
+ embedding_credentials: Mapping[str, str] | None = None,
) -> str:
"""Build the cache key for a polled health-check call.
- The API keys are hashed (never stored in plaintext); rotating a key busts
- the cache automatically because the fingerprint changes.
+ The API keys and credential kwargs are hashed (never stored in plaintext);
+ rotating a key busts the cache automatically because the fingerprint
+ changes.
"""
parts = [
provider or "",
@@ -61,6 +80,8 @@ def cache_key(
embedding_endpoint or "",
embedding_project_id or "",
_fingerprint(embedding_api_key),
+ _fingerprint_mapping(credentials),
+ _fingerprint_mapping(embedding_credentials),
]
return hashlib.blake2b("|".join(parts).encode()).hexdigest() # nosec B324 # lgtm[py/weak-cryptographic-algorithm] — non-cryptographic cache key, not a security hash
diff --git a/tests/integration/core/test_mcp_url_ingest.py b/tests/integration/core/test_mcp_url_ingest.py
index 5bd00bc4c..95e81e067 100644
--- a/tests/integration/core/test_mcp_url_ingest.py
+++ b/tests/integration/core/test_mcp_url_ingest.py
@@ -131,7 +131,7 @@ async def test_loaded_agent_flow_routes_request_globals_into_mcp_headers():
for global_var_name in [
"JWT",
- "OPENAI_API_KEY",
+ "OPENRAG_LLM_TOKEN",
"OPENSEARCH_URL",
"SELECTED_EMBEDDING_MODEL",
"WATSONX_APIKEY",
diff --git a/tests/unit/api/test_settings_endpoints.py b/tests/unit/api/test_settings_endpoints.py
index 1b1c57580..c087e859f 100644
--- a/tests/unit/api/test_settings_endpoints.py
+++ b/tests/unit/api/test_settings_endpoints.py
@@ -9,7 +9,12 @@ import pytest
from fastapi import HTTPException
from api.settings import DoclingPresetBody, update_docling_preset
-from api.settings.models import AssistantMessage, OnboardingFunctionCall
+from api.settings.models import (
+ AssistantMessage,
+ OnboardingBody,
+ OnboardingFunctionCall,
+ SettingsUpdateBody,
+)
from session_manager import User
@@ -93,3 +98,41 @@ def test_assistant_message_citation_serialization():
assert result.metadata == {"custom_key": "val"}
assert result.data is not None
assert result.data.text == "Extracted chunk text"
+
+
+def test_settings_models_accept_arbitrary_provider_credentials():
+ credentials = {
+ "gemini": {
+ "api_key": "secret",
+ "vertex_project": "project-1",
+ "vertex_location": "us-central1",
+ }
+ }
+
+ settings = SettingsUpdateBody(
+ llm_provider="gemini",
+ llm_model="gemini-2.5-pro",
+ provider_credentials=credentials,
+ )
+ onboarding = OnboardingBody(
+ llm_provider="gemini",
+ llm_model="gemini-2.5-pro",
+ provider_credentials=credentials,
+ )
+
+ assert settings.provider_credentials == credentials
+ assert onboarding.provider_credentials == credentials
+
+
+def test_custom_provider_payload_keeps_legacy_openai_secret():
+ from api.settings.endpoints import _custom_providers_for_settings
+ from config.config_manager import OpenRAGConfig
+
+ config = OpenRAGConfig.from_dict({})
+ config.providers.openai.api_key = "sk-test"
+ config.providers.openai.configured = True
+ config.providers.set_credentials("openai", {"organization": "org-1"})
+
+ payload = _custom_providers_for_settings(config)
+ assert payload["openai"].secret_fields == ["api_key"]
+ assert payload["openai"].credential_values["organization"] == "org-1"
diff --git a/tests/unit/api/test_v1_llm.py b/tests/unit/api/test_v1_llm.py
new file mode 100644
index 000000000..19576494d
--- /dev/null
+++ b/tests/unit/api/test_v1_llm.py
@@ -0,0 +1,178 @@
+"""OpenAI-compatible /v1 LLM proxy handlers."""
+
+import inspect
+import json
+from unittest.mock import AsyncMock, MagicMock
+
+import pytest
+from fastapi import params as fastapi_params
+from fastapi.responses import JSONResponse, StreamingResponse
+
+from api.v1 import llm as v1_llm
+from services.llm_gateway import LlmGatewayError
+from services.model_catalog import CATALOG_UNAVAILABLE_MESSAGE, CatalogUnavailableError
+from session_manager import User
+
+
+def _user() -> User:
+ return User(user_id="u1", email="u@x", name="U", provider="api_key")
+
+
+def _get_user_dependency(fn):
+ user_param = inspect.signature(fn).parameters["user"]
+ default = user_param.default
+ assert isinstance(default, fastapi_params.Depends)
+ return default.dependency
+
+
+def test_completions_requires_chat_use():
+ dep = _get_user_dependency(v1_llm.chat_completions_endpoint)
+ perms = [cell.cell_contents for cell in dep.__closure__]
+ assert "chat:use" in perms
+
+
+def test_embeddings_accepts_chat_or_upload():
+ dep = _get_user_dependency(v1_llm.embeddings_endpoint)
+ required = [cell.cell_contents for cell in dep.__closure__]
+ assert any("chat:use" in str(item) or "knowledge:upload" in str(item) for item in required)
+
+
+async def test_list_openai_models_returns_openai_list():
+ response = await v1_llm.list_openai_models_endpoint(user=_user())
+ assert isinstance(response, JSONResponse)
+ data = json.loads(response.body)
+ assert data["object"] == "list"
+ assert data["data"]
+ assert data["data"][0]["object"] == "model"
+
+
+async def test_model_catalog_returns_providers():
+ response = await v1_llm.model_catalog_endpoint(user=_user())
+ data = json.loads(response.body)
+ keys = {p["key"] for p in data["providers"]}
+ assert "openai" in keys
+ assert "anthropic" in keys
+ openai = next(p for p in data["providers"] if p["key"] == "openai")
+ assert openai["models"]
+ assert openai["embedding_models"]
+ assert openai["credential_fields"]
+
+
+async def test_chat_completions_delegates_to_gateway(monkeypatch):
+ monkeypatch.setattr(
+ v1_llm,
+ "chat_completions",
+ AsyncMock(
+ return_value={
+ "id": "chatcmpl-1",
+ "choices": [{"message": {"role": "assistant", "content": "ok"}}],
+ }
+ ),
+ )
+ request = MagicMock()
+ request.json = AsyncMock(
+ return_value={"model": "gpt-4o-mini", "messages": [{"role": "user", "content": "hi"}]}
+ )
+ response = await v1_llm.chat_completions_endpoint(request, user=_user())
+ data = json.loads(response.body)
+ assert data["choices"][0]["message"]["content"] == "ok"
+
+
+async def test_chat_completions_streams(monkeypatch):
+ async def fake_stream():
+ yield 'data: {"choices":[]}\n\n'
+ yield "data: [DONE]\n\n"
+
+ monkeypatch.setattr(v1_llm, "chat_completions", AsyncMock(return_value=fake_stream()))
+ request = MagicMock()
+ request.json = AsyncMock(return_value={"model": "gpt-4o-mini", "messages": [], "stream": True})
+ response = await v1_llm.chat_completions_endpoint(request, user=_user())
+ assert isinstance(response, StreamingResponse)
+ assert response.media_type == "text/event-stream"
+
+
+async def test_chat_completions_maps_gateway_errors(monkeypatch):
+ monkeypatch.setattr(
+ v1_llm,
+ "chat_completions",
+ AsyncMock(side_effect=LlmGatewayError("OpenAI API key is not configured", 400)),
+ )
+ request = MagicMock()
+ request.json = AsyncMock(return_value={"model": "gpt-4o-mini", "messages": []})
+ response = await v1_llm.chat_completions_endpoint(request, user=_user())
+ assert response.status_code == 400
+ data = json.loads(response.body)
+ assert data["error"]["message"] == "OpenAI API key is not configured"
+
+
+async def test_embeddings_delegates_to_gateway(monkeypatch):
+ monkeypatch.setattr(
+ v1_llm,
+ "embeddings",
+ AsyncMock(return_value={"object": "list", "data": [{"embedding": [0.2]}]}),
+ )
+ request = MagicMock()
+ request.json = AsyncMock(return_value={"model": "text-embedding-3-small", "input": ["x"]})
+ response = await v1_llm.embeddings_endpoint(request, user=_user())
+ data = json.loads(response.body)
+ assert data["data"][0]["embedding"] == [0.2]
+
+
+async def test_list_openai_models_hides_catalog_exception_text(monkeypatch):
+ """CodeQL py/stack-trace-exposure: the exception text must not reach the caller."""
+ monkeypatch.setattr(
+ v1_llm,
+ "openai_models_list",
+ MagicMock(side_effect=CatalogUnavailableError("litellm is not installed on the server")),
+ )
+ response = await v1_llm.list_openai_models_endpoint(user=_user())
+ assert response.status_code == 503
+ data = json.loads(response.body)
+ assert data["error"]["message"] == CATALOG_UNAVAILABLE_MESSAGE
+ assert "litellm" not in response.body.decode()
+
+
+async def test_model_catalog_hides_catalog_exception_text(monkeypatch):
+ monkeypatch.setattr(
+ v1_llm,
+ "catalog",
+ MagicMock(side_effect=CatalogUnavailableError("litellm is not installed on the server")),
+ )
+ response = await v1_llm.model_catalog_endpoint(user=_user())
+ assert response.status_code == 503
+ data = json.loads(response.body)
+ assert data["error"] == CATALOG_UNAVAILABLE_MESSAGE
+ assert "litellm" not in response.body.decode()
+
+
+async def test_gateway_error_detail_is_not_returned_to_the_caller(monkeypatch):
+ """`detail` is log-only; only the sanitized `message` is serialized."""
+ monkeypatch.setattr(
+ v1_llm,
+ "chat_completions",
+ AsyncMock(
+ side_effect=LlmGatewayError(
+ "The model provider could not be reached. Please try again.",
+ 502,
+ detail="RuntimeError: connect to 10.0.0.5 failed",
+ )
+ ),
+ )
+ request = MagicMock()
+ request.json = AsyncMock(return_value={"model": "gpt-4o-mini", "messages": []})
+ response = await v1_llm.chat_completions_endpoint(request, user=_user())
+
+ assert response.status_code == 502
+ body = response.body.decode()
+ assert "10.0.0.5" not in body
+ assert "RuntimeError" not in body
+ assert json.loads(body)["error"]["type"] == "api_error"
diff --git a/tests/unit/config/test_generic_provider_config.py b/tests/unit/config/test_generic_provider_config.py
new file mode 100644
index 000000000..f68a70963
--- /dev/null
+++ b/tests/unit/config/test_generic_provider_config.py
@@ -0,0 +1,66 @@
+from config.config_manager import OpenRAGConfig
+
+
+def test_arbitrary_provider_credentials_round_trip():
+ config = OpenRAGConfig.from_dict({})
+ config.providers.set_credentials(
+ "gemini",
+ {
+ "api_key": "secret",
+ "vertex_project": "project-1",
+ "vertex_location": "us-central1",
+ },
+ )
+
+ loaded = OpenRAGConfig.from_dict(config.to_dict())
+
+ assert loaded.providers.custom["gemini"].configured is True
+ assert loaded.providers.credential_values("gemini") == {
+ "api_key": "secret",
+ "vertex_project": "project-1",
+ "vertex_location": "us-central1",
+ }
+
+
+def test_legacy_provider_keeps_extra_catalog_fields():
+ config = OpenRAGConfig.from_dict({})
+ config.providers.set_credentials(
+ "openai",
+ {
+ "api_key": "secret",
+ "api_base": "https://gateway.example/v1",
+ "organization": "org-1",
+ },
+ )
+
+ assert config.providers.openai.api_key == "secret"
+ assert config.providers.credential_values("openai") == {
+ "api_key": "secret",
+ "api_base": "https://gateway.example/v1",
+ "organization": "org-1",
+ }
+
+
+def test_blank_credentials_do_not_register_a_configured_provider():
+ """A submission with no usable values must not create a phantom provider.
+
+ `any_configured()` gates the settings API, and the fallback provider
+ helpers pick the first configured entry — a provider marked configured with
+ zero credentials would be selected and then called with no key at all.
+ """
+ config = OpenRAGConfig.from_dict({})
+
+ config.providers.set_credentials("gemini", {"api_key": " ", "": "x"})
+
+ assert "gemini" not in config.providers.custom
+ assert config.providers.any_configured() is False
+
+
+def test_blank_credentials_leave_an_existing_provider_untouched():
+ config = OpenRAGConfig.from_dict({})
+ config.providers.set_credentials("gemini", {"api_key": "secret"})
+
+ config.providers.set_credentials("gemini", {"api_key": ""})
+
+ assert config.providers.custom["gemini"].configured is True
+ assert config.providers.credential_values("gemini") == {"api_key": "secret"}
diff --git a/tests/unit/dependencies/test_jwt_header_auth.py b/tests/unit/dependencies/test_jwt_header_auth.py
index a667a7902..f7f13ee2f 100644
--- a/tests/unit/dependencies/test_jwt_header_auth.py
+++ b/tests/unit/dependencies/test_jwt_header_auth.py
@@ -161,6 +161,24 @@ async def test_invalid_jwt_rbac_on_401(monkeypatch, _patch_attach):
assert "could not be verified" in exc.value.detail["message"]
+async def test_langflow_llm_hop_token_is_rejected_on_v1_identity_path(monkeypatch, _patch_attach):
+ """A Langflow LLM hop token must not authenticate as the user on /v1/search etc."""
+ monkeypatch.setenv("OPENRAG_RBAC_ENFORCE", "true")
+ from services.langflow_llm_token_service import LangflowLlmTokenService
+
+ token = LangflowLlmTokenService(
+ secret="llm-hop-test-secret-with-32-bytes!!", ttl_seconds=60
+ ).create_token(user_id="alice")
+ req = _FakeRequest({"X-OpenRAG-JWT": f"Bearer {token}"})
+
+ with pytest.raises(HTTPException) as exc:
+ await get_api_key_user_async(req, api_key_service=None, session_manager=None)
+ assert exc.value.status_code == 401
+ assert exc.value.detail["error"] == "langflow_hop_token"
+ assert "user" not in _patch_attach
+
+
@pytest.mark.asyncio
async def test_invalid_jwt_rbac_off_falls_through_to_api_key(monkeypatch):
"""RBAC off + bad JWT -> ignore the JWT and require an API key (terminal 401)."""
diff --git a/tests/unit/services/test_flows_service_bulk_update.py b/tests/unit/services/test_flows_service_bulk_update.py
index 1267f3f7c..78aff2ff9 100644
--- a/tests/unit/services/test_flows_service_bulk_update.py
+++ b/tests/unit/services/test_flows_service_bulk_update.py
@@ -14,6 +14,30 @@ if str(SRC) not in sys.path:
from services.flows_service import FlowsService # noqa: E402
+async def test_arbitrary_provider_uses_openai_compatible_langflow_component():
+ service = FlowsService()
+ update = AsyncMock(return_value={"flow": "retrieval", "success": True})
+
+ with patch.object(service, "_update_provider_components", update):
+ result = await service.change_langflow_model_value(
+ "gemini",
+ llm_model="gemini-2.5-pro",
+ force_llm_update=True,
+ flow_configs=[{"name": "retrieval", "flow_id": "flow-1"}],
+ )
+
+ assert result["success"] is True
+ update.assert_awaited_once_with(
+ {"name": "retrieval", "flow_id": "flow-1"},
+ "openai",
+ embedding_model=None,
+ llm_model="gemini-2.5-pro",
+ force_embedding_update=False,
+ force_llm_update=True,
+ )
+
+
@pytest.mark.asyncio
async def test_bulk_update_flows_creates_backup_flow_in_langflow():
service = FlowsService()
diff --git a/tests/unit/services/test_langflow_llm_token_service.py b/tests/unit/services/test_langflow_llm_token_service.py
new file mode 100644
index 000000000..7a384dd2d
--- /dev/null
+++ b/tests/unit/services/test_langflow_llm_token_service.py
@@ -0,0 +1,86 @@
+"""Short-lived Langflow LLM hop tokens."""
+
+from __future__ import annotations
+
+import time
+
+import jwt
+import pytest
+
+from services.document_index_writer import DocumentIndexContext
+from services.langflow_ingest_token_service import LangflowIngestTokenService
+from services.langflow_llm_token_service import (
+ LANGFLOW_LLM_AUDIENCE,
+ LangflowLlmTokenService,
+ langflow_hop_audience,
+)
+
+SECRET = "llm-hop-test-secret-with-32-bytes!!"
+
+
+def test_round_trip_identifies_the_user():
+ service = LangflowLlmTokenService(secret=SECRET, ttl_seconds=60)
+ token = service.create_token(user_id="alice", email="a@x", name="Alice")
+ user = service.validate_token(token)
+ assert user.user_id == "alice"
+ assert user.email == "a@x"
+ assert user.provider == "langflow_llm"
+ assert langflow_hop_audience(token) == LANGFLOW_LLM_AUDIENCE
+
+
+def test_expired_token_is_rejected():
+ service = LangflowLlmTokenService(secret=SECRET, ttl_seconds=60)
+ token = service.create_token(user_id="alice")
+ payload = jwt.decode(
+ token,
+ SECRET,
+ algorithms=["HS256"],
+ audience=LANGFLOW_LLM_AUDIENCE,
+ options={"verify_exp": False},
+ )
+ payload["exp"] = int(time.time()) - 10
+ expired = jwt.encode(payload, SECRET, algorithm="HS256")
+ with pytest.raises(ValueError, match="Invalid Langflow LLM proxy token"):
+ service.validate_token(expired)
+
+
+def test_ingest_token_is_not_an_llm_token():
+ ingest = LangflowIngestTokenService(secret=SECRET, ttl_seconds=60)
+ token = ingest.create_token(
+ DocumentIndexContext(
+ document_id="doc-1",
+ filename="a.pdf",
+ mimetype="application/pdf",
+ embedding_model="text-embedding-3-small",
+ owner="alice",
+ ingest_run_id="run-1",
+ )
+ )
+ llm = LangflowLlmTokenService(secret=SECRET, ttl_seconds=60)
+ with pytest.raises(ValueError, match="Invalid Langflow LLM proxy token"):
+ llm.validate_token(token)
+ assert langflow_hop_audience(token) == "openrag-langflow-ingest"
+
+
+def test_wrong_scope_is_rejected():
+ service = LangflowLlmTokenService(secret=SECRET, ttl_seconds=60)
+ now = int(time.time())
+ token = jwt.encode(
+ {
+ "aud": LANGFLOW_LLM_AUDIENCE,
+ "scope": "ingest:chunks",
+ "sub": "alice",
+ "user_id": "alice",
+ "iat": now,
+ "exp": now + 60,
+ },
+ SECRET,
+ algorithm="HS256",
+ )
+ with pytest.raises(ValueError, match="invalid scope"):
+ service.validate_token(token)
+
+
+def test_orag_key_is_not_a_hop_token():
+ assert langflow_hop_audience("orag_abc") is None
+ assert langflow_hop_audience("") is None
diff --git a/tests/unit/services/test_llm_gateway.py b/tests/unit/services/test_llm_gateway.py
new file mode 100644
index 000000000..eddd177a9
--- /dev/null
+++ b/tests/unit/services/test_llm_gateway.py
@@ -0,0 +1,1039 @@
+"""LLM gateway: route OpenAI-shaped requests through LiteLLM using OpenRAG config."""
+
+import json
+from types import SimpleNamespace
+
+import pytest
+
+from config.config_manager import (
+ AnthropicConfig,
+ GenericProviderConfig,
+ OllamaConfig,
+ OpenAIConfig,
+ ProvidersConfig,
+ WatsonXConfig,
+)
+from services.llm_gateway import (
+ LlmGatewayError,
+ chat_completions,
+ embeddings,
+ provider_credentials,
+ resolve_call,
+ split_model_id,
+)
+
+
+def _config(**overrides):
+ providers = SimpleNamespace(
+ openai=SimpleNamespace(api_key="sk-openai", configured=True),
+ anthropic=SimpleNamespace(api_key="sk-ant", configured=True),
+ ollama=SimpleNamespace(
+ endpoint="http://localhost:11434", resolved_endpoint="", configured=True
+ ),
+ watsonx=SimpleNamespace(
+ api_key="wx-key",
+ endpoint="https://us-south.ml.cloud.ibm.com",
+ project_id="proj",
+ configured=True,
+ ),
+ )
+ agent = SimpleNamespace(llm_model="gpt-4o-mini", llm_provider="openai")
+ knowledge = SimpleNamespace(
+ embedding_model="text-embedding-3-small", embedding_provider="openai"
+ )
+ cfg = SimpleNamespace(providers=providers, agent=agent, knowledge=knowledge)
+ for key, value in overrides.items():
+ setattr(cfg, key, value)
+ return cfg
+
+
+def test_split_model_id_recognises_known_prefixes():
+ assert split_model_id("anthropic/claude-sonnet-4-5") == ("anthropic", "claude-sonnet-4-5")
+ assert split_model_id("gpt-4o-mini") == (None, "gpt-4o-mini")
+ assert split_model_id("openai/gpt-4o") == ("openai", "gpt-4o")
+
+
+def test_resolve_call_uses_configured_provider_when_model_is_bare():
+ model, provider, creds = resolve_call("gpt-4o-mini", kind="chat", config=_config())
+ assert provider == "openai"
+ assert model == "gpt-4o-mini"
+ assert creds["api_key"] == "sk-openai"
+
+
+def test_resolve_call_anthropic_gets_litellm_prefix():
+ cfg = _config(agent=SimpleNamespace(llm_model="claude-sonnet-4-5", llm_provider="anthropic"))
+ model, provider, creds = resolve_call(None, kind="chat", config=cfg)
+ assert provider == "anthropic"
+ assert model == "anthropic/claude-sonnet-4-5"
+ assert creds["api_key"] == "sk-ant"
+
+
+def test_resolve_call_watsonx_includes_project_and_endpoint():
+ cfg = _config(
+ knowledge=SimpleNamespace(embedding_model="ibm/slate", embedding_provider="watsonx")
+ )
+ model, provider, creds = resolve_call("ibm/slate", kind="embedding", config=cfg)
+ assert provider == "watsonx"
+ assert model == "watsonx/ibm/slate"
+ assert creds["project_id"] == "proj"
+ assert creds["api_base"] == "https://us-south.ml.cloud.ibm.com"
+
+
+def test_provider_credentials_rejects_unknown_provider():
+ with pytest.raises(LlmGatewayError) as exc:
+ provider_credentials("gemini", _config())
+ assert exc.value.status_code == 400
+ assert "gemini" in exc.value.message
+
+
+def test_provider_credentials_rejects_missing_openai_key():
+ cfg = _config()
+ cfg.providers.openai.api_key = ""
+ with pytest.raises(LlmGatewayError) as exc:
+ provider_credentials("openai", cfg)
+ assert "not configured" in exc.value.message
+
+
+def test_provider_credentials_supports_arbitrary_litellm_provider():
+ providers = ProvidersConfig(
+ openai=OpenAIConfig(),
+ anthropic=AnthropicConfig(),
+ watsonx=WatsonXConfig(),
+ ollama=OllamaConfig(),
+ custom={
+ "gemini": GenericProviderConfig(
+ credentials={
+ "api_key": "gemini-secret",
+ "vertex_project": "project-1",
+ },
+ configured=True,
+ )
+ },
+ )
+ cfg = SimpleNamespace(providers=providers)
+
+ assert provider_credentials("gemini", cfg) == {
+ "api_key": "gemini-secret",
+ "vertex_project": "project-1",
+ }
+
+
+async def test_chat_completions_calls_litellm_with_config_key(monkeypatch):
+ captured = {}
+
+ async def fake_acompletion(**kwargs):
+ captured.update(kwargs)
+ return {
+ "id": "chatcmpl-1",
+ "object": "chat.completion",
+ "choices": [{"message": {"role": "assistant", "content": "hi"}}],
+ }
+
+ monkeypatch.setattr("litellm.acompletion", fake_acompletion)
+
+ result = await chat_completions(
+ {"model": "gpt-4o-mini", "messages": [{"role": "user", "content": "hi"}]},
+ config=_config(),
+ )
+ assert result["choices"][0]["message"]["content"] == "hi"
+ assert captured["model"] == "gpt-4o-mini"
+ assert captured["api_key"] == "sk-openai"
+ assert captured["messages"][0]["content"] == "hi"
+
+
+async def test_chat_completions_forwards_tools(monkeypatch):
+ captured = {}
+
+ async def fake_acompletion(**kwargs):
+ captured.update(kwargs)
+ return {"id": "chatcmpl-1", "choices": []}
+
+ monkeypatch.setattr("litellm.acompletion", fake_acompletion)
+ tools = [{"type": "function", "function": {"name": "search"}}]
+ await chat_completions(
+ {
+ "model": "anthropic/claude-sonnet-4-5",
+ "messages": [],
+ "tools": tools,
+ "tool_choice": "auto",
+ },
+ config=_config(),
+ )
+ assert captured["tools"] == tools
+ assert captured["tool_choice"] == "auto"
+ assert captured["model"] == "anthropic/claude-sonnet-4-5"
+ assert captured["api_key"] == "sk-ant"
+
+
+async def test_chat_completions_stream_emits_sse(monkeypatch):
+ class _Chunk:
+ def model_dump_json(self):
+ return '{"choices":[{"delta":{"content":"hi"}}]}'
+
+ async def fake_stream():
+ yield _Chunk()
+
+ async def fake_acompletion(**kwargs):
+ assert kwargs["stream"] is True
+ return fake_stream()
+
+ monkeypatch.setattr("litellm.acompletion", fake_acompletion)
+ stream = await chat_completions(
+ {"model": "gpt-4o-mini", "messages": [], "stream": True},
+ config=_config(),
+ )
+ lines = [line async for line in stream]
+ assert lines[0].startswith("data: {")
+ assert lines[-1] == "data: [DONE]\n\n"
+
+
+async def test_chat_completions_redacts_api_key_on_failure(monkeypatch):
+ async def boom(**kwargs):
+ raise RuntimeError("upstream rejected sk-openai")
+
+ monkeypatch.setattr("litellm.acompletion", boom)
+ with pytest.raises(LlmGatewayError) as exc:
+ await chat_completions({"model": "gpt-4o-mini", "messages": []}, config=_config())
+ assert exc.value.status_code == 502
+ # The key never appears anywhere, and the log-only detail keeps the marker.
+ assert "sk-openai" not in exc.value.message
+ assert "sk-openai" not in exc.value.detail
+ assert "[redacted]" in exc.value.detail
+
+
+async def test_chat_completions_keeps_upstream_internals_out_of_client_message(monkeypatch):
+ """CodeQL py/stack-trace-exposure: upstream exception text is log-only."""
+
+ async def boom(**kwargs):
+ raise RuntimeError("Traceback /srv/app/litellm/router.py line 42: connect to 10.0.0.5")
+
+ monkeypatch.setattr("litellm.acompletion", boom)
+ with pytest.raises(LlmGatewayError) as exc:
+ await chat_completions({"model": "gpt-4o-mini", "messages": []}, config=_config())
+
+ assert exc.value.status_code == 502
+ # A RuntimeError from our own code is not the provider's to explain, so the
+ # message collapses to the fixed literal — only the failing call is named.
+ assert exc.value.message.startswith(
+ "The model provider could not be reached. Please try again."
+ )
+ assert "openai/gpt-4o-mini" in exc.value.message
+ for leak in ("RuntimeError", "Traceback", "/srv/app", "10.0.0.5"):
+ assert leak not in exc.value.message
+ # Operators still get the full picture in logs.
+ assert "RuntimeError" in exc.value.detail
+ assert "10.0.0.5" in exc.value.detail
+
+
+async def test_chat_completions_keeps_credential_errors_actionable(monkeypatch):
+ """A bad key must stay diagnosable in onboarding, not collapse to the generic text."""
+
+ async def boom(**kwargs):
+ raise RuntimeError("Incorrect API key provided")
+
+ monkeypatch.setattr("litellm.acompletion", boom)
+ with pytest.raises(LlmGatewayError) as exc:
+ await chat_completions({"model": "gpt-4o-mini", "messages": []}, config=_config())
+
+ assert exc.value.status_code == 502
+ assert "api key" in exc.value.message.lower()
+ # Classified, not forwarded: the client message is a fixed literal.
+ assert "Incorrect API key provided" not in exc.value.message
+ assert "Incorrect API key provided" in exc.value.detail
+
+
+async def test_embeddings_keeps_upstream_internals_out_of_client_message(monkeypatch):
+ async def boom(**kwargs):
+ raise RuntimeError("Traceback /srv/app/litellm/router.py: connect to 10.0.0.5")
+
+ monkeypatch.setattr("litellm.aembedding", boom)
+ with pytest.raises(LlmGatewayError) as exc:
+ await embeddings({"model": "text-embedding-3-small", "input": ["hi"]}, config=_config())
+
+ assert exc.value.status_code == 502
+ assert exc.value.message.startswith(
+ "The model provider could not be reached. Please try again."
+ )
+ for leak in ("RuntimeError", "Traceback", "/srv/app", "10.0.0.5"):
+ assert leak not in exc.value.message
+ assert "10.0.0.5" in exc.value.detail
+
+
+def test_gateway_error_detail_defaults_to_message():
+ """Authored 4xx messages are already safe, so detail mirrors them."""
+ exc = LlmGatewayError("model is required", 400)
+ assert exc.detail == exc.message
+
+
+async def test_embeddings_calls_litellm(monkeypatch):
+ captured = {}
+
+ async def fake_aembedding(**kwargs):
+ captured.update(kwargs)
+ return {"object": "list", "data": [{"embedding": [0.1], "index": 0}]}
+
+ monkeypatch.setattr("litellm.aembedding", fake_aembedding)
+ result = await embeddings(
+ {"model": "text-embedding-3-small", "input": ["hello"]},
+ config=_config(),
+ )
+ assert result["data"][0]["embedding"] == [0.1]
+ assert captured["api_key"] == "sk-openai"
+ assert captured["input"] == ["hello"]
+
+
+class _RecordingLogger:
+ """structlog-style logger that records calls instead of emitting them."""
+
+ def __init__(self):
+ self.calls: list[tuple[str, str, dict]] = []
+
+ def _record(self, level):
+ def log(event, **kwargs):
+ self.calls.append((level, event, kwargs))
+
+ return log
+
+ def __getattr__(self, name):
+ return self._record(name)
+
+
+def test_log_completion_shape_flags_an_empty_completion(monkeypatch):
+ """An empty completion must be visible in logs, not silently returned.
+
+ Langflow's agent ends its loop on an empty completion and the user just
+ sees "The server didn't return a response", with nothing upstream to
+ explain it.
+ """
+ from services import llm_gateway
+
+ recorder = _RecordingLogger()
+ monkeypatch.setattr(llm_gateway, "logger", recorder)
+
+ payload = {"choices": [{"finish_reason": "stop", "message": {"content": "", "tool_calls": []}}]}
+ llm_gateway._log_completion_shape(payload, "watsonx", "watsonx/ibm/granite-4-h-small")
+
+ assert recorder.calls, "nothing was logged"
+ level, event, fields = recorder.calls[0]
+ assert level == "warning"
+ assert "no content and no tool calls" in event
+ assert fields["provider"] == "watsonx"
+ assert fields["tool_calls"] == 0
+ assert fields["content_chars"] == 0
+
+
+def test_log_completion_shape_reports_a_normal_completion(monkeypatch):
+ from services import llm_gateway
+
+ recorder = _RecordingLogger()
+ monkeypatch.setattr(llm_gateway, "logger", recorder)
+
+ payload = {
+ "choices": [
+ {"finish_reason": "stop", "message": {"content": "secret answer", "tool_calls": []}}
+ ]
+ }
+ llm_gateway._log_completion_shape(payload, "openai", "gpt-4o-mini")
+
+ level, _event, fields = recorder.calls[0]
+ assert level == "info"
+ assert fields["content_chars"] == len("secret answer")
+ # Metadata only — message content must never reach the logs.
+ assert "secret answer" not in str(recorder.calls)
+
+
+def test_log_completion_shape_survives_an_unexpected_payload():
+ from services import llm_gateway
+
+ # Must never raise: diagnostics run on the response path.
+ llm_gateway._log_completion_shape({"choices": "not-a-list"}, "openai", "gpt-4o-mini")
+ llm_gateway._log_completion_shape({}, "openai", "gpt-4o-mini")
+
+
+async def test_stream_sse_still_forwards_every_chunk_and_terminates():
+ """Diagnostics must not disturb the stream itself."""
+ from services import llm_gateway
+
+ chunks = [
+ {"choices": [{"delta": {"content": "he"}}]},
+ {"choices": [{"delta": {"content": "llo"}, "finish_reason": "stop"}]},
+ ]
+
+ async def gen():
+ for chunk in chunks:
+ yield chunk
+
+ out = [line async for line in llm_gateway._stream_sse(gen(), "openai", "gpt-4o-mini")]
+
+ assert out[-1] == "data: [DONE]\n\n"
+ assert len(out) == len(chunks) + 1
+ assert '"content": "he"' in out[0] or '"content":"he"' in out[0]
+
+
+async def test_stream_sse_warns_when_a_stream_yields_nothing_usable(monkeypatch):
+ """The watsonx symptom: 200 OK, chunks arrive, but no content and no tool calls."""
+ from services import llm_gateway
+
+ recorder = _RecordingLogger()
+ monkeypatch.setattr(llm_gateway, "logger", recorder)
+
+ async def gen():
+ yield {"choices": [{"delta": {}, "finish_reason": "stop"}]}
+
+ [
+ line
+ async for line in llm_gateway._stream_sse(gen(), "watsonx", "watsonx/ibm/granite-4-h-small")
+ ]
+
+ levels = [call[0] for call in recorder.calls]
+ assert "warning" in levels
+ _level, event, fields = next(c for c in recorder.calls if c[0] == "warning")
+ assert "no content and no tool calls" in event
+ assert fields["provider"] == "watsonx"
+ assert fields["finish_reason"] == "stop"
+
+
+async def test_stream_sse_counts_tool_calls_as_usable_output(monkeypatch):
+ from services import llm_gateway
+
+ recorder = _RecordingLogger()
+ monkeypatch.setattr(llm_gateway, "logger", recorder)
+
+ async def gen():
+ yield {
+ "choices": [{"delta": {"tool_calls": [{"index": 0}]}, "finish_reason": "tool_calls"}]
+ }
+
+ [line async for line in llm_gateway._stream_sse(gen(), "openai", "gpt-4o-mini")]
+
+ level, event, fields = recorder.calls[0]
+ assert level == "info"
+ assert fields["tool_calls"] == 1
+
+
+async def test_chat_completions_lets_litellm_drop_provider_unsupported_params(monkeypatch):
+ """A multi-provider proxy must degrade, not 502, on provider param gaps.
+
+ OpenAI-compatible clients send OpenAI's full parameter set, but watsonx
+ rejects `parallel_tool_calls`, `max_completion_tokens` and `logit_bias`,
+ and LiteLLM raises UnsupportedParamsError rather than ignoring them.
+ """
+ captured = {}
+
+ async def fake_acompletion(**kwargs):
+ captured.update(kwargs)
+ return {"id": "1", "choices": [{"message": {"role": "assistant", "content": "hi"}}]}
+
+ monkeypatch.setattr("litellm.acompletion", fake_acompletion)
+
+ await chat_completions(
+ {
+ "model": "gpt-4o-mini",
+ "messages": [{"role": "user", "content": "hi"}],
+ "parallel_tool_calls": True,
+ "max_completion_tokens": 64,
+ },
+ config=_config(),
+ )
+
+ assert captured["drop_params"] is True
+ # The params are still forwarded — LiteLLM decides per provider what to keep.
+ assert captured["parallel_tool_calls"] is True
+ assert captured["max_completion_tokens"] == 64
+
+
+def test_watsonx_rejects_params_we_forward_unless_they_are_dropped():
+ """Pin the upstream behaviour this fix relies on.
+
+ If LiteLLM ever starts accepting these for watsonx, `drop_params` becomes
+ redundant rather than wrong — but while it rejects them, forwarding them
+ without the flag is a hard failure for every watsonx caller.
+ """
+ from litellm.exceptions import UnsupportedParamsError
+ from litellm.utils import get_optional_params
+
+ for param, value in (
+ ("parallel_tool_calls", True),
+ ("max_completion_tokens", 64),
+ ("logit_bias", {"1": 1}),
+ ):
+ with pytest.raises(UnsupportedParamsError):
+ get_optional_params(
+ model="ibm/granite-4-h-small",
+ custom_llm_provider="watsonx",
+ **{param: value},
+ )
+
+ dropped = get_optional_params(
+ model="ibm/granite-4-h-small",
+ custom_llm_provider="watsonx",
+ drop_params=True,
+ **{param: value},
+ )
+ assert param not in dropped
+
+
+ ("model_id", "expected"),
+ [
+ # Canonical tag. The name keeps its own slashes and colons.
+ ("watsonx:openai/gpt-oss-120b", ("watsonx", "openai/gpt-oss-120b")),
+ ("watsonx:ibm/granite-4-h-small", ("watsonx", "ibm/granite-4-h-small")),
+ ("ollama:gpt-oss:120b-cloud", ("ollama", "gpt-oss:120b-cloud")),
+ ("openai:ft:gpt-4-0613", ("openai", "ft:gpt-4-0613")),
+ # Legacy `provider/model` tags still resolve.
+ ("watsonx/ibm/granite-4-h-small", ("watsonx", "ibm/granite-4-h-small")),
+ ("anthropic/claude-sonnet-4-5", ("anthropic", "claude-sonnet-4-5")),
+ # Untagged ids are left to the configured default provider.
+ ("gpt-4o-mini", (None, "gpt-4o-mini")),
+ ("gpt-oss:120b-cloud", (None, "gpt-oss:120b-cloud")),
+ ("ft:gpt-4-0613", (None, "ft:gpt-4-0613")),
+ ],
+)
+def test_split_model_id_handles_tagged_and_untagged_ids(model_id, expected):
+ from services.llm_gateway import split_model_id
+
+ assert split_model_id(model_id) == expected
+
+
+def test_a_vendor_qualified_name_is_not_mistaken_for_a_provider_tag():
+ """watsonx serves `openai/gpt-oss-120b`; the `openai/` is part of the name.
+
+ Splitting on the slash routed it to OpenAI as a bare `gpt-oss-120b`, which
+ LiteLLM rejects with "LLM Provider NOT provided", surfacing to the user as
+ "The model provider could not be reached."
+ """
+ from services.llm_gateway import split_model_id
+
+ assert split_model_id("openai/gpt-oss-120b") == ("watsonx", "openai/gpt-oss-120b")
+
+
+def test_model_ids_served_by_v1_models_round_trip():
+ """Every id `/v1/models` publishes must resolve back to its owner."""
+ from services.llm_gateway import split_model_id
+ from services.model_catalog import openai_models_list
+
+ for row in openai_models_list()["data"]:
+ provider, _name = split_model_id(row["id"])
+ if row["owned_by"] == "openai":
+ continue
+ assert provider == row["owned_by"], row
+
+
+def test_no_catalogue_id_has_a_provider_shaped_prefix_before_a_colon():
+ """The property that makes `:` a safe separator.
+
+ If a future model id breaks this, `provider:model` becomes ambiguous the
+ same way `provider/model` already is.
+ """
+ from services.model_catalog import PROVIDER_SEPARATOR_SAFE_CHECK
+
+ ambiguous = PROVIDER_SEPARATOR_SAFE_CHECK()
+ assert ambiguous == [], f"colon-ambiguous catalogue ids: {ambiguous}"
+
+
+# --------------------------------------------------------------------------
+# Tool-call arguments that arrive serialised twice
+# --------------------------------------------------------------------------
+
+#: What `watsonx/ibm/granite-4-h-small` actually sends: the arguments object,
+#: serialised, then serialised again. Captured from a live call.
+_DOUBLE_ENCODED_ARGUMENTS = '"{\\n \\"query\\": \\"Earned Leaves\\"\\n}"'
+_WELL_FORMED_ARGUMENTS = '{"query": "Earned Leaves"}'
+
+
+def test_normalise_tool_arguments_unwraps_a_double_encoded_payload():
+ from services.llm_gateway import _normalise_tool_arguments
+
+ arguments, repaired = _normalise_tool_arguments(_DOUBLE_ENCODED_ARGUMENTS)
+
+ assert repaired is True
+ assert json.loads(arguments) == {"query": "Earned Leaves"}
+
+
+def test_normalise_tool_arguments_leaves_well_formed_payloads_untouched():
+ from services.llm_gateway import _normalise_tool_arguments
+
+ for payload in (_WELL_FORMED_ARGUMENTS, "{}", ' {"a": 1}', "not json", "", None):
+ assert _normalise_tool_arguments(payload) == (payload, False)
+
+
+def test_normalise_tool_arguments_serialises_a_mapping():
+ """Some providers send the object itself; OpenAI clients parse a string."""
+ from services.llm_gateway import _normalise_tool_arguments
+
+ arguments, repaired = _normalise_tool_arguments({"query": "x"})
+ assert repaired is True
+ assert json.loads(arguments) == {"query": "x"}
+
+
+def test_normalise_tool_arguments_refuses_a_quoted_scalar():
+ """`"hello"` is a string, not an arguments object — leave it for the client."""
+ from services.llm_gateway import _normalise_tool_arguments
+
+ assert _normalise_tool_arguments('"hello"') == ('"hello"', False)
+
+
+async def test_chat_completions_repairs_double_encoded_tool_arguments(monkeypatch):
+ """Non-streaming: the client must receive arguments it can parse into a mapping."""
+
+ async def fake(**kwargs):
+ return {
+ "choices": [
+ {
+ "finish_reason": "tool_calls",
+ "message": {
+ "role": "assistant",
+ "content": None,
+ "tool_calls": [
+ {
+ "id": "call_1",
+ "type": "function",
+ "function": {
+ "name": "search_documents",
+ "arguments": _DOUBLE_ENCODED_ARGUMENTS,
+ },
+ }
+ ],
+ },
+ }
+ ]
+ }
+
+ monkeypatch.setattr("litellm.acompletion", fake)
+ payload = await chat_completions(
+ {"model": "watsonx:ibm/granite-4-h-small", "messages": []}, config=_config()
+ )
+
+ arguments = payload["choices"][0]["message"]["tool_calls"][0]["function"]["arguments"]
+ assert json.loads(arguments) == {"query": "Earned Leaves"}
+
+
+def _tool_call_deltas(fragments, name="search_documents", call_id="call_1"):
+ """One chunk per fragment, the way a provider streams a tool call."""
+ chunks = [
+ {
+ "choices": [
+ {
+ "index": 0,
+ "delta": {
+ "role": "assistant",
+ "content": "",
+ "tool_calls": [
+ {
+ "id": call_id,
+ "type": "function",
+ "index": 0,
+ "function": {"name": name, "arguments": ""},
+ }
+ ],
+ },
+ "finish_reason": None,
+ }
+ ]
+ }
+ ]
+ for fragment in fragments:
+ chunks.append(
+ {
+ "choices": [
+ {
+ "index": 0,
+ "delta": {
+ "role": None,
+ "content": "",
+ "tool_calls": [
+ {
+ "id": None,
+ "type": "function",
+ "index": 0,
+ "function": {"name": "", "arguments": fragment},
+ }
+ ],
+ },
+ "finish_reason": None,
+ }
+ ]
+ }
+ )
+ chunks.append(
+ {"choices": [{"index": 0, "delta": {"content": None}, "finish_reason": "tool_calls"}]}
+ )
+ return chunks
+
+
+def _streamed_tool_calls(lines):
+ """Every tool call the gateway put on the wire, in order."""
+ calls = []
+ for line in lines:
+ if not line.startswith("data: ") or line.startswith("data: [DONE]"):
+ continue
+ for choice in json.loads(line[len("data: ") :]).get("choices") or []:
+ calls.extend((choice.get("delta") or {}).get("tool_calls") or [])
+ return calls
+
+
+async def test_stream_sse_reassembles_and_repairs_fragmented_tool_arguments():
+ """The granite-4 symptom: fragments only reveal the double encoding once joined."""
+ from services import llm_gateway
+
+ # Exactly how the model splits it on the wire.
+ fragments = [
+ '"{\\',
+ "n",
+ " ",
+ ' \\"',
+ "query",
+ '\\":',
+ ' \\"',
+ "Earned Leaves",
+ '\\"\\',
+ "n",
+ '}"',
+ ]
+
+ async def gen():
+ for chunk in _tool_call_deltas(fragments):
+ yield chunk
+
+ lines = [
+ line
+ async for line in llm_gateway._stream_sse(gen(), "watsonx", "watsonx/ibm/granite-4-h-small")
+ ]
+
+ calls = _streamed_tool_calls(lines)
+ assert len(calls) == 1, "fragments must be emitted as one complete tool call"
+ assert calls[0]["id"] == "call_1"
+ assert calls[0]["function"]["name"] == "search_documents"
+ assert json.loads(calls[0]["function"]["arguments"]) == {"query": "Earned Leaves"}
+ assert lines[-1] == "data: [DONE]\n\n"
+ # The finishing chunk still arrives, and after the tool call.
+ assert '"finish_reason": "tool_calls"' in lines[-2]
+
+
+async def test_stream_sse_leaves_a_well_formed_tool_call_intact():
+ """Reassembly must be lossless for providers that already behave."""
+ from services import llm_gateway
+
+ fragments = ['{"', "query", '": "', "Earned Leaves", '"}']
+
+ async def gen():
+ for chunk in _tool_call_deltas(fragments):
+ yield chunk
+
+ lines = [line async for line in llm_gateway._stream_sse(gen(), "openai", "gpt-4o-mini")]
+
+ calls = _streamed_tool_calls(lines)
+ assert len(calls) == 1
+ assert json.loads(calls[0]["function"]["arguments"]) == {"query": "Earned Leaves"}
+
+
+async def test_stream_sse_keeps_content_flowing_while_tool_calls_are_held():
+ """Buffering tool calls must not delay or drop streamed text."""
+ from services import llm_gateway
+
+ async def gen():
+ yield {"choices": [{"index": 0, "delta": {"content": "th"}}]}
+ yield {
+ "choices": [
+ {
+ "index": 0,
+ "delta": {
+ "content": "inking",
+ "tool_calls": [
+ {
+ "id": "call_1",
+ "index": 0,
+ "type": "function",
+ "function": {"name": "t", "arguments": "{}"},
+ }
+ ],
+ },
+ }
+ ]
+ }
+ yield {"choices": [{"index": 0, "delta": {}, "finish_reason": "tool_calls"}]}
+
+ lines = [line async for line in llm_gateway._stream_sse(gen(), "openai", "gpt-4o-mini")]
+
+ text = "".join(
+ (choice.get("delta") or {}).get("content") or ""
+ for line in lines
+ if line.startswith("data: ") and not line.startswith("data: [DONE]")
+ for choice in json.loads(line[len("data: ") :]).get("choices") or []
+ )
+ assert text == "thinking"
+ assert len(_streamed_tool_calls(lines)) == 1
+
+
+async def test_stream_sse_flushes_tool_calls_when_the_provider_sends_no_finish_reason():
+ from services import llm_gateway
+
+ async def gen():
+ yield {
+ "choices": [
+ {
+ "index": 0,
+ "delta": {
+ "tool_calls": [
+ {
+ "id": "call_1",
+ "index": 0,
+ "type": "function",
+ "function": {
+ "name": "search_documents",
+ "arguments": _DOUBLE_ENCODED_ARGUMENTS,
+ },
+ }
+ ]
+ },
+ }
+ ]
+ }
+
+ lines = [
+ line
+ async for line in llm_gateway._stream_sse(gen(), "watsonx", "watsonx/ibm/granite-4-h-small")
+ ]
+
+ calls = _streamed_tool_calls(lines)
+ assert len(calls) == 1
+ assert json.loads(calls[0]["function"]["arguments"]) == {"query": "Earned Leaves"}
+
+
+async def test_stream_sse_logs_the_repair(monkeypatch):
+ from services import llm_gateway
+
+ recorder = _RecordingLogger()
+ monkeypatch.setattr(llm_gateway, "logger", recorder)
+
+ async def gen():
+ for chunk in _tool_call_deltas(['"{\\', 'n \\"query\\": \\"x\\"\\', 'n}"']):
+ yield chunk
+
+ [
+ line
+ async for line in llm_gateway._stream_sse(gen(), "watsonx", "watsonx/ibm/granite-4-h-small")
+ ]
+
+ warnings = [call for call in recorder.calls if call[0] == "warning"]
+ assert any("Repaired double-encoded tool call arguments" in call[1] for call in warnings)
+ _level, _event, fields = next(call for call in warnings if "Repaired" in call[1])
+ assert fields["model"] == "watsonx/ibm/granite-4-h-small"
+ assert fields["tool_calls"] == 1
+
+
+# --------------------------------------------------------------------------
+# Surfacing the real upstream failure
+# --------------------------------------------------------------------------
+
+
+class _FakeLiteLLMError(Exception):
+ """Stands in for a LiteLLM exception: tagged with the provider it called."""
+
+ def __init__(self, message, status_code=400):
+ super().__init__(message)
+ self.llm_provider = "watsonx"
+ self.status_code = status_code
+
+
+async def test_chat_completions_surfaces_the_provider_error_body(monkeypatch):
+ """An operator must be able to read what the provider actually objected to."""
+
+ async def boom(**kwargs):
+ raise _FakeLiteLLMError(
+ 'OpenAILikeError: {"errors":[{"code":"model_not_supported","message":'
+ "\"Model 'ibm/granite-3-3-8b-instruct' was not found. This model may be "
+ 'unsupported, deprecated, or removed."}],"status_code":404}'
+ )
+
+ monkeypatch.setattr("litellm.acompletion", boom)
+ with pytest.raises(LlmGatewayError) as exc:
+ await chat_completions(
+ {"model": "watsonx:ibm/granite-3-3-8b-instruct", "messages": []}, config=_config()
+ )
+
+ assert "watsonx/ibm/granite-3-3-8b-instruct" in exc.value.message
+ assert "was not found" in exc.value.message
+ assert "OpenAILikeError" not in exc.value.message
+
+
+async def test_chat_completions_surfaces_a_litellm_exception_without_a_json_body(monkeypatch):
+ async def boom(**kwargs):
+ raise _FakeLiteLLMError("BadRequestError: tool_choice is not supported for this model")
+
+ monkeypatch.setattr("litellm.acompletion", boom)
+ with pytest.raises(LlmGatewayError) as exc:
+ await chat_completions({"model": "gpt-4o-mini", "messages": []}, config=_config())
+
+ assert "tool_choice is not supported" in exc.value.message
+
+
+async def test_chat_completions_passes_through_a_rate_limit_status(monkeypatch):
+ async def boom(**kwargs):
+ raise _FakeLiteLLMError("rate limit exceeded, retry in 30s", status_code=429)
+
+ monkeypatch.setattr("litellm.acompletion", boom)
+ with pytest.raises(LlmGatewayError) as exc:
+ await chat_completions({"model": "gpt-4o-mini", "messages": []}, config=_config())
+
+ assert exc.value.status_code == 429
+ assert "rate limit exceeded" in exc.value.message
+
+
+async def test_chat_completions_masks_an_upstream_4xx_as_a_gateway_failure(monkeypatch):
+ """An upstream 401 must not read to the client as an OpenRAG auth failure."""
+
+ async def boom(**kwargs):
+ raise _FakeLiteLLMError("model does not exist", status_code=404)
+
+ monkeypatch.setattr("litellm.acompletion", boom)
+ with pytest.raises(LlmGatewayError) as exc:
+ await chat_completions({"model": "gpt-4o-mini", "messages": []}, config=_config())
+
+ assert exc.value.status_code == 502
+
+
+def test_sanitise_upstream_detail_drops_interpreter_state():
+ from services.llm_gateway import _sanitise_upstream_detail
+
+ text = _sanitise_upstream_detail(
+ "ConnectError: connect to 10.0.0.5 failed\n"
+ 'Traceback (most recent call last):\n File "/srv/app/litellm/router.py", line 42'
+ )
+ for leak in ("Traceback", "/srv/app", "10.0.0.5"):
+ assert leak not in text
+ assert "connect to <host> failed" in text
+
+
+def test_sanitise_upstream_detail_caps_a_runaway_body():
+ from services import llm_gateway
+
+ text = llm_gateway._sanitise_upstream_detail("x" * 5000)
+ assert len(text) <= llm_gateway._MAX_UPSTREAM_MESSAGE_CHARS
+
+
+async def test_stream_sse_emits_an_error_frame_when_the_provider_fails_mid_stream():
+ """A truncated stream reads as "no response"; an error frame reads as the cause."""
+ from services import llm_gateway
+
+ async def gen():
+ yield {"choices": [{"index": 0, "delta": {"content": "par"}}]}
+ raise _FakeLiteLLMError('{"error":{"message":"context window exceeded"}}')
+
+ lines = [
+ line
+ async for line in llm_gateway._stream_sse(
+ gen(), "watsonx", "watsonx/ibm/granite-4-h-small", {"api_key": "wx-key"}
+ )
+ ]
+
+ assert lines[-1] == "data: [DONE]\n\n"
+ error = json.loads(lines[-2][len("data: ") :])["error"]
+ assert "context window exceeded" in error["message"]
+ assert error["provider"] == "watsonx"
+ assert error["model"] == "watsonx/ibm/granite-4-h-small"
+
+
+async def test_stream_sse_keeps_credentials_out_of_the_error_frame():
+ from services import llm_gateway
+
+ async def gen():
+ raise _FakeLiteLLMError("rejected token wx-super-secret-key")
+ yield # pragma: no cover - generator marker
+
+ lines = [
+ line
+ async for line in llm_gateway._stream_sse(
+ gen(), "watsonx", "watsonx/ibm/granite-4-h-small", {"api_key": "wx-super-secret-key"}
+ )
+ ]
+
+ assert "wx-super-secret-key" not in "".join(lines)
+
+
+async def test_stream_sse_reports_an_empty_completion_instead_of_going_silent():
+ """A 200 that carries nothing must name itself, not read as a dead connection."""
+ from services import llm_gateway
+
+ async def gen():
+ yield {"choices": [{"index": 0, "delta": {"content": ""}, "finish_reason": "stop"}]}
+
+ lines = [
+ line
+ async for line in llm_gateway._stream_sse(gen(), "watsonx", "watsonx/ibm/granite-4-h-small")
+ ]
+
+ assert lines[-1] == "data: [DONE]\n\n"
+ error = json.loads(lines[-2][len("data: ") :])["error"]
+ assert "no content and no tool calls" in error["message"]
+ assert "finish_reason: stop" in error["message"]
+ assert "watsonx/ibm/granite-4-h-small" in error["message"]
+
+
+async def test_stream_sse_stays_quiet_when_the_completion_carried_content():
+ from services import llm_gateway
+
+ async def gen():
+ yield {"choices": [{"index": 0, "delta": {"content": "hi"}, "finish_reason": "stop"}]}
+
+ lines = [line async for line in llm_gateway._stream_sse(gen(), "openai", "gpt-4o-mini")]
+
+ assert not any('"error"' in line for line in lines)
+
+
+async def test_stream_sse_counts_a_repaired_tool_call_as_output():
+ """The repair must clear the empty-completion path, not trip it."""
+ from services import llm_gateway
+
+ async def gen():
+ for chunk in _tool_call_deltas(['"{\\', 'n \\"query\\": \\"x\\"\\', 'n}"']):
+ yield chunk
+
+ lines = [
+ line
+ async for line in llm_gateway._stream_sse(gen(), "watsonx", "watsonx/ibm/granite-4-h-small")
+ ]
+
+ assert not any('"error"' in line for line in lines)
+
+
+async def test_stream_sse_reports_a_stream_that_never_yielded_a_chunk():
+ from services import llm_gateway
+
+ async def gen():
+ return
+ yield # pragma: no cover - generator marker
+
+ lines = [line async for line in llm_gateway._stream_sse(gen(), "openai", "gpt-4o-mini")]
+
+ error = json.loads(lines[-2][len("data: ") :])["error"]
+ assert "no content and no tool calls" in error["message"]
diff --git a/tests/unit/services/test_model_catalog.py b/tests/unit/services/test_model_catalog.py
new file mode 100644
index 000000000..18d08c6ed
--- /dev/null
+++ b/tests/unit/services/test_model_catalog.py
@@ -0,0 +1,107 @@
+"""The LiteLLM-derived model catalogue.
+
+The catalogue replaced per-provider live `/models/{provider}` fetches for the
+settings dropdown, so these tests pin the properties that table used to
+guarantee: a picked model names a provider LiteLLM can call, chat and embedding
+lists are disjoint, and the OpenAI-compatible /v1/models list is derived from
+the same payload.
+"""
+
+from __future__ import annotations
+
+from services import model_catalog
+
+
+def test_catalog_only_groups_supported_providers_with_their_models_and_forms() -> None:
+ providers = {entry["key"]: entry for entry in model_catalog.catalog()["providers"]}
+
+ assert set(providers) == model_catalog.SUPPORTED_PROVIDER_KEYS
+ for key in model_catalog.SUPPORTED_PROVIDER_KEYS:
+ assert key in providers, key
+ assert providers[key]["credential_fields"], key
+
+ openai = providers["openai"]
+ assert openai["name"] == "OpenAI"
+ assert any(entry["model"].startswith("gpt-") for entry in openai["models"])
+ assert any("embedding" in entry["model"] for entry in openai["embedding_models"])
+ field_types = {field["key"]: field["field_type"] for field in openai["credential_fields"]}
+ assert field_types["api_key"] == "password"
+ assert field_types["api_base"] == "text"
+
+
+def test_catalog_chat_models_are_only_text_generation() -> None:
+ modes = {
+ entry["mode"]
+ for provider in model_catalog.catalog()["providers"]
+ for entry in provider["models"]
+ }
+ assert modes <= model_catalog.TEXT_GENERATION_MODES
+ assert "chat" in modes
+
+
+def test_catalog_embedding_models_are_only_embedding_mode() -> None:
+ modes = {
+ entry["mode"]
+ for provider in model_catalog.catalog()["providers"]
+ for entry in provider["embedding_models"]
+ }
+ assert modes <= {model_catalog.EMBEDDING_MODE}
+ assert model_catalog.EMBEDDING_MODE in modes
+
+
+def test_model_ids_are_stored_without_their_provider_prefix() -> None:
+ providers = {entry["key"]: entry for entry in model_catalog.catalog()["providers"]}
+ for provider, entry in providers.items():
+ for model in entry["models"] + entry["embedding_models"]:
+ assert not model["model"].startswith(f"{provider}/")
+
+
+def test_openai_form_is_the_plain_one_not_the_compatible_variant() -> None:
+ required = model_catalog.required_field_keys("openai")
+ assert required == ["api_key"]
+
+
+def test_an_unknown_provider_still_gets_a_usable_form() -> None:
+ fields = model_catalog.credential_fields("some-private-gateway")
+ assert [field["key"] for field in fields] == ["api_key", "api_base"]
+ assert model_catalog.missing_required_fields("some-private-gateway", set()) == []
+
+
+def test_openai_models_list_is_openai_compatible() -> None:
+ payload = model_catalog.openai_models_list()
+ assert payload["object"] == "list"
+ assert payload["data"]
+ ids = {row["id"] for row in payload["data"]}
+ assert any(model_id.startswith("gpt-") for model_id in ids)
+ sample = payload["data"][0]
+ assert sample["object"] == "model"
+ assert "owned_by" in sample
+
+
+def test_is_known_provider_accepts_litellm_handlers() -> None:
+ assert model_catalog.is_known_provider("openai")
+ assert model_catalog.is_known_provider("anthropic")
+ assert not model_catalog.is_known_provider("not-a-real-provider")
+ assert not model_catalog.is_known_provider("")
+
+
+def test_exported_model_ids_route_back_to_their_owner() -> None:
+ """A `/v1/models` id must resolve to the provider that owns it.
+
+ `_catalog()` strips provider prefixes for the picker; without re-attaching
+ them here an Anthropic id sent to `/v1/chat/completions` would fall through
+ to the default provider and be called with the wrong credentials.
+ """
+ from services.llm_gateway import split_model_id
+
+ payload = model_catalog.openai_models_list()
+ non_openai = [row for row in payload["data"] if row["owned_by"] != "openai"]
+ assert non_openai, "catalogue should expose more than OpenAI"
+
+ for row in non_openai:
+ provider, _name = split_model_id(row["id"])
+ assert provider == row["owned_by"], row
+
+ openai_rows = [row for row in payload["data"] if row["owned_by"] == "openai"]
+ assert openai_rows
+ assert all("/" not in row["id"] for row in openai_rows)
diff --git a/tests/unit/test_flow_opensearch_outputs.py b/tests/unit/test_flow_opensearch_outputs.py
index e4bf5c3ef..da89d2ece 100644
--- a/tests/unit/test_flow_opensearch_outputs.py
+++ b/tests/unit/test_flow_opensearch_outputs.py
@@ -14,17 +14,17 @@ def _opensearch_nodes(flow: dict) -> list[dict]:
]
-def test_opensearch_component_returns_table_search_results():
- code = Path("flows/components/opensearch_multimodal.py").read_text(encoding="utf-8")
+def test_opensearch_component_returns_data_search_results():
+ code = Path("custom_components/openrag/opensearch_multimodal.py").read_text(encoding="utf-8")
- assert "from lfx.schema.dataframe import Table" in code
- assert "def search_documents(self) -> Table:" in code
- assert "return Table(data=raw_list)" in code
+ assert "from lfx.schema.data import Data" in code
+ assert "def search_documents(self) -> list[Data]:" in code
+ assert "return Table(data=raw_list)" not in code
assert 'name="dataframe"' not in code
assert "def as_dataframe" not in code
-def test_embedded_opensearch_nodes_expose_table_search_results():
+def test_embedded_opensearch_nodes_expose_json_search_results():
for flow_path in (
"flows/ingestion_flow.json",
"flows/openrag_nudges.json",
@@ -40,7 +40,7 @@ def test_embedded_opensearch_nodes_expose_table_search_results():
output for output in outputs if output.get("name") == "search_results"
)
assert search_output["method"] == "search_documents"
- assert search_output["types"] == ["Table"]
+ assert search_output["types"] == ["JSON"]
assert all(output.get("name") != "dataframe" for output in outputs)
@@ -62,25 +62,24 @@ def test_nudges_flow_uses_opensearch_search_results_table():
assert len(opensearch_to_parser_edges) == 1
source_handle = opensearch_to_parser_edges[0]["data"]["sourceHandle"]
assert source_handle["name"] == "search_results"
- assert source_handle["output_types"] == ["Table"]
+ assert source_handle["output_types"] == ["JSON"]
def test_parser_components_are_not_forked_for_list_data():
- for flow_path in ("flows/openrag_nudges.json", "flows/openrag_url_mcp.json"):
- flow = _load_flow(flow_path)
- parser_node = next(
- node
- for node in flow["data"]["nodes"]
- if node.get("data", {}).get("type") == "ParserComponent"
- )
- code = parser_node["data"]["node"]["template"]["code"]["value"]
+ flow = _load_flow("flows/openrag_nudges.json")
+ parser_node = next(
+ node
+ for node in flow["data"]["nodes"]
+ if node.get("data", {}).get("type") == "ParserComponent"
+ )
+ code = parser_node["data"]["node"]["template"]["code"]["value"]
- assert "return DataFrame(data=[item.data for item in input_data]), None" not in code
+ assert "return DataFrame(data=[item.data for item in input_data]), None" not in code
def test_opensearch_component_fences_retrieved_text_as_untrusted():
"""VULN-13906: retrieved chunk text must be fenced so the LLM treats it as data, not instructions."""
- code = Path("flows/components/opensearch_multimodal.py").read_text(encoding="utf-8")
+ code = Path("custom_components/openrag/opensearch_multimodal.py").read_text(encoding="utf-8")
assert 'UNTRUSTED_CHUNK_FENCE_START = "<<<UNTRUSTED_DOC_CHUNK>>>"' in code
assert 'UNTRUSTED_CHUNK_FENCE_END = "<<<END_UNTRUSTED_DOC_CHUNK>>>"' in code
@@ -91,7 +90,7 @@ def test_opensearch_component_fences_retrieved_text_as_untrusted():
def test_embedded_opensearch_nodes_fence_untrusted_text():
"""The fencing fix must be synced into every flow JSON embedding this component."""
- py_code = Path("flows/components/opensearch_multimodal.py").read_text(encoding="utf-8")
+ py_code = Path("custom_components/openrag/opensearch_multimodal.py").read_text(encoding="utf-8")
for flow_path in (
"flows/ingestion_flow.json",
@@ -104,6 +103,42 @@ def test_embedded_opensearch_nodes_fence_untrusted_text():
embedded_code = node["data"]["node"]["template"]["code"]["value"]
assert embedded_code == py_code, (
f"{flow_path} node {node.get('id')} embedded code is out of sync with "
- "flows/components/opensearch_multimodal.py — re-run "
+ "custom_components/openrag/opensearch_multimodal.py — re-run "
"scripts/update_flow_components.py"
)
+
+
+def test_query_filter_text_input_feeds_opensearch_filter_expression():
+ """The OPENRAG-QUERY-FILTER global var must reach the retrieval component.
+
+ Regression guard: re-exporting a flow from the Langflow canvas silently drops
+ edges. When this one goes missing the retrieval tool runs unfiltered, so
+ knowledge-filter scoping leaks documents the caller excluded.
+ """
+ for flow_path in (
+ "flows/openrag_agent.json",
+ "flows/openrag_nudges.json",
+ ):
+ flow = _load_flow(flow_path)
+ query_filter_inputs = {
+ node["id"]
+ for node in flow["data"]["nodes"]
+ if node.get("data", {}).get("type") == "TextInput"
+ and node["data"]["node"]["template"].get("input_value", {}).get("value")
+ == "OPENRAG-QUERY-FILTER"
+ }
+ assert query_filter_inputs, f"{flow_path} lost its OPENRAG-QUERY-FILTER TextInput"
+
+ opensearch_node_ids = {node["id"] for node in _opensearch_nodes(flow)}
+ wired = {
+ edge["source"]
+ for edge in flow["data"]["edges"]
+ if edge.get("target") in opensearch_node_ids
+ and edge.get("data", {}).get("targetHandle", {}).get("fieldName") == "filter_expression"
+ }
+
+ assert query_filter_inputs <= wired, (
+ f"{flow_path}: OPENRAG-QUERY-FILTER TextInput is not connected to the "
+ "OpenSearch component's filter_expression input — retrieval would ignore "
+ "knowledge filters"
+ )
diff --git a/tests/unit/test_langflow_global_variables.py b/tests/unit/test_langflow_global_variables.py
index 9a238a216..7d2fa1587 100644
--- a/tests/unit/test_langflow_global_variables.py
+++ b/tests/unit/test_langflow_global_variables.py
@@ -255,17 +255,20 @@ async def test_update_langflow_global_variables_marks_non_secret_provider_fields
await langflow_sync._update_langflow_global_variables(config, flows_service=flows_service)
- assert ("WATSONX_APIKEY", "watson-key", True, "Credential") in calls
- assert ("OPENAI_API_KEY", "openai-key", True, "Credential") in calls
- assert ("ANTHROPIC_API_KEY", "anthropic-key", True, "Credential") in calls
- assert ("WATSONX_PROJECT_ID", "watson-project", True, "Generic") in calls
- assert ("WATSONX_URL", "https://watson.example", True, "Generic") in calls
- assert ("OLLAMA_BASE_URL", "http://ollama.local", True, "Generic") in calls
+ names = {name for name, *_ in calls}
+ assert ("OPENRAG_LLM_TOKEN", "None", True, "Credential") in calls
+ assert "ANTHROPIC_API_KEY" not in names
+ assert "WATSONX_APIKEY" not in names
assert ("SELECTED_EMBEDDING_MODEL", "embedding-model", True, "Generic") in calls
+ assert ("SELECTED_EMBEDDING_MODEL_PROVIDER", "OpenAI", True, "Generic") in calls
+ assert ("SELECTED_LANGUAGE_MODEL_PROVIDER", "OpenAI", True, "Generic") in calls
+ assert any(name == "OPENRAG_LLM_BASE_URL" for name, *_ in calls)
@pytest.mark.asyncio
-async def test_ensure_required_langflow_global_variables_creates_all_generics(monkeypatch):
+async def test_ensure_required_langflow_global_variables_creates_generics_and_credential_placeholders(
+ monkeypatch,
+):
calls = []
async def mock_langflow_request(method, endpoint, **kwargs):
@@ -305,50 +308,60 @@ async def test_ensure_required_langflow_global_variables_creates_all_generics(mo
names = {name for name, *_ in calls}
assert langflow_sync.LANGFLOW_GENERIC_GLOBAL_VARIABLES <= names
- assert all(variable_type == "Generic" for *_, variable_type in calls)
+ assert langflow_sync.LANGFLOW_RUNTIME_CREDENTIAL_PLACEHOLDERS <= names
+ generic_calls = [c for c in calls if c[3] == "Generic"]
+ credential_calls = [c for c in calls if c[3] == "Credential"]
+ assert generic_calls
+ assert all(variable_type == "Generic" for *_, variable_type in generic_calls)
assert ("OPENSEARCH_INDEX_NAME", "documents-v2", True, "Generic") in calls
assert ("SELECTED_EMBEDDING_MODEL", "text-embedding-3-large", True, "Generic") in calls
+ assert ("OPENRAG_LLM_TOKEN", "None", True, "Credential") in credential_calls
@pytest.mark.asyncio
-async def test_update_langflow_global_variables_continues_when_one_fails(monkeypatch):
+async def test_update_langflow_global_variable_overwrites_redacted_credential():
+ """Langflow GET hides Credential values as null; still PATCH a placeholder."""
+ client = AppClients()
calls = []
- attempted_names = []
- async def create_variable(name, value, modify=False, variable_type="Credential"):
- attempted_names.append(name)
- if name == "WATSONX_APIKEY":
- raise RuntimeError("Simulated network failure on WATSONX_APIKEY")
- calls.append((name, value, modify, variable_type))
+ async def langflow_request(method, endpoint, **kwargs):
+ calls.append((method, endpoint, kwargs))
+ if method == "GET":
+ return _Response(
+ json_data=[
+ {
+ "id": "var-token",
+ "name": "OPENRAG_LLM_TOKEN",
+ "value": None,
+ "type": "Credential",
+ "default_fields": [],
+ }
+ ]
+ )
+ return _Response(status_code=200)
- monkeypatch.setattr(
- langflow_sync.clients,
- "_create_langflow_global_variable",
- create_variable,
- raising=True,
- )
+ client.langflow_request = langflow_request
- config = SimpleNamespace(
- providers=SimpleNamespace(
- watsonx=SimpleNamespace(api_key="watson-key", project_id="watson-project"),
- openai=SimpleNamespace(api_key="openai-key"),
- ),
- knowledge=SimpleNamespace(embedding_model="embedding-model", embedding_provider=None),
- agent=SimpleNamespace(llm_model=None, llm_provider=None),
+ await client._update_langflow_global_variable(
+ "OPENRAG_LLM_TOKEN", "None", variable_type="Credential"
)
- # Calling sync should raise RuntimeError at the end because WATSONX_APIKEY failed,
- # but it should have attempted all other variables first.
- with pytest.raises(RuntimeError) as exc_info:
- await langflow_sync._update_langflow_global_variables(config)
-
- assert "WATSONX_APIKEY" in str(exc_info.value)
- assert "WATSONX_APIKEY" in attempted_names
- names = {name for name, *_ in calls}
- assert "WATSONX_APIKEY" not in names
- assert "WATSONX_PROJECT_ID" in names
- assert "OPENAI_API_KEY" in names
- assert "SELECTED_EMBEDDING_MODEL" in names
+ assert calls == [
+ ("GET", "/api/v1/variables/", {}),
+ (
+ "PATCH",
+ "/api/v1/variables/var-token",
+ {
+ "json": {
+ "id": "var-token",
+ "name": "OPENRAG_LLM_TOKEN",
+ "value": "None",
+ "default_fields": [],
+ "type": "Credential",
+ }
+ },
+ ),
+ ]
@pytest.mark.asyncio
@@ -458,27 +471,16 @@ async def test_ensure_required_langflow_global_variables_handles_failed_delete_p
@pytest.mark.asyncio
-async def test_ensure_required_globals_skips_creating_empty_valued_variables(monkeypatch):
- """Unconfigured optional providers must not be POSTed to Langflow.
-
- Langflow answers 400 "Variable value cannot be empty", which the create
- helper reports as a generic "Failed to create Langflow global variable"
- warning on every boot.
- """
-
- async def mock_langflow_request(method, endpoint, **kwargs):
- if method == "GET":
- return _Response(json_data=[])
- return _Response(status_code=200)
-
- monkeypatch.setattr(
- langflow_sync.clients, "langflow_request", mock_langflow_request, raising=True
- )
-
- create_calls = []
+async def test_update_langflow_global_variables_continues_when_one_fails(monkeypatch):
+ """One failing upsert must not abort the rest; errors are aggregated (PR #2267)."""
+ calls = []
+ attempted_names = []
async def create_variable(name, value, modify=False, variable_type="Credential"):
- create_calls.append((name, value, modify, variable_type))
+ attempted_names.append(name)
+ if name == "OPENRAG_LLM_BASE_URL":
+ raise RuntimeError("Simulated network failure on OPENRAG_LLM_BASE_URL")
+ calls.append((name, value, modify, variable_type))
monkeypatch.setattr(
langflow_sync.clients,
@@ -487,200 +489,309 @@ async def test_ensure_required_globals_skips_creating_empty_valued_variables(mon
raising=True,
)
- # No ollama / watsonx configured -> OLLAMA_BASE_URL, WATSONX_PROJECT_ID and
- # WATSONX_URL all resolve to "".
- config = SimpleNamespace(providers=SimpleNamespace(), knowledge=SimpleNamespace())
+ config = SimpleNamespace(
+ knowledge=SimpleNamespace(embedding_model="embedding-model"),
+ agent=SimpleNamespace(llm_model="llm-model"),
+ )
- await langflow_sync.ensure_required_langflow_global_variables(config)
+ with pytest.raises(RuntimeError) as exc_info:
+ await langflow_sync._update_langflow_global_variables(config)
- created = {name for name, *_ in create_calls}
- assert "OLLAMA_BASE_URL" not in created
- assert "WATSONX_PROJECT_ID" not in created
- assert "WATSONX_URL" not in created
- # Variables that do have a value are still created.
- assert "OPENSEARCH_INDEX_NAME" in created
- assert all(value for _, value, *_ in create_calls)
+ assert "OPENRAG_LLM_BASE_URL" in str(exc_info.value)
+ assert "OPENRAG_LLM_BASE_URL" in attempted_names
+
+ names = {name for name, *_ in calls}
+ assert "OPENRAG_LLM_BASE_URL" not in names
+ assert "SELECTED_EMBEDDING_MODEL" in names
+ assert "SELECTED_LANGUAGE_MODEL" in names
+ assert langflow_sync.LANGFLOW_RUNTIME_CREDENTIAL_PLACEHOLDERS <= names
@pytest.mark.asyncio
-async def test_ensure_required_globals_creates_optional_provider_var_once_configured(monkeypatch):
- async def mock_langflow_request(method, endpoint, **kwargs):
- if method == "GET":
- return _Response(json_data=[])
- return _Response(status_code=200)
+async def test_model_change_pushes_selected_model_globals(monkeypatch):
+ """A model-only settings change must reach Langflow.
+
+ The flows use one OpenAI-compatible component per kind, so
+ `change_langflow_model_value` finds no per-provider node to patch and the
+ SELECTED_*_MODEL global variables are the only channel left. Those globals
+ used to be written solely when provider credentials changed, which left the
+ retrieval flow embedding with — and labelling chunks as — the previous
+ model until some unrelated credential edit happened to resync it.
+ """
+ upserts: list[tuple[str, str]] = []
- monkeypatch.setattr(
- langflow_sync.clients, "langflow_request", mock_langflow_request, raising=True
- )
+ async def fake_upsert(name, value, **kwargs):
+ upserts.append((name, value))
- create_calls = []
+ monkeypatch.setattr(langflow_sync, "_upsert_langflow_global_variable", fake_upsert)
- async def create_variable(name, value, modify=False, variable_type="Credential"):
- create_calls.append((name, value, modify, variable_type))
+ class _FlowsService:
+ def __init__(self):
+ self.calls = []
- monkeypatch.setattr(
- langflow_sync.clients,
- "_create_langflow_global_variable",
- create_variable,
- raising=True,
+ async def change_langflow_model_value(self, provider, **kwargs):
+ self.calls.append((provider, kwargs))
+ return {"updated": []}
+
+ config = SimpleNamespace(
+ agent=SimpleNamespace(llm_model="gpt-4o-mini", llm_provider="openai"),
+ knowledge=SimpleNamespace(
+ embedding_model="ibm/slate-125m-english-rtrvr-v2",
+ embedding_provider="watsonx",
+ ),
+ )
+
+ await langflow_sync._update_langflow_model_values(
+ config,
+ _FlowsService(),
+ embedding_model="ibm/slate-125m-english-rtrvr-v2",
+ embedding_provider="watsonx",
)
+ assert ("SELECTED_EMBEDDING_MODEL", "ibm/slate-125m-english-rtrvr-v2") in upserts
+ assert not any(name == "SELECTED_LANGUAGE_MODEL" for name, _ in upserts)
+
+
+async def test_llm_model_change_pushes_selected_language_model(monkeypatch):
+ upserts: list[tuple[str, str]] = []
+
+ async def fake_upsert(name, value, **kwargs):
+ upserts.append((name, value))
+
+ monkeypatch.setattr(langflow_sync, "_upsert_langflow_global_variable", fake_upsert)
+
+ class _FlowsService:
+ async def change_langflow_model_value(self, provider, **kwargs):
+ return {"updated": []}
+
config = SimpleNamespace(
- providers=SimpleNamespace(ollama=SimpleNamespace(endpoint="http://localhost:11434")),
- knowledge=SimpleNamespace(),
+ agent=SimpleNamespace(llm_model="ibm/granite-4-h-small", llm_provider="watsonx"),
+ knowledge=SimpleNamespace(embedding_model="", embedding_provider="watsonx"),
)
- await langflow_sync.ensure_required_langflow_global_variables(config)
+ await langflow_sync._update_langflow_model_values(
+ config,
+ _FlowsService(),
+ llm_model="ibm/granite-4-h-small",
+ llm_provider="watsonx",
+ )
- assert ("OLLAMA_BASE_URL", "http://localhost:11434", True, "Generic") in create_calls
+ assert ("SELECTED_LANGUAGE_MODEL", "ibm/granite-4-h-small") in upserts
@pytest.mark.asyncio
-async def test_ensure_required_globals_does_not_blank_existing_value(monkeypatch):
- """An existing variable must not be PATCHed to "" when its provider is gone.
+async def test_selected_model_upsert_failure_is_not_fatal(monkeypatch):
+ async def boom(name, value, **kwargs):
+ raise RuntimeError("langflow down")
- Langflow rejects the empty value, so the PATCH would fail and log a warning
- every boot while leaving the stored value untouched anyway.
- """
- langflow_calls = []
+ monkeypatch.setattr(langflow_sync, "_upsert_langflow_global_variable", boom)
+
+ calls = []
+
+ class _FlowsService:
+ async def change_langflow_model_value(self, provider, **kwargs):
+ calls.append(provider)
+ return {"updated": []}
+
+ config = SimpleNamespace(
+ agent=SimpleNamespace(llm_model="gpt-4o-mini", llm_provider="openai"),
+ knowledge=SimpleNamespace(
+ embedding_model="text-embedding-3-small", embedding_provider="openai"
+ ),
+ )
+
+ await langflow_sync._update_langflow_model_values(
+ config,
+ _FlowsService(),
+ embedding_model="text-embedding-3-small",
+ embedding_provider="openai",
+ )
+
+ assert calls == ["openai"]
+
+
+# --- guards carried over from main (#2265) -------------------------------
+# Those tests exercised OLLAMA_BASE_URL / WATSONX_URL / WATSONX_PROJECT_ID.
+# This branch stops publishing vendor endpoints to Langflow entirely - the
+# /v1 proxy holds the credentials - so those names are no longer in
+# LANGFLOW_GENERIC_GLOBAL_VARIABLES and the originals would have passed
+# vacuously. They are retargeted at OPENRAG_LLM_BASE_URL, which is generic
+# and can still resolve to "" when the proxy URL is not derivable.
+
+def _patch_llm_base_url(monkeypatch, value: str) -> None:
+ monkeypatch.setattr(
+ langflow_sync.settings, "get_langflow_llm_base_url", lambda: value, raising=True
+ )
+
+
+def _stub_langflow(monkeypatch, existing=None, calls=None):
async def mock_langflow_request(method, endpoint, **kwargs):
- langflow_calls.append((method, endpoint, kwargs))
+ if calls is not None:
+ calls.append((method, endpoint, kwargs))
if method == "GET":
- return _Response(
- json_data=[
- {
- "id": "var-1",
- "name": "OLLAMA_BASE_URL",
- "value": "http://localhost:11434",
- "type": "Generic",
- "default_fields": [],
- }
- ]
- )
- return _Response(status_code=200)
+ return _Response(json_data=existing or [])
+ if method == "DELETE":
+ return _Response(status_code=204)
+ return _Response(status_code=201)
monkeypatch.setattr(
langflow_sync.clients, "langflow_request", mock_langflow_request, raising=True
)
+
+async def test_ensure_required_globals_skips_creating_empty_valued_variables(monkeypatch):
+ """Langflow answers 400 "Variable value cannot be empty" for a blank value.
+
+ Creating one anyway logs a "Failed to create Langflow global variable"
+ warning on every boot.
+ """
+ _stub_langflow(monkeypatch)
+ _patch_llm_base_url(monkeypatch, "")
+
+ create_calls = []
+
async def create_variable(name, value, modify=False, variable_type="Credential"):
- pass
+ create_calls.append((name, value, modify, variable_type))
monkeypatch.setattr(
- langflow_sync.clients,
- "_create_langflow_global_variable",
- create_variable,
- raising=True,
+ langflow_sync.clients, "_create_langflow_global_variable", create_variable, raising=True
)
- # ollama no longer configured -> target value is ""
config = SimpleNamespace(providers=SimpleNamespace(), knowledge=SimpleNamespace())
-
await langflow_sync.ensure_required_langflow_global_variables(config)
- assert [c for c in langflow_calls if c[0] == "PATCH"] == []
+ created = {name for name, *_ in create_calls}
+ assert "OPENRAG_LLM_BASE_URL" not in created
+ # Variables that do have a value are still created.
+ assert "OPENSEARCH_INDEX_NAME" in created
+ assert all(value for _, value, *_ in create_calls)
@pytest.mark.asyncio
-async def test_ensure_required_globals_type_migration_keeps_value_when_target_empty(monkeypatch):
- """A Credential->Generic migration must not recreate the variable with "".
+async def test_ensure_required_globals_creates_the_variable_once_it_has_a_value(monkeypatch):
+ _stub_langflow(monkeypatch)
+ _patch_llm_base_url(monkeypatch, "http://openrag-backend:8000/v1")
- The DELETE has already landed by then, so a 400 on the recreate would drop
- the variable entirely.
- """
- langflow_calls = []
+ create_calls = []
- async def mock_langflow_request(method, endpoint, **kwargs):
- langflow_calls.append((method, endpoint, kwargs))
- if method == "GET":
- return _Response(
- json_data=[
- {
- "id": "var-1",
- "name": "WATSONX_URL",
- "value": "https://us-south.ml.cloud.ibm.com",
- "type": "Credential",
- "default_fields": [],
- }
- ]
- )
- if method == "DELETE":
- return _Response(status_code=204)
- return _Response(status_code=201)
+ async def create_variable(name, value, modify=False, variable_type="Credential"):
+ create_calls.append((name, value, modify, variable_type))
monkeypatch.setattr(
- langflow_sync.clients, "langflow_request", mock_langflow_request, raising=True
+ langflow_sync.clients, "_create_langflow_global_variable", create_variable, raising=True
+ )
+
+ config = SimpleNamespace(providers=SimpleNamespace(), knowledge=SimpleNamespace())
+ await langflow_sync.ensure_required_langflow_global_variables(config)
+
+ assert (
+ "OPENRAG_LLM_BASE_URL",
+ "http://openrag-backend:8000/v1",
+ True,
+ "Generic",
+ ) in create_calls
+
+
+async def test_ensure_required_globals_does_not_blank_an_existing_value(monkeypatch):
+ """An empty target must never overwrite what Langflow already holds."""
+ calls = []
+ _stub_langflow(
+ monkeypatch,
+ existing=[
+ {
+ "id": "var-1",
+ "name": "OPENRAG_LLM_BASE_URL",
+ "value": "http://openrag-backend:8000/v1",
+ "type": "Generic",
+ "default_fields": [],
+ }
+ ],
+ calls=calls,
)
+ _patch_llm_base_url(monkeypatch, "")
async def create_variable(name, value, modify=False, variable_type="Credential"):
pass
monkeypatch.setattr(
- langflow_sync.clients,
- "_create_langflow_global_variable",
- create_variable,
- raising=True,
+ langflow_sync.clients, "_create_langflow_global_variable", create_variable, raising=True
)
config = SimpleNamespace(providers=SimpleNamespace(), knowledge=SimpleNamespace())
-
await langflow_sync.ensure_required_langflow_global_variables(config)
- posts = [c for c in langflow_calls if c[0] == "POST"]
- assert len(posts) == 1
- # Recreated as Generic, but carrying the value Langflow already held.
- assert posts[0][2]["json"]["value"] == "https://us-south.ml.cloud.ibm.com"
- assert posts[0][2]["json"]["type"] == "Generic"
+ patched = [c for c in calls if c[0] == "PATCH" and "var-1" in c[1]]
+ assert patched == []
@pytest.mark.asyncio
async def test_ensure_required_globals_defers_type_migration_when_value_is_empty(monkeypatch):
- """A Credential->Generic migration must not delete a variable it can't recreate.
-
- Unlike the "keeps_value_when_target_empty" case above, here the *retained*
- value is also empty (an unconfigured WATSONX_URL stored as Credential).
- Deleting and then recreating with "" would 400, dropping the variable
- entirely, so the migration must be deferred until it has a value.
- """
- langflow_calls = []
+ """The DELETE lands before the recreate, so a refused POST would drop it."""
+ calls = []
+ _stub_langflow(
+ monkeypatch,
+ existing=[
+ {
+ "id": "var-1",
+ "name": "OPENRAG_LLM_BASE_URL",
+ "value": "",
+ "type": "Credential",
+ "default_fields": [],
+ }
+ ],
+ calls=calls,
+ )
+ _patch_llm_base_url(monkeypatch, "")
- async def mock_langflow_request(method, endpoint, **kwargs):
- langflow_calls.append((method, endpoint, kwargs))
- if method == "GET":
- return _Response(
- json_data=[
- {
- "id": "var-1",
- "name": "WATSONX_URL",
- "value": "",
- "type": "Credential",
- "default_fields": [],
- }
- ]
- )
- return _Response(status_code=200)
+ async def create_variable(name, value, modify=False, variable_type="Credential"):
+ pass
monkeypatch.setattr(
- langflow_sync.clients, "langflow_request", mock_langflow_request, raising=True
+ langflow_sync.clients, "_create_langflow_global_variable", create_variable, raising=True
+ )
+
+ config = SimpleNamespace(providers=SimpleNamespace(), knowledge=SimpleNamespace())
+ await langflow_sync.ensure_required_langflow_global_variables(config)
+
+ touched = [c for c in calls if "var-1" in c[1]]
+ assert touched == []
+
+
+async def test_ensure_required_globals_migration_keeps_the_value_when_target_empty(monkeypatch):
+ """A Credential->Generic migration must not recreate the variable with ""."""
+ calls = []
+ _stub_langflow(
+ monkeypatch,
+ existing=[
+ {
+ "id": "var-1",
+ "name": "OPENRAG_LLM_BASE_URL",
+ "value": "http://openrag-backend:8000/v1",
+ "type": "Credential",
+ "default_fields": [],
+ }
+ ],
+ calls=calls,
)
+ _patch_llm_base_url(monkeypatch, "")
async def create_variable(name, value, modify=False, variable_type="Credential"):
pass
monkeypatch.setattr(
- langflow_sync.clients,
- "_create_langflow_global_variable",
- create_variable,
- raising=True,
+ langflow_sync.clients, "_create_langflow_global_variable", create_variable, raising=True
)
- # watsonx is not configured -> WATSONX_URL resolves to "".
config = SimpleNamespace(providers=SimpleNamespace(), knowledge=SimpleNamespace())
-
await langflow_sync.ensure_required_langflow_global_variables(config)
- methods = [c[0] for c in langflow_calls]
- assert "DELETE" not in methods
- assert "POST" not in methods
- assert "PATCH" not in methods
+ posts = [c for c in calls if c[0] == "POST"]
+ assert len(posts) == 1
+ # Recreated as Generic, carrying the value Langflow already held.
+ assert posts[0][2]["json"]["value"] == "http://openrag-backend:8000/v1"
+ assert posts[0][2]["json"]["type"] == "Generic"
diff --git a/tests/unit/test_langflow_ingest_callback.py b/tests/unit/test_langflow_ingest_callback.py
index 1405fe282..b3be59cca 100644
--- a/tests/unit/test_langflow_ingest_callback.py
+++ b/tests/unit/test_langflow_ingest_callback.py
@@ -321,7 +321,7 @@ def test_ingest_flows_resolve_callback_config_from_global_vars(flow_path, compon
assert template["openrag_ingest_url"]["input_types"] == ["Text", "Message"]
assert template["openrag_ingest_token"]["input_types"] == ["Text", "Message"]
assert template["openrag_ingest_run_id"]["input_types"] == ["Text", "Message"]
- assert template["openrag_ingest_token"]["_input_type"] == "StrInput"
+ assert template["openrag_ingest_token"]["_input_type"] == "SecretStrInput"
assert "OPENRAG_INGEST_URL" in template["code"]["value"]
assert "_openrag_ingest_global_placeholders" in template["code"]["value"]
assert 'url = self._openrag_callback_value("openrag_ingest_url")' in template["code"]["value"]
diff --git a/tests/unit/test_langflow_llm_proxy_headers.py b/tests/unit/test_langflow_llm_proxy_headers.py
new file mode 100644
index 000000000..4f34c01ef
--- /dev/null
+++ b/tests/unit/test_langflow_llm_proxy_headers.py
@@ -0,0 +1,94 @@
+"""Langflow talks to the OpenRAG LLM proxy with a hop token, not provider keys."""
+
+from types import SimpleNamespace
+
+import pytest
+
+from services.langflow_llm_token_service import LangflowLlmTokenService
+from utils.langflow_headers import (
+ add_provider_credentials_to_headers,
+ build_model_provider_headers,
+)
+
+
+def test_build_model_provider_headers_forces_openai_client():
+ config = SimpleNamespace(
+ knowledge=SimpleNamespace(
+ embedding_model="text-embedding-3-small", embedding_provider="watsonx"
+ ),
+ agent=SimpleNamespace(llm_model="claude-sonnet-4-5", llm_provider="anthropic"),
+ )
+ headers = build_model_provider_headers(config)
+ assert headers["X-LANGFLOW-GLOBAL-VAR-SELECTED_LANGUAGE_MODEL"] == "claude-sonnet-4-5"
+ assert headers["X-LANGFLOW-GLOBAL-VAR-SELECTED_LANGUAGE_MODEL_PROVIDER"] == "OpenAI"
+ assert headers["X-LANGFLOW-GLOBAL-VAR-SELECTED_EMBEDDING_MODEL"] == "text-embedding-3-small"
+ assert headers["X-LANGFLOW-GLOBAL-VAR-SELECTED_EMBEDDING_MODEL_PROVIDER"] == "OpenAI"
+
+
+async def test_add_provider_credentials_injects_hop_token_not_jwt_or_provider_keys(
+ monkeypatch,
+):
+ monkeypatch.setattr(
+ "config.settings.get_langflow_llm_base_url",
+ lambda: "http://openrag-backend:8000/v1",
+ )
+ monkeypatch.setattr("config.settings.get_langflow_opensearch_url", lambda: "")
+ monkeypatch.setattr("config.settings.get_langflow_docling_url", lambda: "")
+ monkeypatch.setattr("config.settings.get_index_name", lambda: "")
+ monkeypatch.setattr("config.settings.IBM_AUTH_ENABLED", False)
+
+ config = SimpleNamespace(
+ providers=SimpleNamespace(
+ openai=SimpleNamespace(api_key="sk-real-openai"),
+ anthropic=SimpleNamespace(api_key="sk-ant-real"),
+ watsonx=SimpleNamespace(api_key="wx-real", project_id="p", endpoint="https://wx"),
+ ollama=SimpleNamespace(endpoint="http://localhost:11434"),
+ )
+ )
+ headers = {}
+ await add_provider_credentials_to_headers(
+ headers, config, jwt_token="Bearer user-jwt-token", user_id="alice"
+ )
+ hop = headers["X-LANGFLOW-GLOBAL-VAR-OPENRAG_LLM_TOKEN"]
+ assert hop != "user-jwt-token"
+ user = LangflowLlmTokenService().validate_token(hop)
+ assert user.user_id == "alice"
+ assert user.provider == "langflow_llm"
+ assert headers["X-LANGFLOW-GLOBAL-VAR-OPENRAG_LLM_BASE_URL"] == "http://openrag-backend:8000/v1"
+ # Chat (`/v1/chat/completions`) and embeddings (`/v1/embeddings`) share these.
+ assert headers["X-LANGFLOW-GLOBAL-VAR-OPENAI_API_KEY"] == hop
+ assert "X-LANGFLOW-GLOBAL-VAR-OPENRAG_LLM_TOKEN" in headers
+ # Match on the serialized headers: `in headers.values()` compares whole
+ # values, so a secret embedded in a larger value ("Bearer sk-real-openai")
+ # would slip past the very leak this test exists to catch.
+ serialized = "\n".join(f"{name}: {value}" for name, value in headers.items())
+ for secret in ("sk-real-openai", "sk-ant-real", "wx-real"):
+ assert secret not in serialized
+ assert "X-LANGFLOW-GLOBAL-VAR-ANTHROPIC_API_KEY" not in headers
+ assert "X-LANGFLOW-GLOBAL-VAR-WATSONX_APIKEY" not in headers
+
+
+async def test_hop_token_is_minted_when_caller_only_has_ibm_basic():
+ """Basic OpenSearch creds cannot be an OpenAI api_key; mint a hop token instead."""
+ from unittest.mock import patch
+
+ with (
+ patch(
+ "config.settings.get_langflow_llm_base_url", lambda: "http://openrag-backend:8000/v1"
+ ),
+ patch("config.settings.get_langflow_opensearch_url", lambda: ""),
+ patch("config.settings.get_langflow_docling_url", lambda: ""),
+ patch("config.settings.get_index_name", lambda: ""),
+ patch("config.settings.IBM_AUTH_ENABLED", False),
+ ):
+ headers = {}
+ await add_provider_credentials_to_headers(
+ headers, SimpleNamespace(), jwt_token="Basic dXNlcjpwYXNz", user_id="ibm-user"
+ )
+ hop = headers["X-LANGFLOW-GLOBAL-VAR-OPENRAG_LLM_TOKEN"]
+ user = LangflowLlmTokenService().validate_token(hop)
+ assert user.user_id == "ibm-user"
+ assert not hop.startswith("Basic ")
+ assert headers["X-LANGFLOW-GLOBAL-VAR-OPENAI_API_KEY"] == hop
diff --git a/tests/unit/test_models_api_errors.py b/tests/unit/test_models_api_errors.py
index f4d8a5c36..15924fa3d 100644
--- a/tests/unit/test_models_api_errors.py
+++ b/tests/unit/test_models_api_errors.py
@@ -134,3 +134,35 @@ async def test_get_ibm_models_returns_project_configuration_error():
assert response.status_code == 400
payload = json.loads(response.body)
assert payload["error"] == msg
+
+
+async def test_get_model_catalog_returns_only_supported_providers():
+ response = await models_api.get_model_catalog(user=SimpleNamespace())
+ assert isinstance(response, JSONResponse)
+ assert response.status_code == 200
+ payload = json.loads(response.body)
+ keys = {provider["key"] for provider in payload["providers"]}
+ assert keys == {"openai", "anthropic", "ollama", "watsonx"}
+ openai = next(p for p in payload["providers"] if p["key"] == "openai")
+ assert openai["models"]
+ assert openai["embedding_models"]
+ cache_control = response.headers.get("cache-control") or response.headers.get("Cache-Control")
+ assert cache_control == "private, max-age=3600"
+
+
+async def test_get_model_catalog_hides_catalog_exception_text(monkeypatch):
+ """CodeQL py/stack-trace-exposure: log the cause, return a fixed message."""
+ from services import model_catalog
+
+ def boom(*args, **kwargs):
+ raise model_catalog.CatalogUnavailableError("litellm is not installed on the server")
+
+ monkeypatch.setattr(model_catalog, "catalog", boom)
+
+ response = await models_api.get_model_catalog(user=SimpleNamespace())
+ assert response.status_code == 503
+ body = response.body.decode()
+ assert json.loads(body)["error"] == model_catalog.CATALOG_UNAVAILABLE_MESSAGE
+ assert "litellm" not in body
diff --git a/tests/unit/test_openai_compatible_langflow_components.py b/tests/unit/test_openai_compatible_langflow_components.py
new file mode 100644
index 000000000..b01def6d7
--- /dev/null
+++ b/tests/unit/test_openai_compatible_langflow_components.py
@@ -0,0 +1,190 @@
+"""OpenAI-compatible Langflow components bind proxy globals at runtime."""
+
+import hashlib
+import json
+from pathlib import Path
+
+# The Langflow bundle is the single home for these components: the former
+# ``flows/components`` copies were removed once the bundle became canonical.
+BUNDLE = Path("custom_components/openrag")
+# Langflow 1.11 rewrites the bare class name to ``ext:elastic:...@official``
+# via its extension migration table, so the OpenRAG copy must be referenced by
+# its own canonical extension id everywhere (index key and flow node types).
+OPENSEARCH_EXT_ID = "ext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra"
+OPENSEARCH_MODULE = "_lfx_ext.extra.openrag.opensearch_multimodal"
+# Langflow uses the bundle directory name as the sidebar category label.
+BUNDLE_NAME = "OpenRAG"
+
+
+def test_llm_component_binds_proxy_globals():
+ code = (BUNDLE / "openai_compatible_llm.py").read_text(encoding="utf-8")
+ assert 'OPENRAG_LLM_BASE_URL_VAR = "OPENRAG_LLM_BASE_URL"' in code
+ assert 'OPENRAG_LLM_TOKEN_VAR = "OPENRAG_LLM_TOKEN"' in code
+ assert 'SELECTED_LANGUAGE_MODEL_VAR = "SELECTED_LANGUAGE_MODEL"' in code
+ assert 'name="api_key"' in code
+ assert 'name="api_base"' in code
+ assert "load_from_db=True" in code
+ assert "ChatOpenAI" in code
+ assert "class OpenAICompatibleLLMComponent" in code
+
+
+def test_embedding_component_uses_the_same_proxy_globals():
+ """Embeddings hit /v1/embeddings with the same hop token and /v1 base URL."""
+ llm = (BUNDLE / "openai_compatible_llm.py").read_text(encoding="utf-8")
+ embedding = (BUNDLE / "openai_compatible_embedding.py").read_text(encoding="utf-8")
+
+ assert 'OPENRAG_LLM_BASE_URL_VAR = "OPENRAG_LLM_BASE_URL"' in embedding
+ assert 'OPENRAG_LLM_TOKEN_VAR = "OPENRAG_LLM_TOKEN"' in embedding
+ assert 'SELECTED_EMBEDDING_MODEL_VAR = "SELECTED_EMBEDDING_MODEL"' in embedding
+ assert 'name="api_key"' in embedding
+ assert 'name="api_base"' in embedding
+ assert "load_from_db=True" in embedding
+ assert "OpenAIEmbeddings" in embedding
+ assert "check_embedding_ctx_length" in embedding
+ assert "class OpenAICompatibleEmbeddingComponent" in embedding
+
+ assert 'OPENRAG_LLM_BASE_URL_VAR = "OPENRAG_LLM_BASE_URL"' in llm
+ assert 'OPENRAG_LLM_TOKEN_VAR = "OPENRAG_LLM_TOKEN"' in llm
+
+
+def test_langflow_runtime_globals_cover_chat_and_embeddings():
+ from api.settings.langflow_sync import (
+ LANGFLOW_CREDENTIAL_GLOBAL_VARIABLES,
+ LANGFLOW_GENERIC_GLOBAL_VARIABLES,
+ LANGFLOW_RUNTIME_CREDENTIAL_PLACEHOLDERS,
+ )
+
+ assert "OPENRAG_LLM_TOKEN" in LANGFLOW_CREDENTIAL_GLOBAL_VARIABLES
+ assert "OPENRAG_LLM_TOKEN" in LANGFLOW_RUNTIME_CREDENTIAL_PLACEHOLDERS
+ assert {
+ "OPENRAG_LLM_BASE_URL",
+ "SELECTED_LANGUAGE_MODEL",
+ "SELECTED_EMBEDDING_MODEL",
+ } <= LANGFLOW_GENERIC_GLOBAL_VARIABLES
+
+ source = Path("src/services/flows_service.py").read_text(encoding="utf-8")
+ assert '"api_key": "OPENRAG_LLM_TOKEN"' in source
+ assert '"openai_api_key": "OPENRAG_LLM_TOKEN"' in source
+ assert '"api_base": "OPENRAG_LLM_BASE_URL"' in source
+ assert '"openai_api_base": "OPENRAG_LLM_BASE_URL"' in source
+
+
+def test_langflow_image_ships_the_openrag_bundle_as_a_components_path():
+ """The OpenRAG components are delivered by scan, not by the component index.
+
+ ``flows/component_index.json`` is Langflow's stock index and carries no
+ OpenRAG bundle; the image instead copies ``custom_components/`` in and
+ points ``LANGFLOW_COMPONENTS_PATH`` at it, so Langflow discovers the bundle
+ when it scans. If that copy or that env var goes away, every flow node
+ typed ``ext:openrag:...`` stops resolving.
+ """
+ dockerfile = Path("Dockerfile.langflow").read_text(encoding="utf-8")
+ assert "COPY custom_components/ /app/custom_components/" in dockerfile
+ assert "ENV LANGFLOW_COMPONENTS_PATH=/app/custom_components" in dockerfile
+
+ for name in (
+ "openai_compatible_llm.py",
+ "openai_compatible_embedding.py",
+ "opensearch_multimodal.py",
+ ):
+ assert (BUNDLE / name).is_file(), name
+
+ index = json.loads(Path("flows/component_index.json").read_text(encoding="utf-8"))
+ assert BUNDLE_NAME not in dict(index["entries"])
+
+
+def test_docker_compose_seeds_openrag_llm_token_placeholder():
+ compose = Path("docker-compose.yml").read_text(encoding="utf-8")
+ assert "LANGFLOW_COMPONENTS_INDEX_PATH=/app/flows/component_index.json" in compose
+ assert "OPENRAG_LLM_TOKEN=None" in compose
+ assert (
+ "OPENRAG_LLM_TOKEN"
+ in compose.split("LANGFLOW_VARIABLES_TO_GET_FROM_ENVIRONMENT=", 1)[1].split("\n", 1)[0]
+ )
+ helm = Path("kubernetes/helm/openrag/templates/langflow/langflow-dotenv.yaml").read_text(
+ encoding="utf-8"
+ )
+ assert 'OPENRAG_LLM_TOKEN="None"' in helm
+
+
+def test_component_index_sha256_matches_langflow_integrity_check():
+ """Langflow recomputes this digest and silently drops a mismatching index.
+
+ It hashes ``orjson.dumps(index_without_sha, option=OPT_SORT_KEYS)``, which
+ emits UTF-8 rather than the ASCII escapes ``json.dumps`` produces by
+ default. A digest built the other way makes Langflow log
+ "SHA256 mismatch" and fall back to a scan with no OpenRAG bundle, which
+ blocks every flow that uses one of our components.
+ """
+ raw = json.loads(Path("flows/component_index.json").read_text(encoding="utf-8"))
+ stored = raw.pop("sha256")
+ payload = json.dumps(raw, sort_keys=True, separators=(",", ":"), ensure_ascii=False).encode(
+ "utf-8"
+ )
+ assert stored == hashlib.sha256(payload).hexdigest()
+
+
+def test_flows_reference_opensearch_by_canonical_extension_id():
+ """A bare class-name reference gets hijacked by Langflow's migration table."""
+ for path in sorted(Path("flows").glob("*.json")):
+ if path.name == "component_index.json":
+ continue
+ flow = json.loads(path.read_text(encoding="utf-8"))
+ for node in flow.get("data", {}).get("nodes", []):
+ node_type = node.get("data", {}).get("type")
+ if node_type and "OpenSearchVectorStoreComponentMultimodalMultiEmbedding" in node_type:
+ assert node_type == OPENSEARCH_EXT_ID, path.name
+ metadata = node["data"]["node"].get("metadata") or {}
+ assert metadata.get("module") == OPENSEARCH_MODULE, path.name
+
+
+def test_openrag_bundle_directory_is_lowercase_snake_case():
+ """Langflow rejects inline bundle dirs that are not lowercase snake_case."""
+ assert BUNDLE.is_dir()
+ assert BUNDLE.name.islower()
+ assert not Path("custom_components/OpenRAG").is_dir() or BUNDLE.samefile(
+ Path("custom_components/OpenRAG")
+ )
+
+
+def test_embedding_component_pins_deployment_to_the_configured_model():
+ """`OpenAIEmbeddings.deployment` must not keep LangChain's class default.
+
+ That default is the literal "text-embedding-ada-002" for every instance,
+ whatever model is configured. The OpenSearch component keys its embedding
+ lookup on `deployment` as well as `model`, so the default registers a
+ 768-dim watsonx embedder under ada-002 and OpenSearch then rejects the
+ search with "Query vector has invalid dimension: 768. Dimension should be:
+ 1536".
+ """
+ code = (BUNDLE / "openai_compatible_embedding.py").read_text(encoding="utf-8")
+ assert '"deployment": self.model_name' in code
+
+
+def test_flows_embed_the_current_proxy_component_sources():
+ """Flow JSONs carry their own copy of each component; keep them in step.
+
+ A fix applied only to `custom_components/` never reaches a running flow,
+ because Langflow executes the code embedded in the flow node.
+ """
+ for name, node_type in (
+ ("openai_compatible_embedding.py", "OpenAICompatibleEmbedding"),
+ ("openai_compatible_llm.py", "OpenAICompatibleLLM"),
+ ):
+ source = (BUNDLE / name).read_text(encoding="utf-8")
+ expected_hash = hashlib.sha256(source.encode("utf-8")).hexdigest()[:12]
+
+ for path in sorted(Path("flows").glob("*.json")):
+ if path.name == "component_index.json":
+ continue
+ flow = json.loads(path.read_text(encoding="utf-8"))
+ for node in flow.get("data", {}).get("nodes", []):
+ if node.get("data", {}).get("type") != node_type:
+ continue
+ component = node["data"]["node"]
+ assert component["template"]["code"]["value"] == source, (
+ f"{path.name}: embedded {name} is out of sync with the bundle"
+ )
+ assert component.get("metadata", {}).get("code_hash") == expected_hash, (
+ f"{path.name}: {node_type} metadata.code_hash is stale"
+ )
diff --git a/tests/unit/test_patch_langflow_openrag_bundle.py b/tests/unit/test_patch_langflow_openrag_bundle.py
new file mode 100644
index 000000000..cc6c59601
--- /dev/null
+++ b/tests/unit/test_patch_langflow_openrag_bundle.py
@@ -0,0 +1,90 @@
+"""Langflow SIDEBAR_BUNDLES patch registers the OpenRAG custom-component group."""
+
+import importlib.util
+from pathlib import Path
+
+SCRIPT = Path("scripts/patch_langflow_openrag_bundle.py")
+
+
+def _load():
+ spec = importlib.util.spec_from_file_location("patch_langflow_openrag_bundle", SCRIPT)
+ assert spec is not None and spec.loader is not None
+ module = importlib.util.module_from_spec(spec)
+ spec.loader.exec_module(module)
+ return module
+
+
+def test_patch_inserts_pretty_typescript_entries_for_both_folder_casings():
+ patch = _load()
+ source = """export const SIDEBAR_BUNDLES = [
+ { display_name: "OpenAI", name: "openai", icon: "OpenAI" },
+ { display_name: "OpenRouter", name: "openrouter", icon: "OpenRouter" },
+];
+"""
+ updated = patch.patch_text(source)
+ assert updated is not None
+ assert '{ display_name: "OpenRAG", name: "OpenRAG", icon: "OpenRAG" }' in updated
+ assert '{ display_name: "OpenRAG", name: "openrag", icon: "OpenRAG" }' in updated
+ assert updated.index("OpenAI") < updated.index('name: "OpenRAG"') < updated.index("OpenRouter")
+ assert patch.patch_text(updated) == updated
+
+
+def test_patch_inserts_minified_javascript_entries():
+ patch = _load()
+ source = (
+ 'var B=[{display_name:"OpenAI",name:"openai",icon:"OpenAI"},'
+ '{display_name:"OpenRouter",name:"openrouter",icon:"OpenRouter"}];'
+ )
+ updated = patch.patch_text(source)
+ assert updated is not None
+ assert '{display_name:"OpenRAG",name:"OpenRAG",icon:"OpenRAG"}' in updated
+ assert '{display_name:"OpenRAG",name:"openrag",icon:"OpenRAG"}' in updated
+ assert patch.patch_text(updated) == updated
+
+
+def test_patch_inserts_quoted_json_keys_used_by_some_bundlers():
+ patch = _load()
+ source = (
+ '[{"display_name":"OpenAI","name":"openai","icon":"OpenAI"},'
+ '{"display_name":"OpenRouter","name":"openrouter","icon":"OpenRouter"}]'
+ )
+ updated = patch.patch_text(source)
+ assert updated is not None
+ assert '{"display_name":"OpenRAG","name":"OpenRAG","icon":"OpenRAG"}' in updated
+ assert '{"display_name":"OpenRAG","name":"openrag","icon":"OpenRAG"}' in updated
+ assert patch.patch_text(updated) == updated
+
+
+def test_patch_adds_lowercase_name_when_title_case_already_exists():
+ patch = _load()
+ source = """export const SIDEBAR_BUNDLES = [
+ { display_name: "OpenAI", name: "openai", icon: "OpenAI" },
+ { display_name: "OpenRAG", name: "OpenRAG", icon: "OpenRAG" },
+ { display_name: "OpenRouter", name: "openrouter", icon: "OpenRouter" },
+];
+"""
+ updated = patch.patch_text(source)
+ assert updated is not None
+ assert '{ display_name: "OpenRAG", name: "openrag", icon: "OpenRAG" }' in updated
+ assert updated.count('{ display_name: "OpenRAG", name: "OpenRAG", icon: "OpenRAG" }') == 1
+ assert patch.patch_text(updated) == updated
+
+
+def test_patch_files_and_dockerfiles_wire_the_script(tmp_path):
+ patch = _load()
+ target = tmp_path / "styleUtils.ts"
+ target.write_text(
+ '{ display_name: "Docling", name: "docling", icon: "Docling" },\n',
+ encoding="utf-8",
+ )
+ assert patch.patch_paths([target]) == 1
+ text = target.read_text(encoding="utf-8")
+ assert '{ display_name: "OpenRAG", name: "OpenRAG", icon: "OpenRAG" }' in text
+ assert '{ display_name: "OpenRAG", name: "openrag", icon: "OpenRAG" }' in text
+
+ prod = Path("Dockerfile.langflow").read_text(encoding="utf-8")
+ dev = Path("Dockerfile.langflow.dev").read_text(encoding="utf-8")
+ assert "patch_langflow_openrag_bundle.py" in prod
+ assert "python3 /tmp/patch_langflow_openrag_bundle.py" in prod
+ assert "patch_langflow_openrag_bundle.py" in dev
+ assert "styleUtils.ts" in dev
diff --git a/tests/unit/test_provider_health_cache_key.py b/tests/unit/test_provider_health_cache_key.py
new file mode 100644
index 000000000..563a5ce30
--- /dev/null
+++ b/tests/unit/test_provider_health_cache_key.py
@@ -0,0 +1,145 @@
+"""The health-cache key must accept everything ``check_provider_health`` sends.
+
+A missing keyword here is not a quiet degradation: ``cache_key()`` is called
+before any provider validation runs, so a ``TypeError`` there surfaces in the
+UI as "<Provider> error - cache_key() got an unexpected keyword argument ..."
+for whichever provider happens to be configured — i.e. it breaks the health
+banner for every provider at once.
+"""
+
+import inspect
+
+from api import provider_health
+from utils import provider_health_cache
+
+
+def _calls(function_name: str, callee: str) -> list[set[str]]:
+ """Keyword names for each call to ``callee`` in ``function_name``'s source."""
+ import ast
+
+ source = inspect.getsource(getattr(provider_health, function_name))
+ tree = ast.parse(inspect.cleandoc(source))
+ calls: list[set[str]] = []
+ for node in ast.walk(tree):
+ if not isinstance(node, ast.Call):
+ continue
+ func = node.func
+ attribute = func.attr if isinstance(func, ast.Attribute) else None
+ plain = func.id if isinstance(func, ast.Name) else None
+ if attribute != callee and plain != callee:
+ continue
+ calls.append({kw.arg for kw in node.keywords if kw.arg})
+ return calls
+
+
+def _call_kwargs(function_name: str, callee: str) -> set[str]:
+ """Union of keyword names passed to ``callee``."""
+ return set().union(*_calls(function_name, callee)) if _calls(function_name, callee) else set()
+
+
+def test_cache_key_accepts_every_keyword_the_endpoint_passes():
+ accepted = set(inspect.signature(provider_health_cache.cache_key).parameters)
+ passed = _call_kwargs("check_provider_health", "cache_key")
+
+ assert passed, "expected check_provider_health to call cache_key with keywords"
+ assert passed <= accepted, f"cache_key() cannot accept: {sorted(passed - accepted)}"
+
+
+def test_credentials_change_the_cache_key():
+ """Rotating a generic provider's credentials must bust the cached verdict."""
+ base = {
+ "provider": "openai",
+ "embedding_provider": "openai",
+ "test_completion": False,
+ "llm_model": "gpt-4o-mini",
+ "embedding_model": "text-embedding-3-small",
+ "endpoint": None,
+ "project_id": None,
+ "api_key": "sk-same",
+ }
+
+ unset = provider_health_cache.cache_key(**base)
+ first = provider_health_cache.cache_key(**base, credentials={"api_key": "sk-one"})
+ second = provider_health_cache.cache_key(**base, credentials={"api_key": "sk-two"})
+ embedding = provider_health_cache.cache_key(**base, embedding_credentials={"api_key": "sk-one"})
+
+ assert first != second
+ assert first != unset
+ assert embedding != unset
+ assert first != embedding
+
+
+def test_credential_key_is_order_independent():
+ base = {
+ "provider": "custom",
+ "embedding_provider": "custom",
+ "test_completion": False,
+ "llm_model": None,
+ "embedding_model": None,
+ "endpoint": None,
+ "project_id": None,
+ "api_key": None,
+ }
+
+ forward = provider_health_cache.cache_key(
+ **base, credentials={"api_base": "https://x", "api_key": "k"}
+ )
+ reversed_ = provider_health_cache.cache_key(
+ **base, credentials={"api_key": "k", "api_base": "https://x"}
+ )
+
+ assert forward == reversed_
+
+
+def test_credentials_never_appear_in_plaintext_in_the_key():
+ key = provider_health_cache.cache_key(
+ provider="custom",
+ embedding_provider="custom",
+ test_completion=False,
+ llm_model=None,
+ embedding_model=None,
+ endpoint=None,
+ project_id=None,
+ api_key=None,
+ credentials={"api_key": "super-secret-value"},
+ )
+
+ assert "super-secret-value" not in key
+
+
+def test_every_validation_call_forwards_credentials():
+ """Generic providers carry their secrets only in ``credentials``.
+
+ Covers the specific-provider branch too — it is what the providers page
+ hits when you click Configure on a non-built-in provider, and it silently
+ validated with no credentials at all before.
+ """
+ calls = _calls("check_provider_health", "validate_provider_setup")
+
+ assert calls, "expected check_provider_health to call validate_provider_setup"
+ missing = [index for index, kwargs in enumerate(calls) if "credentials" not in kwargs]
+ assert not missing, f"validate_provider_setup call(s) {missing} drop credentials"
+
+
+def test_health_endpoint_accepts_an_explicit_validation_model():
+ """Generic providers are validated by a real LiteLLM call, which needs a model.
+
+ A provider that is not the selected LLM/embedding provider has no model in
+ config, and providers whose model names are per-account deployments (Azure,
+ Bedrock, SageMaker) cannot be validated against catalogue names at all —
+ that is what surfaces as "AzureException APIError - Resource not found".
+ """
+ params = inspect.signature(provider_health.check_provider_health).parameters
+
+ assert "model" in params
+ assert "embedding_model_override" in params
+ assert params["model"].default is None
+ assert params["embedding_model_override"].default is None
+
+
+def test_explicit_model_replaces_the_configured_one():
+ """The override must clear the other slot, or a chat model gets embedded."""
+ source = inspect.getsource(provider_health.check_provider_health)
+
+ assert "llm_model = model or None" in source
+ assert "embedding_model = embedding_model_override or None" in source
diff --git a/tests/unit/test_watsonx_model_list_errors.py b/tests/unit/test_watsonx_model_list_errors.py
new file mode 100644
index 000000000..ad77ba25b
--- /dev/null
+++ b/tests/unit/test_watsonx_model_list_errors.py
@@ -0,0 +1,24 @@
+from services.models_service import _watsonx_rate_limited
+
+REAL_403 = (
+ '{"errors":[{"code":"user_authorization_failed","message":"Failed to find the '
+ "IBMid-6950006MXS member in project_id 1f17210f-84ff-4865-b94f-d0a80ad0f62a "
+ '{\\"code\\":429,\\"error\\":\\"Too Many Requests\\"}"}]}'
+)
+
+
+def test_throttling_hidden_inside_a_403_is_detected():
+ assert _watsonx_rate_limited([("text chat", 403, REAL_403)]) is True
+
+
+def test_plain_429_is_detected():
+ assert _watsonx_rate_limited([("embedding", 429, "")]) is True
+
+
+def test_a_real_authorization_failure_is_not_called_throttling():
+ body = '{"errors":[{"code":"user_authorization_failed","message":"not a member"}]}'
+ assert _watsonx_rate_limited([("text chat", 403, body)]) is False
+
+
+def test_no_failures_is_not_throttling():
+ assert _watsonx_rate_limited([]) is False