mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-12 23:01:41 +00:00
fix(vector_stores): reject MongoDB search params the provider cannot honour
filters was already refused, but ranking_options and rewrite_query were accepted and then dropped. A caller asking for score_threshold 0.9 got results scoring 0.5 with a 200 and no indication the threshold never ran, which is the silent-wrong-answer case the filters check exists to prevent. Both now raise the same 400 naming the parameter and what to do instead.
This commit is contained in:
parent
1b47486724
commit
52de1bb1d3
2 changed files with 35 additions and 0 deletions
|
|
@ -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(
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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})
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
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()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue