This commit is contained in:
Wu Shuwen 2026-09-23 14:47:03 +00:00 • committed by GitHub
commit 718f3204ca
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 52 additions and 6 deletions

View file

@ -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:

View file

@ -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