Skip to content

Commit 58f82be

Browse files
authored
Updated docs (#1542)
1 parent 638cf7a commit 58f82be

File tree

3 files changed

+250
-207
lines changed

3 files changed

+250
-207
lines changed

pgml-cms/docs/api/client-sdk/search.md

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,3 +641,119 @@ char **results = pgml_collectionc_vector_search(collection, "{\
641641
{% endtabs %}
642642

643643
The above query would filter out all documents that do not have a key `special` with a value `True` or (have a key `user_id` equal to 1 and a key `user_score` less than 100).
644+
645+
## **Re-ranking**
646+
647+
Vector search results can be reranked in the same query they are retrieved in. To enable this, provide the `rerank` key.
648+
649+
{% tabs %}
650+
{% tab title="JavaScript" %}
651+
```javascript
652+
const results = await collection.vector_search(
653+
{
654+
query: {
655+
fields: {
656+
body: {
657+
query: "What is the best database?", parameters: {
658+
prompt:
659+
"Represent this sentence for searching relevant passages: ",
660+
}
661+
},
662+
},
663+
},
664+
rerank: {
665+
model: "mixedbread-ai/mxbai-rerank-base-v1",
666+
query: "What is the best database?",
667+
num_documents_to_rerank: 100,
668+
},
669+
limit: 5,
670+
},
671+
pipeline,
672+
);
673+
```
674+
{% endtab %}
675+
676+
{% tab title="Python" %}
677+
```python
678+
results = await collection.vector_search(
679+
{
680+
"query": {
681+
"fields": {
682+
"body": {
683+
"query": "What is the best database?",
684+
"parameters": {
685+
"prompt": "Represent this sentence for searching relevant passages: ",
686+
},
687+
},
688+
},
689+
},
690+
"rerank": {
691+
"model": "mixedbread-ai/mxbai-rerank-base-v1",
692+
"query": "What is the best database",
693+
"num_documents_to_rerank": 100,
694+
},
695+
"limit": 5,
696+
},
697+
pipeline,
698+
)
699+
```
700+
{% endtab %}
701+
702+
{% tab title="Rust" %}
703+
```rust
704+
let results = collection
705+
.vector_search(
706+
serde_json::json!({
707+
"query": {
708+
"fields": {
709+
"body": {
710+
"query": "What is the best database?",
711+
"parameters": {
712+
"prompt": "Represent this sentence for searching relevant passages: ",
713+
},
714+
},
715+
},
716+
},
717+
"rerank": {
718+
"model": "mixedbread-ai/mxbai-rerank-base-v1",
719+
"query": "What is the best database",
720+
"num_documents_to_rerank": 100,
721+
},
722+
"limit": 5,
723+
})
724+
.into(),
725+
&mut pipeline,
726+
)
727+
.await?;
728+
```
729+
{% endtab %}
730+
731+
{% tab title="C" %}
732+
```cpp
733+
r_size = 0;
734+
char **results = pgml_collectionc_vector_search(collection, "{\
735+
\"query\": {\
736+
\"fields\": {\
737+
\"body\": {\
738+
\"query\": \"What is the best database?\",\
739+
\"parameters\": {\
740+
\"prompt\": \"Represent this sentence for searching relevant passages: \"\
741+
}\
742+
}\
743+
}\
744+
},\
745+
\"rerank\": {\
746+
\"model\": \"mixedbread-ai/mxbai-rerank-base-v1\",\
747+
\"query\": \"What is the best database\",\
748+
\"num_documents_to_rerank\": 100\
749+
},\
750+
\"limit\": 5\
751+
}",
752+
pipeline, &r_size);
753+
```
754+
{% endtab %}
755+
{% endtabs %}
756+
757+
This query will first get the top 100 documents from the initial vector search and then rerank them using the `mixedbread-ai/mxbai-rerank-base-v1` cross-encoder.
758+
759+
You can specify the number of documents to rerank with the `num_documents_to_rerank` parameter. The query returns the top `limit` results after re-ranking.

0 commit comments

Comments
 (0)