pinecone .data .dataclasses .search_query
1from dataclasses import dataclass 2from typing import Optional, Any, Dict, Union 3from .search_query_vector import SearchQueryVector 4from ..types.search_query_vector_typed_dict import SearchQueryVectorTypedDict 5 6 7@dataclass 8class SearchQuery: 9 """ 10 SearchQuery represents the query when searching within a specific namespace. 11 """ 12 13 inputs: Dict[str, Any] 14 """ 15 The input data to search with. 16 Required. 17 """ 18 19 top_k: int 20 """ 21 The number of results to return with each search. 22 Required. 23 """ 24 25 filter: Optional[Dict[str, Any]] = None 26 """ 27 The filter to apply to the search. 28 Optional. 29 """ 30 31 vector: Optional[Union[SearchQueryVectorTypedDict, SearchQueryVector]] = None 32 """ 33 The vector values to search with. If provided, it overwrites the inputs. 34 """ 35 36 id: Optional[str] = None 37 """ 38 The unique ID of the vector to be used as a query vector. 39 """ 40 41 def __post_init__(self): 42 """ 43 Converts `vector` to a `SearchQueryVectorTypedDict` instance if an enum is provided. 44 """ 45 if isinstance(self.vector, SearchQueryVector): 46 self.vector = self.vector.as_dict() 47 48 def as_dict(self) -> Dict[str, Any]: 49 """ 50 Returns the SearchQuery as a dictionary. 51 """ 52 d = { 53 "inputs": self.inputs, 54 "top_k": self.top_k, 55 "filter": self.filter, 56 "vector": self.vector, 57 "id": self.id, 58 } 59 return {k: v for k, v in d.items() if v is not None}
@dataclass
class
SearchQuery:
8@dataclass 9class SearchQuery: 10 """ 11 SearchQuery represents the query when searching within a specific namespace. 12 """ 13 14 inputs: Dict[str, Any] 15 """ 16 The input data to search with. 17 Required. 18 """ 19 20 top_k: int 21 """ 22 The number of results to return with each search. 23 Required. 24 """ 25 26 filter: Optional[Dict[str, Any]] = None 27 """ 28 The filter to apply to the search. 29 Optional. 30 """ 31 32 vector: Optional[Union[SearchQueryVectorTypedDict, SearchQueryVector]] = None 33 """ 34 The vector values to search with. If provided, it overwrites the inputs. 35 """ 36 37 id: Optional[str] = None 38 """ 39 The unique ID of the vector to be used as a query vector. 40 """ 41 42 def __post_init__(self): 43 """ 44 Converts `vector` to a `SearchQueryVectorTypedDict` instance if an enum is provided. 45 """ 46 if isinstance(self.vector, SearchQueryVector): 47 self.vector = self.vector.as_dict() 48 49 def as_dict(self) -> Dict[str, Any]: 50 """ 51 Returns the SearchQuery as a dictionary. 52 """ 53 d = { 54 "inputs": self.inputs, 55 "top_k": self.top_k, 56 "filter": self.filter, 57 "vector": self.vector, 58 "id": self.id, 59 } 60 return {k: v for k, v in d.items() if v is not None}
SearchQuery represents the query when searching within a specific namespace.
SearchQuery( inputs: Dict[str, Any], top_k: int, filter: Optional[Dict[str, Any]] = None, vector: Union[pinecone.data.types.search_query_vector_typed_dict.SearchQueryVectorTypedDict, pinecone.data.dataclasses.search_query_vector.SearchQueryVector, NoneType] = None, id: Optional[str] = None)
vector: Union[pinecone.data.types.search_query_vector_typed_dict.SearchQueryVectorTypedDict, pinecone.data.dataclasses.search_query_vector.SearchQueryVector, NoneType] =
None
The vector values to search with. If provided, it overwrites the inputs.
def
as_dict(self) -> Dict[str, Any]:
49 def as_dict(self) -> Dict[str, Any]: 50 """ 51 Returns the SearchQuery as a dictionary. 52 """ 53 d = { 54 "inputs": self.inputs, 55 "top_k": self.top_k, 56 "filter": self.filter, 57 "vector": self.vector, 58 "id": self.id, 59 } 60 return {k: v for k, v in d.items() if v is not None}
Returns the SearchQuery as a dictionary.