The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix(vector_stores): reject MongoDB search params the provider cannot honour
Yuneng Jiang52de1bb1d338
diff --git a/litellm/llms/mongodb/vector_stores/transformation.py b/litellm/llms/mongodb/vector_stores/transformation.pyindex 9f5e40f69ef..5e59fd30f1b 100644--- a/litellm/llms/mongodb/vector_stores/transformation.py+++ b/litellm/llms/mongodb/vector_stores/transformation.py@@ -236,6 +236,17 @@ class MongoDBVectorStoreConfig(BaseDirectVectorStoreConfig):"MongoDB vector store does not support the filters parameter yet. ""Restrict the collection or the Atlas Vector Search index definition instead.")+ if vector_store_search_optional_params.get("ranking_options") is not None:+ raise config_error(+ "MongoDB vector store does not support the ranking_options parameter yet. "+ "Every result already carries the Atlas vectorSearchScore, so filter or re-rank "+ "on that rather than having the threshold silently ignored."+ )+ if vector_store_search_optional_params.get("rewrite_query") is not None:+ raise config_error(+ "MongoDB vector store does not support the rewrite_query parameter. The query is "+ "embedded exactly as sent; rewrite it before calling if you need that."+ )limit: Final = cls._limit(vector_store_search_optional_params)search: Final = MappingProxyType({diff --git a/tests/test_litellm/llms/mongodb/vector_stores/test_mongodb_transformation.py b/tests/test_litellm/llms/mongodb/vector_stores/test_mongodb_transformation.pyindex 6d932c05065..668fa676692 100644--- a/tests/test_litellm/llms/mongodb/vector_stores/test_mongodb_transformation.py+++ b/tests/test_litellm/llms/mongodb/vector_stores/test_mongodb_transformation.py@@ -448,6 +448,30 @@ async def test_async_search_rejects_filters_rather_than_silently_ignoring_them()await _asearch(config, optional_params={"filters": {"genre": "sci-fi"}})+def test_search_rejects_ranking_options_rather_than_silently_ignoring_them():+ """A score_threshold that is quietly dropped is worse than an error: the caller asked for+ results above 0.9, gets results scoring 0.5, and nothing says the threshold never ran."""+ config, _, _ = _config()++ with pytest.raises(BadRequestError, match="does not support the ranking_options parameter"):+ _search(config, optional_params={"ranking_options": {"score_threshold": 0.9}})+++def test_search_rejects_rewrite_query_rather_than_silently_ignoring_it():+ config, _, _ = _config()++ with pytest.raises(BadRequestError, match="does not support the rewrite_query parameter"):+ _search(config, optional_params={"rewrite_query": True})+++async def test_async_search_rejects_ranking_options_rather_than_silently_ignoring_them():+ config, _, _ = _async_config()++ with pytest.raises(BadRequestError, match="does not support the ranking_options parameter"):+ await _asearch(config, optional_params={"ranking_options": {"score_threshold": 0.9}})++@pytest.mark.parametrize("query", ["", " ", "\n\t", []])def test_search_rejects_an_empty_query(query):config, _, _ = _config()