From 32296d54c2a815e3f89b22280062ee16f19dac8a Mon Sep 17 00:00:00 2001 From: "shuwen.wu" Date: Wed, 2 Sep 2026 17:59:36 +0800 Subject: [PATCH 1/5] fix: VectorStore registries use None default to avoid mutable default arguments Fixes #38874 - VectorStoreIndexRegistry and VectorStoreRegistry use mutable default list arguments ([]), causing shared state between instances. Changed both classes to use None as the default and instantiate a new list per instance, matching the convention used throughout the codebase. --- .../vector_stores/vector_store_registry.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/litellm/vector_stores/vector_store_registry.py b/litellm/vector_stores/vector_store_registry.py index b71d6784873..9a18f88a9fc 100644 --- a/litellm/vector_stores/vector_store_registry.py +++ b/litellm/vector_stores/vector_store_registry.py @@ -6,6 +6,7 @@ from typing import ( TYPE_CHECKING, Any, # noqa: TID251 # untyped non_default_params dict is the only source of the unknown key type Final, + Optional, cast, # noqa: TID251 # untyped non_default_params dict is the only source of the unknown key type get_args, ) @@ -32,8 +33,13 @@ else: class VectorStoreIndexRegistry: - def __init__(self, vector_store_indexes: list[LiteLLM_ManagedVectorStoreIndex] = []): - self.vector_store_indexes: list[LiteLLM_ManagedVectorStoreIndex] = vector_store_indexes + def __init__( + self, + vector_store_indexes: Optional[list[LiteLLM_ManagedVectorStoreIndex]] = None, + ): + self.vector_store_indexes: list[LiteLLM_ManagedVectorStoreIndex] = ( + vector_store_indexes if vector_store_indexes is not None else [] + ) def get_vector_store_indexes(self) -> list[LiteLLM_ManagedVectorStoreIndex]: """ @@ -101,8 +107,13 @@ class VectorStoreIndexRegistry: class VectorStoreRegistry: - def __init__(self, vector_stores: list[LiteLLM_ManagedVectorStore] = []): - self.vector_stores: list[LiteLLM_ManagedVectorStore] = vector_stores + def __init__( + self, + vector_stores: Optional[list[LiteLLM_ManagedVectorStore]] = None, + ): + self.vector_stores: list[LiteLLM_ManagedVectorStore] = ( + vector_stores if vector_stores is not None else [] + ) self.vector_store_ids_to_vector_store_map: dict[str, LiteLLM_ManagedVectorStore] = {} def _extract_tool_params(self, tool: dict) -> VectorStoreToolParams: From 5b9c7aeb15d8924f4aa224d994fd75352db07ec1 Mon Sep 17 00:00:00 2001 From: dajiaohuang Date: Fri, 4 Sep 2026 14:15:04 +0800 Subject: [PATCH 2/5] test: isolate vector store registry defaults --- .../vector_stores/test_vector_store_registry.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/test_litellm/vector_stores/test_vector_store_registry.py b/tests/test_litellm/vector_stores/test_vector_store_registry.py index f19c3706845..4d8b16ada5e 100644 --- a/tests/test_litellm/vector_stores/test_vector_store_registry.py +++ b/tests/test_litellm/vector_stores/test_vector_store_registry.py @@ -71,6 +71,22 @@ def test_get_credentials_for_vector_store(): assert result == {} +def test_vector_store_registries_do_not_share_default_list(): + first = VectorStoreRegistry() + second = VectorStoreRegistry() + + first.vector_stores.append( + LiteLLM_ManagedVectorStore( + vector_store_id="first", + custom_llm_provider="openai", + created_at=datetime.now(timezone.utc), + updated_at=datetime.now(timezone.utc), + ) + ) + + assert second.vector_stores == [] + + def test_add_vector_store_to_registry(): """Test that add_vector_store_to_registry adds vector store correctly when there are pre-existing stores""" # Create pre-existing vector stores From 0f58e6e57c60d19e6db50176a42511cd57fa021e Mon Sep 17 00:00:00 2001 From: dajiaohuang Date: Thu, 10 Sep 2026 12:04:42 +0800 Subject: [PATCH 3/5] style: format vector store registry --- litellm/vector_stores/vector_store_registry.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/litellm/vector_stores/vector_store_registry.py b/litellm/vector_stores/vector_store_registry.py index 9a18f88a9fc..d6fa3e9ea28 100644 --- a/litellm/vector_stores/vector_store_registry.py +++ b/litellm/vector_stores/vector_store_registry.py @@ -111,9 +111,7 @@ class VectorStoreRegistry: self, vector_stores: Optional[list[LiteLLM_ManagedVectorStore]] = None, ): - self.vector_stores: list[LiteLLM_ManagedVectorStore] = ( - vector_stores if vector_stores is not None else [] - ) + self.vector_stores: list[LiteLLM_ManagedVectorStore] = vector_stores if vector_stores is not None else [] self.vector_store_ids_to_vector_store_map: dict[str, LiteLLM_ManagedVectorStore] = {} def _extract_tool_params(self, tool: dict) -> VectorStoreToolParams: From 9365ffd83592f017269cfff4e63ff51453077d02 Mon Sep 17 00:00:00 2001 From: dajiaohuang Date: Thu, 10 Sep 2026 12:12:28 +0800 Subject: [PATCH 4/5] fix: satisfy ruff optional annotations --- litellm/vector_stores/vector_store_registry.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/litellm/vector_stores/vector_store_registry.py b/litellm/vector_stores/vector_store_registry.py index d6fa3e9ea28..2d4d5fe5749 100644 --- a/litellm/vector_stores/vector_store_registry.py +++ b/litellm/vector_stores/vector_store_registry.py @@ -6,7 +6,6 @@ from typing import ( TYPE_CHECKING, Any, # noqa: TID251 # untyped non_default_params dict is the only source of the unknown key type Final, - Optional, cast, # noqa: TID251 # untyped non_default_params dict is the only source of the unknown key type get_args, ) @@ -35,7 +34,7 @@ else: class VectorStoreIndexRegistry: def __init__( self, - vector_store_indexes: Optional[list[LiteLLM_ManagedVectorStoreIndex]] = None, + vector_store_indexes: list[LiteLLM_ManagedVectorStoreIndex] | None = None, ): self.vector_store_indexes: list[LiteLLM_ManagedVectorStoreIndex] = ( vector_store_indexes if vector_store_indexes is not None else [] @@ -109,7 +108,7 @@ class VectorStoreIndexRegistry: class VectorStoreRegistry: def __init__( self, - vector_stores: Optional[list[LiteLLM_ManagedVectorStore]] = None, + vector_stores: list[LiteLLM_ManagedVectorStore] | None = None, ): self.vector_stores: list[LiteLLM_ManagedVectorStore] = vector_stores if vector_stores is not None else [] self.vector_store_ids_to_vector_store_map: dict[str, LiteLLM_ManagedVectorStore] = {} From 06b380e8137fb4dde8ff72de646872df84ead68d Mon Sep 17 00:00:00 2001 From: dajiaohuang Date: Sun, 13 Sep 2026 15:10:33 +0800 Subject: [PATCH 5/5] test: cover vector store index default isolation --- .../test_vector_store_registry.py | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/tests/test_litellm/vector_stores/test_vector_store_registry.py b/tests/test_litellm/vector_stores/test_vector_store_registry.py index 4d8b16ada5e..420cc4da032 100644 --- a/tests/test_litellm/vector_stores/test_vector_store_registry.py +++ b/tests/test_litellm/vector_stores/test_vector_store_registry.py @@ -11,9 +11,13 @@ from datetime import datetime, timezone from unittest.mock import MagicMock import litellm -from litellm.types.vector_stores import LiteLLM_ManagedVectorStore +from litellm.types.vector_stores import ( + IndexCreateLiteLLMParams, + LiteLLM_ManagedVectorStore, + LiteLLM_ManagedVectorStoreIndex, +) from litellm.vector_stores.main import search -from litellm.vector_stores.vector_store_registry import VectorStoreRegistry +from litellm.vector_stores.vector_store_registry import VectorStoreIndexRegistry, VectorStoreRegistry @pytest.fixture(autouse=True) @@ -87,6 +91,24 @@ def test_vector_store_registries_do_not_share_default_list(): assert second.vector_stores == [] +def test_vector_store_index_registries_do_not_share_default_list(): + first = VectorStoreIndexRegistry() + second = VectorStoreIndexRegistry() + + first.vector_store_indexes.append( + LiteLLM_ManagedVectorStoreIndex( + id="first", + index_name="first", + litellm_params=IndexCreateLiteLLMParams( + vector_store_index="first", + vector_store_name="first", + ), + ) + ) + + assert second.vector_store_indexes == [] + + def test_add_vector_store_to_registry(): """Test that add_vector_store_to_registry adds vector store correctly when there are pre-existing stores""" # Create pre-existing vector stores