Skip to main content
The prompt tuning API automatically generates optimized prompts tailored to your specific domain and documents. This eliminates the need for manual prompt engineering and ensures prompts are well-suited to your data.

generate_indexing_prompts

Generate domain-specific prompts for entity extraction, entity summarization, and community summarization.

Parameters

config
GraphRagConfig
required
GraphRAG configuration object. The function uses the configured input source to load documents for prompt generation.
limit
PositiveInt
default:"15"
The maximum number of text chunks to load from the input documents. Higher values provide more context but take longer to process.
selection_method
DocSelectionType
default:"DocSelectionType.RANDOM"
The method for selecting document chunks:
  • DocSelectionType.RANDOM - Randomly select chunks
  • DocSelectionType.TOP - Select the first chunks
  • DocSelectionType.AUTO - Automatically select representative chunks using embeddings
domain
str | None
default:"None"
The domain to map the input documents to (e.g., “medical research”, “legal documents”, “news articles”). If None, the domain will be automatically detected from the documents.
language
str | None
default:"None"
The language to use for the prompts (e.g., “English”, “Spanish”, “French”). If None, the language will be automatically detected from the documents.
max_tokens
int
default:"MAX_TOKEN_COUNT"
The maximum number of tokens to use in entity extraction prompts. Controls the length and complexity of the generated prompts.
discover_entity_types
bool
default:"True"
Whether to automatically discover entity types from the documents. When True, the system analyzes your documents to identify relevant entity types. When False, generic entity types are used.
min_examples_required
PositiveInt
default:"2"
The minimum number of examples required in entity extraction prompts. Higher values provide more guidance but make prompts longer.
n_subset_max
PositiveInt
default:"300"
The maximum number of text chunks to embed when using DocSelectionType.AUTO selection method. Only relevant when selection_method is AUTO.
k
PositiveInt
default:"15"
The number of documents to select when using DocSelectionType.AUTO selection method. Only relevant when selection_method is AUTO.
verbose
bool
default:"False"
Enable verbose logging output.

Returns

extract_prompt
str
The entity extraction prompt. Use this prompt in the extract_graph section of your GraphRAG configuration to guide entity and relationship extraction.
entity_prompt
str
The entity summarization prompt. Use this prompt in the entity_summarization section of your configuration to guide how entities are summarized.
community_prompt
str
The community summarization prompt. Use this prompt in the community_summarization section of your configuration to guide how community reports are generated.

DocSelectionType

Enum for document selection methods:

Example: Basic usage

Example: Specify domain and language

Example: Auto-detect domain and language

Example: Fine-tune generation parameters

Using generated prompts

After generating prompts, update your GraphRAG configuration to use them:
Then run the indexing pipeline:

How it works

The prompt tuning process:
  1. Document sampling - Loads a sample of your documents using the specified selection method
  2. Domain detection - Analyzes documents to identify the domain (if not specified)
  3. Language detection - Detects the language used in documents (if not specified)
  4. Persona generation - Creates a persona suitable for the domain
  5. Entity type discovery - Identifies relevant entity types from your documents (if enabled)
  6. Example generation - Creates example extractions from your documents
  7. Prompt assembly - Constructs complete prompts using the generated components

Selection methods

Random selection

Randomly samples chunks from your documents:
Best for: Large, homogeneous document sets where any sample is representative.

Top selection

Selects the first chunks in document order:
Best for: When your documents are already ordered by relevance or importance.

Auto selection

Uses embeddings to select diverse, representative chunks:
Best for: Heterogeneous document sets where you want diverse representation.

Best practices

  1. Use AUTO selection for diverse document sets to ensure representative prompts
  2. Specify domain and language if you know them to save processing time
  3. Enable entity type discovery for domain-specific entity extraction
  4. Use more chunks (limit=20-30) for complex or diverse document sets
  5. Save prompts to files for version control and reproducibility
  6. Review generated prompts before using them in production
  7. Regenerate prompts when your document domain changes significantly