Return documents selected using the maximal marginal relevance.
Maximal marginal relevance optimizes for similarity to query AND diversity among selected documents.
max_marginal_relevance_search(
self,
query: str,
k: int = 4,
fetch_k: int = 20,
lambda_mult: float = 0.5,
pre_filter: Optional[Dict[str, Any]] = None,
post_filter_pipeline: Optional[List[Dict]] = None,
**kwargs: Any = {}
) -> List[Document]Returns: List of documents selected by maximal marginal relevance.
| Name | Type | Description |
|---|---|---|
query* | str | Text to look up documents similar to. |
k | int | Default: 4(Optional) number of documents to return. Defaults to 4. |
fetch_k | int | Default: 20(Optional) number of documents to fetch before passing to MMR algorithm. Defaults to 20. |
lambda_mult | float | Default: 0.5Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. Defaults to 0.5. |
pre_filter | Optional[Dict[str, Any]] | Default: NoneList of MQL match expressions comparing an indexed field |
post_filter_pipeline | Optional[List[Dict]] | Default: None(Optional) pipeline of MongoDB aggregation stages following the $vectorSearch stage. |