pinecone.data.dataclasses.search_rerank

 1from dataclasses import dataclass
 2from typing import Optional, Dict, Any, List
 3from ..features.inference import RerankModel
 4
 5
 6@dataclass
 7class SearchRerank:
 8    """
 9    SearchRerank represents a rerank request when searching within a specific namespace.
10    """
11
12    model: str
13    """
14    The name of the [reranking model](https://docs.pinecone.io/guides/inference/understanding-inference#reranking-models) to use.
15    Required.
16    """
17
18    rank_fields: List[str]
19    """
20    The fields to use for reranking.
21    Required.
22    """
23
24    top_n: Optional[int] = None
25    """
26    The number of top results to return after reranking. Defaults to top_k.
27    Optional.
28    """
29
30    parameters: Optional[Dict[str, Any]] = None
31    """
32    Additional model-specific parameters. Refer to the [model guide](https://docs.pinecone.io/guides/inference/understanding-inference#models)
33    for available model parameters.
34    Optional.
35    """
36
37    query: Optional[str] = None
38    """
39    The query to rerank documents against. If a specific rerank query is specified, it overwrites
40    the query input that was provided at the top level.
41    """
42
43    def __post_init__(self):
44        """
45        Converts `model` to a string if an instance of `RerankEnum` is provided.
46        """
47        if isinstance(self.model, RerankModel):
48            self.model = self.model.value  # Convert Enum to string
49
50    def as_dict(self) -> Dict[str, Any]:
51        """
52        Returns the SearchRerank as a dictionary.
53        """
54        d = {
55            "model": self.model,
56            "rank_fields": self.rank_fields,
57            "top_n": self.top_n,
58            "parameters": self.parameters,
59            "query": self.query,
60        }
61        return {k: v for k, v in d.items() if v is not None}
@dataclass
class SearchRerank:
 7@dataclass
 8class SearchRerank:
 9    """
10    SearchRerank represents a rerank request when searching within a specific namespace.
11    """
12
13    model: str
14    """
15    The name of the [reranking model](https://docs.pinecone.io/guides/inference/understanding-inference#reranking-models) to use.
16    Required.
17    """
18
19    rank_fields: List[str]
20    """
21    The fields to use for reranking.
22    Required.
23    """
24
25    top_n: Optional[int] = None
26    """
27    The number of top results to return after reranking. Defaults to top_k.
28    Optional.
29    """
30
31    parameters: Optional[Dict[str, Any]] = None
32    """
33    Additional model-specific parameters. Refer to the [model guide](https://docs.pinecone.io/guides/inference/understanding-inference#models)
34    for available model parameters.
35    Optional.
36    """
37
38    query: Optional[str] = None
39    """
40    The query to rerank documents against. If a specific rerank query is specified, it overwrites
41    the query input that was provided at the top level.
42    """
43
44    def __post_init__(self):
45        """
46        Converts `model` to a string if an instance of `RerankEnum` is provided.
47        """
48        if isinstance(self.model, RerankModel):
49            self.model = self.model.value  # Convert Enum to string
50
51    def as_dict(self) -> Dict[str, Any]:
52        """
53        Returns the SearchRerank as a dictionary.
54        """
55        d = {
56            "model": self.model,
57            "rank_fields": self.rank_fields,
58            "top_n": self.top_n,
59            "parameters": self.parameters,
60            "query": self.query,
61        }
62        return {k: v for k, v in d.items() if v is not None}

SearchRerank represents a rerank request when searching within a specific namespace.

SearchRerank( model: str, rank_fields: List[str], top_n: Optional[int] = None, parameters: Optional[Dict[str, Any]] = None, query: Optional[str] = None)
model: str

The name of the reranking model to use. Required.

rank_fields: List[str]

The fields to use for reranking. Required.

top_n: Optional[int] = None

The number of top results to return after reranking. Defaults to top_k. Optional.

parameters: Optional[Dict[str, Any]] = None

Additional model-specific parameters. Refer to the model guide for available model parameters. Optional.

query: Optional[str] = None

The query to rerank documents against. If a specific rerank query is specified, it overwrites the query input that was provided at the top level.

def as_dict(self) -> Dict[str, Any]:
51    def as_dict(self) -> Dict[str, Any]:
52        """
53        Returns the SearchRerank as a dictionary.
54        """
55        d = {
56            "model": self.model,
57            "rank_fields": self.rank_fields,
58            "top_n": self.top_n,
59            "parameters": self.parameters,
60            "query": self.query,
61        }
62        return {k: v for k, v in d.items() if v is not None}

Returns the SearchRerank as a dictionary.