Skip to content

Updated docs #1542

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 116 additions & 0 deletions pgml-cms/docs/api/client-sdk/search.md
Original file line number Diff line number Diff line change
Expand Up @@ -641,3 +641,119 @@ char **results = pgml_collectionc_vector_search(collection, "{\
{% endtabs %}

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).

## **Re-ranking**

Vector search results can be reranked in the same query they are retrieved in. To enable this, provide the `rerank` key.

{% tabs %}
{% tab title="JavaScript" %}
```javascript
const results = await collection.vector_search(
{
query: {
fields: {
body: {
query: "What is the best database?", parameters: {
prompt:
"Represent this sentence for searching relevant passages: ",
}
},
},
},
rerank: {
model: "mixedbread-ai/mxbai-rerank-base-v1",
query: "What is the best database?",
num_documents_to_rerank: 100,
},
limit: 5,
},
pipeline,
);
```
{% endtab %}

{% tab title="Python" %}
```python
results = await collection.vector_search(
{
"query": {
"fields": {
"body": {
"query": "What is the best database?",
"parameters": {
"prompt": "Represent this sentence for searching relevant passages: ",
},
},
},
},
"rerank": {
"model": "mixedbread-ai/mxbai-rerank-base-v1",
"query": "What is the best database",
"num_documents_to_rerank": 100,
},
"limit": 5,
},
pipeline,
)
```
{% endtab %}

{% tab title="Rust" %}
```rust
let results = collection
.vector_search(
serde_json::json!({
"query": {
"fields": {
"body": {
"query": "What is the best database?",
"parameters": {
"prompt": "Represent this sentence for searching relevant passages: ",
},
},
},
},
"rerank": {
"model": "mixedbread-ai/mxbai-rerank-base-v1",
"query": "What is the best database",
"num_documents_to_rerank": 100,
},
"limit": 5,
})
.into(),
&mut pipeline,
)
.await?;
```
{% endtab %}

{% tab title="C" %}
```cpp
r_size = 0;
char **results = pgml_collectionc_vector_search(collection, "{\
\"query\": {\
\"fields\": {\
\"body\": {\
\"query\": \"What is the best database?\",\
\"parameters\": {\
\"prompt\": \"Represent this sentence for searching relevant passages: \"\
}\
}\
}\
},\
\"rerank\": {\
\"model\": \"mixedbread-ai/mxbai-rerank-base-v1\",\
\"query\": \"What is the best database\",\
\"num_documents_to_rerank\": 100\
},\
\"limit\": 5\
}",
pipeline, &r_size);
```
{% endtab %}
{% endtabs %}

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.

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.
Loading