agents.rag.common.query_constructors.hyde.enhanced_prompts

Enhanced HyDE prompts based on LangChain best practices.

This module provides improved HyDE prompt templates that follow the principle of separating document generation from structured output parsing.

Key improvements: - Simplified generation prompts focused on content creation - Domain-specific prompt templates - Separate analysis/parsing prompts for structured output - Multi-perspective generation support - Controlled document length

Classes

HyDEPerspective

Different perspectives for multi-angle document generation.

HyDEPromptConfig

Configuration for HyDE prompt selection.

HyDEPromptType

Types of HyDE prompts for different domains.

Functions

create_hyde_prompt(config, query)

Create a HyDE prompt based on configuration.

get_ensemble_prompt([num_documents, target_length])

Get an ensemble generation prompt for multiple documents.

get_generation_prompt([prompt_type, target_length])

Get a generation prompt for the specified type and length.

get_perspective_prompt(perspective[, target_length])

Get a perspective-based generation prompt.

select_prompt_automatically(query)

Automatically select appropriate prompt type based on query analysis.

Module Contents

class agents.rag.common.query_constructors.hyde.enhanced_prompts.HyDEPerspective

Bases: str, enum.Enum

Different perspectives for multi-angle document generation.

Initialize self. See help(type(self)) for accurate signature.

class agents.rag.common.query_constructors.hyde.enhanced_prompts.HyDEPromptConfig(/, **data)

Bases: pydantic.BaseModel

Configuration for HyDE prompt selection.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Parameters:

data (Any)

class agents.rag.common.query_constructors.hyde.enhanced_prompts.HyDEPromptType

Bases: str, enum.Enum

Types of HyDE prompts for different domains.

Initialize self. See help(type(self)) for accurate signature.

agents.rag.common.query_constructors.hyde.enhanced_prompts.create_hyde_prompt(config, query)

Create a HyDE prompt based on configuration.

Parameters:
Returns:

Configured ChatPromptTemplate ready for use

Return type:

langchain_core.prompts.ChatPromptTemplate

agents.rag.common.query_constructors.hyde.enhanced_prompts.get_ensemble_prompt(num_documents=3, target_length=1000)

Get an ensemble generation prompt for multiple documents.

Parameters:
  • num_documents (int) – Number of documents to generate

  • target_length (int) – Target character length per document

Returns:

Configured ChatPromptTemplate

Return type:

langchain_core.prompts.ChatPromptTemplate

agents.rag.common.query_constructors.hyde.enhanced_prompts.get_generation_prompt(prompt_type=HyDEPromptType.GENERAL, target_length=1000)

Get a generation prompt for the specified type and length.

Parameters:
  • prompt_type (HyDEPromptType) – Type of prompt to use

  • target_length (int) – Target character length for generated document

Returns:

Configured ChatPromptTemplate

Return type:

langchain_core.prompts.ChatPromptTemplate

agents.rag.common.query_constructors.hyde.enhanced_prompts.get_perspective_prompt(perspective, target_length=1000)

Get a perspective-based generation prompt.

Parameters:
  • perspective (HyDEPerspective) – Perspective to use for generation

  • target_length (int) – Target character length for generated document

Returns:

Configured ChatPromptTemplate

Return type:

langchain_core.prompts.ChatPromptTemplate

agents.rag.common.query_constructors.hyde.enhanced_prompts.select_prompt_automatically(query)

Automatically select appropriate prompt type based on query analysis.

Parameters:

query (str) – User query to analyze

Returns:

Recommended prompt type

Return type:

HyDEPromptType