Elffuss BraidHub

kikocis/lancedb public

main · 2.1 KiBRenderedRawPermalink
1# Linear Combination Reranker
2
3!!! note
4 This is depricated. It is recommended to use the `RRFReranker` instead, if you want to use a score based reranker.
5
6It combines the results of semantic and full-text search using a linear combination of the scores. The weights for the linear combination can be specified. It defaults to 0.7, i.e, 70% weight for semantic search and 30% weight for full-text search.
7
8!!! note
9 Supported Query Types: Hybrid
10
11
12```python
13import numpy
14import lancedb
15from lancedb.embeddings import get_registry
16from lancedb.pydantic import LanceModel, Vector
17from lancedb.rerankers import LinearCombinationReranker
18
19embedder = get_registry().get("sentence-transformers").create()
20db = lancedb.connect("~/.lancedb")
21
22class Schema(LanceModel):
23 text: str = embedder.SourceField()
24 vector: Vector(embedder.ndims()) = embedder.VectorField()
25
26data = [
27 {"text": "hello world"},
28 {"text": "goodbye world"}
29 ]
30tbl = db.create_table("test", schema=Schema, mode="overwrite")
31tbl.add(data)
32reranker = LinearCombinationReranker()
33
34# Run hybrid search with a reranker
35tbl.create_fts_index("text", replace=True)
36result = tbl.search("hello", query_type="hybrid").rerank(reranker=reranker).to_list()
37
38```
39
40Accepted Arguments
41----------------
42| Argument | Type | Default | Description |
43| --- | --- | --- | --- |
44| `weight` | `float` | `0.7` | The weight to use for the semantic search score. The weight for the full-text search score is `1 - weights`. |
45| `return_score` | str | `"relevance"` | Options are "relevance" or "all". The type of score to return. If "relevance", will return only the `_relevance_score. If "all", will return all scores from the vector and FTS search along with the relevance score. |
46
47
48## Supported Scores for each query type
49You can specify the type of scores you want the reranker to return. The following are the supported scores for each query type:
50
51### Hybrid Search
52|`return_score`| Status | Description |
53| --- | --- | --- |
54| `relevance` | ✅ Supported | Returns only have the `_relevance_score` column |
55| `all` | ✅ Supported | Returns have vector(`_distance`) and FTS(`score`) along with Hybrid Search score(`_distance`) |