Skip to content

Commit 5d0e9f5

Browse files
authored
feat: Remove support for multiple MLT ids (#64)
1 parent 30553e1 commit 5d0e9f5

3 files changed

Lines changed: 4 additions & 63 deletions

File tree

paradedb/sqlalchemy/search.py

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from collections.abc import Sequence
66
from typing import Any
77

8-
from sqlalchemy import Text, cast, func, literal, literal_column, or_
8+
from sqlalchemy import Text, cast, func, literal, literal_column
99
from sqlalchemy.dialects.postgresql import ARRAY, array
1010
from sqlalchemy.sql import operators
1111
from sqlalchemy.sql.elements import ClauseElement, ColumnElement
@@ -386,7 +386,6 @@ def more_like_this(
386386
field: ColumnElement,
387387
*,
388388
document_id: Any | None = None,
389-
document_ids: list[Any] | None = None,
390389
document: dict[str, Any] | str | None = None,
391390
fields: list[str] | None = None,
392391
min_term_frequency: int | None = None,
@@ -400,17 +399,13 @@ def more_like_this(
400399
) -> ColumnElement[bool]:
401400
error_cls = InvalidMoreLikeThisOptionsError
402401

403-
sources_provided = sum(x is not None for x in (document_id, document_ids, document))
402+
sources_provided = sum(x is not None for x in (document_id, document))
404403
if sources_provided != 1:
405-
raise error_cls("exactly one of document_id, document_ids, or document must be provided")
406-
if document_ids is not None and len(document_ids) == 0:
407-
raise error_cls("document_ids must not be empty")
404+
raise error_cls("exactly one of document_id, or document must be provided")
408405
if document is not None and fields is not None:
409-
raise error_cls("fields can only be used with document_id or document_ids")
406+
raise error_cls("fields can only be used with document_id")
410407
if fields is not None:
411408
require_non_empty_sequence(fields, field_name="fields", error_cls=error_cls)
412-
if document_ids is not None and any(doc_id is None for doc_id in document_ids):
413-
raise error_cls("document_ids entries cannot be null")
414409
if isinstance(document, dict) and not document:
415410
raise error_cls("document must not be empty")
416411

@@ -469,12 +464,6 @@ def _build_mlt_call(source_arg: ClauseElement, *, include_fields: bool) -> Claus
469464
positional_args.append(_text_array(fields))
470465
return PDBFunctionWithNamedArgs("more_like_this", positional_args, named_options)
471466

472-
if document_ids is not None:
473-
clauses = [
474-
field.operate(_QUERY, _build_mlt_call(literal(doc_id), include_fields=True)) for doc_id in document_ids
475-
]
476-
return or_(*clauses)
477-
478467
if document_id is not None:
479468
return field.operate(_QUERY, _build_mlt_call(literal(document_id), include_fields=True))
480469

tests/integration/test_advanced_search_integration.py

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -78,32 +78,6 @@ def test_more_like_this_rejects_invalid_numeric_options():
7878
search.more_like_this(Product.id, document_id=1, boost_factor=-1.0)
7979

8080

81-
def test_more_like_this_by_document_ids(session):
82-
"""document_ids ORs results from multiple individual MLT queries."""
83-
stmt_combined = (
84-
select(Product.id)
85-
.where(search.more_like_this(Product.id, document_ids=[1, 3], fields=["description"]))
86-
.order_by(Product.id)
87-
)
88-
stmt_id1 = (
89-
select(Product.id)
90-
.where(search.more_like_this(Product.id, document_id=1, fields=["description"]))
91-
.order_by(Product.id)
92-
)
93-
stmt_id3 = (
94-
select(Product.id)
95-
.where(search.more_like_this(Product.id, document_id=3, fields=["description"]))
96-
.order_by(Product.id)
97-
)
98-
assert_uses_paradedb_scan(session, stmt_combined)
99-
ids_combined = set(session.scalars(stmt_combined))
100-
ids_1 = set(session.scalars(stmt_id1))
101-
ids_3 = set(session.scalars(stmt_id3))
102-
# Combined should be union of individual results
103-
assert ids_1.issubset(ids_combined)
104-
assert ids_3.issubset(ids_combined)
105-
106-
10781
def test_proximity(session):
10882
prox = search.prox_str("sleek").within(3, "shoes")
10983
stmt = select(Product.id).where(search.proximity(Product.description, prox)).order_by(Product.id)

tests/integration/test_paradedb_queries_integration.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -418,22 +418,6 @@ def test_more_like_this_by_document_id(mock_session):
418418
assert ids == MLT_RUNNING_SHOES_IDS
419419

420420

421-
def test_more_like_this_by_document_ids(mock_session):
422-
"""MLT with multiple document_ids ORs the results together."""
423-
stmt_combined = select(MockItem.id).where(
424-
search.more_like_this(MockItem.id, document_ids=[3, 12], fields=["description"])
425-
)
426-
stmt_id1 = select(MockItem.id).where(search.more_like_this(MockItem.id, document_id=3, fields=["description"]))
427-
stmt_id2 = select(MockItem.id).where(search.more_like_this(MockItem.id, document_id=12, fields=["description"]))
428-
assert_uses_paradedb_scan(mock_session, stmt_combined, index_name="mock_items_bm25_idx")
429-
ids_combined = _ids(mock_session, stmt_combined)
430-
ids_1 = _ids(mock_session, stmt_id1)
431-
ids_2 = _ids(mock_session, stmt_id2)
432-
assert ids_1 == MLT_RUNNING_SHOES_IDS
433-
assert ids_2 == WIRELESS_IDS
434-
assert ids_combined == MLT_COMBINED_IDS
435-
436-
437421
def test_more_like_this_by_document_payload(mock_session):
438422
"""MLT with document dict finds similar documents."""
439423
stmt = select(MockItem.id).where(
@@ -476,12 +460,6 @@ def test_more_like_this_with_min_word_length(mock_session):
476460
assert ids_filtered == RUNNING_IDS
477461

478462

479-
def test_more_like_this_document_ids_empty_raises(mock_session):
480-
"""document_ids=[] raises an error."""
481-
with pytest.raises(InvalidMoreLikeThisOptionsError, match="document_ids must not be empty"):
482-
search.more_like_this(MockItem.id, document_ids=[])
483-
484-
485463
def test_more_like_this_multiple_sources_raises(mock_session):
486464
"""Providing more than one input source raises an error."""
487465
with pytest.raises(InvalidMoreLikeThisOptionsError):

0 commit comments

Comments
 (0)