Skip to content

Commit 1fb317b

Browse files
committed
MLT rebase
1 parent acfa74c commit 1fb317b

7 files changed

Lines changed: 434 additions & 172 deletions

File tree

README.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ Product.objects.filter(description=ParadeDB('shoes'))
6464

6565
Check out some examples:
6666

67-
- [Quick Start](examples/quickstart.py)
68-
- [Faceted Search](examples/faceted_search.py)
69-
- [Autocomplete](examples/autocomplete.py)
70-
- [More Like This](examples/more_like_this.py)
71-
- [Hybrid Search (RRF)](examples/hybrid_rrf.py)
72-
- [RAG](examples/rag.py)
67+
- [Quick Start](examples/quickstart/quickstart.py)
68+
- [Faceted Search](examples/faceted_search/faceted_search.py)
69+
- [Autocomplete](examples/autocomplete/autocomplete.py)
70+
- [More Like This](examples/more_like_this/more_like_this.py)
71+
- [Hybrid Search (RRF)](examples/hybrid_rrf/hybrid_rrf.py)
72+
- [RAG](examples/rag/rag.py)
7373

7474
## BM25 Index
7575

@@ -224,6 +224,11 @@ Product.objects.filter(MoreLikeThis(product_id=42))
224224
# Similar to multiple documents
225225
Product.objects.filter(MoreLikeThis(product_ids=[1, 2, 3]))
226226

227+
# Similar to a custom document
228+
Product.objects.filter(
229+
MoreLikeThis(document={"description": "comfortable running shoes"})
230+
)
231+
227232
# With tuning parameters
228233
Product.objects.filter(
229234
MoreLikeThis(

examples/README.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,15 +188,12 @@ Product.objects.filter(
188188
MoreLikeThis(product_ids=[5, 12, 23], fields=["description"])
189189
)
190190

191-
# Similar to text (user describes what they want)
191+
# Similar to a custom document (user describes what they want)
192192
Product.objects.filter(
193-
MoreLikeThis(text='{"description": "comfortable running shoes"}')
193+
MoreLikeThis(document={"description": "comfortable running shoes"})
194194
)
195195
```
196196

197-
> **Note:** `MoreLikeThis` is used directly in `.filter()`, not wrapped in `ParadeDB()`.
198-
> This is because it's a table-level similarity query, not a field-targeted search.
199-
200197
**Tuning Parameters:**
201198

202199
| Parameter | Description | Default |
@@ -207,7 +204,6 @@ Product.objects.filter(
207204
| `max_doc_freq` | Maximum docs term can appear in | unlimited |
208205

209206
```python
210-
# Tuned for precision
211207
Product.objects.filter(
212208
MoreLikeThis(
213209
product_id=5,

examples/more_like_this/more_like_this.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,21 @@
22
"""MoreLikeThis example: find similar documents without vectors.
33
44
This example demonstrates ParadeDB's MoreLikeThis feature, which finds similar
5-
documents based on term frequency analysis (TF-IDF), not vector embeddings.
6-
7-
NOTE: MoreLikeThis is used directly in .filter(), not wrapped in ParadeDB().
8-
This is because it's a table-level similarity query that uses the primary key
9-
internally, rather than a field-targeted search expression.
5+
documents based BM25 provided by ParadeDB, not vector embeddings.
106
117
Use cases:
128
- "Related products" on product pages
139
- "Similar articles" recommendations
1410
- Content discovery and exploration
1511
"""
1612

17-
from _common import MockItem, setup_mock_items
13+
import sys
14+
from pathlib import Path
15+
16+
# Add parent directory to path for importing common utilities
17+
sys.path.insert(0, str(Path(__file__).parent.parent))
18+
19+
from common import MockItem, setup_mock_items
1820

1921
from paradedb.functions import Score
2022
from paradedb.search import MoreLikeThis
@@ -83,8 +85,8 @@ def demo_similar_to_multiple_products() -> None:
8385
print(f" {item.id}: {item.description[:50]}... [{item.category}]")
8486

8587

86-
def demo_similar_by_text() -> None:
87-
"""Find products similar to a text description.
88+
def demo_similar_by_document() -> None:
89+
"""Find products similar to a custom document.
8890
8991
Use case: User describes what they want, find matching products.
9092
This is different from regular search - it uses MLT's term analysis.
@@ -97,11 +99,10 @@ def demo_similar_by_text() -> None:
9799
user_description = "comfortable wireless audio for running"
98100
print(f"\nUser wants: '{user_description}'")
99101

100-
# MoreLikeThis with text requires fields parameter
101102
print("\nMatching products:")
102103
similar = (
103104
MockItem.objects.filter(
104-
MoreLikeThis(text=user_description, fields=["description"])
105+
MoreLikeThis(document={"description": user_description})
105106
)
106107
.annotate(score=Score())
107108
.order_by("-score")[:5]
@@ -235,7 +236,7 @@ def demo_multifield_similarity() -> None:
235236

236237
demo_similar_to_single_product()
237238
demo_similar_to_multiple_products()
238-
demo_similar_by_text()
239+
demo_similar_by_document()
239240
demo_tuning_parameters()
240241
demo_combined_with_filters()
241242
demo_multifield_similarity()

0 commit comments

Comments
 (0)