Represents a vector query. Args: field_name (str): The name of the field in the search index that stores the vector. vector (Union[List[float], str]): The vector to use in the query. num_candidates (int, optional): Specifies the number of results returned. If provided,
| 28 | |
| 29 | |
| 30 | class VectorQuery: |
| 31 | """ Represents a vector query. |
| 32 | |
| 33 | Args: |
| 34 | field_name (str): The name of the field in the search index that stores the vector. |
| 35 | vector (Union[List[float], str]): The vector to use in the query. |
| 36 | num_candidates (int, optional): Specifies the number of results returned. If provided, must be greater or equal to 1. |
| 37 | boost (float, optional): Add boost to query. |
| 38 | prefilter (`~couchbase.search.SearchQuery`, optional): Specifies a pre-filter to use for the vector query. |
| 39 | |
| 40 | Raises: |
| 41 | :class:`~couchbase.exceptions.InvalidArgumentException`: If the vector is not provided. |
| 42 | :class:`~couchbase.exceptions.InvalidArgumentException`: If the vector is not a list or str. |
| 43 | :class:`~couchbase.exceptions.InvalidArgumentException`: If vector is a list and all values of the provided vector are not instances of float. |
| 44 | |
| 45 | Returns: |
| 46 | :class:`~couchbase.vector_search.VectorQuery`: The created vector query. |
| 47 | """ # noqa: E501 |
| 48 | |
| 49 | def __init__(self, |
| 50 | field_name, # type: str |
| 51 | vector, # type: Union[List[float], str] |
| 52 | num_candidates=None, # type: Optional[int] |
| 53 | boost=None, # type: Optional[float] |
| 54 | prefilter=None, # type: Optional[SearchQuery] |
| 55 | ): |
| 56 | if is_null_or_empty(field_name): |
| 57 | raise InvalidArgumentException('Must provide a field name.') |
| 58 | self._field_name = field_name |
| 59 | self._vector = None |
| 60 | self._vector_base64 = None |
| 61 | self._validate_and_set_vector(vector) |
| 62 | self._num_candidates = self._boost = self._prefilter = None |
| 63 | if num_candidates is not None: |
| 64 | self.num_candidates = num_candidates |
| 65 | if boost is not None: |
| 66 | self.boost = boost |
| 67 | if prefilter is not None: |
| 68 | self.prefilter = prefilter |
| 69 | |
| 70 | @property |
| 71 | def boost(self) -> Optional[float]: |
| 72 | """ |
| 73 | Optional[float]: Returns vector query's boost value, if it exists. |
| 74 | """ |
| 75 | return self._boost |
| 76 | |
| 77 | @boost.setter |
| 78 | def boost(self, |
| 79 | value # type: float |
| 80 | ): |
| 81 | if not isinstance(value, float): |
| 82 | raise InvalidArgumentException('boost must be a float.') |
| 83 | self._boost = value |
| 84 | |
| 85 | @property |
| 86 | def field_name(self) -> str: |
| 87 | """ |
no outgoing calls