|
| 1 | +--- |
| 2 | +description:Rank documents against a piece of text using the specified ranking model. |
| 3 | +--- |
| 4 | + |
| 5 | +#pgml.rank() |
| 6 | + |
| 7 | +The`pgml.rank()` function is used to compute a relevance score between documents and some text. This function is primarily used as the last step in a search system where the results returned from the initial search are re-ranked by relevance before being used. |
| 8 | + |
| 9 | +##API |
| 10 | + |
| 11 | +```postgresql |
| 12 | +pgml.rank( |
| 13 | + transformer TEXT, -- transformer name |
| 14 | + query TEXT, -- text to rank against |
| 15 | + documents TEXT[], -- documents to rank |
| 16 | + kwargs JSON -- optional arguments (see below) |
| 17 | +) |
| 18 | +``` |
| 19 | + |
| 20 | +##Example |
| 21 | + |
| 22 | +Ranking documents is as simple as calling the the function with the documents you want to rank, and text you want to rank against: |
| 23 | + |
| 24 | +```postgresql |
| 25 | +SELECT pgml.rank('mixedbread-ai/mxbai-rerank-base-v1', 'test', ARRAY['doc1', 'doc2']); |
| 26 | +``` |
| 27 | + |
| 28 | +By default the`pgml.rank()` function will return and rank all of the documents. The function can be configured to only return the relevance score and index of the top k documents by setting`return_documents` to`false` and`top_k` to the number of documents you want returned. |
| 29 | + |
| 30 | +```postgresql |
| 31 | +SELECT pgml.rank('mixedbread-ai/mxbai-rerank-base-v1', 'test', ARRAY['doc1', 'doc2'], '{"return_documents": false, "top_k": 10}'::JSONB); |
| 32 | +``` |
| 33 | + |
| 34 | +##Supported ranking models |
| 35 | + |
| 36 | +We currently support cross-encoders for re-ranking. Check out[Sentence Transformer's documentation](https://sbert.net/examples/applications/cross-encoder/README.html) for more information on how cross-encoders work. |
| 37 | + |
| 38 | +By default we provide the following ranking models: |
| 39 | + |
| 40 | +*`mixedbread-ai/mxbai-rerank-base-v1` |