|
38 | 38 |
|
39 | 39 | See [`full_text/5`](https://hexdocs.pm/torus/Torus.html#full_text/5) for more details. |
40 | 40 |
|
41 | | -## 6 types of search: |
| 41 | +## 7 types of search: |
42 | 42 |
|
43 | 43 | 1. **Pattern matching**: Searches for a specific pattern in a string. |
44 | 44 |
|
@@ -84,10 +84,28 @@ See [`full_text/5`](https://hexdocs.pm/torus/Torus.html#full_text/5) for more de |
84 | 84 | ["Diagon Bombshell"] |
85 | 85 | ``` |
86 | 86 |
|
87 | | - Use it when you don’t care about spelling, the documents are long, or if you need to order the results by rank. |
| 87 | + Use it when you don't care about spelling, the documents are long, you need multi-column search with weights, or if you need to order the results by rank. |
88 | 88 |
|
89 | 89 | See [`full_text/5`](https://hexdocs.pm/torus/Torus.html#full_text/5) for more details. |
90 | 90 |
|
| 91 | +1. **BM25 full text**: Modern BM25 ranking algorithm for superior relevance scoring using the [pg_textsearch](https://github.com/timescale/pg_textsearch) extension. BM25 generally provides better ranking than traditional built-in TF-IDF full text search and is optimized for top-k queries. |
| 92 | + |
| 93 | + ```elixir |
| 94 | + iex> insert_post!(body: "PostgreSQL is a powerful relational database system") |
| 95 | + ...> insert_post!(body: "BM25 is a ranking function used in search engines") |
| 96 | + ...> insert_post!(body: "Full text search enables finding relevant documents") |
| 97 | + ...> Post |
| 98 | + ...> |> Torus.bm25([p], p.body, "database system") |
| 99 | + ...> |> limit(10) |
| 100 | + ...> |> select([p], p.body) |
| 101 | + ...> |> Repo.all() |
| 102 | + ["PostgreSQL is a powerful relational database system"] |
| 103 | + ``` |
| 104 | + |
| 105 | + Use it when you need state-of-the-art relevance ranking for single-column search, especially with LIMIT clauses. Requires PostgreSQL 17+. |
| 106 | + |
| 107 | + See [`bm25/5`](https://hexdocs.pm/torus/Torus.html#bm25/5) for more details. |
| 108 | + |
91 | 109 | 1. **Semantic Search**: Understands the contextual meaning of queries to match and retrieve related content utilizing natural language processing. Read more about semantic search in [Semantic search with Torus guide](/guides/semantic_search.md). |
92 | 110 |
|
93 | 111 | ```elixir |
@@ -131,7 +149,7 @@ Torus offers a few helpers to debug, explain, and analyze your queries before us |
131 | 149 |
|
132 | 150 | ## Torus support |
133 | 151 |
|
134 | | -For now, Torus supports pattern match, similarity, full-text, and semantic search, with plans to expand support further. These docs will be updated with more examples on which search type to choose and how to make them more performant (by adding indexes or using specific functions). |
| 152 | +For now, Torus supports pattern match, similarity, full-text (TF-IDF and BM25), and semantic search, with plans to expand support further. These docs will be updated with more examples on which search type to choose and how to make them more performant (by adding indexes or using specific functions). |
135 | 153 |
|
136 | 154 | <!-- MDOC --> |
137 | 155 |
|
|
0 commit comments