Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

1.7 KB
Raw Blame
"""Protection tests for the vector-store provider registry/factory.

``get_vector_store_class`` (``vector_stores/config.py``) is the single
resolution entry point callers use to turn a provider key into a
:class:`BaseVectorStore` subclass. Two invariants matter here:

1. An unknown provider key must raise ``ValueError`` naming the bad key and
   listing the valid providers — NOT silently fall back to a default class
   (e.g. via a ``.get(key, FaissVectorStore)`` idiom).
2. A "dirty" provider value (surrounding whitespace / wrapping quotes / mixed
   case, as could arrive from a settings/DB value) is normalized the same way
   ``embeddings_config.get_embeddings`` normalizes provider strings, and an
   empty-string provider falls through to the default provider.
"""

import pytest

from local_deep_research.vector_stores.config import (
    VALID_VECTOR_STORE_PROVIDERS,
    get_vector_store_class,
)
from local_deep_research.vector_stores.implementations.segmented_faiss import (
    SegmentedFaissStore,
)


def test_get_vector_store_class_unknown_provider_raises_valueerror():
    with pytest.raises(ValueError) as exc_info:
        get_vector_store_class(provider="not_a_real_provider")

    message = str(exc_info.value)
    assert "not_a_real_provider" in message
    for provider in VALID_VECTOR_STORE_PROVIDERS:
        assert provider in message


def test_get_vector_store_class_normalizes_dirty_provider():
    dirty = '  "FAISS"  '
    assert get_vector_store_class(provider=dirty) is SegmentedFaissStore

    # Empty-string provider is falsy -> falls through to resolve_provider's
    # default, not treated as an (invalid) literal empty key.
    assert get_vector_store_class(provider="") is SegmentedFaissStore