ContrieverRetriever.predict:v1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import weave
from medrag_multi_modal.retrieval.common import SimilarityMetric
@weave.op()
def predict(
self,
query: str,
top_k: int = 2,
metric: SimilarityMetric = SimilarityMetric.COSINE,
):
"""
Predicts the top-k most relevant chunks for a given query using the specified similarity metric.
This function is a wrapper around the `retrieve` method. It takes an input query string,
retrieves the top-k most relevant chunks from the precomputed vector index based on the
specified similarity metric, and returns the results as a list of dictionaries, each containing
a chunk and its corresponding relevance score.
!!! example "Example Usage"
```python
import weave
from dotenv import load_dotenv
from medrag_multi_modal.retrieval.text_retrieval import ContrieverRetriever