Skip to content

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

Python

fix: persist Langflow database across container restarts

Mike Pawlowskia1dd86e64704
diff --git a/.github/workflows/test-e2e.yml b/.github/workflows/test-e2e.yml
index f73f89bb7..6b80efbeb 100644
--- a/.github/workflows/test-e2e.yml
+++ b/.github/workflows/test-e2e.yml
@@ -37,10 +37,10 @@ jobs:
docker builder prune -af || true
docker compose -f docker-compose.yml down -v --remove-orphans || true
- - name: Cleanup root-owned files (OpenSearch data, config)
+ - name: Cleanup root-owned files (OpenSearch data, config, Langflow data)
run: |
for i in 1 2 3; do
- docker run --rm -v $(pwd):/work alpine sh -c "rm -rf /work/opensearch-data /work/config" && break
+ docker run --rm -v $(pwd):/work alpine sh -c "rm -rf /work/opensearch-data /work/config /work/langflow-data" && break
echo "Attempt $i failed, retrying in 5s..."
sleep 5
done || true
diff --git a/.github/workflows/test-integration.yml b/.github/workflows/test-integration.yml
index 4dd3485e3..470ccbaa5 100644
--- a/.github/workflows/test-integration.yml
+++ b/.github/workflows/test-integration.yml
@@ -42,10 +42,10 @@ jobs:
docker builder prune -af || true
docker compose -f docker-compose.yml down -v --remove-orphans || true
- - name: Cleanup root-owned files (OpenSearch data, config)
+ - name: Cleanup root-owned files (OpenSearch data, config, Langflow data)
run: |
for i in 1 2 3; do
- docker run --rm -v $(pwd):/work alpine sh -c "rm -rf /work/opensearch-data /work/config" && break
+ docker run --rm -v $(pwd):/work alpine sh -c "rm -rf /work/opensearch-data /work/config /work/langflow-data" && break
echo "Attempt $i failed, retrying in 5s..."
sleep 5
done || true
diff --git a/docs/docs/reference/configuration.mdx b/docs/docs/reference/configuration.mdx
index 65484f2df..895892b96 100644
--- a/docs/docs/reference/configuration.mdx
+++ b/docs/docs/reference/configuration.mdx
@@ -94,6 +94,7 @@ For better security, it is recommended to set `LANGFLOW_SUPERUSER_PASSWORD` so t
| Variable | Default | Description |
|----------|---------|-------------|
+| `LANGFLOW_DATA_PATH` | `./langflow-data` | The path where OpenRAG persists the Langflow database (flows, credentials, settings) across container restarts. |
| `LANGFLOW_AUTO_LOGIN` | Determined by `LANGFLOW_SUPERUSER_PASSWORD` | Whether to enable [auto-login mode](https://docs.langflow.org/api-keys-and-authentication#langflow-auto-login) for the Langflow visual editor and CLI. If `LANGFLOW_SUPERUSER_PASSWORD` isn't set, then `LANGFLOW_AUTO_LOGIN` is `True` and auto-login mode is enabled. If `LANGFLOW_SUPERUSER_PASSWORD` is set, then `LANGFLOW_AUTO_LOGIN` is `False` and auto-login mode is disabled. Langflow API calls always require authentication with a Langflow API key regardless of the auto-login setting. |
| `LANGFLOW_ENABLE_SUPERUSER_CLI` | Determined by `LANGFLOW_SUPERUSER_PASSWORD` | Whether to enable the [Langflow CLI `langflow superuser` command](https://docs.langflow.org/api-keys-and-authentication#langflow-enable-superuser-cli). If `LANGFLOW_SUPERUSER_PASSWORD` isn't set, then `LANGFLOW_ENABLE_SUPERUSER_CLI` is `True` and superuser accounts can be created with the Langflow CLI. If `LANGFLOW_SUPERUSER_PASSWORD` is set, then `LANGFLOW_ENABLE_SUPERUSER_CLI` is `False` and the `langflow superuser` command is disabled. |
| `LANGFLOW_NEW_USER_IS_ACTIVE` | Determined by `LANGFLOW_SUPERUSER_PASSWORD` | Whether new [Langflow user accounts are active by default](https://docs.langflow.org/api-keys-and-authentication#langflow-new-user-is-active). If `LANGFLOW_SUPERUSER_PASSWORD` isn't set, then `LANGFLOW_NEW_USER_IS_ACTIVE` is `True` and new user accounts are active by default. If `LANGFLOW_SUPERUSER_PASSWORD` is set, then `LANGFLOW_NEW_USER_IS_ACTIVE` is `False` and new user accounts are inactive by default. |
diff --git a/frontend/.env.test.example b/frontend/.env.test.example
index f53600840..c053ca248 100644
--- a/frontend/.env.test.example
+++ b/frontend/.env.test.example
@@ -7,6 +7,7 @@ OPENSEARCH_PASSWORD=
# Paths
OPENSEARCH_DATA_PATH=./opensearch-data
+LANGFLOW_DATA_PATH=./langflow-data
OPENSEARCH_INDEX_NAME=documents
# Model Providers
diff --git a/src/tui/config_fields.py b/src/tui/config_fields.py
index 73bdcf37d..19aa01631 100644
--- a/src/tui/config_fields.py
+++ b/src/tui/config_fields.py
@@ -112,6 +112,12 @@ CONFIG_SECTIONS: list[ConfigSection] = [
"langflow_superuser", "LANGFLOW_SUPERUSER", "Admin Username",
placeholder="admin", default="admin",
),
+ ConfigField(
+ "langflow_data_path", "LANGFLOW_DATA_PATH", "Data Path",
+ placeholder="~/.openrag/data/langflow-data",
+ default="$HOME/.openrag/data/langflow-data",
+ helper_text="Directory to persist Langflow flows and state across restarts",
+ ),
ConfigField(
"langflow_public_url", "LANGFLOW_PUBLIC_URL", "Public URL",
placeholder="http://localhost:7860",
diff --git a/src/tui/managers/env_manager.py b/src/tui/managers/env_manager.py
index 791507885..175c94e45 100644
--- a/src/tui/managers/env_manager.py
+++ b/src/tui/managers/env_manager.py
@@ -98,6 +98,7 @@ class EnvConfig:
openrag_config_path: str = "$HOME/.openrag/config"
openrag_data_path: str = "$HOME/.openrag/data" # Backend data (conversations, tokens, etc.)
opensearch_data_path: str = "$HOME/.openrag/data/opensearch-data"
+ langflow_data_path: str = "$HOME/.openrag/data/langflow-data"
openrag_tui_config_path_legacy: str = "$HOME/.openrag/tui/config"
# Container version (linked to TUI version)
@@ -223,6 +224,7 @@ class EnvManager:
"OPENRAG_CONFIG_PATH": "openrag_config_path",
"OPENRAG_DATA_PATH": "openrag_data_path",
"OPENSEARCH_DATA_PATH": "opensearch_data_path",
+ "LANGFLOW_DATA_PATH": "langflow_data_path",
"LANGFLOW_AUTO_LOGIN": "langflow_auto_login",
"LANGFLOW_NEW_USER_IS_ACTIVE": "langflow_new_user_is_active",
"LANGFLOW_ENABLE_SUPERUSER_CLI": "langflow_enable_superuser_cli",
@@ -507,6 +509,9 @@ class EnvManager:
f.write(
f"OPENSEARCH_DATA_PATH={self._quote_env_value(expand_path(self.config.opensearch_data_path))}\n"
)
+ f.write(
+ f"LANGFLOW_DATA_PATH={self._quote_env_value(expand_path(self.config.langflow_data_path))}\n"
+ )
# Set OPENRAG_VERSION to TUI version
if self.config.openrag_version:
f.write(f"OPENRAG_VERSION={self._quote_env_value(self.config.openrag_version)}\n")
diff --git a/src/tui/screens/config.py b/src/tui/screens/config.py
index 54873b00d..4ca6c8bd0 100644
--- a/src/tui/screens/config.py
+++ b/src/tui/screens/config.py
@@ -203,6 +203,7 @@ class ConfigScreen(Screen):
"opensearch_data_path",
"langflow_superuser_password",
"langflow_superuser",
+ "langflow_data_path",
"google_oauth_client_id",
"microsoft_graph_oauth_client_id",
"openrag_documents_paths",
@@ -306,6 +307,25 @@ class ConfigScreen(Screen):
self.inputs[field.name] = input_widget
yield Static(" ")
+ def _render_langflow_data_path(self, field: ConfigField) -> ComposeResult:
+ """Langflow data path with file picker."""
+ yield Label(field.label)
+ yield Static(field.helper_text, classes="helper-text")
+ current_value = getattr(self.env_manager.config, field.name, field.default)
+ input_widget = Input(
+ placeholder=field.placeholder,
+ value=current_value,
+ id=f"input-{field.name}",
+ )
+ yield input_widget
+ yield Horizontal(
+ Button("Pick…", id="pick-langflow-data-btn"),
+ id="langflow-data-path-actions",
+ classes="controls-row",
+ )
+ self.inputs[field.name] = input_widget
+ yield Static(" ")
+
def _render_langflow_superuser_password(self, field: ConfigField) -> ComposeResult:
"""Langflow password with generate checkbox and eye toggle."""
with Horizontal():
@@ -456,6 +476,8 @@ class ConfigScreen(Screen):
self.action_pick_documents_path()
elif event.button.id == "pick-opensearch-data-btn":
self.action_pick_opensearch_data_path()
+ elif event.button.id == "pick-langflow-data-btn":
+ self.action_pick_langflow_data_path()
elif event.button.id and event.button.id.startswith("toggle-"):
# Generic toggle for password/secret field visibility
field_name = event.button.id.removeprefix("toggle-")
@@ -665,6 +687,58 @@ class ConfigScreen(Screen):
self._opensearch_data_pick_callback = _set_path # type: ignore[attr-defined]
self.app.push_screen(picker)
+ def action_pick_langflow_data_path(self) -> None:
+ """Open textual-fspicker to select Langflow data directory."""
+ try:
+ import importlib
+
+ fsp = importlib.import_module("textual_fspicker")
+ except Exception:
+ self.notify("textual-fspicker not available", severity="warning")
+ return
+
+ input_widget = self.inputs.get("langflow_data_path")
+ start = Path.home()
+ if input_widget and input_widget.value:
+ path_str = input_widget.value.strip()
+ if path_str:
+ candidate = Path(path_str).expanduser()
+ if candidate.exists():
+ start = candidate
+ elif candidate.parent.exists():
+ start = candidate.parent
+
+ PickerClass = getattr(fsp, "SelectDirectory", None) or getattr(
+ fsp, "FileOpen", None
+ )
+ if PickerClass is None:
+ self.notify(
+ "No compatible picker found in textual-fspicker", severity="warning"
+ )
+ return
+ try:
+ picker = PickerClass(location=start)
+ except Exception:
+ try:
+ picker = PickerClass(start)
+ except Exception:
+ self.notify("Could not initialize textual-fspicker", severity="warning")
+ return
+
+ def _set_path(result) -> None:
+ if not result:
+ return
+ path_str = str(result)
+ if input_widget is None:
+ return
+ input_widget.value = path_str
+
+ try:
+ self.app.push_screen(picker, _set_path) # type: ignore[arg-type]
+ except TypeError:
+ self._langflow_data_pick_callback = _set_path # type: ignore[attr-defined]
+ self.app.push_screen(picker)
+
def on_screen_dismissed(self, event) -> None: # type: ignore[override]
try:
# textual-fspicker screens should dismiss with a result; hand to callback if present
@@ -684,6 +758,15 @@ class ConfigScreen(Screen):
delattr(self, "_opensearch_data_pick_callback")
except Exception:
pass
+
+ # Handle Langflow data path picker callback
+ cb = getattr(self, "_langflow_data_pick_callback", None)
+ if cb is not None:
+ cb(getattr(event, "result", None))
+ try:
+ delattr(self, "_langflow_data_pick_callback")
+ except Exception:
+ pass
except Exception:
pass
diff --git a/tests/conftest.py b/tests/conftest.py
index ffe80467e..eced102f5 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -51,6 +51,15 @@ async def onboard_system():
except Exception as e:
print(f"[DEBUG] Could not clean OpenSearch data directory: {e}")
+ # Clean up Langflow data directory to ensure a fresh Langflow DB for tests
+ langflow_data_path = Path(os.getenv("LANGFLOW_DATA_PATH", "./langflow-data"))
+ if langflow_data_path.exists():
+ try:
+ shutil.rmtree(langflow_data_path)
+ print(f"[DEBUG] Cleaned up Langflow data directory: {langflow_data_path}")
+ except Exception as e:
+ print(f"[DEBUG] Could not clean Langflow data directory: {e}")
+
# Initialize clients
await clients.initialize()