diff --git a/litellm/vector_stores/vector_store_registry.py b/litellm/vector_stores/vector_store_registry.py index e78d2aa5f6a..a53da0b7090 100644 --- a/litellm/vector_stores/vector_store_registry.py +++ b/litellm/vector_stores/vector_store_registry.py @@ -32,8 +32,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: list[LiteLLM_ManagedVectorStoreIndex] | None = 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 +106,11 @@ 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: 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] = {} def _extract_tool_params(self, tool: dict) -> VectorStoreToolParams: 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 762176d6a81..59ea672418f 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 AsyncMock, 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) @@ -71,6 +75,40 @@ 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_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