MCPcopy Create free account
hub / github.com/cosdata/cosdata / hybrid

Function hybrid

tests/test_hybrid.py:348–381  ·  view source on GitHub ↗

Hybrid search that combines dense and sparse (TF-IDF) signals. Uses raw text without client-side preprocessing - server handles all processing.

(
    self,
    *,
    dense_query: List[float],
    sparse_query: str,
    top_k: int = 10,
    dense_weight: float = 0.5,
    sparse_weight: float = 0.5,
    return_raw_text: bool = False,
)

Source from the content-addressed store, hash-verified

346 return DEFAULT_PASS or getpass.getpass("Enter cosdata admin password: ")
347
348def hybrid(
349 self,
350 *,
351 dense_query: List[float],
352 sparse_query: str,
353 top_k: int = 10,
354 dense_weight: float = 0.5,
355 sparse_weight: float = 0.5,
356 return_raw_text: bool = False,
357) -> Dict[str, Any]:
358 """
359 Hybrid search that combines dense and sparse (TF-IDF) signals.
360 Uses raw text without client-side preprocessing - server handles all processing.
361 """
362 url = f"{self.collection.client.base_url}/collections/{self.collection.name}/search/hybrid"
363
364 payload = {
365 "query_vector": dense_query,
366 "query_text": sparse_query, # Raw text for server-side TF-IDF processing
367 "top_k": top_k,
368 "fusion_constant_k": 60.0,
369 "return_raw_text": return_raw_text,
370 }
371
372 rsp = requests.post(
373 url,
374 headers=self.collection.client._get_headers(),
375 json=payload,
376 verify=self.collection.client.verify_ssl,
377 )
378 if rsp.status_code != 200:
379 raise Exception(f"Hybrid search failed: {rsp.text}")
380
381 return rsp.json()
382
383
384def batch_hybrid(

Callers

nothing calls this directly

Calls 1

_get_headersMethod · 0.45

Tested by

no test coverage detected