协作头脑风暴
brainstorming
在实现前澄清需求、探索设计选择,并形成清晰的开发方向。
hub-mcp-and-evaluation【开发与工程】Route Hugging Face Hub exchange, local MCP serving, and bounded BEIR-style evaluation for bm25s without hiding network, credential, or optional-dependency boundaries.
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
Use this route when a task needs to exchange a bm25s index through the
Hugging Face Hub, expose a local saved index through MCP, or turn retrieval
outputs into BEIR/pytrec_eval metrics. Keep ordinary local indexing,
retrieval, persistence, and tokenization in their sibling routes.
BM25HF.load_from_hub and all Hub snapshot operations as network and
possibly credential dependent. A local fixture check is not evidence of Hub
access.mcp<2 (the verified environment used
1.29.0). Treat this as version-sensitive, not as a claim that every latest
release works.| Need | Route | Required observation |
|---|---|---|
| Share or consume an index remotely | BM25HF in huggingface.md | Explicit Hub authorization, dependency, network, and access result |
| Share/recover tokenizer vocabulary or stopwords | TokenizerHF in huggingface.md | Same authorization boundary; preserve tokenizer configuration |
| Check tools without a server | create_mcp_server plus the bundled fixtures | Local index has a corpus; get_info and bounded retrieve calls return |
| Launch the package entry point | bm25 mcp launch | Help/parser and dependency checks first; current factory runs MCP's default transport |
| Score a retrieval result set | evaluation.md | Query/document IDs, qrels, result order, and non-empty evaluation inputs align |
| Time or inspect memory only | bm25s.utils.benchmark | Small, reproducible local run; do not call it a full comparison benchmark |
private=True unless the
user explicitly requests a public repository.bm25s.hf imports huggingface_hub at module
import time; MCP imports mcp and mcp.server.fastmcp; evaluation imports
pytrec_eval only when evaluate is called. Use the package extra or the
individual dependency and record unavailable optional routes.local_dir or explicitly allow local overwrite, and
only then call save_to_hub. overwrite_local controls the staging folder,
not remote history or permission. include_readme, corpus, and
allow_pickle are deliberate choices.revision when a branch,
tag, or commit is required; use local_dir for the download destination;
choose load_corpus=True only when MCP or document-returning retrieval
needs it; choose mmap=True for a memory-constrained local load.bm25 mcp launch --index-dir DIR [--port PORT]. In this revision the
factory accepts port but does not pass it to FastMCP; main calls
mcp.run() with its default transport. Do not promise an HTTP endpoint from
the --port flag without separately verifying the installed MCP API.postprocess_results_for_eval(results, scores, query_ids), load compatible
qrels, and call evaluate(qrels, results_dict, [k...]). Use local tiny
qrels for a smoke check and report metrics with their exact keys.pytrec_eval is a
diagnosis—not a reason to silently substitute a remote download or a
different metric implementation.bm25s.hf.BM25HF.save_to_hub(repo_id, token=None, local_dir=None, corpus=None, private=True, overwrite_local=False, include_readme=True, allow_pickle=False, ...)bm25s.hf.BM25HF.load_from_hub(repo_name, revision=None, token=None, local_dir=None, load_corpus=False, mmap=False, allow_pickle=False, ...)bm25s.hf.TokenizerHF.save_vocab_to_hub, load_vocab_from_hub,
save_stopwords_to_hub, and load_stopwords_from_hub; these reuse the
tokenizer's local JSON vocabulary/stopword formats.bm25s.mcp.server.create_mcp_server(index_dir, port=8000) returns a
FastMCP instance with retrieve(query, k=10) and get_info() tools.bm25s.utils.beir.clean_results_keys,
postprocess_results_for_eval, download_dataset, load_corpus,
load_queries, load_qrels, and evaluate provide adapters, not a
guarantee that a BEIR dataset is present.See mcp.md for the import detail and version gate, huggingface.md for remote/local semantics, and evaluation.md for data contracts and metrics. Use troubleshooting.md when a route fails.
python scripts/create_mcp_fixture.py --output-dir ./bm25s-mcp-fixture
python scripts/verify_mcp_fixture.py --index-dir ./bm25s-mcp-fixture
python scripts/verify_mcp_fixture.py --diagnose-import
These commands are intentionally local and bounded. The first command refuses
an existing non-empty destination unless --overwrite is explicit. The second
requires a saved corpus and reports tool results without opening a listener.
The diagnostic mode is safe when MCP is unavailable or its API is incompatible.
This route does not manage Hub credentials, upload policy, BEIR data licenses, large benchmark runs, MCP authentication, transport deployment, or a full comparison against other rankers. Hand those concerns to the operator with the exact failure, dependency/version, requested permission, and local artifact state; never hide them behind a fallback that changes the experiment.