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

Method _truncate_context

methods/graph_rag.py:306–312  ·  view source on GitHub ↗

Truncate text to fit within token limit.

(self, text: str, max_tokens: int = LLM_CONTEXT_LIMIT)

Source from the content-addressed store, hash-verified

304 return prompt | self.llm.with_structured_output(AnswerCheck)
305
306 def _truncate_context(self, text: str, max_tokens: int = LLM_CONTEXT_LIMIT) -> str:
307 """Truncate text to fit within token limit."""
308 tokens = self._tokenizer.encode(text)
309 if len(tokens) > max_tokens:
310 logger.warning(f"[GraphRAG] Context too long ({len(tokens)} tokens), truncating to {max_tokens}")
311 return self._tokenizer.decode(tokens[:max_tokens])
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."""

Callers 1

_generate_answerMethod · 0.95

Calls 3

encodeMethod · 0.45
warningMethod · 0.45
decodeMethod · 0.45

Tested by

no test coverage detected