Coverage for src / qdrant_loader_mcp_server / search / hybrid / adapters.py: 69%

36 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-06-11 09:38 +0000

1from __future__ import annotations 

2 

3from ..components.keyword_search_service import KeywordSearchService 

4from ..components.result_combiner import ResultCombiner 

5from ..components.vector_search_service import VectorSearchService 

6from .interfaces import KeywordSearcher, ResultCombinerLike, VectorSearcher 

7 

8 

9class VectorSearcherAdapter(VectorSearcher): 

10 def __init__(self, service: VectorSearchService): 

11 self._service = service 

12 

13 async def search(self, query: str, limit: int, project_ids: list[str] | None): # type: ignore[override] 

14 return await self._service.vector_search(query, limit, project_ids) 

15 

16 def used_qdrant_hybrid_last_query(self) -> bool: 

17 getter = getattr(self._service, "used_qdrant_hybrid_last_query", None) 

18 if callable(getter): 

19 try: 

20 return bool(getter()) 

21 except Exception: 

22 return False 

23 return False 

24 

25 async def supports_qdrant_hybrid(self) -> bool: 

26 """Forward the service's pre-flight capability check to the pipeline.""" 

27 check = getattr(self._service, "supports_qdrant_hybrid", None) 

28 if not callable(check): 

29 return False 

30 try: 

31 return bool(await check()) 

32 except Exception: 

33 return False 

34 

35 

36class KeywordSearcherAdapter(KeywordSearcher): 

37 def __init__(self, service: KeywordSearchService): 

38 self._service = service 

39 

40 async def search(self, query: str, limit: int, project_ids: list[str] | None): # type: ignore[override] 

41 return await self._service.keyword_search(query, limit, project_ids) 

42 

43 

44class ResultCombinerAdapter(ResultCombinerLike): 

45 def __init__(self, combiner: ResultCombiner): 

46 self._combiner = combiner 

47 

48 async def combine_results( # type: ignore[override] 

49 self, 

50 vector_results: list[dict], 

51 keyword_results: list[dict], 

52 query_context: dict, 

53 limit: int, 

54 source_types: list[str] | None, 

55 project_ids: list[str] | None, 

56 ): 

57 return await self._combiner.combine_results( 

58 vector_results, 

59 keyword_results, 

60 query_context, 

61 limit, 

62 source_types, 

63 project_ids, 

64 )