Spaces:
Sleeping
Sleeping
File size: 1,151 Bytes
881aff7 4f6fcea 881aff7 4f6fcea 881aff7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | """Metadata search MCP tool implementations."""
from __future__ import annotations
import json
from metadata_search.search_service import document_ids_from_ranks, search_metadata, search_score_mode
def search_metadata_tool(
query: str,
top_k: int = 10,
year_from: int | None = None,
year_to: int | None = None,
) -> str:
results = search_metadata(
query,
top_k=top_k,
year_from=year_from,
year_to=year_to,
)
return json.dumps(
{"query": query, "results": results, "score_mode": search_score_mode()},
indent=2,
)
def select_papers_from_search_tool(
query: str,
ranks: list[int],
top_k: int = 10,
year_from: int | None = None,
year_to: int | None = None,
) -> str:
results = search_metadata(
query,
top_k=top_k,
year_from=year_from,
year_to=year_to,
)
document_ids = document_ids_from_ranks(results, ranks)
selected = [item for item in results if int(item["rank"]) in ranks]
return json.dumps(
{"query": query, "document_ids": document_ids, "papers": selected},
indent=2,
)
|