Skip to content
Open
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
11 changes: 11 additions & 0 deletions docs/agents/_includes/query_agent.mts
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,17 @@ for (const obj of basicSearchResponse.searchResults.objects) {
}
// END BasicSearchQuery

// START DiversityRanking
const diversitySearchResponse = await qa.search("summer shoes", {
limit: 10,
diversityWeight: 0.5
})

// Access the search results
for (const obj of diversitySearchResponse.searchResults.objects) {
console.log(`Product: ${obj.properties['name']} - ${obj.properties['price']}`)
}
// END DiversityRanking

// START BasicAskQuery
// Perform a query
Expand Down
12 changes: 12 additions & 0 deletions docs/agents/_includes/query_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,18 @@ def populate_weaviate(client, overwrite_existing=False):
print()
# END SearchPagination

# START DiversityRanking
search_response = qa.search(
"summer shoes",
limit=10,
diversity_weight=0.5,
)

# Access the search results
for obj in search_response.search_results.objects:
print(f"Product: {obj.properties['name']} - ${obj.properties['price']}")
# END DiversityRanking

# START FollowUpQuery
# Perform a follow-up query and include the answer from the previous query
from weaviate.agents.classes import ChatMessage
Expand Down
26 changes: 26 additions & 0 deletions docs/agents/query/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,32 @@ Page 3:

</details>

#### `Search` with diversity ranking

`Search` supports adding diversity weighting to search result rankings using Maximal Marginal Relevance (MMR). This is enabled by passing a `diversity_weight` parameter in the range of 0.0 to 1.0. To use diversity ranking with target vectors, set the single target vector that you want to use in the Query Agent's constructor. Diversity ranking is not yet supported with collections using multi-vector embeddings. Diversity ranking will work with multiple collections, unless they are using **different** embedding models.

<Tabs className="code" groupId="languages">
<TabItem value="py_agents" label="Python">
<FilteredTextBlock
text={PyCode}
startMarker="# START DiversityRanking"
endMarker="# END DiversityRanking"
language="py"
/>
</TabItem>
<TabItem value="ts_agents" label="JavaScript/TypeScript">
<FilteredTextBlock
text={TSCode}
startMarker="// START DiversityRanking"
endMarker="// END DiversityRanking"
language="ts"
/>
</TabItem>

</Tabs>



### `Ask`

`Ask` the Query Agent a question using natural language. The Query Agent will process the question, perform the necessary searches in Weaviate, and return the answer.
Expand Down
Loading