From 32296d54c2a815e3f89b22280062ee16f19dac8a Mon Sep 17 00:00:00 2001 From: "shuwen.wu" Date: Wed, 2 Sep 2026 17:59:36 +0800 Subject: [PATCH] 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: