Execute a hybrid search using both text and vector queries Args: - **query**: HybridQuery object Contains the text and vector queries - **combine_method**: CombineResultsMethod object Contains the combine metho
(
self,
query: HybridQuery,
combine_method: Optional[CombineResultsMethod] = None,
post_processing: Optional[HybridPostProcessingConfig] = None,
params_substitution: Optional[Dict[str, Union[str, int, float, bytes]]] = None,
timeout: Optional[int] = None,
cursor: Optional[HybridCursorQuery] = None,
)
| 1285 | |
| 1286 | @experimental_method() |
| 1287 | def hybrid_search( |
| 1288 | self, |
| 1289 | query: HybridQuery, |
| 1290 | combine_method: Optional[CombineResultsMethod] = None, |
| 1291 | post_processing: Optional[HybridPostProcessingConfig] = None, |
| 1292 | params_substitution: Optional[Dict[str, Union[str, int, float, bytes]]] = None, |
| 1293 | timeout: Optional[int] = None, |
| 1294 | cursor: Optional[HybridCursorQuery] = None, |
| 1295 | ) -> Union[HybridResult, HybridCursorResult, Pipeline]: |
| 1296 | """ |
| 1297 | Execute a hybrid search using both text and vector queries |
| 1298 | |
| 1299 | Args: |
| 1300 | - **query**: HybridQuery object |
| 1301 | Contains the text and vector queries |
| 1302 | - **combine_method**: CombineResultsMethod object |
| 1303 | Contains the combine method and parameters |
| 1304 | - **post_processing**: HybridPostProcessingConfig object |
| 1305 | Contains the post processing configuration |
| 1306 | - **params_substitution**: Dict[str, Union[str, int, float, bytes]] |
| 1307 | Contains the parameters substitution |
| 1308 | - **timeout**: int - contains the timeout in milliseconds |
| 1309 | - **cursor**: HybridCursorQuery object - contains the cursor configuration |
| 1310 | |
| 1311 | |
| 1312 | For more information see `FT.SEARCH <https://redis.io/commands/ft.hybrid>`. |
| 1313 | """ |
| 1314 | index = self.index_name |
| 1315 | options = {} |
| 1316 | pieces = [HYBRID_CMD, index] |
| 1317 | pieces.extend(query.get_args()) |
| 1318 | if combine_method: |
| 1319 | pieces.extend(combine_method.get_args()) |
| 1320 | if post_processing: |
| 1321 | pieces.extend(post_processing.build_args()) |
| 1322 | options["post_processing"] = post_processing |
| 1323 | if params_substitution: |
| 1324 | pieces.extend(self.get_params_args(params_substitution)) |
| 1325 | if timeout: |
| 1326 | pieces.extend(("TIMEOUT", timeout)) |
| 1327 | if cursor: |
| 1328 | options["cursor"] = True |
| 1329 | pieces.extend(cursor.build_args()) |
| 1330 | |
| 1331 | # Preserve HYBRID result values as bytes by default, matching the |
| 1332 | # legacy RESP2 Search surface; selected LOAD fields can opt into |
| 1333 | # decoding through HybridPostProcessingConfig.load(..., decode_field=True). |
| 1334 | options[NEVER_DECODE] = True |
| 1335 | options["query"] = query |
| 1336 | |
| 1337 | res = self.execute_command(*pieces, **options) |
| 1338 | |
| 1339 | if isinstance(res, Pipeline): |
| 1340 | return res |
| 1341 | |
| 1342 | return self._parse_results(HYBRID_CMD, res, **options) |
| 1343 | |
| 1344 | def explain( |