MCPcopy Create free account
hub / github.com/SkyworkAI/DeepResearchAgent / retrieve

Method retrieve

src/agent/context.py:1058–1115  ·  view source on GitHub ↗

Retrieve similar agents using FAISS similarity search. Args: query: Query string to search for k: Number of results to return (default: 4) Returns: List of dictionaries containing agent information with similarity scores

(self, query: str, k: int = 4)

Source from the content-addressed store, hash-verified

1056 return contract_text
1057
1058 async def retrieve(self, query: str, k: int = 4) -> List[Dict[str, Any]]:
1059 """Retrieve similar agents using FAISS similarity search.
1060
1061 Args:
1062 query: Query string to search for
1063 k: Number of results to return (default: 4)
1064
1065 Returns:
1066 List of dictionaries containing agent information with similarity scores
1067 """
1068 if self._faiss_service is None:
1069 logger.warning("| ⚠️ FAISS service not initialized, cannot retrieve agents")
1070 return []
1071
1072 try:
1073 from src.environment.faiss.types import FaissSearchRequest
1074
1075 request = FaissSearchRequest(
1076 query=query,
1077 k=k,
1078 fetch_k=k * 5 # Fetch more candidates before filtering
1079 )
1080
1081 result = await self._faiss_service.search_similar(request)
1082
1083 if not result.success:
1084 logger.warning(f"| ⚠️ FAISS search failed: {result.message}")
1085 return []
1086
1087 # Extract documents and scores from result
1088 documents = []
1089 if result.extra and "documents" in result.extra:
1090 docs = result.extra["documents"]
1091 scores = result.extra.get("scores", [])
1092
1093 for doc, score in zip(docs, scores):
1094 # Extract agent name from metadata
1095 metadata = doc.get("metadata", {}) if isinstance(doc, dict) else {}
1096 agent_name = metadata.get("name", "")
1097
1098 # Get agent config if available
1099 agent_config = None
1100 if agent_name and agent_name in self._agent_configs:
1101 agent_config = self._agent_configs[agent_name]
1102
1103 documents.append({
1104 "name": agent_name,
1105 "description": metadata.get("description", ""),
1106 "score": float(score),
1107 "content": doc.get("page_content", "") if isinstance(doc, dict) else str(doc),
1108 "config": agent_config.model_dump() if agent_config else None
1109 })
1110
1111 return documents
1112
1113 except Exception as e:
1114 logger.error(f"| ❌ Error retrieving agents: {e}")
1115 return []

Callers

nothing calls this directly

Calls 7

FaissSearchRequestClass · 0.90
warningMethod · 0.80
search_similarMethod · 0.45
getMethod · 0.45
appendMethod · 0.45
model_dumpMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected