Skip to main content
Glama

compute_topic_df_cache

Calculates document frequency cache for Topic entities to optimize search performance in academic literature management systems.

Instructions

计算 Topic 实体的文档频率缓存

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The handler function for the compute_topic_df_cache tool. It is decorated with @mcp.tool(), which registers it with the MCP server. The function computes the document frequency (DF) cache for Topic entities by inserting or updating the entity_stats table based on relations where papers have topics.
    @mcp.tool()
    def compute_topic_df_cache() -> dict[str, Any]:
        """计算 Topic 实体的文档频率缓存"""
        try:
            with get_db() as conn:
                with conn.cursor() as cur:
                    # 计算每个 Topic 出现在多少篇 Paper 中
                    cur.execute("""
                        INSERT INTO entity_stats (entity_id, doc_frequency)
                        SELECT x.entity_id, COUNT(DISTINCT p.entity_id)
                        FROM relations r
                        JOIN entities p ON p.entity_id = r.subj_entity_id AND p.type = 'Paper'
                        JOIN entities x ON x.entity_id = r.obj_entity_id AND x.type = 'Topic'
                        WHERE r.predicate = 'PAPER_HAS_TOPIC'
                        GROUP BY x.entity_id
                        ON CONFLICT (entity_id) DO UPDATE SET 
                            doc_frequency = EXCLUDED.doc_frequency,
                            updated_at = now()
                    """)
                    cur.execute("SELECT COUNT(*) as n FROM entity_stats WHERE doc_frequency > 0")
                    count = cur.fetchone()["n"]
            return {"topics_cached": count}
        except Exception as e:
            return {"error": str(e)}
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden. It implies a computational operation ('compute') but doesn't disclose behavioral traits such as whether it's read-only or mutative, performance characteristics (e.g., time-intensive), side effects (e.g., caching results), or error handling. This is inadequate for a tool with zero annotation coverage.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence in Chinese that directly states the tool's purpose without unnecessary words. It's appropriately sized and front-loaded, with no wasted content.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool has 0 parameters, 100% schema coverage, and an output schema exists (which should document return values), the description is minimally complete. However, it lacks context about when and why to use it, and with no annotations, it doesn't fully compensate for missing behavioral details, making it adequate but with gaps.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The tool has 0 parameters, and schema description coverage is 100% (empty schema). With no parameters to document, the description doesn't need to add parameter semantics. A baseline score of 4 is appropriate as it avoids redundancy while the schema fully covers the parameter aspect.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose3/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description '计算 Topic 实体的文档频率缓存' (Compute document frequency cache for Topic entities) states a clear verb ('compute') and resource ('document frequency cache for Topic entities'), but it's somewhat vague about what 'document frequency cache' entails and doesn't differentiate from siblings like 'build_evidence_pack' or 'summarize_community_v1'. It avoids tautology but lacks specificity.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives. The description doesn't mention prerequisites, context (e.g., after data ingestion), or exclusions. With many sibling tools for data processing and analysis, this omission leaves the agent without clear usage cues.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/h-lu/paperlib-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server