julep-ai / julep

A new DSL and server for AI agents and multi-step tasks
https://julep.ai
Apache License 2.0
2.65k stars 912 forks source link

[Bug]: MMR query is broken #748

Closed creatorrr closed 3 weeks ago

creatorrr commented 4 weeks ago

📜 Description

No response

👟 Reproduction steps

No response

👀 Have you spent some time to check if this bug has been raised before?

creatorrr commented 3 weeks ago

our current mmr implementation is here. It's written in cozoscript but unfortunately the logic is incorrect. Technically it is possible to implement it in cozo but it's a pretty crazy query and looks like this

For reference: MMR Algorithm

creatorrr commented 3 weeks ago

recommendation: instead of applying MMR in cozo script, when it is turned on, get (n=3*k) results from the search query and then re-rank using MMR to get new (n=k*) results. This can be done in python at the routers/ level. MMR only applies to hybrid and vector searches.

You can add this to the search_docs router here.

Flag for activating mmr is mmr_strength > 0 here.

Important note: mmr_strength = 1 - mmr_lambda where mmr_lambda is the hyperparameter for the mmr algorithm.

Reference implementation: in keybert