query_analyze_prompt.py


Overview

The query_analyze_prompt.py file contains prompt templates designed for natural language processing tasks focused on keyword extraction from user queries. These prompts are intended for use with language models or AI assistants to guide them in identifying and categorizing keywords in input queries, with a particular emphasis on separating answer-type keywords, high-level concepts, and low-level details.

The file defines a dictionary PROMPTS containing string templates formatted as instructions and examples for generating keyword extraction outputs in JSON format. These prompts serve as a standardized interface to instruct language models on how to process and categorize query keywords effectively.


Detailed Explanation

PROMPTS Dictionary

The core data structure in this file is the PROMPTS dictionary. It holds multiple prompt templates as string values, each associated with a key that indicates its usage scenario.


1. minirag_query2kwd (Prompt Template)

Purpose:
This prompt instructs the assistant to identify two types of keywords from a user's query:

Format:
The output is expected in JSON with two keys:

Key Features:

Usage Example:

Suppose the input query is:
"When was SpaceX's first rocket launch?"

And the answer type pool is provided as a dictionary of types and sample examples.

The assistant should output:

{
  "answer_type_keywords": ["DATE AND TIME", "ORGANIZATION", "PLAN"],
  "entities_from_query": ["SpaceX", "Rocket launch", "Aerospace", "Power Recovery"]
}

2. keywords_extraction (Prompt Template)

Purpose:
This prompt instructs the assistant to extract two categories of keywords from the query:

Format:
Output JSON with two keys:

Key Features:

Usage Example:

For the query:
"What is the role of education in reducing poverty?"

The expected output could be:

{
  "high_level_keywords": ["Education", "Poverty reduction", "Socioeconomic development"],
  "low_level_keywords": ["School access", "Literacy rates", "Job training", "Income inequality"]
}

3. keywords_extraction_examples (List of Strings)

Purpose:
A collection of example outputs demonstrating the expected JSON format and keyword classification for the keywords_extraction prompt.

Contained Examples:

Usage:
This list enables reuse of examples without cluttering the main prompt, facilitating maintainable and modular prompt construction.


Important Implementation Details


Interaction with Other System Components


Mermaid Diagram

Below is a flowchart representing the structure and relationships between the main functions (prompts) in this utility file:

flowchart TD
    A[PROMPTS Dictionary] --> B["minirag_query2kwd"]
    A --> C["keywords_extraction"]
    A --> D["keywords_extraction_examples"]

    B --> E["Uses placeholders: {query}, {TYPE_POOL}"]
    C --> F["Uses placeholders: {query}, {examples}"]
    D --> G["Provides example outputs for 'keywords_extraction'"]

Summary


End of Documentation for query_analyze_prompt.py