From 5f5562a6e452aeb61620b14149cbbb600ee22dbd Mon Sep 17 00:00:00 2001 From: yzy <1585004297@qq.com> Date: Mon, 1 Jun 2026 18:19:49 +0800 Subject: [PATCH] Fix whitespace-only LanceDB db_uri fallback --- .../next-release/patch-20260601101913537242.json | 4 ++++ .../graphrag/config/models/graph_rag_config.py | 3 ++- tests/unit/config/test_config.py | 13 +++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 .semversioner/next-release/patch-20260601101913537242.json diff --git a/.semversioner/next-release/patch-20260601101913537242.json b/.semversioner/next-release/patch-20260601101913537242.json new file mode 100644 index 0000000000..ba2e5feeca --- /dev/null +++ b/.semversioner/next-release/patch-20260601101913537242.json @@ -0,0 +1,4 @@ +{ + "type": "patch", + "description": "Fix whitespace-only LanceDB vector store db_uri fallback." +} diff --git a/packages/graphrag/graphrag/config/models/graph_rag_config.py b/packages/graphrag/graphrag/config/models/graph_rag_config.py index 1b753d58fc..8b0280af20 100644 --- a/packages/graphrag/graphrag/config/models/graph_rag_config.py +++ b/packages/graphrag/graphrag/config/models/graph_rag_config.py @@ -270,7 +270,8 @@ def _validate_vector_store_db_uri(self) -> None: """Validate the vector store configuration.""" store = self.vector_store if store.type == VectorStoreType.LanceDB: - if not store.db_uri or store.db_uri.strip == "": + # Treat whitespace-only values the same as a missing db_uri. + if not store.db_uri or store.db_uri.strip() == "": store.db_uri = graphrag_config_defaults.vector_store.db_uri store.db_uri = str(Path(store.db_uri).resolve()) diff --git a/tests/unit/config/test_config.py b/tests/unit/config/test_config.py index 75a472f023..ffd8af5097 100644 --- a/tests/unit/config/test_config.py +++ b/tests/unit/config/test_config.py @@ -5,6 +5,7 @@ from pathlib import Path from unittest import mock +from graphrag.config.defaults import graphrag_config_defaults from graphrag.config.load_config import load_config from graphrag.config.models.graph_rag_config import GraphRagConfig @@ -26,6 +27,18 @@ def test_default_config() -> None: assert_graphrag_configs(actual, expected) +def test_lancedb_vector_store_whitespace_db_uri_uses_default() -> None: + actual = GraphRagConfig( + completion_models=DEFAULT_COMPLETION_MODELS, # type: ignore + embedding_models=DEFAULT_EMBEDDING_MODELS, # type: ignore + vector_store={"db_uri": " "}, + ) + + # Whitespace-only values are equivalent to an omitted db_uri. + expected_db_uri = Path(graphrag_config_defaults.vector_store.db_uri).resolve() + assert actual.vector_store.db_uri == str(expected_db_uri) + + @mock.patch.dict(os.environ, {"CUSTOM_API_KEY": FAKE_API_KEY}, clear=True) def test_load_minimal_config() -> None: cwd = Path.cwd()