OUTPUT #1070 | 1726 karakter | 24 satır
116:    return catalog
119:def _bm25_score(query_tokens: List[str], doc_tokens: List[str], doc_lengths: List[int],
122:    """Standard BM25 for one query against one document (inlined; the catalog is bounded —
138:def _corpus_stats(catalog: List[CatalogEntry]) -> _CorpusStats:
139:    """Compute the BM25 statistics shared by every query over a catalog."""
140:    doc_lengths = [len(entry._tokens) for entry in catalog]
142:    doc_freq = Counter(tok for entry in catalog for tok in set(entry._tokens))
143:    return doc_lengths, avg_dl, dict(doc_freq), len(catalog)
146:def search_catalog(catalog: List[CatalogEntry], query: str, limit: int = 5, *,
148:    """Top-``limit`` catalog entries for ``query`` by BM25 (exact name match ranks first).
152:    query_tokens = _tokenize(query) if catalog and limit > 0 else []
155:    corpus_stats = corpus_stats or _corpus_stats(catalog)
158:    for entry in catalog:
164:        scored = [(0.1, entry) for entry in catalog if query.lower() in entry.name.lower()]
173:def _short_desc(description: str, max_chars: int = 60) -> str:
174:    """First sentence of a tool description, clipped to ``max_chars`` on a word boundary.
177:    text = " ".join((description or "").split())
187:def _listing_group_label(source_name: str) -> str:
188:    """Human-facing group heading for a toolset, e.g. ``mcp-github`` -> ``github``."""
193:def build_catalog_listing_with_form(
195:    """Render the deferred-catalog manifest: ``- name: short desc`` lines grouped per source.
208:            groups.setdefault(label, []).append((name, _short_desc(fn.get("description", ""))))
225:    header = ("Deferred tool catalog (call schemas via "
root@213-238-170-219:/home/hermes#