MCPcopy Create free account
hub / github.com/AQ-MedAI/MedMemoryBench / query

Method query

methods/graph_rag.py:314–333  ·  view source on GitHub ↗

Process a query and return answer with context.

(self, query: str)

Source from the content-addressed store, hash-verified

312 return text
313
314 def query(self, query: str) -> Tuple[str, str, List[int], Dict[int, str]]:
315 """Process a query and return answer with context."""
316 # Extract the actual question for retrieval
317 retrieval_query = self._extract_retrieval_query(query)
318 logger.debug(f"[GraphRAG] Retrieval query: {retrieval_query[:100]}...")
319
320 # Retrieve relevant documents
321 relevant_docs = self._retrieve_relevant_documents(retrieval_query)
322
323 # Expand context using graph traversal
324 expanded_context, traversal_path, filtered_content, final_answer = self._expand_context(
325 query, relevant_docs
326 )
327
328 # Generate final answer if not found during traversal
329 if not final_answer:
330 logger.debug("[GraphRAG] Generating final answer with LLM...")
331 final_answer = self._generate_answer(query, expanded_context)
332
333 return final_answer, expanded_context, traversal_path, filtered_content
334
335 def _extract_retrieval_query(self, query: str) -> str:
336 """Extract the actual question from formatted query."""

Callers

nothing calls this directly

Calls 5

_expand_contextMethod · 0.95
_generate_answerMethod · 0.95
debugMethod · 0.65

Tested by

no test coverage detected